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 "cellular_call_connection.h"
17
18 #include <thread>
19
20 #include "call_manager_errors.h"
21 #include "call_manager_hisysevent.h"
22 #include "cellular_call_proxy.h"
23 #include "iservice_registry.h"
24 #include "system_ability.h"
25 #include "system_ability_definition.h"
26 #include "telephony_log_wrapper.h"
27
28 namespace OHOS {
29 namespace Telephony {
30 #ifdef RECONNECT_MAX_TRY_COUNT
31 constexpr uint16_t CONNECT_MAX_TRY_COUNT = 5;
32 #endif
33 constexpr uint16_t DELAY_TIME = 10;
34
CellularCallConnection()35 CellularCallConnection::CellularCallConnection()
36 : systemAbilityId_(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID), cellularCallCallbackPtr_(nullptr),
37 cellularCallInterfacePtr_(nullptr), connectState_(false)
38 {}
39
~CellularCallConnection()40 CellularCallConnection::~CellularCallConnection()
41 {
42 UnInit();
43 }
44
Init(int32_t systemAbilityId)45 void CellularCallConnection::Init(int32_t systemAbilityId)
46 {
47 TELEPHONY_LOGI("CellularCallConnection Init start");
48 if (connectState_) {
49 TELEPHONY_LOGE("Init, connectState is true");
50 return;
51 }
52 systemAbilityId_ = systemAbilityId;
53 ConnectService();
54
55 statusChangeListener_ = new (std::nothrow) SystemAbilityListener();
56 if (statusChangeListener_ == nullptr) {
57 TELEPHONY_LOGE("Init, failed to create statusChangeListener.");
58 return;
59 }
60 auto managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
61 if (managerPtr == nullptr) {
62 TELEPHONY_LOGE("Init, get system ability manager error.");
63 return;
64 }
65 int32_t ret = managerPtr->SubscribeSystemAbility(systemAbilityId_, statusChangeListener_);
66 if (ret != TELEPHONY_SUCCESS) {
67 TELEPHONY_LOGE("Init, failed to subscribe sa:%{public}d", systemAbilityId_);
68 return;
69 }
70
71 TELEPHONY_LOGI("connected to cellular call service successfully!");
72 }
73
UnInit()74 void CellularCallConnection::UnInit()
75 {
76 DisconnectService();
77 if (statusChangeListener_ != nullptr) {
78 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
79 if (samgrProxy != nullptr) {
80 samgrProxy->UnSubscribeSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID, statusChangeListener_);
81 statusChangeListener_ = nullptr;
82 }
83 }
84 }
85
IsConnect() const86 bool CellularCallConnection::IsConnect() const
87 {
88 return connectState_;
89 }
90
ConnectService()91 int32_t CellularCallConnection::ConnectService()
92 {
93 Utils::UniqueWriteGuard<Utils::RWLock> guard(rwClientLock_);
94 if (cellularCallInterfacePtr_ != nullptr) {
95 return TELEPHONY_SUCCESS;
96 }
97 sptr<ISystemAbilityManager> managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
98 if (managerPtr == nullptr) {
99 return TELEPHONY_ERR_LOCAL_PTR_NULL;
100 }
101 sptr<CellularCallInterface> cellularCallInterfacePtr = nullptr;
102 sptr<IRemoteObject> iRemoteObjectPtr = managerPtr->GetSystemAbility(systemAbilityId_);
103 if (iRemoteObjectPtr == nullptr) {
104 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
105 }
106 cellularCallInterfacePtr = iface_cast<CellularCallInterface>(iRemoteObjectPtr);
107 if (!cellularCallInterfacePtr) {
108 return TELEPHONY_ERR_LOCAL_PTR_NULL;
109 }
110
111 cellularCallInterfacePtr_ = cellularCallInterfacePtr;
112 int32_t ret = RegisterCallBackFun();
113 if (ret != TELEPHONY_SUCCESS) {
114 return ret;
115 }
116 connectState_ = true;
117 return TELEPHONY_SUCCESS;
118 }
119
RegisterCallBackFun()120 int32_t CellularCallConnection::RegisterCallBackFun()
121 {
122 if (cellularCallInterfacePtr_ == nullptr) {
123 TELEPHONY_LOGE("cellularCallInterfacePtr_ is nullptr!");
124 return TELEPHONY_ERR_LOCAL_PTR_NULL;
125 }
126 cellularCallCallbackPtr_ = (std::make_unique<CallStatusCallback>()).release();
127 if (cellularCallCallbackPtr_ == nullptr) {
128 Clean();
129 TELEPHONY_LOGE("cellularCallCallbackPtr_ is nullptr!");
130 return TELEPHONY_ERR_LOCAL_PTR_NULL;
131 }
132 int32_t ret = cellularCallInterfacePtr_->RegisterCallManagerCallBack(cellularCallCallbackPtr_);
133 if (ret != TELEPHONY_SUCCESS) {
134 Clean();
135 return TELEPHONY_ERR_REGISTER_CALLBACK_FAIL;
136 }
137 return TELEPHONY_SUCCESS;
138 }
139
DisconnectService()140 void CellularCallConnection::DisconnectService()
141 {
142 Clean();
143 }
144
ReConnectService()145 int32_t CellularCallConnection::ReConnectService()
146 {
147 #ifdef ABILITY_CELLULAR_SUPPORT
148 if (cellularCallInterfacePtr_ == nullptr) {
149 TELEPHONY_LOGI("try to reconnect cellular call service now...");
150 int32_t result = ConnectService();
151 if (result != TELEPHONY_SUCCESS) {
152 TELEPHONY_LOGE("Connect service: %{public}d", result);
153 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
154 }
155 }
156 #endif
157 return TELEPHONY_SUCCESS;
158 }
159
Clean()160 void CellularCallConnection::Clean()
161 {
162 Utils::UniqueWriteGuard<Utils::RWLock> guard(rwClientLock_);
163 UnRegisterCallBack();
164 if (cellularCallInterfacePtr_ != nullptr) {
165 cellularCallInterfacePtr_.clear();
166 cellularCallInterfacePtr_ = nullptr;
167 }
168
169 if (cellularCallCallbackPtr_ != nullptr) {
170 cellularCallCallbackPtr_.clear();
171 cellularCallCallbackPtr_ = nullptr;
172 }
173
174 connectState_ = false;
175 }
176
Dial(const CellularCallInfo & callInfo)177 int CellularCallConnection::Dial(const CellularCallInfo &callInfo)
178 {
179 if (ReConnectService() != TELEPHONY_SUCCESS) {
180 TELEPHONY_LOGE("ipc reconnect failed!");
181 CallManagerHisysevent::WriteDialCallFaultEvent(callInfo.accountId, static_cast<int32_t>(callInfo.callType),
182 callInfo.videoState, TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL, "ReConnectService failed");
183 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
184 }
185 TELEPHONY_LOGI("callType:%{public}d", callInfo.callType);
186 int errCode = cellularCallInterfacePtr_->Dial(callInfo);
187 if (errCode != TELEPHONY_SUCCESS) {
188 TELEPHONY_LOGE("dial failed, errcode:%{public}d", errCode);
189 return errCode;
190 }
191 return TELEPHONY_SUCCESS;
192 }
193
HangUp(const CellularCallInfo & callInfo,CallSupplementType type)194 int CellularCallConnection::HangUp(const CellularCallInfo &callInfo, CallSupplementType type)
195 {
196 if (ReConnectService() != TELEPHONY_SUCCESS) {
197 TELEPHONY_LOGE("ipc reconnect failed!");
198 CallManagerHisysevent::WriteHangUpFaultEvent(
199 callInfo.accountId, callInfo.callId, TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL, "HangUp ipc reconnect failed");
200 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
201 }
202 int errCode = cellularCallInterfacePtr_->HangUp(callInfo, type);
203 if (errCode != TELEPHONY_SUCCESS) {
204 TELEPHONY_LOGE("hangup call failed, errcode:%{public}d", errCode);
205 return errCode;
206 }
207 return TELEPHONY_SUCCESS;
208 }
209
Reject(const CellularCallInfo & callInfo)210 int CellularCallConnection::Reject(const CellularCallInfo &callInfo)
211 {
212 if (ReConnectService() != TELEPHONY_SUCCESS) {
213 TELEPHONY_LOGE("ipc reconnect failed!");
214 CallManagerHisysevent::WriteHangUpFaultEvent(
215 callInfo.accountId, callInfo.callId, TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL, "Reject ipc reconnect failed");
216 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
217 }
218 int errCode = cellularCallInterfacePtr_->Reject(callInfo);
219 if (errCode != TELEPHONY_SUCCESS) {
220 TELEPHONY_LOGE("rejecting call failed, errcode:%{public}d", errCode);
221 return errCode;
222 }
223 return TELEPHONY_SUCCESS;
224 }
225
Answer(const CellularCallInfo & callInfo)226 int CellularCallConnection::Answer(const CellularCallInfo &callInfo)
227 {
228 if (ReConnectService() != TELEPHONY_SUCCESS) {
229 TELEPHONY_LOGE("ipc reconnect failed!");
230 CallManagerHisysevent::WriteAnswerCallFaultEvent(callInfo.accountId, callInfo.callId, callInfo.videoState,
231 TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL, "ipc reconnect failed");
232 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
233 }
234 int errCode = cellularCallInterfacePtr_->Answer(callInfo);
235 if (errCode != TELEPHONY_SUCCESS) {
236 TELEPHONY_LOGE("answering call failed, errcode:%{public}d", errCode);
237 return errCode;
238 }
239 return TELEPHONY_SUCCESS;
240 }
241
HoldCall(const CellularCallInfo & callInfo)242 int CellularCallConnection::HoldCall(const CellularCallInfo &callInfo)
243 {
244 if (ReConnectService() != TELEPHONY_SUCCESS) {
245 TELEPHONY_LOGE("ipc reconnect failed!");
246 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
247 }
248 int errCode = cellularCallInterfacePtr_->HoldCall(callInfo);
249 if (errCode != TELEPHONY_SUCCESS) {
250 TELEPHONY_LOGE("holding call failed, errcode:%{public}d", errCode);
251 return errCode;
252 }
253 return TELEPHONY_SUCCESS;
254 }
255
UnHoldCall(const CellularCallInfo & callInfo)256 int CellularCallConnection::UnHoldCall(const CellularCallInfo &callInfo)
257 {
258 if (ReConnectService() != TELEPHONY_SUCCESS) {
259 TELEPHONY_LOGE("ipc reconnect failed!");
260 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
261 }
262 int errCode = cellularCallInterfacePtr_->UnHoldCall(callInfo);
263 if (errCode != TELEPHONY_SUCCESS) {
264 TELEPHONY_LOGE("unhold call failed, errcode:%{public}d", errCode);
265 return errCode;
266 }
267 return TELEPHONY_SUCCESS;
268 }
269
SwitchCall(const CellularCallInfo & callInfo)270 int CellularCallConnection::SwitchCall(const CellularCallInfo &callInfo)
271 {
272 if (ReConnectService() != TELEPHONY_SUCCESS) {
273 TELEPHONY_LOGE("ipc reconnect failed!");
274 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
275 }
276 int errCode = cellularCallInterfacePtr_->SwitchCall(callInfo);
277 if (errCode != TELEPHONY_SUCCESS) {
278 TELEPHONY_LOGE("switch call failed, errcode:%{public}d", errCode);
279 return errCode;
280 }
281 return TELEPHONY_SUCCESS;
282 }
283
IsEmergencyPhoneNumber(const std::string & phoneNum,int32_t slotId,bool & enabled)284 int CellularCallConnection::IsEmergencyPhoneNumber(const std::string &phoneNum, int32_t slotId, bool &enabled)
285 {
286 if (ReConnectService() != TELEPHONY_SUCCESS) {
287 TELEPHONY_LOGE("ipc reconnect failed!");
288 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
289 }
290 return cellularCallInterfacePtr_->IsEmergencyPhoneNumber(slotId, phoneNum, enabled);
291 }
292
CombineConference(const CellularCallInfo & callInfo)293 int CellularCallConnection::CombineConference(const CellularCallInfo &callInfo)
294 {
295 if (ReConnectService() != TELEPHONY_SUCCESS) {
296 TELEPHONY_LOGE("ipc reconnect failed!");
297 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
298 }
299 int errCode = cellularCallInterfacePtr_->CombineConference(callInfo);
300 if (errCode != TELEPHONY_SUCCESS) {
301 TELEPHONY_LOGE("combine conference failed, errcode:%{public}d", errCode);
302 return errCode;
303 }
304 return TELEPHONY_SUCCESS;
305 }
306
SeparateConference(const CellularCallInfo & callInfo)307 int CellularCallConnection::SeparateConference(const CellularCallInfo &callInfo)
308 {
309 if (ReConnectService() != TELEPHONY_SUCCESS) {
310 TELEPHONY_LOGE("ipc reconnect failed!");
311 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
312 }
313 int errCode = cellularCallInterfacePtr_->SeparateConference(callInfo);
314 if (errCode != TELEPHONY_SUCCESS) {
315 TELEPHONY_LOGE("separate conference failed, errcode:%{public}d", errCode);
316 return errCode;
317 }
318 return TELEPHONY_SUCCESS;
319 }
320
KickOutFromConference(const CellularCallInfo & callInfo)321 int CellularCallConnection::KickOutFromConference(const CellularCallInfo &callInfo)
322 {
323 if (ReConnectService() != TELEPHONY_SUCCESS) {
324 TELEPHONY_LOGE("ipc reconnect failed!");
325 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
326 }
327 int errCode = cellularCallInterfacePtr_->KickOutFromConference(callInfo);
328 if (errCode != TELEPHONY_SUCCESS) {
329 TELEPHONY_LOGE("Kick out from conference failed, errcode:%{public}d", errCode);
330 return errCode;
331 }
332 return TELEPHONY_SUCCESS;
333 }
334
StartDtmf(char cDTMFCode,const CellularCallInfo & callInfo)335 int CellularCallConnection::StartDtmf(char cDTMFCode, const CellularCallInfo &callInfo)
336 {
337 if (ReConnectService() != TELEPHONY_SUCCESS) {
338 TELEPHONY_LOGE("ipc reconnect failed!");
339 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
340 }
341 int errCode = cellularCallInterfacePtr_->StartDtmf(cDTMFCode, callInfo);
342 if (errCode != TELEPHONY_SUCCESS) {
343 TELEPHONY_LOGE("start dtmf failed, errcode:%{public}d", errCode);
344 return errCode;
345 }
346 return TELEPHONY_SUCCESS;
347 }
348
StopDtmf(const CellularCallInfo & callInfo)349 int CellularCallConnection::StopDtmf(const CellularCallInfo &callInfo)
350 {
351 if (ReConnectService() != TELEPHONY_SUCCESS) {
352 TELEPHONY_LOGE("ipc reconnect failed!");
353 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
354 }
355 int errCode = cellularCallInterfacePtr_->StopDtmf(callInfo);
356 if (errCode != TELEPHONY_SUCCESS) {
357 TELEPHONY_LOGE("stop dtmf failed, errcode:%{public}d", errCode);
358 return errCode;
359 }
360 return TELEPHONY_SUCCESS;
361 }
362
PostDialProceed(const CellularCallInfo & callInfo,const bool proceed)363 int CellularCallConnection::PostDialProceed(const CellularCallInfo &callInfo, const bool proceed)
364 {
365 if (ReConnectService() != TELEPHONY_SUCCESS) {
366 TELEPHONY_LOGE("ipc reconnect failed!");
367 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
368 }
369 int errCode = cellularCallInterfacePtr_->PostDialProceed(callInfo, proceed);
370 if (errCode != TELEPHONY_SUCCESS) {
371 TELEPHONY_LOGE("post dial continue failed, errcode:%{public}d", errCode);
372 return errCode;
373 }
374 return TELEPHONY_SUCCESS;
375 }
376
SendDtmf(char cDTMFCode,const std::string & phoneNum)377 int CellularCallConnection::SendDtmf(char cDTMFCode, const std::string &phoneNum)
378 {
379 if (ReConnectService() != TELEPHONY_SUCCESS) {
380 TELEPHONY_LOGE("ipc reconnect failed!");
381 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
382 }
383 CellularCallInfo callInfo;
384 if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
385 TELEPHONY_LOGE("send dtmf return, memset_s failed.");
386 return TELEPHONY_ERR_MEMSET_FAIL;
387 }
388 if (phoneNum.length() + 1 > static_cast<size_t>(kMaxNumberLen)) {
389 return TELEPHONY_ERR_STRCPY_FAIL;
390 }
391 if (strcpy_s(callInfo.phoneNum, strlen(phoneNum.c_str()) + 1, phoneNum.c_str()) != EOK) {
392 TELEPHONY_LOGE("send dtmf return, strcpy_s fail.");
393 return TELEPHONY_ERR_STRCPY_FAIL;
394 }
395 int errCode = cellularCallInterfacePtr_->SendDtmf(cDTMFCode, callInfo);
396 if (errCode != TELEPHONY_SUCCESS) {
397 TELEPHONY_LOGE("send dtmf failed, errcode:%{public}d", errCode);
398 return errCode;
399 }
400 return TELEPHONY_SUCCESS;
401 }
402
SendDtmfString(const std::string & dtmfCodeStr,const std::string & phoneNum,PhoneNetType phoneNetType,int32_t switchOn,int32_t switchOff)403 int CellularCallConnection::SendDtmfString(const std::string &dtmfCodeStr, const std::string &phoneNum,
404 PhoneNetType phoneNetType, int32_t switchOn, int32_t switchOff)
405 {
406 if (ReConnectService() != TELEPHONY_SUCCESS) {
407 TELEPHONY_LOGE("ipc reconnect failed!");
408 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
409 }
410 return TELEPHONY_SUCCESS;
411 }
412
SetCallTransferInfo(const CallTransferInfo & info,int32_t slotId)413 int CellularCallConnection::SetCallTransferInfo(const CallTransferInfo &info, int32_t slotId)
414 {
415 if (ReConnectService() != TELEPHONY_SUCCESS) {
416 TELEPHONY_LOGE("ipc reconnect failed!");
417 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
418 }
419 return cellularCallInterfacePtr_->SetCallTransferInfo(slotId, info);
420 }
421
CanSetCallTransferTime(int32_t slotId,bool & result)422 int CellularCallConnection::CanSetCallTransferTime(int32_t slotId, bool &result)
423 {
424 if (ReConnectService() != TELEPHONY_SUCCESS) {
425 TELEPHONY_LOGE("[slot%{public}d] ipc reconnect failed!", slotId);
426 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
427 }
428 return cellularCallInterfacePtr_->CanSetCallTransferTime(slotId, result);
429 }
430
GetCallTransferInfo(CallTransferType type,int32_t slotId)431 int CellularCallConnection::GetCallTransferInfo(CallTransferType type, int32_t slotId)
432 {
433 if (ReConnectService() != TELEPHONY_SUCCESS) {
434 TELEPHONY_LOGE("ipc reconnect failed!");
435 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
436 }
437 return cellularCallInterfacePtr_->GetCallTransferInfo(slotId, type);
438 }
439
SetCallWaiting(bool activate,int32_t slotId)440 int CellularCallConnection::SetCallWaiting(bool activate, int32_t slotId)
441 {
442 if (ReConnectService() != TELEPHONY_SUCCESS) {
443 TELEPHONY_LOGE("ipc reconnect failed!");
444 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
445 }
446 int errCode = cellularCallInterfacePtr_->SetCallWaiting(slotId, activate);
447 if (errCode != TELEPHONY_SUCCESS) {
448 TELEPHONY_LOGE("SetCallWaiting failed, errcode:%{public}d", errCode);
449 return errCode;
450 }
451 return TELEPHONY_SUCCESS;
452 }
453
GetCallWaiting(int32_t slotId)454 int CellularCallConnection::GetCallWaiting(int32_t slotId)
455 {
456 if (ReConnectService() != TELEPHONY_SUCCESS) {
457 TELEPHONY_LOGE("ipc reconnect failed!");
458 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
459 }
460 int errCode = cellularCallInterfacePtr_->GetCallWaiting(slotId);
461 if (errCode != TELEPHONY_SUCCESS) {
462 TELEPHONY_LOGE("GetCallWaiting failed, errcode:%{public}d", errCode);
463 return errCode;
464 }
465 return TELEPHONY_SUCCESS;
466 }
467
SetCallRestriction(const CallRestrictionInfo & info,int32_t slotId)468 int CellularCallConnection::SetCallRestriction(const CallRestrictionInfo &info, int32_t slotId)
469 {
470 if (ReConnectService() != TELEPHONY_SUCCESS) {
471 TELEPHONY_LOGE("ipc reconnect failed!");
472 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
473 }
474 return cellularCallInterfacePtr_->SetCallRestriction(slotId, info);
475 }
476
GetCallRestriction(CallRestrictionType facType,int32_t slotId)477 int CellularCallConnection::GetCallRestriction(CallRestrictionType facType, int32_t slotId)
478 {
479 if (ReConnectService() != TELEPHONY_SUCCESS) {
480 TELEPHONY_LOGE("ipc reconnect failed!");
481 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
482 }
483 return cellularCallInterfacePtr_->GetCallRestriction(slotId, facType);
484 }
485
SetCallRestrictionPassword(int32_t slotId,CallRestrictionType fac,const char * oldPassword,const char * newPassword)486 int CellularCallConnection::SetCallRestrictionPassword(
487 int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword)
488 {
489 if (ReConnectService() != TELEPHONY_SUCCESS) {
490 TELEPHONY_LOGE("ipc reconnect failed!");
491 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
492 }
493 return cellularCallInterfacePtr_->SetCallRestrictionPassword(slotId, fac, oldPassword, newPassword);
494 }
495
SetCallPreferenceMode(int32_t slotId,int32_t mode)496 int CellularCallConnection::SetCallPreferenceMode(int32_t slotId, int32_t mode)
497 {
498 if (ReConnectService() != TELEPHONY_SUCCESS) {
499 TELEPHONY_LOGE("ipc reconnect failed!");
500 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
501 }
502 int errCode = cellularCallInterfacePtr_->SetDomainPreferenceMode(slotId, mode);
503 if (errCode != TELEPHONY_SUCCESS) {
504 TELEPHONY_LOGE("SetCallPreferenceMode failed, errcode:%{public}d", errCode);
505 return errCode;
506 }
507 return TELEPHONY_SUCCESS;
508 }
509
StartRtt(const CellularCallInfo & callInfo,std::u16string & msg)510 int CellularCallConnection::StartRtt(const CellularCallInfo &callInfo, std::u16string &msg)
511 {
512 if (ReConnectService() != TELEPHONY_SUCCESS) {
513 TELEPHONY_LOGE("ipc reconnect failed!");
514 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
515 }
516 int32_t slotId = callInfo.slotId;
517 int errCode = cellularCallInterfacePtr_->StartRtt(slotId, Str16ToStr8(msg));
518 if (errCode != TELEPHONY_SUCCESS) {
519 TELEPHONY_LOGE("StartRtt failed, errcode:%{public}d", errCode);
520 return errCode;
521 }
522 return TELEPHONY_SUCCESS;
523 }
524
StopRtt(const CellularCallInfo & callInfo)525 int CellularCallConnection::StopRtt(const CellularCallInfo &callInfo)
526 {
527 if (ReConnectService() != TELEPHONY_SUCCESS) {
528 TELEPHONY_LOGE("ipc reconnect failed!");
529 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
530 }
531 int32_t slotId = callInfo.slotId;
532 int errCode = cellularCallInterfacePtr_->StopRtt(slotId);
533 if (errCode != TELEPHONY_SUCCESS) {
534 TELEPHONY_LOGE("StopRtt failed, errcode:%{public}d", errCode);
535 return errCode;
536 }
537 return TELEPHONY_SUCCESS;
538 }
539
RegisterCallBack(const sptr<ICallStatusCallback> & callback)540 int CellularCallConnection::RegisterCallBack(const sptr<ICallStatusCallback> &callback)
541 {
542 if (ReConnectService() != TELEPHONY_SUCCESS) {
543 TELEPHONY_LOGE("ipc reconnect failed!");
544 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
545 }
546 int errCode = cellularCallInterfacePtr_->RegisterCallManagerCallBack(callback);
547 if (errCode != TELEPHONY_SUCCESS) {
548 TELEPHONY_LOGE("registerCallBack failed, errcode:%{public}d", errCode);
549 return errCode;
550 }
551 return TELEPHONY_SUCCESS;
552 }
553
UnRegisterCallBack()554 int32_t CellularCallConnection::UnRegisterCallBack()
555 {
556 if (cellularCallInterfacePtr_ == nullptr) {
557 TELEPHONY_LOGE("cellularCallInterfacePtr_ is nullptr!");
558 return TELEPHONY_ERR_LOCAL_PTR_NULL;
559 }
560 int errCode = cellularCallInterfacePtr_->UnRegisterCallManagerCallBack();
561 if (errCode != TELEPHONY_SUCCESS) {
562 TELEPHONY_LOGE("UnRegisterCallBack failed, errcode:%{public}d", errCode);
563 return errCode;
564 }
565 return TELEPHONY_SUCCESS;
566 }
567
ControlCamera(std::u16string cameraId,int32_t callingUid,int32_t callingPid)568 int32_t CellularCallConnection::ControlCamera(std::u16string cameraId, int32_t callingUid, int32_t callingPid)
569 {
570 if (ReConnectService() != TELEPHONY_SUCCESS) {
571 TELEPHONY_LOGE("ipc reconnect failed!");
572 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
573 }
574 int errCode = cellularCallInterfacePtr_->CtrlCamera(cameraId, callingUid, callingPid);
575 if (errCode != TELEPHONY_SUCCESS) {
576 TELEPHONY_LOGE("cellularCallInterface CtrlCamera failed, errcode:%{public}d", errCode);
577 return errCode;
578 }
579 return TELEPHONY_SUCCESS;
580 }
SetPreviewWindow(VideoWindow & window)581 int32_t CellularCallConnection::SetPreviewWindow(VideoWindow &window)
582 {
583 if (ReConnectService() != TELEPHONY_SUCCESS) {
584 TELEPHONY_LOGE("ipc reconnect failed!");
585 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
586 }
587 int errCode =
588 cellularCallInterfacePtr_->SetPreviewWindow(window.x, window.y, window.z, window.width, window.height);
589 if (errCode != TELEPHONY_SUCCESS) {
590 TELEPHONY_LOGE("SetPreviewWindow failed, errcode:%{public}d", errCode);
591 return errCode;
592 }
593 return TELEPHONY_SUCCESS;
594 }
595
SetDisplayWindow(VideoWindow & window)596 int32_t CellularCallConnection::SetDisplayWindow(VideoWindow &window)
597 {
598 if (ReConnectService() != TELEPHONY_SUCCESS) {
599 TELEPHONY_LOGE("ipc reconnect failed!");
600 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
601 }
602 int errCode =
603 cellularCallInterfacePtr_->SetDisplayWindow(window.x, window.y, window.z, window.width, window.height);
604 if (errCode != TELEPHONY_SUCCESS) {
605 TELEPHONY_LOGE("SetDisplayWindow failed, errcode:%{public}d", errCode);
606 return errCode;
607 }
608 return TELEPHONY_SUCCESS;
609 }
610
SetCameraZoom(float zoomRatio)611 int32_t CellularCallConnection::SetCameraZoom(float zoomRatio)
612 {
613 if (ReConnectService() != TELEPHONY_SUCCESS) {
614 TELEPHONY_LOGE("ipc reconnect failed!");
615 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
616 }
617 int errCode = cellularCallInterfacePtr_->SetCameraZoom(zoomRatio);
618 if (errCode != TELEPHONY_SUCCESS) {
619 TELEPHONY_LOGE("SetCameraZoom failed, errcode:%{public}d", errCode);
620 return errCode;
621 }
622 return TELEPHONY_SUCCESS;
623 }
624
SetPausePicture(std::u16string path)625 int32_t CellularCallConnection::SetPausePicture(std::u16string path)
626 {
627 if (ReConnectService() != TELEPHONY_SUCCESS) {
628 TELEPHONY_LOGE("ipc reconnect failed!");
629 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
630 }
631 int errCode = cellularCallInterfacePtr_->SetPauseImage(path);
632 if (errCode != TELEPHONY_SUCCESS) {
633 TELEPHONY_LOGE("SetPauseImage failed, errcode:%{public}d", errCode);
634 return errCode;
635 }
636 return TELEPHONY_SUCCESS;
637 }
638
SetDeviceDirection(int32_t rotation)639 int32_t CellularCallConnection::SetDeviceDirection(int32_t rotation)
640 {
641 if (ReConnectService() != TELEPHONY_SUCCESS) {
642 TELEPHONY_LOGE("ipc reconnect failed!");
643 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
644 }
645 int errCode = cellularCallInterfacePtr_->SetDeviceDirection(rotation);
646 if (errCode != TELEPHONY_SUCCESS) {
647 TELEPHONY_LOGE("SetDeviceDirection failed, errcode:%{public}d", errCode);
648 return errCode;
649 }
650 return TELEPHONY_SUCCESS;
651 }
652
SetImsSwitchStatus(int32_t slotId,bool active)653 int32_t CellularCallConnection::SetImsSwitchStatus(int32_t slotId, bool active)
654 {
655 if (ReConnectService() != TELEPHONY_SUCCESS) {
656 TELEPHONY_LOGE("ipc reconnect failed!");
657 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
658 }
659 int errCode = cellularCallInterfacePtr_->SetImsSwitchStatus(slotId, active);
660 if (errCode != TELEPHONY_SUCCESS) {
661 TELEPHONY_LOGE("SetImsSwitchStatus failed, errcode:%{public}d", errCode);
662 return errCode;
663 }
664 return TELEPHONY_SUCCESS;
665 }
666
GetImsSwitchStatus(int32_t slotId,bool & enabled)667 int32_t CellularCallConnection::GetImsSwitchStatus(int32_t slotId, bool &enabled)
668 {
669 if (ReConnectService() != TELEPHONY_SUCCESS) {
670 TELEPHONY_LOGE("ipc reconnect failed!");
671 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
672 }
673 int errCode = cellularCallInterfacePtr_->GetImsSwitchStatus(slotId, enabled);
674 if (errCode != TELEPHONY_SUCCESS) {
675 TELEPHONY_LOGE("GetImsSwitchStatus failed, errcode:%{public}d", errCode);
676 return errCode;
677 }
678 return TELEPHONY_SUCCESS;
679 }
680
SetVoNRState(int32_t slotId,int32_t state)681 int32_t CellularCallConnection::SetVoNRState(int32_t slotId, int32_t state)
682 {
683 if (ReConnectService() != TELEPHONY_SUCCESS) {
684 TELEPHONY_LOGE("ipc reconnect failed!");
685 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
686 }
687 int errCode = cellularCallInterfacePtr_->SetVoNRState(slotId, state);
688 if (errCode != TELEPHONY_SUCCESS) {
689 TELEPHONY_LOGE("SetVoNRState failed, errcode:%{public}d", errCode);
690 return errCode;
691 }
692 return TELEPHONY_SUCCESS;
693 }
694
GetVoNRState(int32_t slotId,int32_t & state)695 int32_t CellularCallConnection::GetVoNRState(int32_t slotId, int32_t &state)
696 {
697 if (ReConnectService() != TELEPHONY_SUCCESS) {
698 TELEPHONY_LOGE("ipc reconnect failed!");
699 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
700 }
701 int errCode = cellularCallInterfacePtr_->GetVoNRState(slotId, state);
702 if (errCode != TELEPHONY_SUCCESS) {
703 TELEPHONY_LOGE("GetVoNRState failed, errcode:%{public}d", errCode);
704 return errCode;
705 }
706 return TELEPHONY_SUCCESS;
707 }
708
SendUpdateCallMediaModeRequest(const CellularCallInfo & callInfo,ImsCallMode mode)709 int32_t CellularCallConnection::SendUpdateCallMediaModeRequest(const CellularCallInfo &callInfo, ImsCallMode mode)
710 {
711 if (ReConnectService() != TELEPHONY_SUCCESS) {
712 TELEPHONY_LOGE("ipc reconnect failed!");
713 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
714 }
715 int errCode = cellularCallInterfacePtr_->UpdateImsCallMode(callInfo, mode);
716 if (errCode != TELEPHONY_SUCCESS) {
717 TELEPHONY_LOGE("send media modify request failed, errcode:%{public}d", errCode);
718 return errCode;
719 }
720 return TELEPHONY_SUCCESS;
721 }
722
SetImsConfig(ImsConfigItem item,const std::string & value,int32_t slotId)723 int32_t CellularCallConnection::SetImsConfig(ImsConfigItem item, const std::string &value, int32_t slotId)
724 {
725 if (ReConnectService() != TELEPHONY_SUCCESS) {
726 TELEPHONY_LOGE("ipc reconnect failed!");
727 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
728 }
729 int errCode = cellularCallInterfacePtr_->SetImsConfig(slotId, item, value);
730 if (errCode != TELEPHONY_SUCCESS) {
731 TELEPHONY_LOGE("SetImsConfig for string value failed, errcode:%{public}d", errCode);
732 return errCode;
733 }
734 return TELEPHONY_SUCCESS;
735 }
736
SetImsConfig(ImsConfigItem item,int32_t value,int32_t slotId)737 int32_t CellularCallConnection::SetImsConfig(ImsConfigItem item, int32_t value, int32_t slotId)
738 {
739 if (ReConnectService() != TELEPHONY_SUCCESS) {
740 TELEPHONY_LOGE("ipc reconnect failed!");
741 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
742 }
743 int errCode = cellularCallInterfacePtr_->SetImsConfig(slotId, item, value);
744 if (errCode != TELEPHONY_SUCCESS) {
745 TELEPHONY_LOGE("SetImsConfig for int value failed, errcode:%{public}d", errCode);
746 return errCode;
747 }
748 return TELEPHONY_SUCCESS;
749 }
750
GetImsConfig(ImsConfigItem item,int32_t slotId)751 int32_t CellularCallConnection::GetImsConfig(ImsConfigItem item, int32_t slotId)
752 {
753 if (ReConnectService() != TELEPHONY_SUCCESS) {
754 TELEPHONY_LOGE("ipc reconnect failed!");
755 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
756 }
757 int errCode = cellularCallInterfacePtr_->GetImsConfig(slotId, item);
758 if (errCode != TELEPHONY_SUCCESS) {
759 TELEPHONY_LOGE("GetImsConfig failed, errcode:%{public}d", errCode);
760 return errCode;
761 }
762 return TELEPHONY_SUCCESS;
763 }
764
SetImsFeatureValue(FeatureType type,int32_t value,int32_t slotId)765 int32_t CellularCallConnection::SetImsFeatureValue(FeatureType type, int32_t value, int32_t slotId)
766 {
767 if (ReConnectService() != TELEPHONY_SUCCESS) {
768 TELEPHONY_LOGE("ipc reconnect failed!");
769 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
770 }
771 int errCode = cellularCallInterfacePtr_->SetImsFeatureValue(slotId, type, value);
772 if (errCode != TELEPHONY_SUCCESS) {
773 TELEPHONY_LOGE("SetImsFeatureValue failed, errcode:%{public}d", errCode);
774 return errCode;
775 }
776 return TELEPHONY_SUCCESS;
777 }
778
GetImsFeatureValue(FeatureType type,int32_t slotId)779 int32_t CellularCallConnection::GetImsFeatureValue(FeatureType type, int32_t slotId)
780 {
781 if (ReConnectService() != TELEPHONY_SUCCESS) {
782 TELEPHONY_LOGE("ipc reconnect failed!");
783 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
784 }
785 int errCode = cellularCallInterfacePtr_->GetImsFeatureValue(slotId, type);
786 if (errCode != TELEPHONY_SUCCESS) {
787 TELEPHONY_LOGE("GetImsFeatureValue failed, errcode:%{public}d", errCode);
788 return errCode;
789 }
790 return TELEPHONY_SUCCESS;
791 }
792
InviteToConference(const std::vector<std::string> & numberList,int32_t slotId)793 int32_t CellularCallConnection::InviteToConference(const std::vector<std::string> &numberList, int32_t slotId)
794 {
795 if (ReConnectService() != TELEPHONY_SUCCESS) {
796 TELEPHONY_LOGE("ipc reconnect failed!");
797 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
798 }
799 int errCode = cellularCallInterfacePtr_->InviteToConference(slotId, numberList);
800 if (errCode != TELEPHONY_SUCCESS) {
801 TELEPHONY_LOGE("InviteToConference failed, errcode:%{public}d", errCode);
802 return errCode;
803 }
804 return TELEPHONY_SUCCESS;
805 }
806
SetMute(int32_t mute,int32_t slotId)807 int32_t CellularCallConnection::SetMute(int32_t mute, int32_t slotId)
808 {
809 if (ReConnectService() != TELEPHONY_SUCCESS) {
810 TELEPHONY_LOGE("ipc reconnect failed!");
811 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
812 }
813 int errCode = cellularCallInterfacePtr_->SetMute(slotId, mute);
814 if (errCode != TELEPHONY_SUCCESS) {
815 TELEPHONY_LOGE("SetMute failed, errcode:%{public}d", errCode);
816 return errCode;
817 }
818 return TELEPHONY_SUCCESS;
819 }
820
CloseUnFinishedUssd(int32_t slotId)821 int CellularCallConnection::CloseUnFinishedUssd(int32_t slotId)
822 {
823 if (ReConnectService() != TELEPHONY_SUCCESS) {
824 TELEPHONY_LOGE("ipc reconnect failed!");
825 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
826 }
827 int errCode = cellularCallInterfacePtr_->CloseUnFinishedUssd(slotId);
828 if (errCode != TELEPHONY_SUCCESS) {
829 TELEPHONY_LOGE("CloseUnFinishedUssd failed, errcode:%{public}d", errCode);
830 return errCode;
831 }
832 return TELEPHONY_SUCCESS;
833 }
834
ClearAllCalls()835 int32_t CellularCallConnection::ClearAllCalls()
836 {
837 if (!CallObjectManager::HasCallExist()) {
838 TELEPHONY_LOGI("no call exist, no need to clear");
839 return TELEPHONY_SUCCESS;
840 }
841 std::vector<CellularCallInfo> callsInfo;
842 std::vector<CallAttributeInfo> infos = CallObjectManager::GetCarrierCallInfoList();
843 for (auto &info : infos) {
844 CellularCallInfo callInfo;
845 callInfo.callId = info.callId;
846 if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
847 TELEPHONY_LOGE("memset_s fail");
848 return TELEPHONY_ERR_MEMSET_FAIL;
849 }
850 if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, info.accountNumber, strlen(info.accountNumber)) != EOK) {
851 TELEPHONY_LOGE("memcpy_s fail");
852 return TELEPHONY_ERR_MEMCPY_FAIL;
853 }
854 callInfo.slotId = info.accountId;
855 callInfo.accountId = info.accountId;
856 callInfo.callType = info.callType;
857 callInfo.videoState = static_cast<int32_t>(info.videoState);
858 callInfo.index = info.index;
859 callsInfo.push_back(callInfo);
860 }
861 if (callsInfo.empty()) {
862 TELEPHONY_LOGE("callsInfo is empty");
863 return TELEPHONY_ERR_ARGUMENT_INVALID;
864 }
865 std::this_thread::sleep_for(std::chrono::milliseconds(DELAY_TIME));
866 if (ReConnectService() != TELEPHONY_SUCCESS) {
867 TELEPHONY_LOGE("ipc reconnect failed!");
868 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
869 }
870 int32_t errCode = cellularCallInterfacePtr_->ClearAllCalls(callsInfo);
871 if (errCode != TELEPHONY_SUCCESS) {
872 TELEPHONY_LOGE("ClearAllCalls fail, errcode:%{public}d", errCode);
873 }
874 return errCode;
875 }
876
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)877 void CellularCallConnection::SystemAbilityListener::OnAddSystemAbility(
878 int32_t systemAbilityId, const std::string &deviceId)
879 {
880 TELEPHONY_LOGI("SA:%{public}d is added!", systemAbilityId);
881 if (!CheckInputSysAbilityId(systemAbilityId)) {
882 TELEPHONY_LOGE("add SA:%{public}d is invalid!", systemAbilityId);
883 return;
884 }
885
886 auto cellularCallConnection = DelayedSingleton<CellularCallConnection>::GetInstance();
887 if (cellularCallConnection == nullptr) {
888 TELEPHONY_LOGE("cellularCallConnection is nullptr");
889 return;
890 }
891
892 if (cellularCallConnection->IsConnect()) {
893 TELEPHONY_LOGI("SA:%{public}d already connected!", systemAbilityId);
894 return;
895 }
896
897 cellularCallConnection->Clean();
898 int32_t res = cellularCallConnection->ReConnectService();
899 if (res != TELEPHONY_SUCCESS) {
900 TELEPHONY_LOGE("SA:%{public}d reconnect service failed!", systemAbilityId);
901 return;
902 }
903 cellularCallConnection->ClearAllCalls();
904 TELEPHONY_LOGI("SA:%{public}d reconnect service successfully!", systemAbilityId);
905 }
906
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)907 void CellularCallConnection::SystemAbilityListener::OnRemoveSystemAbility(
908 int32_t systemAbilityId, const std::string &deviceId)
909 {
910 TELEPHONY_LOGI("SA:%{public}d is removed!", systemAbilityId);
911 auto cellularCallConnection = DelayedSingleton<CellularCallConnection>::GetInstance();
912 if (cellularCallConnection == nullptr) {
913 TELEPHONY_LOGE("cellularCallConnection is nullptr");
914 return;
915 }
916
917 if (!cellularCallConnection->IsConnect()) {
918 return;
919 }
920
921 cellularCallConnection->Clean();
922 }
923 } // namespace Telephony
924 } // namespace OHOS
925