• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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_manager_proxy.h"
17 
18 #include "iservice_registry.h"
19 #include "system_ability.h"
20 #include "system_ability_definition.h"
21 
22 #include "call_manager_errors.h"
23 #include "telephony_log_wrapper.h"
24 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
25 #include "core_manager_inner.h"
26 #endif
27 
28 namespace OHOS {
29 namespace Telephony {
CallManagerProxy()30 CallManagerProxy::CallManagerProxy()
31     : systemAbilityId_(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID), registerStatus_(false), initStatus_(false)
32 {}
33 
34 CallManagerProxy::~CallManagerProxy() = default;
35 
36 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
IsServiceStart()37 bool CallManagerProxy::IsServiceStart()
38 {
39     sptr<ISystemAbilityManager> managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
40     if (managerPtr == nullptr) {
41         TELEPHONY_LOGE("GetSystemAbilityManager failed!");
42         return false;
43     }
44     if (managerPtr->CheckSystemAbility(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID) == nullptr) {
45         return false;
46     }
47     return true;
48 }
49 
SetInitState(bool status)50 void CallManagerProxy::SetInitState(bool status)
51 {
52     initStatus_ = status;
53 }
54 
GetCallBack()55 std::unique_ptr<CallManagerCallback> CallManagerProxy::GetCallBack()
56 {
57     return std::move(callBack_);
58 }
59 #endif
60 
Init(int32_t systemAbilityId)61 void CallManagerProxy::Init(int32_t systemAbilityId)
62 {
63     std::lock_guard<std::mutex> lock(mutex_);
64     if (initStatus_) {
65         TELEPHONY_LOGW("you have already initialized");
66         return;
67     }
68     systemAbilityId_ = systemAbilityId;
69 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
70     if (!IsServiceStart()) {
71         EventFwk::MatchingSkills matchingSkills;
72         matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_RADIO_STATE_CHANGE);
73         EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
74         subscriberInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
75         std::shared_ptr<CallManagerProxySubcribed> subscriberPtr =
76             std::make_shared<CallManagerProxySubcribed>(subscriberInfo);
77 
78         if (subscriberPtr == nullptr) {
79             TELEPHONY_LOGE("CallManagerProxy::Init subscriberPtr is nullptr");
80             return;
81         }
82 
83         bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberPtr);
84         TELEPHONY_LOGI("CallManagerProxy::Init subscribeResult = %{public}d", subscribeResult);
85         return;
86     }
87 #endif
88     int32_t result = ConnectService();
89     if (result != TELEPHONY_SUCCESS) {
90         TELEPHONY_LOGE("connect service failed,errCode: %{public}d", result);
91         return;
92     }
93     initStatus_ = true;
94     TELEPHONY_LOGI("connected to call manager service successfully!");
95 }
96 
97 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
CallManagerProxySubcribed(const EventFwk::CommonEventSubscribeInfo & subscriberInfo)98 CallManagerProxy::CallManagerProxySubcribed::CallManagerProxySubcribed(
99     const EventFwk::CommonEventSubscribeInfo &subscriberInfo)
100     : CommonEventSubscriber(subscriberInfo)
101 {}
102 
OnReceiveEvent(const EventFwk::CommonEventData & data)103 void CallManagerProxy::CallManagerProxySubcribed::OnReceiveEvent(const EventFwk::CommonEventData &data)
104 {
105     std::shared_ptr<CallManagerProxy> proxy = DelayedSingleton<CallManagerProxy>::GetInstance();
106     if (proxy == nullptr) {
107         TELEPHONY_LOGE("proxy is nullptr");
108         return;
109     }
110     int32_t result = proxy->ConnectService();
111     if (result != TELEPHONY_SUCCESS) {
112         TELEPHONY_LOGE("OnReceiveEvent connect service failed,errCode: %{public}d", result);
113         return;
114     }
115     result = proxy->RegisterCallBack(proxy->GetCallBack());
116     if (result != TELEPHONY_SUCCESS) {
117         TELEPHONY_LOGE("OnReceiveEvent register callback failed,errCode: %{public}d", result);
118         return;
119     }
120     proxy->SetInitState(true);
121     TELEPHONY_LOGI("OnReceiveEvent connected to call manager service successfully!");
122     bool unsubscribeResult = EventFwk::CommonEventManager::UnSubscribeCommonEvent(shared_from_this());
123     TELEPHONY_LOGI("OnReceiveEvent UnSubscribeCommonEvent unsubscribeResult: %{public}d", unsubscribeResult);
124 }
125 #endif
126 
UnInit()127 void CallManagerProxy::UnInit()
128 {
129     DisconnectService();
130     std::lock_guard<std::mutex> lock(mutex_);
131     initStatus_ = false;
132     TELEPHONY_LOGI("disconnect service\n");
133 }
134 
135 /**
136  * Register a callback with the CallManager, through which the CallManager's data is notified to the NAPI.
137  */
RegisterCallBack(std::unique_ptr<CallManagerCallback> callback)138 int32_t CallManagerProxy::RegisterCallBack(std::unique_ptr<CallManagerCallback> callback)
139 {
140     std::lock_guard<std::mutex> lock(mutex_);
141     if (registerStatus_) {
142         TELEPHONY_LOGE("you have already register callback yet!");
143         return TELEPHONY_ERR_REGISTER_CALLBACK_FAIL;
144     }
145     if (callManagerServicePtr_ == nullptr) {
146         TELEPHONY_LOGE("callManagerServicePtr_ is null");
147 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
148         callBack_ = std::move(callback);
149 #endif
150         return TELEPHONY_ERR_LOCAL_PTR_NULL;
151     }
152     callAbilityCallbackPtr_ = new (std::nothrow) CallAbilityCallback();
153     if (callAbilityCallbackPtr_ == nullptr) {
154         TELEPHONY_LOGE("create CallAbilityCallback object failed!");
155         return TELEPHONY_ERR_LOCAL_PTR_NULL;
156     }
157     int32_t ret = callManagerServicePtr_->RegisterCallBack(callAbilityCallbackPtr_);
158     if (ret != TELEPHONY_SUCCESS) {
159         callAbilityCallbackPtr_.clear();
160         callAbilityCallbackPtr_ = nullptr;
161         TELEPHONY_LOGE("register callback to call manager service failed,result: %{public}d", ret);
162         if (ret == TELEPHONY_ERR_PERMISSION_ERR) {
163             return TELEPHONY_ERR_PERMISSION_ERR;
164         } else if (ret == TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API) {
165             return TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API;
166         }
167         return TELEPHONY_ERR_REGISTER_CALLBACK_FAIL;
168     }
169     TELEPHONY_LOGI("register call ability callback success!");
170     callAbilityCallbackPtr_->SetProcessCallback(std::move(callback));
171     registerStatus_ = true;
172     return TELEPHONY_SUCCESS;
173 }
174 
UnRegisterCallBack()175 int32_t CallManagerProxy::UnRegisterCallBack()
176 {
177     std::lock_guard<std::mutex> lock(mutex_);
178     if (!registerStatus_) {
179         TELEPHONY_LOGE("you haven't register callback yet, please RegisterCallBack first!");
180         return TELEPHONY_ERR_REGISTER_CALLBACK_FAIL;
181     }
182     if (callManagerServicePtr_ == nullptr) {
183         TELEPHONY_LOGE("callManagerServicePtr_ is null");
184         return TELEPHONY_ERR_LOCAL_PTR_NULL;
185     }
186     int32_t ret = callManagerServicePtr_->UnRegisterCallBack();
187     if (ret != TELEPHONY_SUCCESS) {
188         TELEPHONY_LOGE("UnRegisterCallBack failed,result: %{public}d", ret);
189         if (ret == TELEPHONY_ERR_PERMISSION_ERR) {
190             return TELEPHONY_ERR_PERMISSION_ERR;
191         } else if (ret == TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API) {
192             return TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API;
193         }
194         return TELEPHONY_ERR_UNREGISTER_CALLBACK_FAIL;
195     }
196     if (callAbilityCallbackPtr_ == nullptr) {
197         TELEPHONY_LOGE("callAbilityCallbackPtr_ is nullptr!");
198         return TELEPHONY_ERR_LOCAL_PTR_NULL;
199     }
200     callAbilityCallbackPtr_.clear();
201     callAbilityCallbackPtr_ = nullptr;
202     registerStatus_ = false;
203     TELEPHONY_LOGI("UnRegisterCallBack success!");
204     return TELEPHONY_SUCCESS;
205 }
206 
ConnectService()207 int32_t CallManagerProxy::ConnectService()
208 {
209     Utils::UniqueWriteGuard<Utils::RWLock> guard(rwClientLock_);
210     if (callManagerServicePtr_ != nullptr) {
211         return TELEPHONY_SUCCESS;
212     }
213     sptr<ISystemAbilityManager> managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
214     if (managerPtr == nullptr) {
215         TELEPHONY_LOGE("GetSystemAbilityManager failed!");
216         return TELEPHONY_ERR_LOCAL_PTR_NULL;
217     }
218     sptr<ICallManagerService> callManagerServicePtr = nullptr;
219     sptr<IRemoteObject> iRemoteObjectPtr = managerPtr->GetSystemAbility(systemAbilityId_);
220     if (iRemoteObjectPtr == nullptr) {
221         TELEPHONY_LOGE("GetSystemAbility failed!");
222         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
223     }
224 
225     std::unique_ptr<CallManagerServiceDeathRecipient> recipient =
226         std::make_unique<CallManagerServiceDeathRecipient>(*this);
227     if (recipient == nullptr) {
228         TELEPHONY_LOGE("recipient is null");
229         return TELEPHONY_ERROR;
230     }
231     sptr<IRemoteObject::DeathRecipient> dr(recipient.release());
232     if ((iRemoteObjectPtr->IsProxyObject()) && (!iRemoteObjectPtr->AddDeathRecipient(dr))) {
233         TELEPHONY_LOGE("Failed to add death recipient");
234         return TELEPHONY_ERROR;
235     }
236     callManagerServicePtr = iface_cast<ICallManagerService>(iRemoteObjectPtr);
237     if (!callManagerServicePtr) {
238         TELEPHONY_LOGE("iface_cast<ICallManagerService> failed!");
239         return TELEPHONY_ERR_LOCAL_PTR_NULL;
240     }
241     callManagerServicePtr_ = callManagerServicePtr;
242     deathRecipient_ = dr;
243     return TELEPHONY_SUCCESS;
244 }
245 
DisconnectService()246 void CallManagerProxy::DisconnectService()
247 {
248     UnRegisterCallBack();
249     Utils::UniqueWriteGuard<Utils::RWLock> guard(rwClientLock_);
250     if (callManagerServicePtr_ != nullptr) {
251         callManagerServicePtr_.clear();
252         callManagerServicePtr_ = nullptr;
253     }
254 }
255 
ReConnectService()256 int32_t CallManagerProxy::ReConnectService()
257 {
258     if (callManagerServicePtr_ == nullptr) {
259         TELEPHONY_LOGI("try to reconnect call manager service now...");
260         int32_t result = ConnectService();
261         if (result != TELEPHONY_SUCCESS) {
262             TELEPHONY_LOGE("Connect service: %{public}d", result);
263             return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
264         }
265         if (registerStatus_) {
266             ReRegisterCallBack();
267         }
268     }
269     return TELEPHONY_SUCCESS;
270 }
271 
ReRegisterCallBack()272 int32_t CallManagerProxy::ReRegisterCallBack()
273 {
274     std::lock_guard<std::mutex> lock(mutex_);
275     if (callManagerServicePtr_ == nullptr) {
276         TELEPHONY_LOGE("callManagerServicePtr_ is null");
277         return TELEPHONY_ERR_LOCAL_PTR_NULL;
278     }
279     if (callAbilityCallbackPtr_ == nullptr) {
280         TELEPHONY_LOGE("create CallAbilityCallback object failed!");
281         return TELEPHONY_ERR_LOCAL_PTR_NULL;
282     }
283     int32_t ret = callManagerServicePtr_->RegisterCallBack(callAbilityCallbackPtr_);
284     if (ret != TELEPHONY_SUCCESS) {
285         callAbilityCallbackPtr_.clear();
286         callAbilityCallbackPtr_ = nullptr;
287         TELEPHONY_LOGE("register callback to call manager service failed,result: %{public}d", ret);
288         if (ret == TELEPHONY_ERR_PERMISSION_ERR) {
289             return TELEPHONY_ERR_PERMISSION_ERR;
290         }
291         return TELEPHONY_ERR_REGISTER_CALLBACK_FAIL;
292     }
293     TELEPHONY_LOGI("register call ability callback again success!");
294     return TELEPHONY_SUCCESS;
295 }
296 
DialCall(std::u16string number,AppExecFwk::PacMap & extras)297 int32_t CallManagerProxy::DialCall(std::u16string number, AppExecFwk::PacMap &extras)
298 {
299     if (ReConnectService() != TELEPHONY_SUCCESS) {
300         TELEPHONY_LOGE("ipc reconnect failed!");
301         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
302     }
303     std::lock_guard<std::mutex> lock(mutex_);
304     int32_t errCode = callManagerServicePtr_->DialCall(number, extras);
305     if (errCode != TELEPHONY_SUCCESS) {
306         TELEPHONY_LOGE("DialCall failed, errcode:%{public}d", errCode);
307         return errCode;
308     }
309     return TELEPHONY_SUCCESS;
310 }
311 
AnswerCall(int32_t callId,int32_t videoState)312 int32_t CallManagerProxy::AnswerCall(int32_t callId, int32_t videoState)
313 {
314     if (ReConnectService() != TELEPHONY_SUCCESS) {
315         TELEPHONY_LOGE("ipc reconnect failed!");
316         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
317     }
318     std::lock_guard<std::mutex> lock(mutex_);
319     int32_t errCode = callManagerServicePtr_->AnswerCall(callId, videoState);
320     if (errCode != TELEPHONY_SUCCESS) {
321         TELEPHONY_LOGE("AnswerCall failed, errcode:%{public}d", errCode);
322         return errCode;
323     }
324     return TELEPHONY_SUCCESS;
325 }
326 
RejectCall(int32_t callId,bool isSendSms,std::u16string content)327 int32_t CallManagerProxy::RejectCall(int32_t callId, bool isSendSms, std::u16string content)
328 {
329     if (ReConnectService() != TELEPHONY_SUCCESS) {
330         TELEPHONY_LOGE("ipc reconnect failed!");
331         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
332     }
333     std::lock_guard<std::mutex> lock(mutex_);
334     int32_t errCode = callManagerServicePtr_->RejectCall(callId, isSendSms, content);
335     if (errCode != TELEPHONY_SUCCESS) {
336         TELEPHONY_LOGE("RejectCall failed, errcode:%{public}d", errCode);
337         return errCode;
338     }
339     return TELEPHONY_SUCCESS;
340 }
341 
HangUpCall(int32_t callId)342 int32_t CallManagerProxy::HangUpCall(int32_t callId)
343 {
344     if (ReConnectService() != TELEPHONY_SUCCESS) {
345         TELEPHONY_LOGE("ipc reconnect failed!");
346         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
347     }
348     std::lock_guard<std::mutex> lock(mutex_);
349     int32_t errCode = callManagerServicePtr_->HangUpCall(callId);
350     if (errCode != TELEPHONY_SUCCESS) {
351         TELEPHONY_LOGE("HangUpCall failed, errcode:%{public}d", errCode);
352         return errCode;
353     }
354     return TELEPHONY_SUCCESS;
355 }
356 
GetCallState()357 int32_t CallManagerProxy::GetCallState()
358 {
359     if (ReConnectService() != TELEPHONY_SUCCESS) {
360         TELEPHONY_LOGE("ipc reconnect failed!");
361         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
362     }
363     std::lock_guard<std::mutex> lock(mutex_);
364     int32_t errCode = callManagerServicePtr_->GetCallState();
365     if (errCode != TELEPHONY_SUCCESS) {
366         TELEPHONY_LOGE("GetCallState failed, errcode:%{public}d", errCode);
367         return errCode;
368     }
369     return TELEPHONY_SUCCESS;
370 }
371 
HoldCall(int32_t callId)372 int32_t CallManagerProxy::HoldCall(int32_t callId)
373 {
374     if (ReConnectService() != TELEPHONY_SUCCESS) {
375         TELEPHONY_LOGE("ipc reconnect failed!");
376         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
377     }
378     std::lock_guard<std::mutex> lock(mutex_);
379     int32_t errCode = callManagerServicePtr_->HoldCall(callId);
380     if (errCode != TELEPHONY_SUCCESS) {
381         TELEPHONY_LOGE("HoldCall failed, errcode:%{public}d", errCode);
382         return errCode;
383     }
384     return TELEPHONY_SUCCESS;
385 }
386 
UnHoldCall(int32_t callId)387 int32_t CallManagerProxy::UnHoldCall(int32_t callId)
388 {
389     if (ReConnectService() != TELEPHONY_SUCCESS) {
390         TELEPHONY_LOGE("ipc reconnect failed!");
391         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
392     }
393     std::lock_guard<std::mutex> lock(mutex_);
394     int32_t errCode = callManagerServicePtr_->UnHoldCall(callId);
395     if (errCode != TELEPHONY_SUCCESS) {
396         TELEPHONY_LOGE("UnHoldCall failed, errcode:%{public}d", errCode);
397         return errCode;
398     }
399     return TELEPHONY_SUCCESS;
400 }
401 
SwitchCall(int32_t callId)402 int32_t CallManagerProxy::SwitchCall(int32_t callId)
403 {
404     if (ReConnectService() != TELEPHONY_SUCCESS) {
405         TELEPHONY_LOGE("ipc reconnect failed!");
406         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
407     }
408     std::lock_guard<std::mutex> lock(mutex_);
409     int32_t errCode = callManagerServicePtr_->SwitchCall(callId);
410     if (errCode != TELEPHONY_SUCCESS) {
411         TELEPHONY_LOGE("SwitchCall failed, errcode:%{public}d", errCode);
412         return errCode;
413     }
414     return TELEPHONY_SUCCESS;
415 }
416 
CombineConference(int32_t callId)417 int32_t CallManagerProxy::CombineConference(int32_t callId)
418 {
419     if (ReConnectService() != TELEPHONY_SUCCESS) {
420         TELEPHONY_LOGE("ipc reconnect failed!");
421         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
422     }
423     std::lock_guard<std::mutex> lock(mutex_);
424     int32_t errCode = callManagerServicePtr_->CombineConference(callId);
425     if (errCode != TELEPHONY_SUCCESS) {
426         TELEPHONY_LOGE("CombineConference failed, errcode:%{public}d", errCode);
427         return errCode;
428     }
429     return TELEPHONY_SUCCESS;
430 }
431 
SeparateConference(int32_t callId)432 int32_t CallManagerProxy::SeparateConference(int32_t callId)
433 {
434     if (ReConnectService() != TELEPHONY_SUCCESS) {
435         TELEPHONY_LOGE("ipc reconnect failed!");
436         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
437     }
438     std::lock_guard<std::mutex> lock(mutex_);
439     int32_t errCode = callManagerServicePtr_->SeparateConference(callId);
440     if (errCode != TELEPHONY_SUCCESS) {
441         TELEPHONY_LOGE("SeparateConference failed, errcode:%{public}d", errCode);
442         return errCode;
443     }
444     return TELEPHONY_SUCCESS;
445 }
446 
KickOutFromConference(int32_t callId)447 int32_t CallManagerProxy::KickOutFromConference(int32_t callId)
448 {
449     if (ReConnectService() != TELEPHONY_SUCCESS) {
450         TELEPHONY_LOGE("ipc reconnect failed!");
451         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
452     }
453     std::lock_guard<std::mutex> lock(mutex_);
454     int32_t errCode = callManagerServicePtr_->KickOutFromConference(callId);
455     if (errCode != TELEPHONY_SUCCESS) {
456         TELEPHONY_LOGE("KickOutFromConference failed, errcode:%{public}d", errCode);
457         return errCode;
458     }
459     return TELEPHONY_SUCCESS;
460 }
461 
GetMainCallId(int32_t & callId,int32_t & mainCallId)462 int32_t CallManagerProxy::GetMainCallId(int32_t &callId, int32_t &mainCallId)
463 {
464     if (ReConnectService() != TELEPHONY_SUCCESS) {
465         TELEPHONY_LOGE("ipc reconnect failed!");
466         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
467     }
468     std::lock_guard<std::mutex> lock(mutex_);
469     int32_t errCode = callManagerServicePtr_->GetMainCallId(callId, mainCallId);
470     if (errCode != TELEPHONY_SUCCESS) {
471         TELEPHONY_LOGE("GetMainCallId failed, errcode:%{public}d", errCode);
472         return errCode;
473     }
474     return TELEPHONY_SUCCESS;
475 }
476 
GetSubCallIdList(int32_t callId,std::vector<std::u16string> & callIdList)477 int32_t CallManagerProxy::GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList)
478 {
479     if (ReConnectService() != TELEPHONY_SUCCESS) {
480         TELEPHONY_LOGE("ipc reconnect failed!");
481         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
482     }
483     std::lock_guard<std::mutex> lock(mutex_);
484     int32_t errCode = callManagerServicePtr_->GetSubCallIdList(callId, callIdList);
485     if (errCode != TELEPHONY_SUCCESS) {
486         TELEPHONY_LOGE("GetMainCallId failed, errcode:%{public}d", errCode);
487         return errCode;
488     }
489     return TELEPHONY_SUCCESS;
490 }
491 
GetCallIdListForConference(int32_t callId,std::vector<std::u16string> & callIdList)492 int32_t CallManagerProxy::GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList)
493 {
494     if (ReConnectService() != TELEPHONY_SUCCESS) {
495         TELEPHONY_LOGE("ipc reconnect failed!");
496         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
497     }
498     std::lock_guard<std::mutex> lock(mutex_);
499     int32_t errCode = callManagerServicePtr_->GetCallIdListForConference(callId, callIdList);
500     if (errCode != TELEPHONY_SUCCESS) {
501         TELEPHONY_LOGE("GetMainCallId failed, errcode:%{public}d", errCode);
502         return errCode;
503     }
504     return TELEPHONY_SUCCESS;
505 }
506 
GetCallWaiting(int32_t slotId)507 int32_t CallManagerProxy::GetCallWaiting(int32_t slotId)
508 {
509     if (ReConnectService() != TELEPHONY_SUCCESS) {
510         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
511         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
512     }
513     std::lock_guard<std::mutex> lock(mutex_);
514     int32_t errCode = callManagerServicePtr_->GetCallWaiting(slotId);
515     if (errCode != TELEPHONY_SUCCESS) {
516         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
517         return errCode;
518     }
519     return TELEPHONY_SUCCESS;
520 }
521 
SetCallWaiting(int32_t slotId,bool activate)522 int32_t CallManagerProxy::SetCallWaiting(int32_t slotId, bool activate)
523 {
524     if (ReConnectService() != TELEPHONY_SUCCESS) {
525         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
526         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
527     }
528     std::lock_guard<std::mutex> lock(mutex_);
529     int32_t errCode = callManagerServicePtr_->SetCallWaiting(slotId, activate);
530     if (errCode != TELEPHONY_SUCCESS) {
531         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
532         return errCode;
533     }
534     return TELEPHONY_SUCCESS;
535 }
536 
GetCallRestriction(int32_t slotId,CallRestrictionType type)537 int32_t CallManagerProxy::GetCallRestriction(int32_t slotId, CallRestrictionType type)
538 {
539     if (ReConnectService() != TELEPHONY_SUCCESS) {
540         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
541         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
542     }
543     std::lock_guard<std::mutex> lock(mutex_);
544     int32_t errCode = callManagerServicePtr_->GetCallRestriction(slotId, type);
545     if (errCode != TELEPHONY_SUCCESS) {
546         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
547         return errCode;
548     }
549     return TELEPHONY_SUCCESS;
550 }
551 
SetCallRestriction(int32_t slotId,CallRestrictionInfo & info)552 int32_t CallManagerProxy::SetCallRestriction(int32_t slotId, CallRestrictionInfo &info)
553 {
554     if (ReConnectService() != TELEPHONY_SUCCESS) {
555         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
556         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
557     }
558     std::lock_guard<std::mutex> lock(mutex_);
559     int32_t errCode = callManagerServicePtr_->SetCallRestriction(slotId, info);
560     if (errCode != TELEPHONY_SUCCESS) {
561         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
562         return errCode;
563     }
564     return TELEPHONY_SUCCESS;
565 }
566 
SetCallRestrictionPassword(int32_t slotId,CallRestrictionType fac,const char * oldPassword,const char * newPassword)567 int32_t CallManagerProxy::SetCallRestrictionPassword(
568     int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword)
569 {
570     if (ReConnectService() != TELEPHONY_SUCCESS) {
571         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
572         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
573     }
574     std::lock_guard<std::mutex> lock(mutex_);
575     int32_t errCode = callManagerServicePtr_->SetCallRestrictionPassword(slotId, fac, oldPassword, newPassword);
576     if (errCode != TELEPHONY_SUCCESS) {
577         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
578         return errCode;
579     }
580     return TELEPHONY_SUCCESS;
581 }
582 
GetCallTransferInfo(int32_t slotId,CallTransferType type)583 int32_t CallManagerProxy::GetCallTransferInfo(int32_t slotId, CallTransferType type)
584 {
585     if (ReConnectService() != TELEPHONY_SUCCESS) {
586         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
587         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
588     }
589     std::lock_guard<std::mutex> lock(mutex_);
590     int32_t errCode = callManagerServicePtr_->GetCallTransferInfo(slotId, type);
591     if (errCode != TELEPHONY_SUCCESS) {
592         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
593         return errCode;
594     }
595     return TELEPHONY_SUCCESS;
596 }
597 
SetCallTransferInfo(int32_t slotId,CallTransferInfo & info)598 int32_t CallManagerProxy::SetCallTransferInfo(int32_t slotId, CallTransferInfo &info)
599 {
600     if (ReConnectService() != TELEPHONY_SUCCESS) {
601         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
602         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
603     }
604     std::lock_guard<std::mutex> lock(mutex_);
605     int32_t errCode = callManagerServicePtr_->SetCallTransferInfo(slotId, info);
606     if (errCode != TELEPHONY_SUCCESS) {
607         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
608         return errCode;
609     }
610     return TELEPHONY_SUCCESS;
611 }
612 
CanSetCallTransferTime(int32_t slotId,bool & result)613 int32_t CallManagerProxy::CanSetCallTransferTime(int32_t slotId, bool &result)
614 {
615     if (ReConnectService() != TELEPHONY_SUCCESS) {
616         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
617         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
618     }
619     std::lock_guard<std::mutex> lock(mutex_);
620     return callManagerServicePtr_->CanSetCallTransferTime(slotId, result);
621 }
622 
SetCallPreferenceMode(int32_t slotId,int32_t mode)623 int32_t CallManagerProxy::SetCallPreferenceMode(int32_t slotId, int32_t mode)
624 {
625     if (ReConnectService() != TELEPHONY_SUCCESS) {
626         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
627         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
628     }
629     std::lock_guard<std::mutex> lock(mutex_);
630     int32_t errCode = callManagerServicePtr_->SetCallPreferenceMode(slotId, mode);
631     if (errCode != TELEPHONY_SUCCESS) {
632         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
633         return errCode;
634     }
635     return TELEPHONY_SUCCESS;
636 }
637 
StartDtmf(int32_t callId,char str)638 int32_t CallManagerProxy::StartDtmf(int32_t callId, char str)
639 {
640     if (ReConnectService() != TELEPHONY_SUCCESS) {
641         TELEPHONY_LOGE("ipc reconnect failed!");
642         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
643     }
644     std::lock_guard<std::mutex> lock(mutex_);
645     int32_t errCode = callManagerServicePtr_->StartDtmf(callId, str);
646     if (errCode != TELEPHONY_SUCCESS) {
647         TELEPHONY_LOGE("StartDtmf failed, errcode:%{public}d", errCode);
648         return errCode;
649     }
650     return TELEPHONY_SUCCESS;
651 }
652 
StopDtmf(int32_t callId)653 int32_t CallManagerProxy::StopDtmf(int32_t callId)
654 {
655     if (ReConnectService() != TELEPHONY_SUCCESS) {
656         TELEPHONY_LOGE("ipc reconnect failed!");
657         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
658     }
659     std::lock_guard<std::mutex> lock(mutex_);
660     int32_t errCode = callManagerServicePtr_->StopDtmf(callId);
661     if (errCode != TELEPHONY_SUCCESS) {
662         TELEPHONY_LOGE("StopDtmf failed, errcode:%{public}d", errCode);
663         return errCode;
664     }
665     return TELEPHONY_SUCCESS;
666 }
667 
PostDialProceed(int32_t callId,bool proceed)668 int32_t CallManagerProxy::PostDialProceed(int32_t callId, bool proceed)
669 {
670     if (ReConnectService() != TELEPHONY_SUCCESS) {
671         TELEPHONY_LOGE("ipc reconnect failed!");
672         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
673     }
674     std::lock_guard<std::mutex> lock(mutex_);
675     int32_t errCode = callManagerServicePtr_->PostDialProceed(callId, proceed);
676     if (errCode != TELEPHONY_SUCCESS) {
677         TELEPHONY_LOGE("PostDialProceed failed, errcode:%{public}d", errCode);
678         return errCode;
679     }
680     return TELEPHONY_SUCCESS;
681 }
682 
IsRinging(bool & enabled)683 int32_t CallManagerProxy::IsRinging(bool &enabled)
684 {
685     if (ReConnectService() != TELEPHONY_SUCCESS) {
686         TELEPHONY_LOGE("ipc reconnect failed!");
687         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
688     }
689     std::lock_guard<std::mutex> lock(mutex_);
690     return callManagerServicePtr_->IsRinging(enabled);
691 }
692 
HasCall()693 bool CallManagerProxy::HasCall()
694 {
695     if (ReConnectService() != TELEPHONY_SUCCESS) {
696         TELEPHONY_LOGE("ipc reconnect failed!");
697         return false;
698     }
699     std::lock_guard<std::mutex> lock(mutex_);
700     return callManagerServicePtr_->HasCall();
701 }
702 
IsNewCallAllowed(bool & enabled)703 int32_t CallManagerProxy::IsNewCallAllowed(bool &enabled)
704 {
705     if (ReConnectService() != TELEPHONY_SUCCESS) {
706         TELEPHONY_LOGE("ipc reconnect failed!");
707         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
708     }
709     std::lock_guard<std::mutex> lock(mutex_);
710     return callManagerServicePtr_->IsNewCallAllowed(enabled);
711 }
712 
IsInEmergencyCall(bool & enabled)713 int32_t CallManagerProxy::IsInEmergencyCall(bool &enabled)
714 {
715     if (ReConnectService() != TELEPHONY_SUCCESS) {
716         TELEPHONY_LOGE("ipc reconnect failed!");
717         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
718     }
719     std::lock_guard<std::mutex> lock(mutex_);
720     return callManagerServicePtr_->IsInEmergencyCall(enabled);
721 }
722 
IsEmergencyPhoneNumber(std::u16string & number,int32_t slotId,bool & enabled)723 int32_t CallManagerProxy::IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled)
724 {
725     if (ReConnectService() != TELEPHONY_SUCCESS) {
726         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
727         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
728     }
729     std::lock_guard<std::mutex> lock(mutex_);
730     return callManagerServicePtr_->IsEmergencyPhoneNumber(number, slotId, enabled);
731 }
732 
FormatPhoneNumber(std::u16string & number,std::u16string & countryCode,std::u16string & formatNumber)733 int32_t CallManagerProxy::FormatPhoneNumber(
734     std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber)
735 {
736     if (ReConnectService() != TELEPHONY_SUCCESS) {
737         TELEPHONY_LOGE("ipc reconnect failed!");
738         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
739     }
740     std::lock_guard<std::mutex> lock(mutex_);
741     int32_t errCode = callManagerServicePtr_->FormatPhoneNumber(number, countryCode, formatNumber);
742     if (errCode != TELEPHONY_SUCCESS) {
743         TELEPHONY_LOGE("FormatPhoneNumber failed, errcode:%{public}d", errCode);
744         return errCode;
745     }
746     return TELEPHONY_SUCCESS;
747 }
748 
FormatPhoneNumberToE164(std::u16string & number,std::u16string & countryCode,std::u16string & formatNumber)749 int32_t CallManagerProxy::FormatPhoneNumberToE164(
750     std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber)
751 {
752     if (ReConnectService() != TELEPHONY_SUCCESS) {
753         TELEPHONY_LOGE("ipc reconnect failed!");
754         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
755     }
756     std::lock_guard<std::mutex> lock(mutex_);
757     int32_t errCode = callManagerServicePtr_->FormatPhoneNumberToE164(number, countryCode, formatNumber);
758     if (errCode != TELEPHONY_SUCCESS) {
759         TELEPHONY_LOGE("FormatPhoneNumberToE164 failed, errcode:%{public}d", errCode);
760         return errCode;
761     }
762     return TELEPHONY_SUCCESS;
763 }
764 
SetMuted(bool isMute)765 int32_t CallManagerProxy::SetMuted(bool isMute)
766 {
767     if (ReConnectService() != TELEPHONY_SUCCESS) {
768         TELEPHONY_LOGE("ipc reconnect failed!");
769         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
770     }
771     std::lock_guard<std::mutex> lock(mutex_);
772     int32_t errCode = callManagerServicePtr_->SetMuted(isMute);
773     if (errCode != TELEPHONY_SUCCESS) {
774         TELEPHONY_LOGE("SetMute failed, errcode:%{public}d", errCode);
775         return errCode;
776     }
777     return TELEPHONY_SUCCESS;
778 }
779 
MuteRinger()780 int32_t CallManagerProxy::MuteRinger()
781 {
782     if (ReConnectService() != TELEPHONY_SUCCESS) {
783         TELEPHONY_LOGE("ipc reconnect failed!");
784         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
785     }
786     std::lock_guard<std::mutex> lock(mutex_);
787     int32_t errCode = callManagerServicePtr_->MuteRinger();
788     if (errCode != TELEPHONY_SUCCESS) {
789         TELEPHONY_LOGE("MuteRinger failed, errcode:%{public}d", errCode);
790         return errCode;
791     }
792     return TELEPHONY_SUCCESS;
793 }
794 
SetAudioDevice(const AudioDevice & audioDevice)795 int32_t CallManagerProxy::SetAudioDevice(const AudioDevice &audioDevice)
796 {
797     if (ReConnectService() != TELEPHONY_SUCCESS) {
798         TELEPHONY_LOGE("ipc reconnect failed!");
799         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
800     }
801     std::lock_guard<std::mutex> lock(mutex_);
802     int32_t errCode = callManagerServicePtr_->SetAudioDevice(audioDevice);
803     if (errCode != TELEPHONY_SUCCESS) {
804         TELEPHONY_LOGE("SetAudioDevice failed, errcode:%{public}d", errCode);
805         return errCode;
806     }
807     return TELEPHONY_SUCCESS;
808 }
809 
ControlCamera(std::u16string cameraId)810 int32_t CallManagerProxy::ControlCamera(std::u16string cameraId)
811 {
812     if (ReConnectService() != TELEPHONY_SUCCESS) {
813         TELEPHONY_LOGE("ipc reconnect failed!");
814         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
815     }
816     std::lock_guard<std::mutex> lock(mutex_);
817     int32_t errCode = callManagerServicePtr_->ControlCamera(cameraId);
818     if (errCode != TELEPHONY_SUCCESS) {
819         TELEPHONY_LOGE("ControlCamera failed, errcode:%{public}d", errCode);
820         return errCode;
821     }
822     return TELEPHONY_SUCCESS;
823 }
824 
SetPreviewWindow(VideoWindow & window)825 int32_t CallManagerProxy::SetPreviewWindow(VideoWindow &window)
826 {
827     if (ReConnectService() != TELEPHONY_SUCCESS) {
828         TELEPHONY_LOGE("ipc reconnect failed!");
829         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
830     }
831     std::lock_guard<std::mutex> lock(mutex_);
832     int32_t errCode = callManagerServicePtr_->SetPreviewWindow(window);
833     if (errCode != TELEPHONY_SUCCESS) {
834         TELEPHONY_LOGE("SetPreviewWindow failed, errcode:%{public}d", errCode);
835         return errCode;
836     }
837     return TELEPHONY_SUCCESS;
838 }
839 
SetDisplayWindow(VideoWindow & window)840 int32_t CallManagerProxy::SetDisplayWindow(VideoWindow &window)
841 {
842     if (ReConnectService() != TELEPHONY_SUCCESS) {
843         TELEPHONY_LOGE("ipc reconnect failed!");
844         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
845     }
846     std::lock_guard<std::mutex> lock(mutex_);
847     int32_t errCode = callManagerServicePtr_->SetDisplayWindow(window);
848     if (errCode != TELEPHONY_SUCCESS) {
849         TELEPHONY_LOGE("SetDisplayWindow failed, errcode:%{public}d", errCode);
850         return errCode;
851     }
852     return TELEPHONY_SUCCESS;
853 }
854 
SetCameraZoom(float zoomRatio)855 int32_t CallManagerProxy::SetCameraZoom(float zoomRatio)
856 {
857     if (ReConnectService() != TELEPHONY_SUCCESS) {
858         TELEPHONY_LOGE("ipc reconnect failed!");
859         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
860     }
861     std::lock_guard<std::mutex> lock(mutex_);
862     int32_t errCode = callManagerServicePtr_->SetCameraZoom(zoomRatio);
863     if (errCode != TELEPHONY_SUCCESS) {
864         TELEPHONY_LOGE("SetCameraZoom failed, errcode:%{public}d", errCode);
865         return errCode;
866     }
867     return TELEPHONY_SUCCESS;
868 }
869 
SetPausePicture(std::u16string path)870 int32_t CallManagerProxy::SetPausePicture(std::u16string path)
871 {
872     if (ReConnectService() != TELEPHONY_SUCCESS) {
873         TELEPHONY_LOGE("ipc reconnect failed!");
874         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
875     }
876     std::lock_guard<std::mutex> lock(mutex_);
877     int32_t errCode = callManagerServicePtr_->SetPausePicture(path);
878     if (errCode != TELEPHONY_SUCCESS) {
879         TELEPHONY_LOGE("SetPausePicture failed, errcode:%{public}d", errCode);
880         return errCode;
881     }
882     return TELEPHONY_SUCCESS;
883 }
884 
SetDeviceDirection(int32_t rotation)885 int32_t CallManagerProxy::SetDeviceDirection(int32_t rotation)
886 {
887     if (ReConnectService() != TELEPHONY_SUCCESS) {
888         TELEPHONY_LOGE("ipc reconnect failed!");
889         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
890     }
891     std::lock_guard<std::mutex> lock(mutex_);
892     int32_t errCode = callManagerServicePtr_->SetDeviceDirection(rotation);
893     if (errCode != TELEPHONY_SUCCESS) {
894         TELEPHONY_LOGE("SetDeviceDirection failed, errcode:%{public}d", errCode);
895         return errCode;
896     }
897     return TELEPHONY_SUCCESS;
898 }
899 
GetImsConfig(int32_t slotId,ImsConfigItem item)900 int32_t CallManagerProxy::GetImsConfig(int32_t slotId, ImsConfigItem item)
901 {
902     if (ReConnectService() != TELEPHONY_SUCCESS) {
903         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
904         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
905     }
906     std::lock_guard<std::mutex> lock(mutex_);
907     int32_t errCode = callManagerServicePtr_->GetImsConfig(slotId, item);
908     if (errCode != TELEPHONY_SUCCESS) {
909         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
910         return errCode;
911     }
912     return TELEPHONY_SUCCESS;
913 }
914 
SetImsConfig(int32_t slotId,ImsConfigItem item,std::u16string & value)915 int32_t CallManagerProxy::SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value)
916 {
917     if (ReConnectService() != TELEPHONY_SUCCESS) {
918         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
919         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
920     }
921     std::lock_guard<std::mutex> lock(mutex_);
922     int32_t errCode = callManagerServicePtr_->SetImsConfig(slotId, item, value);
923     if (errCode != TELEPHONY_SUCCESS) {
924         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
925         return errCode;
926     }
927     return TELEPHONY_SUCCESS;
928 }
929 
GetImsFeatureValue(int32_t slotId,FeatureType type)930 int32_t CallManagerProxy::GetImsFeatureValue(int32_t slotId, FeatureType type)
931 {
932     if (ReConnectService() != TELEPHONY_SUCCESS) {
933         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
934         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
935     }
936     std::lock_guard<std::mutex> lock(mutex_);
937     int32_t errCode = callManagerServicePtr_->GetImsFeatureValue(slotId, type);
938     if (errCode != TELEPHONY_SUCCESS) {
939         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
940         return errCode;
941     }
942     return TELEPHONY_SUCCESS;
943 }
944 
SetImsFeatureValue(int32_t slotId,FeatureType type,int32_t value)945 int32_t CallManagerProxy::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
946 {
947     if (ReConnectService() != TELEPHONY_SUCCESS) {
948         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
949         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
950     }
951     std::lock_guard<std::mutex> lock(mutex_);
952     int32_t errCode = callManagerServicePtr_->SetImsFeatureValue(slotId, type, value);
953     if (errCode != TELEPHONY_SUCCESS) {
954         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
955         return errCode;
956     }
957     return TELEPHONY_SUCCESS;
958 }
959 
UpdateImsCallMode(int32_t callId,ImsCallMode mode)960 int32_t CallManagerProxy::UpdateImsCallMode(int32_t callId, ImsCallMode mode)
961 {
962     if (ReConnectService() != TELEPHONY_SUCCESS) {
963         TELEPHONY_LOGE("ipc reconnect failed!");
964         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
965     }
966     std::lock_guard<std::mutex> lock(mutex_);
967     int32_t errCode = callManagerServicePtr_->UpdateImsCallMode(callId, mode);
968     if (errCode != TELEPHONY_SUCCESS) {
969         TELEPHONY_LOGE("UpdateImsCallMode failed, errcode:%{public}d", errCode);
970         return errCode;
971     }
972     return TELEPHONY_SUCCESS;
973 }
974 
EnableImsSwitch(int32_t slotId)975 int32_t CallManagerProxy::EnableImsSwitch(int32_t slotId)
976 {
977     if (ReConnectService() != TELEPHONY_SUCCESS) {
978         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
979         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
980     }
981     std::lock_guard<std::mutex> lock(mutex_);
982     int32_t errCode = callManagerServicePtr_->EnableImsSwitch(slotId);
983     if (errCode != TELEPHONY_SUCCESS) {
984         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
985         return errCode;
986     }
987     return TELEPHONY_SUCCESS;
988 }
989 
DisableImsSwitch(int32_t slotId)990 int32_t CallManagerProxy::DisableImsSwitch(int32_t slotId)
991 {
992     if (ReConnectService() != TELEPHONY_SUCCESS) {
993         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
994         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
995     }
996     std::lock_guard<std::mutex> lock(mutex_);
997     int32_t errCode = callManagerServicePtr_->DisableImsSwitch(slotId);
998     if (errCode != TELEPHONY_SUCCESS) {
999         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
1000         return errCode;
1001     }
1002     return TELEPHONY_SUCCESS;
1003 }
1004 
IsImsSwitchEnabled(int32_t slotId,bool & enabled)1005 int32_t CallManagerProxy::IsImsSwitchEnabled(int32_t slotId, bool &enabled)
1006 {
1007     if (ReConnectService() != TELEPHONY_SUCCESS) {
1008         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
1009         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1010     }
1011     std::lock_guard<std::mutex> lock(mutex_);
1012     int32_t errCode = callManagerServicePtr_->IsImsSwitchEnabled(slotId, enabled);
1013     if (errCode != TELEPHONY_SUCCESS) {
1014         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
1015         return errCode;
1016     }
1017     return TELEPHONY_SUCCESS;
1018 }
1019 
SetVoNRState(int32_t slotId,int32_t state)1020 int32_t CallManagerProxy::SetVoNRState(int32_t slotId, int32_t state)
1021 {
1022     if (ReConnectService() != TELEPHONY_SUCCESS) {
1023         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
1024         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1025     }
1026     std::lock_guard<std::mutex> lock(mutex_);
1027     int32_t errCode = callManagerServicePtr_->SetVoNRState(slotId, state);
1028     if (errCode != TELEPHONY_SUCCESS) {
1029         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
1030         return errCode;
1031     }
1032     return TELEPHONY_SUCCESS;
1033 }
1034 
GetVoNRState(int32_t slotId,int32_t & state)1035 int32_t CallManagerProxy::GetVoNRState(int32_t slotId, int32_t &state)
1036 {
1037     if (ReConnectService() != TELEPHONY_SUCCESS) {
1038         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
1039         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1040     }
1041     std::lock_guard<std::mutex> lock(mutex_);
1042     int32_t errCode = callManagerServicePtr_->GetVoNRState(slotId, state);
1043     if (errCode != TELEPHONY_SUCCESS) {
1044         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
1045         return errCode;
1046     }
1047     return TELEPHONY_SUCCESS;
1048 }
1049 
StartRtt(int32_t callId,std::u16string & msg)1050 int32_t CallManagerProxy::StartRtt(int32_t callId, std::u16string &msg)
1051 {
1052     if (ReConnectService() != TELEPHONY_SUCCESS) {
1053         TELEPHONY_LOGE("ipc reconnect failed!");
1054         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1055     }
1056     std::lock_guard<std::mutex> lock(mutex_);
1057     int32_t errCode = callManagerServicePtr_->StartRtt(callId, msg);
1058     if (errCode != TELEPHONY_SUCCESS) {
1059         TELEPHONY_LOGE("StartRtt failed, errcode:%{public}d", errCode);
1060         return errCode;
1061     }
1062     return TELEPHONY_SUCCESS;
1063 }
1064 
StopRtt(int32_t callId)1065 int32_t CallManagerProxy::StopRtt(int32_t callId)
1066 {
1067     if (ReConnectService() != TELEPHONY_SUCCESS) {
1068         TELEPHONY_LOGE("ipc reconnect failed!");
1069         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1070     }
1071     std::lock_guard<std::mutex> lock(mutex_);
1072     int32_t errCode = callManagerServicePtr_->StopRtt(callId);
1073     if (errCode != TELEPHONY_SUCCESS) {
1074         TELEPHONY_LOGE("StopRtt failed, errcode:%{public}d", errCode);
1075         return errCode;
1076     }
1077     return TELEPHONY_SUCCESS;
1078 }
1079 
JoinConference(int32_t callId,std::vector<std::u16string> & numberList)1080 int32_t CallManagerProxy::JoinConference(int32_t callId, std::vector<std::u16string> &numberList)
1081 {
1082     if (ReConnectService() != TELEPHONY_SUCCESS) {
1083         TELEPHONY_LOGE("ipc reconnect failed!");
1084         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1085     }
1086     std::lock_guard<std::mutex> lock(mutex_);
1087     int32_t errCode = callManagerServicePtr_->JoinConference(callId, numberList);
1088     if (errCode != TELEPHONY_SUCCESS) {
1089         TELEPHONY_LOGE("JoinConference failed, errcode:%{public}d", errCode);
1090         return errCode;
1091     }
1092     return TELEPHONY_SUCCESS;
1093 }
1094 
ReportOttCallDetailsInfo(std::vector<OttCallDetailsInfo> & ottVec)1095 int32_t CallManagerProxy::ReportOttCallDetailsInfo(std::vector<OttCallDetailsInfo> &ottVec)
1096 {
1097     if (ReConnectService() != TELEPHONY_SUCCESS) {
1098         TELEPHONY_LOGE("ipc reconnect failed!");
1099         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1100     }
1101     std::lock_guard<std::mutex> lock(mutex_);
1102     int32_t errCode = callManagerServicePtr_->ReportOttCallDetailsInfo(ottVec);
1103     if (errCode != TELEPHONY_SUCCESS) {
1104         TELEPHONY_LOGE("ReportOttCallInfo failed, errcode:%{public}d", errCode);
1105         return errCode;
1106     }
1107     return TELEPHONY_SUCCESS;
1108 }
1109 
ReportOttCallEventInfo(OttCallEventInfo & eventInfo)1110 int32_t CallManagerProxy::ReportOttCallEventInfo(OttCallEventInfo &eventInfo)
1111 {
1112     if (ReConnectService() != TELEPHONY_SUCCESS) {
1113         TELEPHONY_LOGE("ipc reconnect failed!");
1114         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1115     }
1116     std::lock_guard<std::mutex> lock(mutex_);
1117     int32_t errCode = callManagerServicePtr_->ReportOttCallEventInfo(eventInfo);
1118     if (errCode != TELEPHONY_SUCCESS) {
1119         TELEPHONY_LOGE("ReportOttCallEventInfo failed, errcode:%{public}d", errCode);
1120         return errCode;
1121     }
1122     return TELEPHONY_SUCCESS;
1123 }
1124 
CloseUnFinishedUssd(int32_t slotId)1125 int32_t CallManagerProxy::CloseUnFinishedUssd(int32_t slotId)
1126 {
1127     if (ReConnectService() != TELEPHONY_SUCCESS) {
1128         TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
1129         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1130     }
1131     std::lock_guard<std::mutex> lock(mutex_);
1132     int32_t errCode = callManagerServicePtr_->CloseUnFinishedUssd(slotId);
1133     if (errCode != TELEPHONY_SUCCESS) {
1134         TELEPHONY_LOGE("[slot%{public}d] failed, errcode:%{public}d", slotId, errCode);
1135         return errCode;
1136     }
1137     return TELEPHONY_SUCCESS;
1138 }
1139 
InputDialerSpecialCode(const std::string & specialCode)1140 int32_t CallManagerProxy::InputDialerSpecialCode(const std::string &specialCode)
1141 {
1142     if (ReConnectService() != TELEPHONY_SUCCESS) {
1143         TELEPHONY_LOGE("ipc reconnect failed!");
1144         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1145     }
1146 
1147     std::lock_guard<std::mutex> lock(mutex_);
1148     int32_t errCode = callManagerServicePtr_->InputDialerSpecialCode(specialCode);
1149     if (errCode != TELEPHONY_SUCCESS) {
1150         TELEPHONY_LOGE("InputDialerSpecialCode failed, errcode:%{public}d", errCode);
1151         return errCode;
1152     }
1153     return TELEPHONY_SUCCESS;
1154 }
1155 
RemoveMissedIncomingCallNotification()1156 int32_t CallManagerProxy::RemoveMissedIncomingCallNotification()
1157 {
1158     if (ReConnectService() != TELEPHONY_SUCCESS) {
1159         TELEPHONY_LOGE("ipc reconnect failed!");
1160         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1161     }
1162 
1163     std::lock_guard<std::mutex> lock(mutex_);
1164     int32_t errCode = callManagerServicePtr_->RemoveMissedIncomingCallNotification();
1165     if (errCode != TELEPHONY_SUCCESS) {
1166         TELEPHONY_LOGE("RemoveMissedIncomingCallNotification failed, errcode:%{public}d", errCode);
1167         return errCode;
1168     }
1169     return TELEPHONY_SUCCESS;
1170 }
1171 
GetProxyObjectPtr(CallManagerProxyType proxyType)1172 sptr<IRemoteObject> CallManagerProxy::GetProxyObjectPtr(CallManagerProxyType proxyType)
1173 {
1174     if (ReConnectService() != TELEPHONY_SUCCESS) {
1175         TELEPHONY_LOGE("ipc reconnect failed!");
1176         return nullptr;
1177     }
1178     std::lock_guard<std::mutex> lock(mutex_);
1179     sptr<IRemoteObject> ptr = callManagerServicePtr_->GetProxyObjectPtr(proxyType);
1180     if (ptr == nullptr) {
1181         TELEPHONY_LOGE("GetProxyObjectPtr failed");
1182         return nullptr;
1183     }
1184     return ptr;
1185 }
1186 
OnRemoteDied(const wptr<IRemoteObject> & remote)1187 void CallManagerProxy::OnRemoteDied(const wptr<IRemoteObject> &remote)
1188 {
1189     if (remote == nullptr) {
1190         TELEPHONY_LOGE("OnRemoteDied failed, remote is nullptr");
1191         return;
1192     }
1193     std::lock_guard<std::mutex> lock(mutex_);
1194     if (callManagerServicePtr_ == nullptr) {
1195         TELEPHONY_LOGE("OnRemoteDied failed, callManagerServicePtr_ is nullptr");
1196         return;
1197     }
1198     auto serviceRemote = callManagerServicePtr_->AsObject();
1199     if (serviceRemote != nullptr && serviceRemote == remote.promote()) {
1200         serviceRemote->RemoveDeathRecipient(deathRecipient_);
1201         callManagerServicePtr_ = nullptr;
1202         initStatus_ = false;
1203         TELEPHONY_LOGE("on remote died");
1204     }
1205 }
1206 
ReportAudioDeviceInfo()1207 int32_t CallManagerProxy::ReportAudioDeviceInfo()
1208 {
1209     if (ReConnectService() != TELEPHONY_SUCCESS) {
1210         TELEPHONY_LOGE("ipc reconnect failed!");
1211         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1212     }
1213     std::lock_guard<std::mutex> lock(mutex_);
1214     int32_t errCode = callManagerServicePtr_->ReportAudioDeviceInfo();
1215     if (errCode != TELEPHONY_SUCCESS) {
1216         TELEPHONY_LOGE("ReportAudioDeviceInfo failed, errcode:%{public}d", errCode);
1217         return errCode;
1218     }
1219     return TELEPHONY_SUCCESS;
1220 }
1221 } // namespace Telephony
1222 } // namespace OHOS
1223