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