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