• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "call_state_report_proxy.h"
17 
18 #include <string_ex.h>
19 
20 #include "iservice_registry.h"
21 #include "system_ability.h"
22 #include "system_ability_definition.h"
23 
24 #include "call_manager_errors.h"
25 #include "call_manager_inner_type.h"
26 #include "telephony_log_wrapper.h"
27 #include "telephony_state_registry_client.h"
28 
29 namespace OHOS {
30 namespace Telephony {
CallStateReportProxy()31 CallStateReportProxy::CallStateReportProxy() {}
32 
~CallStateReportProxy()33 CallStateReportProxy::~CallStateReportProxy() {}
34 
CallStateUpdated(sptr<CallBase> & callObjectPtr,TelCallState priorState,TelCallState nextState)35 void CallStateReportProxy::CallStateUpdated(
36     sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState)
37 {
38     if (callObjectPtr == nullptr) {
39         TELEPHONY_LOGE("callObjectPtr is nullptr!");
40         return;
41     }
42     CallAttributeInfo info;
43     callObjectPtr->GetCallAttributeInfo(info);
44     std::string str(info.accountNumber);
45     std::u16string accountNumber = Str8ToStr16(str);
46     if (info.callState == TelCallState::CALL_STATUS_INCOMING) {
47         ReportCallState(info.accountId, static_cast<int32_t>(info.callState), accountNumber);
48     } else {
49         ReportCallStateForCallId(info.accountId, info.callId, static_cast<int32_t>(info.callState), accountNumber);
50     }
51 }
52 
ReportCallState(int32_t slotId,int32_t callState,std::u16string phoneNumber)53 int32_t CallStateReportProxy::ReportCallState(int32_t slotId, int32_t callState, std::u16string phoneNumber)
54 {
55     int32_t ret = TELEPHONY_ERR_FAIL;
56     ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCallState(
57         slotId, callState, phoneNumber);
58     if (ret != TELEPHONY_SUCCESS) {
59         TELEPHONY_LOGE("notifyCallStateUpdated failed, errcode:%{public}d", ret);
60         return ret;
61     }
62     TELEPHONY_LOGI("report call state:%{public}d", callState);
63     return ret;
64 }
65 
ReportCallStateForCallId(int32_t slotId,int32_t callId,int32_t callState,std::u16string incomingNumber)66 int32_t CallStateReportProxy::ReportCallStateForCallId(
67     int32_t slotId, int32_t callId, int32_t callState, std::u16string incomingNumber)
68 {
69     int32_t ret = TELEPHONY_ERR_FAIL;
70     ret = DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateCallStateForSlotId(
71         slotId, callId, callState, incomingNumber);
72     if (ret != TELEPHONY_SUCCESS) {
73         TELEPHONY_LOGE("NotifyCallStateUpdated failed, errcode:%{public}d", ret);
74         return ret;
75     }
76     TELEPHONY_LOGI("report call state:%{public}d, callId:%{public}d", callState, callId);
77     return ret;
78 }
79 } // namespace Telephony
80 } // namespace OHOS
81