• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 "ims_call_client.h"
17 
18 #include "cellular_call_hisysevent.h"
19 #include "ims_call_callback_stub.h"
20 #include "iservice_registry.h"
21 #include "system_ability_definition.h"
22 #include "telephony_errors.h"
23 #include "telephony_log_wrapper.h"
24 
25 namespace OHOS {
26 namespace Telephony {
27 ImsCallClient::ImsCallClient() = default;
28 
~ImsCallClient()29 ImsCallClient::~ImsCallClient()
30 {
31     UnInit();
32 }
33 
Init()34 void ImsCallClient::Init()
35 {
36     TELEPHONY_LOGI("Init start");
37     if (IsConnect()) {
38         TELEPHONY_LOGE("Init, IsConnect return true");
39         return;
40     }
41 
42     GetImsCallProxy();
43     if (imsCallProxy_ == nullptr) {
44         TELEPHONY_LOGE("Init, get ims call proxy failed!");
45     }
46 
47     statusChangeListener_ = new (std::nothrow) SystemAbilityListener();
48     if (statusChangeListener_ == nullptr) {
49         TELEPHONY_LOGE("Init, failed to create statusChangeListener.");
50         return;
51     }
52     auto managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
53     if (managerPtr == nullptr) {
54         TELEPHONY_LOGE("Init, get system ability manager error.");
55         return;
56     }
57     int32_t ret = managerPtr->SubscribeSystemAbility(TELEPHONY_IMS_SYS_ABILITY_ID,
58         statusChangeListener_);
59     if (ret) {
60         TELEPHONY_LOGE("Init, failed to subscribe sa:%{public}d", TELEPHONY_IMS_SYS_ABILITY_ID);
61         return;
62     }
63     TELEPHONY_LOGI("Init successfully");
64 }
65 
UnInit()66 void ImsCallClient::UnInit()
67 {
68     Clean();
69     if (statusChangeListener_ != nullptr) {
70         statusChangeListener_.clear();
71         statusChangeListener_ = nullptr;
72     }
73     handlerMap_.clear();
74 }
75 
GetImsCallProxy()76 sptr<ImsCallInterface> ImsCallClient::GetImsCallProxy()
77 {
78     Utils::UniqueWriteGuard<Utils::RWLock> guard(rwClientLock_);
79     if (imsCallProxy_ != nullptr) {
80         return imsCallProxy_;
81     }
82     auto managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
83     if (managerPtr == nullptr) {
84         TELEPHONY_LOGE("GetImsCallProxy return, get system ability manager error.");
85         return nullptr;
86     }
87     auto remoteObjectPtr = managerPtr->CheckSystemAbility(TELEPHONY_IMS_SYS_ABILITY_ID);
88     if (remoteObjectPtr == nullptr) {
89         TELEPHONY_LOGE("GetImsCallProxy return, remote service not exists.");
90         return nullptr;
91     }
92     imsCoreServiceProxy_ = iface_cast<ImsCoreServiceInterface>(remoteObjectPtr);
93     if (imsCoreServiceProxy_ == nullptr) {
94         TELEPHONY_LOGE("GetImsCallProxy return, imsCoreServiceProxy_ is nullptr.");
95         return nullptr;
96     }
97     sptr<IRemoteObject> imsCallRemoteObjectPtr = imsCoreServiceProxy_->GetProxyObjectPtr(PROXY_IMS_CALL);
98     if (imsCallRemoteObjectPtr == nullptr) {
99         TELEPHONY_LOGE("GetImsCallProxy return, ImsCallRemoteObjectPtr is nullptr.");
100         return nullptr;
101     }
102 
103     imsCallProxy_ = iface_cast<ImsCallInterface>(imsCallRemoteObjectPtr);
104     if (imsCallProxy_ == nullptr) {
105         TELEPHONY_LOGE("GetImsCallProxy return, iface_cast<imsCallProxy_> failed!");
106         return nullptr;
107     }
108     // register callback
109     RegisterImsCallCallback();
110     TELEPHONY_LOGI("GetImsCallProxy success.");
111     return imsCallProxy_;
112 }
113 
IsConnect() const114 bool ImsCallClient::IsConnect() const
115 {
116     return (imsCallProxy_ != nullptr);
117 }
118 
RegisterImsCallCallback()119 int32_t ImsCallClient::RegisterImsCallCallback()
120 {
121     if (imsCallProxy_ == nullptr) {
122         TELEPHONY_LOGE("imsCallProxy_ is null!");
123         return TELEPHONY_ERR_LOCAL_PTR_NULL;
124     }
125     imsCallCallback_ = (std::make_unique<ImsCallCallbackStub>()).release();
126     if (imsCallCallback_ == nullptr) {
127         TELEPHONY_LOGE("RegisterImsCallCallback return, make unique error.");
128         return TELEPHONY_ERR_LOCAL_PTR_NULL;
129     }
130     int32_t ret = imsCallProxy_->RegisterImsCallCallback(imsCallCallback_);
131     if (ret) {
132         TELEPHONY_LOGE("RegisterImsCallCallback return, register callback error.");
133         return TELEPHONY_ERR_FAIL;
134     }
135     TELEPHONY_LOGI("RegisterImsCallCallback success.");
136     return TELEPHONY_SUCCESS;
137 }
138 
RegisterImsCallCallbackHandler(int32_t slotId,const std::shared_ptr<AppExecFwk::EventHandler> & handler)139 int32_t ImsCallClient::RegisterImsCallCallbackHandler(int32_t slotId,
140     const std::shared_ptr<AppExecFwk::EventHandler> &handler)
141 {
142     if (handler == nullptr) {
143         TELEPHONY_LOGE("RegisterImsCallCallbackHandler return, handler is null.");
144         return TELEPHONY_ERR_LOCAL_PTR_NULL;
145     }
146 
147     handlerMap_.insert(std::make_pair(slotId, handler));
148     TELEPHONY_LOGI("RegisterImsCallCallbackHandler success.");
149     return TELEPHONY_SUCCESS;
150 }
151 
GetHandler(int32_t slotId)152 std::shared_ptr<AppExecFwk::EventHandler> ImsCallClient::GetHandler(int32_t slotId)
153 {
154     return handlerMap_[slotId];
155 }
156 
Dial(const ImsCallInfo & callInfo,CLIRMode mode)157 int32_t ImsCallClient::Dial(const ImsCallInfo &callInfo, CLIRMode mode)
158 {
159     if (ReConnectService() != TELEPHONY_SUCCESS) {
160         TELEPHONY_LOGE("ipc reconnect failed!");
161         CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, callInfo.videoState,
162             TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL, "ipc reconnect failed");
163         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
164     }
165     return imsCallProxy_->Dial(callInfo, mode);
166 }
167 
HangUp(const ImsCallInfo & callInfo)168 int32_t ImsCallClient::HangUp(const ImsCallInfo &callInfo)
169 {
170     if (ReConnectService() != TELEPHONY_SUCCESS) {
171         TELEPHONY_LOGE("ipc reconnect failed!");
172         CellularCallHiSysEvent::WriteHangUpFaultEvent(
173             callInfo.slotId, INVALID_PARAMETER, TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL, "HangUp ims ipc reconnect failed");
174         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
175     }
176     return imsCallProxy_->HangUp(callInfo);
177 }
178 
Reject(const ImsCallInfo & callInfo)179 int32_t ImsCallClient::Reject(const ImsCallInfo &callInfo)
180 {
181     if (ReConnectService() != TELEPHONY_SUCCESS) {
182         TELEPHONY_LOGE("ipc reconnect failed!");
183         CellularCallHiSysEvent::WriteHangUpFaultEvent(
184             callInfo.slotId, INVALID_PARAMETER, TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL, "Reject ims ipc reconnect failed");
185         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
186     }
187     return imsCallProxy_->RejectWithReason(callInfo, ImsRejectReason::USER_DECLINE);
188 }
189 
RejectWithReason(const ImsCallInfo & callInfo,const ImsRejectReason & reason)190 int32_t ImsCallClient::RejectWithReason(const ImsCallInfo &callInfo, const ImsRejectReason &reason)
191 {
192     if (ReConnectService() != TELEPHONY_SUCCESS) {
193         TELEPHONY_LOGE("ipc reconnect failed!");
194         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
195     }
196     return imsCallProxy_->RejectWithReason(callInfo, reason);
197 }
198 
Answer(const ImsCallInfo & callInfo)199 int32_t ImsCallClient::Answer(const ImsCallInfo &callInfo)
200 {
201     if (ReConnectService() != TELEPHONY_SUCCESS) {
202         TELEPHONY_LOGE("ipc reconnect failed!");
203         CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, callInfo.videoState,
204             TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL, "answer ims ipc reconnect failed");
205         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
206     }
207     return imsCallProxy_->Answer(callInfo);
208 }
209 
HoldCall(int32_t slotId,int32_t callType)210 int32_t ImsCallClient::HoldCall(int32_t slotId, int32_t callType)
211 {
212     if (ReConnectService() != TELEPHONY_SUCCESS) {
213         TELEPHONY_LOGE("ipc reconnect failed!");
214         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
215     }
216     return imsCallProxy_->HoldCall(slotId, callType);
217 }
218 
UnHoldCall(int32_t slotId,int32_t callType)219 int32_t ImsCallClient::UnHoldCall(int32_t slotId, int32_t callType)
220 {
221     if (ReConnectService() != TELEPHONY_SUCCESS) {
222         TELEPHONY_LOGE("ipc reconnect failed!");
223         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
224     }
225     return imsCallProxy_->UnHoldCall(slotId, callType);
226 }
227 
SwitchCall(int32_t slotId,int32_t callType)228 int32_t ImsCallClient::SwitchCall(int32_t slotId, int32_t callType)
229 {
230     if (ReConnectService() != TELEPHONY_SUCCESS) {
231         TELEPHONY_LOGE("ipc reconnect failed!");
232         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
233     }
234     return imsCallProxy_->SwitchCall(slotId, callType);
235 }
236 
CombineConference(int32_t slotId)237 int32_t ImsCallClient::CombineConference(int32_t slotId)
238 {
239     if (ReConnectService() != TELEPHONY_SUCCESS) {
240         TELEPHONY_LOGE("ipc reconnect failed!");
241         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
242     }
243     return imsCallProxy_->CombineConference(slotId);
244 }
245 
InviteToConference(int32_t slotId,const std::vector<std::string> & numberList)246 int32_t ImsCallClient::InviteToConference(int32_t slotId, const std::vector<std::string> &numberList)
247 {
248     if (ReConnectService() != TELEPHONY_SUCCESS) {
249         TELEPHONY_LOGE("ipc reconnect failed!");
250         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
251     }
252     return imsCallProxy_->InviteToConference(slotId, numberList);
253 }
254 
KickOutFromConference(int32_t slotId,const std::vector<std::string> & numberList)255 int32_t ImsCallClient::KickOutFromConference(int32_t slotId, const std::vector<std::string> &numberList)
256 {
257     if (ReConnectService() != TELEPHONY_SUCCESS) {
258         TELEPHONY_LOGE("ipc reconnect failed!");
259         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
260     }
261     return imsCallProxy_->KickOutFromConference(slotId, numberList);
262 }
263 
UpdateImsCallMode(const ImsCallInfo & callInfo,ImsCallMode mode)264 int32_t ImsCallClient::UpdateImsCallMode(const ImsCallInfo &callInfo, ImsCallMode mode)
265 {
266     if (ReConnectService() != TELEPHONY_SUCCESS) {
267         TELEPHONY_LOGE("ipc reconnect failed!");
268         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
269     }
270     return imsCallProxy_->UpdateImsCallMode(callInfo, mode);
271 }
272 
GetImsCallsDataRequest(int32_t slotId,int64_t lastCallsDataFlag)273 int32_t ImsCallClient::GetImsCallsDataRequest(int32_t slotId, int64_t lastCallsDataFlag)
274 {
275     if (ReConnectService() != TELEPHONY_SUCCESS) {
276         TELEPHONY_LOGE("ipc reconnect failed!");
277         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
278     }
279     return imsCallProxy_->GetImsCallsDataRequest(slotId, lastCallsDataFlag);
280 }
281 
GetLastCallFailReason(int32_t slotId)282 int32_t ImsCallClient::GetLastCallFailReason(int32_t slotId)
283 {
284     if (ReConnectService() != TELEPHONY_SUCCESS) {
285         TELEPHONY_LOGE("ipc reconnect failed!");
286         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
287     }
288     return imsCallProxy_->GetLastCallFailReason(slotId);
289 }
290 
StartDtmf(int32_t slotId,char cDtmfCode,int32_t index)291 int32_t ImsCallClient::StartDtmf(int32_t slotId, char cDtmfCode, int32_t index)
292 {
293     if (ReConnectService() != TELEPHONY_SUCCESS) {
294         TELEPHONY_LOGE("ipc reconnect failed!");
295         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
296     }
297     return imsCallProxy_->StartDtmf(slotId, cDtmfCode, index);
298 }
299 
SendDtmf(int32_t slotId,char cDtmfCode,int32_t index)300 int32_t ImsCallClient::SendDtmf(int32_t slotId, char cDtmfCode, int32_t index)
301 {
302     if (ReConnectService() != TELEPHONY_SUCCESS) {
303         TELEPHONY_LOGE("ipc reconnect failed!");
304         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
305     }
306     return imsCallProxy_->SendDtmf(slotId, cDtmfCode, index);
307 }
308 
StopDtmf(int32_t slotId,int32_t index)309 int32_t ImsCallClient::StopDtmf(int32_t slotId, int32_t index)
310 {
311     if (ReConnectService() != TELEPHONY_SUCCESS) {
312         TELEPHONY_LOGE("ipc reconnect failed!");
313         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
314     }
315     return imsCallProxy_->StopDtmf(slotId, index);
316 }
317 
StartRtt(int32_t slotId,const std::string & msg)318 int32_t ImsCallClient::StartRtt(int32_t slotId, const std::string &msg)
319 {
320     if (ReConnectService() != TELEPHONY_SUCCESS) {
321         TELEPHONY_LOGE("ipc reconnect failed!");
322         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
323     }
324     return imsCallProxy_->StartRtt(slotId, msg);
325 }
326 
StopRtt(int32_t slotId)327 int32_t ImsCallClient::StopRtt(int32_t slotId)
328 {
329     if (ReConnectService() != TELEPHONY_SUCCESS) {
330         TELEPHONY_LOGE("ipc reconnect failed!");
331         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
332     }
333     return imsCallProxy_->StopRtt(slotId);
334 }
335 
SetDomainPreferenceMode(int32_t slotId,int32_t mode)336 int32_t ImsCallClient::SetDomainPreferenceMode(int32_t slotId, int32_t mode)
337 {
338     if (ReConnectService() != TELEPHONY_SUCCESS) {
339         TELEPHONY_LOGE("ipc reconnect failed!");
340         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
341     }
342     return imsCallProxy_->SetDomainPreferenceMode(slotId, mode);
343 }
344 
GetDomainPreferenceMode(int32_t slotId)345 int32_t ImsCallClient::GetDomainPreferenceMode(int32_t slotId)
346 {
347     if (ReConnectService() != TELEPHONY_SUCCESS) {
348         TELEPHONY_LOGE("ipc reconnect failed!");
349         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
350     }
351     return imsCallProxy_->GetDomainPreferenceMode(slotId);
352 }
353 
SetImsSwitchStatus(int32_t slotId,int32_t active)354 int32_t ImsCallClient::SetImsSwitchStatus(int32_t slotId, int32_t active)
355 {
356     if (ReConnectService() != TELEPHONY_SUCCESS) {
357         TELEPHONY_LOGE("ipc reconnect failed!");
358         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
359     }
360     return imsCallProxy_->SetImsSwitchStatus(slotId, active);
361 }
362 
GetImsSwitchStatus(int32_t slotId)363 int32_t ImsCallClient::GetImsSwitchStatus(int32_t slotId)
364 {
365     if (ReConnectService() != TELEPHONY_SUCCESS) {
366         TELEPHONY_LOGE("ipc reconnect failed!");
367         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
368     }
369     return imsCallProxy_->GetImsSwitchStatus(slotId);
370 }
371 
SetImsConfig(ImsConfigItem item,const std::string & value)372 int32_t ImsCallClient::SetImsConfig(ImsConfigItem item, const std::string &value)
373 {
374     if (ReConnectService() != TELEPHONY_SUCCESS) {
375         TELEPHONY_LOGE("ipc reconnect failed!");
376         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
377     }
378     return imsCallProxy_->SetImsConfig(item, value);
379 }
380 
SetImsConfig(ImsConfigItem item,int32_t value)381 int32_t ImsCallClient::SetImsConfig(ImsConfigItem item, int32_t value)
382 {
383     if (ReConnectService() != TELEPHONY_SUCCESS) {
384         TELEPHONY_LOGE("ipc reconnect failed!");
385         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
386     }
387     return imsCallProxy_->SetImsConfig(item, value);
388 }
389 
GetImsConfig(ImsConfigItem item)390 int32_t ImsCallClient::GetImsConfig(ImsConfigItem item)
391 {
392     if (ReConnectService() != TELEPHONY_SUCCESS) {
393         TELEPHONY_LOGE("ipc reconnect failed!");
394         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
395     }
396     return imsCallProxy_->GetImsConfig(item);
397 }
398 
SetImsFeatureValue(FeatureType type,int32_t value)399 int32_t ImsCallClient::SetImsFeatureValue(FeatureType type, int32_t value)
400 {
401     if (ReConnectService() != TELEPHONY_SUCCESS) {
402         TELEPHONY_LOGE("ipc reconnect failed!");
403         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
404     }
405     return imsCallProxy_->SetImsFeatureValue(type, value);
406 }
407 
GetImsFeatureValue(FeatureType type,int32_t & value)408 int32_t ImsCallClient::GetImsFeatureValue(FeatureType type, int32_t &value)
409 {
410     if (ReConnectService() != TELEPHONY_SUCCESS) {
411         TELEPHONY_LOGE("ipc reconnect failed!");
412         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
413     }
414     return imsCallProxy_->GetImsFeatureValue(type, value);
415 }
416 
SetMute(int32_t slotId,int32_t mute)417 int32_t ImsCallClient::SetMute(int32_t slotId, int32_t mute)
418 {
419     if (ReConnectService() != TELEPHONY_SUCCESS) {
420         TELEPHONY_LOGE("ipc reconnect failed!");
421         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
422     }
423     return imsCallProxy_->SetMute(slotId, mute);
424 }
425 
GetMute(int32_t slotId)426 int32_t ImsCallClient::GetMute(int32_t slotId)
427 {
428     if (ReConnectService() != TELEPHONY_SUCCESS) {
429         TELEPHONY_LOGE("ipc reconnect failed!");
430         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
431     }
432     return imsCallProxy_->GetMute(slotId);
433 }
434 
CtrlCamera(const std::u16string & cameraId,int32_t callingUid,int32_t callingPid)435 int32_t ImsCallClient::CtrlCamera(const std::u16string &cameraId, int32_t callingUid, int32_t callingPid)
436 {
437     if (ReConnectService() != TELEPHONY_SUCCESS) {
438         TELEPHONY_LOGE("ipc reconnect failed!");
439         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
440     }
441     return imsCallProxy_->CtrlCamera(cameraId, callingUid, callingPid);
442 }
443 
SetPreviewWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)444 int32_t ImsCallClient::SetPreviewWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
445 {
446     if (ReConnectService() != TELEPHONY_SUCCESS) {
447         TELEPHONY_LOGE("ipc reconnect failed!");
448         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
449     }
450     return imsCallProxy_->SetPreviewWindow(x, y, z, width, height);
451 }
452 
SetDisplayWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)453 int32_t ImsCallClient::SetDisplayWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
454 {
455     if (ReConnectService() != TELEPHONY_SUCCESS) {
456         TELEPHONY_LOGE("ipc reconnect failed!");
457         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
458     }
459     return imsCallProxy_->SetDisplayWindow(x, y, z, width, height);
460 }
461 
SetCameraZoom(float zoomRatio)462 int32_t ImsCallClient::SetCameraZoom(float zoomRatio)
463 {
464     if (ReConnectService() != TELEPHONY_SUCCESS) {
465         TELEPHONY_LOGE("ipc reconnect failed!");
466         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
467     }
468     return imsCallProxy_->SetCameraZoom(zoomRatio);
469 }
470 
SetPauseImage(const std::u16string & path)471 int32_t ImsCallClient::SetPauseImage(const std::u16string &path)
472 {
473     if (ReConnectService() != TELEPHONY_SUCCESS) {
474         TELEPHONY_LOGE("ipc reconnect failed!");
475         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
476     }
477     return imsCallProxy_->SetPauseImage(path);
478 }
479 
SetDeviceDirection(int32_t rotation)480 int32_t ImsCallClient::SetDeviceDirection(int32_t rotation)
481 {
482     if (ReConnectService() != TELEPHONY_SUCCESS) {
483         TELEPHONY_LOGE("ipc reconnect failed!");
484         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
485     }
486     return imsCallProxy_->SetDeviceDirection(rotation);
487 }
488 
SetClip(int32_t slotId,int32_t action)489 int32_t ImsCallClient::SetClip(int32_t slotId, int32_t action)
490 {
491     if (ReConnectService() != TELEPHONY_SUCCESS) {
492         TELEPHONY_LOGE("ipc reconnect failed!");
493         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
494     }
495     return imsCallProxy_->SetClip(slotId, action);
496 }
497 
GetClip(int32_t slotId)498 int32_t ImsCallClient::GetClip(int32_t slotId)
499 {
500     if (ReConnectService() != TELEPHONY_SUCCESS) {
501         TELEPHONY_LOGE("ipc reconnect failed!");
502         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
503     }
504     return imsCallProxy_->GetClip(slotId);
505 }
506 
SetClir(int32_t slotId,int32_t action)507 int32_t ImsCallClient::SetClir(int32_t slotId, int32_t action)
508 {
509     if (ReConnectService() != TELEPHONY_SUCCESS) {
510         TELEPHONY_LOGE("ipc reconnect failed!");
511         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
512     }
513     return imsCallProxy_->SetClir(slotId, action);
514 }
515 
GetClir(int32_t slotId)516 int32_t ImsCallClient::GetClir(int32_t slotId)
517 {
518     if (ReConnectService() != TELEPHONY_SUCCESS) {
519         TELEPHONY_LOGE("ipc reconnect failed!");
520         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
521     }
522     return imsCallProxy_->GetClir(slotId);
523 }
524 
SetCallTransfer(int32_t slotId,int32_t reason,int32_t mode,const std::string & transferNum,int32_t classType)525 int32_t ImsCallClient::SetCallTransfer(
526     int32_t slotId, int32_t reason, int32_t mode, const std::string &transferNum, int32_t classType)
527 {
528     if (ReConnectService() != TELEPHONY_SUCCESS) {
529         TELEPHONY_LOGE("ipc reconnect failed!");
530         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
531     }
532     return imsCallProxy_->SetCallTransfer(slotId, reason, mode, transferNum, classType);
533 }
534 
GetCallTransfer(int32_t slotId,int32_t reason)535 int32_t ImsCallClient::GetCallTransfer(int32_t slotId, int32_t reason)
536 {
537     if (ReConnectService() != TELEPHONY_SUCCESS) {
538         TELEPHONY_LOGE("ipc reconnect failed!");
539         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
540     }
541     return imsCallProxy_->GetCallTransfer(slotId, reason);
542 }
543 
SetCallRestriction(int32_t slotId,const std::string & fac,int32_t mode,const std::string & pw)544 int32_t ImsCallClient::SetCallRestriction(int32_t slotId, const std::string &fac, int32_t mode, const std::string &pw)
545 {
546     if (ReConnectService() != TELEPHONY_SUCCESS) {
547         TELEPHONY_LOGE("ipc reconnect failed!");
548         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
549     }
550     return imsCallProxy_->SetCallRestriction(slotId, fac, mode, pw);
551 }
552 
GetCallRestriction(int32_t slotId,const std::string & fac)553 int32_t ImsCallClient::GetCallRestriction(int32_t slotId, const std::string &fac)
554 {
555     if (ReConnectService() != TELEPHONY_SUCCESS) {
556         TELEPHONY_LOGE("ipc reconnect failed!");
557         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
558     }
559     return imsCallProxy_->GetCallRestriction(slotId, fac);
560 }
561 
SetCallWaiting(int32_t slotId,bool activate,int32_t classType)562 int32_t ImsCallClient::SetCallWaiting(int32_t slotId, bool activate, int32_t classType)
563 {
564     if (ReConnectService() != TELEPHONY_SUCCESS) {
565         TELEPHONY_LOGE("ipc reconnect failed!");
566         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
567     }
568     return imsCallProxy_->SetCallWaiting(slotId, activate, classType);
569 }
570 
GetCallWaiting(int32_t slotId)571 int32_t ImsCallClient::GetCallWaiting(int32_t slotId)
572 {
573     if (ReConnectService() != TELEPHONY_SUCCESS) {
574         TELEPHONY_LOGE("ipc reconnect failed!");
575         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
576     }
577     return imsCallProxy_->GetCallWaiting(slotId);
578 }
579 
SetColr(int32_t slotId,int32_t presentation)580 int32_t ImsCallClient::SetColr(int32_t slotId, int32_t presentation)
581 {
582     if (ReConnectService() != TELEPHONY_SUCCESS) {
583         TELEPHONY_LOGE("ipc reconnect failed!");
584         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
585     }
586     return imsCallProxy_->SetColr(slotId, presentation);
587 }
588 
GetColr(int32_t slotId)589 int32_t ImsCallClient::GetColr(int32_t slotId)
590 {
591     if (ReConnectService() != TELEPHONY_SUCCESS) {
592         TELEPHONY_LOGE("ipc reconnect failed!");
593         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
594     }
595     return imsCallProxy_->GetColr(slotId);
596 }
597 
SetColp(int32_t slotId,int32_t action)598 int32_t ImsCallClient::SetColp(int32_t slotId, int32_t action)
599 {
600     if (ReConnectService() != TELEPHONY_SUCCESS) {
601         TELEPHONY_LOGE("ipc reconnect failed!");
602         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
603     }
604     return imsCallProxy_->SetColp(slotId, action);
605 }
606 
GetColp(int32_t slotId)607 int32_t ImsCallClient::GetColp(int32_t slotId)
608 {
609     if (ReConnectService() != TELEPHONY_SUCCESS) {
610         TELEPHONY_LOGE("ipc reconnect failed!");
611         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
612     }
613     return imsCallProxy_->GetColp(slotId);
614 }
615 
ReConnectService()616 int32_t ImsCallClient::ReConnectService()
617 {
618     if (imsCallProxy_ == nullptr) {
619         TELEPHONY_LOGI("try to reconnect ims call service now...");
620         GetImsCallProxy();
621         if (imsCallProxy_ == nullptr) {
622             TELEPHONY_LOGE("Connect service failed");
623             return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
624         }
625     }
626     return TELEPHONY_SUCCESS;
627 }
628 
Clean()629 void ImsCallClient::Clean()
630 {
631     Utils::UniqueWriteGuard<Utils::RWLock> guard(rwClientLock_);
632     if (imsCoreServiceProxy_ != nullptr) {
633         imsCoreServiceProxy_.clear();
634         imsCoreServiceProxy_ = nullptr;
635     }
636     if (imsCallProxy_ != nullptr) {
637         imsCallProxy_.clear();
638         imsCallProxy_ = nullptr;
639     }
640     if (imsCallCallback_ != nullptr) {
641         imsCallCallback_.clear();
642         imsCallCallback_ = nullptr;
643     }
644 }
645 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)646 void ImsCallClient::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId,
647     const std::string& deviceId)
648 {
649     TELEPHONY_LOGI("SA:%{public}d is added!", systemAbilityId);
650     if (!CheckInputSysAbilityId(systemAbilityId)) {
651         TELEPHONY_LOGE("add SA:%{public}d is invalid!", systemAbilityId);
652         return;
653     }
654 
655     auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
656     if (imsCallClient->IsConnect()) {
657         TELEPHONY_LOGE("SA:%{public}d already connected!", systemAbilityId);
658         return;
659     }
660 
661     imsCallClient->Clean();
662     int32_t res = imsCallClient->ReConnectService();
663     if (res != TELEPHONY_SUCCESS) {
664         TELEPHONY_LOGE("SA:%{public}d reconnect service failed!", systemAbilityId);
665         return;
666     }
667     TELEPHONY_LOGI("SA:%{public}d reconnect service successfully!", systemAbilityId);
668 }
669 
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)670 void ImsCallClient::SystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId,
671     const std::string& deviceId)
672 {
673     TELEPHONY_LOGI("SA:%{public}d is removed!", systemAbilityId);
674     auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
675     if (!imsCallClient->IsConnect()) {
676         return;
677     }
678 
679     imsCallClient->Clean();
680 }
681 
UpdateImsCapabilities(int32_t slotId,const ImsCapabilityList & imsCapabilityList)682 int32_t ImsCallClient::UpdateImsCapabilities(int32_t slotId, const ImsCapabilityList &imsCapabilityList)
683 {
684     if (ReConnectService() != TELEPHONY_SUCCESS) {
685         TELEPHONY_LOGE("ipc reconnect failed!");
686         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
687     }
688     return imsCallProxy_->UpdateImsCapabilities(slotId, imsCapabilityList);
689 }
690 } // namespace Telephony
691 } // namespace OHOS
692