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