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