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_service.h"
17
18 #include <sstream>
19
20 #include "string_ex.h"
21 #include "system_ability_definition.h"
22
23 #include "cellular_call_dump_helper.h"
24 #include "cellular_call_callback.h"
25 #include "emergency_utils.h"
26 #include "module_service_utils.h"
27 #include "radio_event.h"
28 #include "telephony_permission.h"
29
30 namespace OHOS {
31 namespace Telephony {
32 bool g_registerResult =
33 SystemAbility::MakeAndRegisterAbility(DelayedSingleton<CellularCallService>::GetInstance().get());
34
CellularCallService()35 CellularCallService::CellularCallService() : SystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID, true)
36 {
37 state_ = ServiceRunningState::STATE_STOPPED;
38 }
39
~CellularCallService()40 CellularCallService::~CellularCallService()
41 {
42 state_ = ServiceRunningState::STATE_STOPPED;
43 }
44
Init()45 bool CellularCallService::Init()
46 {
47 TELEPHONY_LOGI("CellularCallService::Init start");
48 eventLoop_ = AppExecFwk::EventRunner::Create("CellularCallServiceLoop");
49 if (eventLoop_ == nullptr) {
50 TELEPHONY_LOGE("CellularCallService::Init return, failed to create EventRunner");
51 return false;
52 }
53 CreateHandler();
54 SendEventRegisterHandler();
55 SendEventRegisterImsCallback();
56 ModuleServiceUtils utils;
57 utils.ConnectImsService();
58 TELEPHONY_LOGI("CellularCallService::Init, init success");
59 return true;
60 }
61
OnStart()62 void CellularCallService::OnStart()
63 {
64 TELEPHONY_LOGI("CellularCallService OnStart");
65 bindTime_ =
66 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
67 .count();
68 if (state_ == ServiceRunningState::STATE_RUNNING) {
69 TELEPHONY_LOGE("CellularCallService::OnStart return, has already started.");
70 return;
71 }
72 if (!Init()) {
73 TELEPHONY_LOGE("CellularCallService::OnStart return, failed to init service.");
74 return;
75 }
76 state_ = ServiceRunningState::STATE_RUNNING;
77 if (eventLoop_ != nullptr) {
78 eventLoop_->Run();
79 }
80 bool ret = Publish(DelayedSingleton<CellularCallService>::GetInstance().get());
81 if (!ret) {
82 TELEPHONY_LOGE("CellularCallService::OnStart Publish failed!");
83 }
84 endTime_ =
85 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
86 .count();
87 TELEPHONY_LOGI("CellularCallService start success.");
88 }
89
OnStop()90 void CellularCallService::OnStop()
91 {
92 TELEPHONY_LOGI("CellularCallService stop service");
93 if (eventLoop_ != nullptr) {
94 eventLoop_.reset();
95 }
96 state_ = ServiceRunningState::STATE_STOPPED;
97 HandlerResetUnRegister();
98 }
99
RegisterHandler()100 void CellularCallService::RegisterHandler()
101 {
102 TELEPHONY_LOGI("connect core service Register Handler start");
103 networkSearchCallBack_ = (std::make_unique<CellularCallCallback>()).release();
104 for (uint32_t i = 0; i < CONNECT_MAX_TRY_COUNT; i++) {
105 std::this_thread::sleep_for(std::chrono::milliseconds(CONNECT_SERVICE_WAIT_TIME));
106 if (CoreManagerInner::GetInstance().IsInitFinishedForTelRil()) {
107 TELEPHONY_LOGI("connect core service Register Handler start");
108 RegisterCoreServiceHandler();
109 CoreManagerInner::GetInstance().RegisterCellularCallObject(networkSearchCallBack_);
110 break;
111 }
112 TELEPHONY_LOGW("connect core service Register Handler null or not init");
113 }
114 TELEPHONY_LOGI("connect core service Register Handler end");
115 }
116
CreateHandler()117 void CellularCallService::CreateHandler()
118 {
119 ModuleServiceUtils obtain;
120 std::vector<int32_t> slotVector = obtain.GetSlotInfo();
121 for (const auto &it : slotVector) {
122 auto handler = std::make_shared<CellularCallHandler>(eventLoop_);
123 handler->SetSlotId(it);
124 handlerMap_.insert(std::make_pair(it, handler));
125 }
126 }
127
HandlerResetUnRegister()128 void CellularCallService::HandlerResetUnRegister()
129 {
130 for (const auto &it : handlerMap_) {
131 int32_t slot = it.first;
132 auto handler = it.second;
133 if (handler != nullptr) {
134 handler.reset();
135 }
136
137 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_AVAIL);
138 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_NOT_AVAIL);
139 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_STATUS_INFO);
140 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_IMS_SERVICE_STATUS);
141 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_USSD_NOTICE);
142 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_RINGBACK_VOICE);
143
144 if (GetCsControl(slot) != nullptr) {
145 GetCsControl(slot)->ReleaseAllConnection();
146 }
147
148 if (GetImsControl(slot) != nullptr) {
149 GetImsControl(slot)->ReleaseAllConnection();
150 }
151 }
152 }
153
RegisterCoreServiceHandler()154 void CellularCallService::RegisterCoreServiceHandler()
155 {
156 for (const auto &it : handlerMap_) {
157 int32_t slot = it.first;
158 auto handler = it.second;
159 if (handler != nullptr) {
160 CoreManagerInner::GetInstance().RegisterCoreNotify(slot, handler, RadioEvent::RADIO_AVAIL, nullptr);
161 CoreManagerInner::GetInstance().RegisterCoreNotify(slot, handler, RadioEvent::RADIO_NOT_AVAIL, nullptr);
162 CoreManagerInner::GetInstance().RegisterCoreNotify(
163 slot, handler, RadioEvent::RADIO_CALL_STATUS_INFO, nullptr);
164 CoreManagerInner::GetInstance().RegisterCoreNotify(
165 slot, handler, RadioEvent::RADIO_CALL_IMS_SERVICE_STATUS, nullptr);
166 CoreManagerInner::GetInstance().RegisterCoreNotify(
167 slot, handler, RadioEvent::RADIO_CALL_USSD_NOTICE, nullptr);
168 CoreManagerInner::GetInstance().RegisterCoreNotify(
169 slot, handler, RadioEvent::RADIO_CALL_RINGBACK_VOICE, nullptr);
170 }
171
172 CellularCallConfig config;
173 config.InitModeActive();
174 if (config.GetDomainPreferenceMode(slot) != TELEPHONY_SUCCESS) {
175 TELEPHONY_LOGW("RegisterCoreServiceHandler, GetDomainPreferenceMode request fail");
176 }
177 if (config.GetLteImsSwitchStatus(slot) != TELEPHONY_SUCCESS) {
178 TELEPHONY_LOGW("RegisterCoreServiceHandler, GetLteImsSwitchStatus request fail");
179 }
180 if (config.GetEmergencyCallList(it.first) != TELEPHONY_SUCCESS) {
181 TELEPHONY_LOGW("RegisterCoreServiceHandler, GetEmergencyCallList request fail");
182 }
183 }
184 }
185
SendEventRegisterHandler()186 void CellularCallService::SendEventRegisterHandler()
187 {
188 int64_t delayTime = 1000;
189 int32_t slot = DEFAULT_SIM_SLOT_ID;
190 auto handler = handlerMap_[slot];
191 if (handler == nullptr) {
192 TELEPHONY_LOGE("SendEventRegisterHandler return, handler is nullptr");
193 return;
194 }
195 handler->SendEvent(handler->REGISTER_HANDLER_ID, delayTime, CellularCallHandler::Priority::HIGH);
196 }
197
SendEventRegisterImsCallback()198 void CellularCallService::SendEventRegisterImsCallback()
199 {
200 TELEPHONY_LOGI("CellularCallService::SendEventRegisterImsCallback entry");
201 int64_t delayTime = 2000;
202 int32_t slot = DEFAULT_SIM_SLOT_ID;
203 auto handler = handlerMap_[slot];
204 if (handler == nullptr) {
205 TELEPHONY_LOGE("SendEventRegisterImsCallback return, handler is nullptr");
206 return;
207 }
208 handler->SendEvent(handler->REGISTER_IMS_CALLBACK_ID, delayTime, CellularCallHandler::Priority::HIGH);
209 }
210
Dump(int32_t fd,const std::vector<std::u16string> & args)211 int32_t CellularCallService::Dump(int32_t fd, const std::vector<std::u16string> &args)
212 {
213 if (fd < 0) {
214 TELEPHONY_LOGE("dump fd invalid");
215 return TELEPHONY_ERR_FAIL;
216 }
217 std::vector<std::string> argsInStr;
218 for (const auto &arg : args) {
219 argsInStr.emplace_back(Str16ToStr8(arg));
220 }
221 std::string result;
222 CellularCallDumpHelper dumpHelper;
223 if (dumpHelper.Dump(argsInStr, result)) {
224 int32_t ret = dprintf(fd, "%s", result.c_str());
225 if (ret < 0) {
226 TELEPHONY_LOGE("dprintf to dump fd failed");
227 return TELEPHONY_ERR_FAIL;
228 }
229 return TELEPHONY_SUCCESS;
230 }
231 TELEPHONY_LOGW("dumpHelper failed");
232 return TELEPHONY_ERR_FAIL;
233 }
234
GetBindTime()235 std::string CellularCallService::GetBindTime()
236 {
237 std::ostringstream oss;
238 oss << bindTime_;
239 return oss.str();
240 }
241
GetEndTime()242 std::string CellularCallService::GetEndTime()
243 {
244 std::ostringstream oss;
245 oss << endTime_;
246 return oss.str();
247 }
248
GetSpendTime()249 std::string CellularCallService::GetSpendTime()
250 {
251 spendTime_ = endTime_ - bindTime_;
252 std::ostringstream oss;
253 oss << spendTime_;
254 return oss.str();
255 }
256
Dial(const CellularCallInfo & callInfo)257 int32_t CellularCallService::Dial(const CellularCallInfo &callInfo)
258 {
259 if (!TelephonyPermission::CheckPermission(Permission::PLACE_CALL)) {
260 TELEPHONY_LOGE("Check permission failed, no PLACE_CALL permisson.");
261 return TELEPHONY_PERMISSION_ERROR;
262 }
263
264 if (!IsValidSlotId(callInfo.slotId)) {
265 TELEPHONY_LOGE("CellularCallService::Dial return, invalid slot id");
266 return CALL_ERR_INVALID_SLOT_ID;
267 }
268 auto handler = GetHandler(callInfo.slotId);
269 if (handler == nullptr) {
270 TELEPHONY_LOGE("CellularCallService::Dial return, handler is nullptr");
271 return TELEPHONY_ERR_LOCAL_PTR_NULL;
272 }
273 if (srvccState_ == SrvccState::STARTED) {
274 return TELEPHONY_ERR_FAIL;
275 }
276 if (IsNeedIms(callInfo.slotId)) {
277 handler->SetCallType(CallType::TYPE_IMS);
278 auto imsControl = GetImsControl(callInfo.slotId);
279 if (imsControl == nullptr) {
280 TELEPHONY_LOGE("CellularCallService::Dial ims dial");
281 imsControl = std::make_shared<IMSControl>();
282 if (imsControl == nullptr) {
283 TELEPHONY_LOGE("CellularCallService::Dial return, imsControl create fail");
284 return TELEPHONY_ERR_LOCAL_PTR_NULL;
285 }
286 SetImsControl(callInfo.slotId, imsControl);
287 }
288 return imsControl->Dial(callInfo);
289 }
290
291 handler->SetCallType(CallType::TYPE_CS);
292 auto csControl = GetCsControl(callInfo.slotId);
293 if (csControl == nullptr) {
294 csControl = std::make_shared<CSControl>();
295 if (csControl == nullptr) {
296 TELEPHONY_LOGE("CellularCallService::Dial return, csControl create fail");
297 return TELEPHONY_ERR_LOCAL_PTR_NULL;
298 }
299 SetCsControl(callInfo.slotId, csControl);
300 }
301 return csControl->Dial(callInfo);
302 }
303
HangUp(const CellularCallInfo & callInfo,CallSupplementType type)304 int32_t CellularCallService::HangUp(const CellularCallInfo &callInfo, CallSupplementType type)
305 {
306 if (!IsValidSlotId(callInfo.slotId)) {
307 TELEPHONY_LOGE("CellularCallService::HangUp return, invalid slot id");
308 return CALL_ERR_INVALID_SLOT_ID;
309 }
310 if (srvccState_ == SrvccState::STARTED) {
311 return TELEPHONY_ERR_FAIL;
312 }
313 if (CallType::TYPE_CS == callInfo.callType) {
314 auto csControl = GetCsControl(callInfo.slotId);
315 if (csControl == nullptr) {
316 TELEPHONY_LOGE("CellularCallService::HangUp return, csControl is nullptr");
317 return TELEPHONY_ERR_LOCAL_PTR_NULL;
318 }
319 return csControl->HangUp(callInfo, type);
320 } else if (CallType::TYPE_IMS == callInfo.callType) {
321 auto imsControl = GetImsControl(callInfo.slotId);
322 if (imsControl == nullptr) {
323 TELEPHONY_LOGE("CellularCallService::HangUp return, imsControl is nullptr");
324 return TELEPHONY_ERR_LOCAL_PTR_NULL;
325 }
326 return imsControl->HangUp(callInfo, type);
327 }
328 TELEPHONY_LOGE("CellularCallService::HangUp return, call type error.");
329 return TELEPHONY_ERR_ARGUMENT_INVALID;
330 }
331
Reject(const CellularCallInfo & callInfo)332 int32_t CellularCallService::Reject(const CellularCallInfo &callInfo)
333 {
334 if (!IsValidSlotId(callInfo.slotId)) {
335 TELEPHONY_LOGE("CellularCallService::Reject return, invalid slot id");
336 return CALL_ERR_INVALID_SLOT_ID;
337 }
338 if (srvccState_ == SrvccState::STARTED) {
339 return TELEPHONY_ERR_FAIL;
340 }
341 if (CallType::TYPE_CS == callInfo.callType) {
342 auto csControl = GetCsControl(callInfo.slotId);
343 if (csControl == nullptr) {
344 TELEPHONY_LOGE("CellularCallService::Reject return, csControl is nullptr");
345 return TELEPHONY_ERR_LOCAL_PTR_NULL;
346 }
347 return csControl->Reject(callInfo);
348 } else if (CallType::TYPE_IMS == callInfo.callType) {
349 auto imsControl = GetImsControl(callInfo.slotId);
350 if (imsControl == nullptr) {
351 TELEPHONY_LOGE("CellularCallService::Reject return, imsControl is nullptr");
352 return TELEPHONY_ERR_LOCAL_PTR_NULL;
353 }
354 return imsControl->Reject(callInfo);
355 }
356 TELEPHONY_LOGE("CellularCallService::Reject return, call type error.");
357 return TELEPHONY_ERR_ARGUMENT_INVALID;
358 }
359
Answer(const CellularCallInfo & callInfo)360 int32_t CellularCallService::Answer(const CellularCallInfo &callInfo)
361 {
362 if (!TelephonyPermission::CheckPermission(Permission::ANSWER_CALL)) {
363 TELEPHONY_LOGE("Check permission failed, no ANSWER_CALL permisson.");
364 return TELEPHONY_PERMISSION_ERROR;
365 }
366
367 if (!IsValidSlotId(callInfo.slotId)) {
368 TELEPHONY_LOGE("CellularCallService::Answer return, invalid slot id");
369 return CALL_ERR_INVALID_SLOT_ID;
370 }
371 if (srvccState_ == SrvccState::STARTED) {
372 return TELEPHONY_ERR_FAIL;
373 }
374 if (CallType::TYPE_CS == callInfo.callType) {
375 auto csControl = GetCsControl(callInfo.slotId);
376 if (csControl == nullptr) {
377 TELEPHONY_LOGE("CellularCallService::Answer return, csControl is nullptr");
378 return TELEPHONY_ERR_LOCAL_PTR_NULL;
379 }
380 return csControl->Answer(callInfo);
381 } else if (CallType::TYPE_IMS == callInfo.callType) {
382 auto imsControl = GetImsControl(callInfo.slotId);
383 if (imsControl == nullptr) {
384 TELEPHONY_LOGE("CellularCallService::Answer return, imsControl is nullptr");
385 return TELEPHONY_ERR_LOCAL_PTR_NULL;
386 }
387 return imsControl->Answer(callInfo);
388 }
389 TELEPHONY_LOGE("CellularCallService::Answer return, call type error.");
390 return TELEPHONY_ERR_ARGUMENT_INVALID;
391 }
392
RegisterCallManagerCallBack(const sptr<ICallStatusCallback> & callback)393 int32_t CellularCallService::RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback)
394 {
395 if (DelayedSingleton<CellularCallRegister>::GetInstance() == nullptr) {
396 TELEPHONY_LOGE("CellularCallService::RegisterCallManagerCallBack return, instance is nullptr.");
397 return TELEPHONY_ERR_LOCAL_PTR_NULL;
398 }
399 return DelayedSingleton<CellularCallRegister>::GetInstance()->RegisterCallManagerCallBack(callback);
400 }
401
UnRegisterCallManagerCallBack()402 int32_t CellularCallService::UnRegisterCallManagerCallBack()
403 {
404 if (DelayedSingleton<CellularCallRegister>::GetInstance() == nullptr) {
405 TELEPHONY_LOGE("CellularCallService::UnRegisterCallManagerCallBack return, instance is nullptr.");
406 return TELEPHONY_ERR_LOCAL_PTR_NULL;
407 }
408 return DelayedSingleton<CellularCallRegister>::GetInstance()->UnRegisterCallManagerCallBack();
409 }
410
HoldCall(const CellularCallInfo & callInfo)411 int32_t CellularCallService::HoldCall(const CellularCallInfo &callInfo)
412 {
413 if (!IsValidSlotId(callInfo.slotId)) {
414 TELEPHONY_LOGE("CellularCallService::HoldCall return, invalid slot id");
415 return CALL_ERR_INVALID_SLOT_ID;
416 }
417 if (srvccState_ == SrvccState::STARTED) {
418 return TELEPHONY_ERR_FAIL;
419 }
420 if (CallType::TYPE_IMS == callInfo.callType) {
421 auto imsControl = GetImsControl(callInfo.slotId);
422 if (imsControl == nullptr) {
423 TELEPHONY_LOGE("CellularCallService::HoldCall return, imsControl is nullptr");
424 return TELEPHONY_ERR_LOCAL_PTR_NULL;
425 }
426 return imsControl->HoldCall(callInfo.slotId);
427 } else if (CallType::TYPE_CS == callInfo.callType) {
428 auto csControl = GetCsControl(callInfo.slotId);
429 if (csControl == nullptr) {
430 TELEPHONY_LOGE("CellularCallService::HoldCall return, csControl is nullptr");
431 return TELEPHONY_ERR_LOCAL_PTR_NULL;
432 }
433 return csControl->HoldCall(callInfo.slotId);
434 }
435 TELEPHONY_LOGE("CellularCallService::HoldCall return, call type error.");
436 return TELEPHONY_ERR_ARGUMENT_INVALID;
437 }
438
UnHoldCall(const CellularCallInfo & callInfo)439 int32_t CellularCallService::UnHoldCall(const CellularCallInfo &callInfo)
440 {
441 if (!IsValidSlotId(callInfo.slotId)) {
442 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, invalid slot id");
443 return CALL_ERR_INVALID_SLOT_ID;
444 }
445 if (srvccState_ == SrvccState::STARTED) {
446 return TELEPHONY_ERR_FAIL;
447 }
448 if (CallType::TYPE_IMS == callInfo.callType) {
449 auto imsControl = GetImsControl(callInfo.slotId);
450 if (imsControl == nullptr) {
451 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, imsControl is nullptr");
452 return TELEPHONY_ERR_LOCAL_PTR_NULL;
453 }
454 return imsControl->UnHoldCall(callInfo.slotId);
455 } else if (CallType::TYPE_CS == callInfo.callType) {
456 auto csControl = GetCsControl(callInfo.slotId);
457 if (csControl == nullptr) {
458 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, csControl is nullptr");
459 return TELEPHONY_ERR_LOCAL_PTR_NULL;
460 }
461 return csControl->UnHoldCall(callInfo.slotId);
462 }
463 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, call type error.");
464 return TELEPHONY_ERR_ARGUMENT_INVALID;
465 }
466
SwitchCall(const CellularCallInfo & callInfo)467 int32_t CellularCallService::SwitchCall(const CellularCallInfo &callInfo)
468 {
469 if (!IsValidSlotId(callInfo.slotId)) {
470 TELEPHONY_LOGE("CellularCallService::SwitchCall return, invalid slot id");
471 return CALL_ERR_INVALID_SLOT_ID;
472 }
473 if (srvccState_ == SrvccState::STARTED) {
474 return TELEPHONY_ERR_FAIL;
475 }
476 if (CallType::TYPE_IMS == callInfo.callType) {
477 auto imsControl = GetImsControl(callInfo.slotId);
478 if (imsControl == nullptr) {
479 TELEPHONY_LOGE("CellularCallService::SwitchCall return, imsControl is nullptr");
480 return TELEPHONY_ERR_LOCAL_PTR_NULL;
481 }
482 return imsControl->SwitchCall(callInfo.slotId);
483 } else if (CallType::TYPE_CS == callInfo.callType) {
484 auto csControl = GetCsControl(callInfo.slotId);
485 if (csControl == nullptr) {
486 TELEPHONY_LOGE("CellularCallService::SwitchCall return, csControl is nullptr");
487 return TELEPHONY_ERR_LOCAL_PTR_NULL;
488 }
489 return csControl->SwitchCall(callInfo.slotId);
490 }
491 TELEPHONY_LOGE("CellularCallService::SwitchCall return, call type error.");
492 return TELEPHONY_ERR_ARGUMENT_INVALID;
493 }
494
CombineConference(const CellularCallInfo & callInfo)495 int32_t CellularCallService::CombineConference(const CellularCallInfo &callInfo)
496 {
497 if (!IsValidSlotId(callInfo.slotId)) {
498 TELEPHONY_LOGE("CellularCallService::CombineConference return, invalid slot id");
499 return CALL_ERR_INVALID_SLOT_ID;
500 }
501 if (srvccState_ == SrvccState::STARTED) {
502 return TELEPHONY_ERR_FAIL;
503 }
504 if (CallType::TYPE_IMS == callInfo.callType) {
505 auto imsControl = GetImsControl(callInfo.slotId);
506 if (imsControl == nullptr) {
507 TELEPHONY_LOGE("CellularCallService::CombineConference return, imsControl is nullptr");
508 return TELEPHONY_ERR_LOCAL_PTR_NULL;
509 }
510 return imsControl->CombineConference(callInfo.slotId);
511 } else if (CallType::TYPE_CS == callInfo.callType) {
512 auto csControl = GetCsControl(callInfo.slotId);
513 if (csControl == nullptr) {
514 TELEPHONY_LOGE("CellularCallService::CombineConference return, csControl is nullptr");
515 return TELEPHONY_ERR_LOCAL_PTR_NULL;
516 }
517 return csControl->CombineConference(callInfo.slotId);
518 }
519 TELEPHONY_LOGE("CellularCallService::CombineConference return, call type error.");
520 return TELEPHONY_ERR_ARGUMENT_INVALID;
521 }
522
SeparateConference(const CellularCallInfo & callInfo)523 int32_t CellularCallService::SeparateConference(const CellularCallInfo &callInfo)
524 {
525 if (!IsValidSlotId(callInfo.slotId)) {
526 TELEPHONY_LOGE("CellularCallService::SeparateConference return, invalid slot id");
527 return CALL_ERR_INVALID_SLOT_ID;
528 }
529 if (CallType::TYPE_IMS == callInfo.callType) {
530 auto imsControl = GetImsControl(callInfo.slotId);
531 if (imsControl == nullptr) {
532 TELEPHONY_LOGE("CellularCallService::SeparateConference return, imsControl is nullptr");
533 return TELEPHONY_ERR_LOCAL_PTR_NULL;
534 }
535 std::vector<std::string> numberList;
536 numberList.emplace_back(callInfo.phoneNum);
537 return imsControl->KickOutFromConference(callInfo.slotId, numberList);
538 } else if (CallType::TYPE_CS == callInfo.callType) {
539 auto csControl = GetCsControl(callInfo.slotId);
540 if (csControl == nullptr) {
541 TELEPHONY_LOGE("CellularCallService::SeparateConference return, csControl is nullptr");
542 return TELEPHONY_ERR_LOCAL_PTR_NULL;
543 }
544 return csControl->SeparateConference(callInfo.slotId, callInfo.phoneNum, callInfo.index);
545 }
546 TELEPHONY_LOGE("CellularCallService::SeparateConference return, call type error.");
547 return TELEPHONY_ERR_ARGUMENT_INVALID;
548 }
549
InviteToConference(int32_t slotId,const std::vector<std::string> & numberList)550 int32_t CellularCallService::InviteToConference(int32_t slotId, const std::vector<std::string> &numberList)
551 {
552 auto control = GetImsControl(slotId);
553 if (control == nullptr) {
554 TELEPHONY_LOGE("CellularCallService::InviteToConference return, control is nullptr");
555 return TELEPHONY_ERR_LOCAL_PTR_NULL;
556 }
557 return control->InviteToConference(slotId, numberList);
558 }
559
KickOutFromConference(int32_t slotId,const std::vector<std::string> & numberList)560 int32_t CellularCallService::KickOutFromConference(int32_t slotId, const std::vector<std::string> &numberList)
561 {
562 auto control = GetImsControl(slotId);
563 if (control == nullptr) {
564 TELEPHONY_LOGE("CellularCallService::KickOutFromConference return, control is nullptr");
565 return TELEPHONY_ERR_LOCAL_PTR_NULL;
566 }
567 return control->KickOutFromConference(slotId, numberList);
568 }
569
HangUpAllConnection()570 int32_t CellularCallService::HangUpAllConnection()
571 {
572 ModuleServiceUtils obtain;
573 std::vector<int32_t> slotVector = obtain.GetSlotInfo();
574 for (const auto &it : slotVector) {
575 if (GetCsControl(it)) {
576 GetCsControl(it)->HangUpAllConnection(it);
577 }
578 if (GetImsControl(it)) {
579 GetImsControl(it)->HangUpAllConnection(it);
580 }
581 }
582 return TELEPHONY_SUCCESS;
583 }
584
UpdateImsCallMode(const CellularCallInfo & callInfo,ImsCallMode mode)585 int32_t CellularCallService::UpdateImsCallMode(const CellularCallInfo &callInfo, ImsCallMode mode)
586 {
587 auto control = GetImsControl(callInfo.slotId);
588 if (control == nullptr) {
589 TELEPHONY_LOGE("CellularCallService::UpdateImsCallMode return, control is nullptr");
590 return TELEPHONY_ERR_LOCAL_PTR_NULL;
591 }
592 return control->UpdateImsCallMode(callInfo, mode);
593 }
594
StartDtmf(char cDtmfCode,const CellularCallInfo & callInfo)595 int32_t CellularCallService::StartDtmf(char cDtmfCode, const CellularCallInfo &callInfo)
596 {
597 if (!IsValidSlotId(callInfo.slotId)) {
598 TELEPHONY_LOGE("CellularCallService::StartDtmf return, invalid slot id");
599 return CALL_ERR_INVALID_SLOT_ID;
600 }
601 if (srvccState_ == SrvccState::STARTED) {
602 return TELEPHONY_ERR_FAIL;
603 }
604 if (CallType::TYPE_IMS == callInfo.callType) {
605 auto imsControl = GetImsControl(callInfo.slotId);
606 if (imsControl == nullptr) {
607 TELEPHONY_LOGE("CellularCallService::StartDtmf return, imsControl is nullptr");
608 return TELEPHONY_ERR_LOCAL_PTR_NULL;
609 }
610 return imsControl->StartDtmf(imsControl->GetConnectionMap(), cDtmfCode, callInfo);
611 } else if (CallType::TYPE_CS == callInfo.callType) {
612 auto csControl = GetCsControl(callInfo.slotId);
613 if (csControl == nullptr) {
614 TELEPHONY_LOGE("CellularCallService::StartDtmf return, csControl is nullptr");
615 return TELEPHONY_ERR_LOCAL_PTR_NULL;
616 }
617 return csControl->StartDtmf(csControl->GetConnectionMap(), cDtmfCode, callInfo);
618 }
619 TELEPHONY_LOGE("CellularCallService::StartDtmf return, call type error.");
620 return TELEPHONY_ERR_ARGUMENT_INVALID;
621 }
622
StopDtmf(const CellularCallInfo & callInfo)623 int32_t CellularCallService::StopDtmf(const CellularCallInfo &callInfo)
624 {
625 if (!IsValidSlotId(callInfo.slotId)) {
626 TELEPHONY_LOGE("CellularCallService::StopDtmf return, invalid slot id");
627 return CALL_ERR_INVALID_SLOT_ID;
628 }
629 if (srvccState_ == SrvccState::STARTED) {
630 return TELEPHONY_ERR_FAIL;
631 }
632 if (CallType::TYPE_IMS == callInfo.callType) {
633 auto imsControl = GetImsControl(callInfo.slotId);
634 if (imsControl == nullptr) {
635 TELEPHONY_LOGE("CellularCallService::StopDtmf return, imsControl is nullptr");
636 return TELEPHONY_ERR_LOCAL_PTR_NULL;
637 }
638 return imsControl->StopDtmf(imsControl->GetConnectionMap(), callInfo);
639 } else if (CallType::TYPE_CS == callInfo.callType) {
640 auto csControl = GetCsControl(callInfo.slotId);
641 if (csControl == nullptr) {
642 TELEPHONY_LOGE("CellularCallService::StopDtmf return, csControl is nullptr");
643 return TELEPHONY_ERR_LOCAL_PTR_NULL;
644 }
645 return csControl->StopDtmf(csControl->GetConnectionMap(), callInfo);
646 }
647 TELEPHONY_LOGE("CellularCallService::StopDtmf return, call type error.");
648 return TELEPHONY_ERR_ARGUMENT_INVALID;
649 }
650
SendDtmf(char cDtmfCode,const CellularCallInfo & callInfo)651 int32_t CellularCallService::SendDtmf(char cDtmfCode, const CellularCallInfo &callInfo)
652 {
653 if (!IsValidSlotId(callInfo.slotId)) {
654 TELEPHONY_LOGE("CellularCallService::SendDtmf return, invalid slot id");
655 return CALL_ERR_INVALID_SLOT_ID;
656 }
657 if (srvccState_ == SrvccState::STARTED) {
658 return TELEPHONY_ERR_FAIL;
659 }
660 if (CallType::TYPE_IMS == callInfo.callType) {
661 auto imsControl = GetImsControl(callInfo.slotId);
662 if (imsControl == nullptr) {
663 TELEPHONY_LOGE("CellularCallService::SendDtmf return, imsControl is nullptr");
664 return TELEPHONY_ERR_LOCAL_PTR_NULL;
665 }
666 return imsControl->SendDtmf(imsControl->GetConnectionMap(), cDtmfCode, callInfo);
667 } else if (CallType::TYPE_CS == callInfo.callType) {
668 auto csControl = GetCsControl(callInfo.slotId);
669 if (csControl == nullptr) {
670 TELEPHONY_LOGE("CellularCallService::SendDtmf return, csControl is nullptr");
671 return TELEPHONY_ERR_LOCAL_PTR_NULL;
672 }
673 return csControl->SendDtmf(csControl->GetConnectionMap(), cDtmfCode, callInfo);
674 }
675 TELEPHONY_LOGE("CellularCallService::SendDtmf return, call type error.");
676 return TELEPHONY_ERR_ARGUMENT_INVALID;
677 }
678
StartRtt(int32_t slotId,const std::string & msg)679 int32_t CellularCallService::StartRtt(int32_t slotId, const std::string &msg)
680 {
681 auto control = GetImsControl(slotId);
682 if (control == nullptr) {
683 TELEPHONY_LOGE("CellularCallService::StartRtt return, control is nullptr");
684 return TELEPHONY_ERR_LOCAL_PTR_NULL;
685 }
686 return control->StartRtt(slotId, msg);
687 }
688
StopRtt(int32_t slotId)689 int32_t CellularCallService::StopRtt(int32_t slotId)
690 {
691 auto control = GetImsControl(slotId);
692 if (control == nullptr) {
693 TELEPHONY_LOGE("CellularCallService::StopRtt return, control is nullptr");
694 return TELEPHONY_ERR_LOCAL_PTR_NULL;
695 }
696 return control->StopRtt(slotId);
697 }
698
SetCallTransferInfo(int32_t slotId,const CallTransferInfo & cTInfo)699 int32_t CellularCallService::SetCallTransferInfo(int32_t slotId, const CallTransferInfo &cTInfo)
700 {
701 if (!IsValidSlotId(slotId)) {
702 TELEPHONY_LOGE("CellularCallService::SetCallTransferInfo return, invalid slot id");
703 return CALL_ERR_INVALID_SLOT_ID;
704 }
705
706 CellularCallSupplement cellularCallSupplement;
707 return cellularCallSupplement.SetCallTransferInfo(slotId, cTInfo);
708 }
709
GetCallTransferInfo(int32_t slotId,CallTransferType type)710 int32_t CellularCallService::GetCallTransferInfo(int32_t slotId, CallTransferType type)
711 {
712 TELEPHONY_LOGI("CellularCallService::GetCallTransferInfo");
713 if (!IsValidSlotId(slotId)) {
714 TELEPHONY_LOGE("CellularCallService::GetCallTransferInfo return, invalid slot id");
715 return CALL_ERR_INVALID_SLOT_ID;
716 }
717 CellularCallSupplement cellularCallSupplement;
718 return cellularCallSupplement.GetCallTransferInfo(slotId, type);
719 }
720
GetCsControl(int32_t slotId)721 std::shared_ptr<CSControl> CellularCallService::GetCsControl(int32_t slotId)
722 {
723 return csControlMap_[slotId];
724 }
725
GetImsControl(int32_t slotId)726 std::shared_ptr<IMSControl> CellularCallService::GetImsControl(int32_t slotId)
727 {
728 return imsControlMap_[slotId];
729 }
730
SetCsControl(int32_t slotId,const std::shared_ptr<CSControl> & csControl)731 void CellularCallService::SetCsControl(int32_t slotId, const std::shared_ptr<CSControl> &csControl)
732 {
733 csControlMap_[slotId] = csControl;
734 }
735
SetImsControl(int32_t slotId,const std::shared_ptr<IMSControl> & imsControl)736 void CellularCallService::SetImsControl(int32_t slotId, const std::shared_ptr<IMSControl> &imsControl)
737 {
738 imsControlMap_[slotId] = imsControl;
739 }
740
CleanControlMap()741 void CellularCallService::CleanControlMap()
742 {
743 csControlMap_.clear();
744 imsControlMap_.clear();
745 }
746
SetCallWaiting(int32_t slotId,bool activate)747 int32_t CellularCallService::SetCallWaiting(int32_t slotId, bool activate)
748 {
749 if (!IsValidSlotId(slotId)) {
750 TELEPHONY_LOGE("CellularCallService::SetCallWaiting return, invalid slot id");
751 return CALL_ERR_INVALID_SLOT_ID;
752 }
753 CellularCallSupplement cellularCallSupplement;
754 return cellularCallSupplement.SetCallWaiting(slotId, activate);
755 }
756
GetCallWaiting(int32_t slotId)757 int32_t CellularCallService::GetCallWaiting(int32_t slotId)
758 {
759 TELEPHONY_LOGI("CellularCallService::GetCallWaiting");
760 if (!IsValidSlotId(slotId)) {
761 TELEPHONY_LOGE("CellularCallService::GetCallWaiting return, invalid slot id");
762 return CALL_ERR_INVALID_SLOT_ID;
763 }
764 CellularCallSupplement cellularCallSupplement;
765 return cellularCallSupplement.GetCallWaiting(slotId);
766 }
767
SetCallRestriction(int32_t slotId,const CallRestrictionInfo & crInfo)768 int32_t CellularCallService::SetCallRestriction(int32_t slotId, const CallRestrictionInfo &crInfo)
769 {
770 TELEPHONY_LOGI("CellularCallService::SetCallRestriction");
771 if (!IsValidSlotId(slotId)) {
772 TELEPHONY_LOGE("CellularCallService::SetCallRestriction return, invalid slot id");
773 return CALL_ERR_INVALID_SLOT_ID;
774 }
775 CellularCallSupplement cellularCallSupplement;
776 return cellularCallSupplement.SetCallRestriction(slotId, crInfo);
777 }
778
GetCallRestriction(int32_t slotId,CallRestrictionType facType)779 int32_t CellularCallService::GetCallRestriction(int32_t slotId, CallRestrictionType facType)
780 {
781 TELEPHONY_LOGI("CellularCallService::GetCallRestriction");
782 if (!IsValidSlotId(slotId)) {
783 TELEPHONY_LOGE("CellularCallService::GetCallRestriction return, invalid slot id");
784 return CALL_ERR_INVALID_SLOT_ID;
785 }
786 CellularCallSupplement cellularCallSupplement;
787 return cellularCallSupplement.GetCallRestriction(slotId, facType);
788 }
789
IsEmergencyPhoneNumber(int32_t slotId,const std::string & phoneNum,int32_t & errorCode)790 int32_t CellularCallService::IsEmergencyPhoneNumber(int32_t slotId, const std::string &phoneNum, int32_t &errorCode)
791 {
792 if (!IsValidSlotId(slotId)) {
793 TELEPHONY_LOGE("CellularCallService::IsEmergencyPhoneNumber return, invalid slot id");
794 errorCode = CALL_ERR_INVALID_SLOT_ID;
795 return false;
796 }
797 EmergencyUtils emergencyUtils;
798 errorCode = TELEPHONY_SUCCESS;
799 return emergencyUtils.IsEmergencyCall(slotId, phoneNum);
800 }
801
SetDomainPreferenceMode(int32_t slotId,int32_t mode)802 int32_t CellularCallService::SetDomainPreferenceMode(int32_t slotId, int32_t mode)
803 {
804 if (!IsValidSlotId(slotId)) {
805 TELEPHONY_LOGE("CellularCallService::SetDomainPreferenceMode return, invalid slot id");
806 return CALL_ERR_INVALID_SLOT_ID;
807 }
808 CellularCallConfig config;
809 return config.SetDomainPreferenceMode(slotId, mode);
810 }
811
GetDomainPreferenceMode(int32_t slotId)812 int32_t CellularCallService::GetDomainPreferenceMode(int32_t slotId)
813 {
814 if (!IsValidSlotId(slotId)) {
815 TELEPHONY_LOGE("CellularCallService::GetDomainPreferenceMode return, invalid slot id");
816 return CALL_ERR_INVALID_SLOT_ID;
817 }
818 CellularCallConfig config;
819 return config.GetDomainPreferenceMode(slotId);
820 }
821
SetLteImsSwitchStatus(int32_t slotId,bool active)822 int32_t CellularCallService::SetLteImsSwitchStatus(int32_t slotId, bool active)
823 {
824 if (!IsValidSlotId(slotId)) {
825 TELEPHONY_LOGE("CellularCallService::SetLteImsSwitchStatus return, invalid slot id");
826 return CALL_ERR_INVALID_SLOT_ID;
827 }
828 CellularCallConfig config;
829 return config.SetLteImsSwitchStatus(slotId, active);
830 }
831
GetLteImsSwitchStatus(int32_t slotId)832 int32_t CellularCallService::GetLteImsSwitchStatus(int32_t slotId)
833 {
834 if (!IsValidSlotId(slotId)) {
835 TELEPHONY_LOGE("CellularCallService::GetLteImsSwitchStatus return, invalid slot id");
836 return CALL_ERR_INVALID_SLOT_ID;
837 }
838 CellularCallConfig config;
839 return config.GetLteImsSwitchStatus(slotId);
840 }
841
SetImsConfig(int32_t slotId,ImsConfigItem item,const std::string & value)842 int32_t CellularCallService::SetImsConfig(int32_t slotId, ImsConfigItem item, const std::string &value)
843 {
844 if (!IsValidSlotId(slotId)) {
845 TELEPHONY_LOGE("CellularCallService::SetImsConfig return, invalid slot id");
846 return CALL_ERR_INVALID_SLOT_ID;
847 }
848 CellularCallConfig config;
849 return config.SetImsConfig(item, value);
850 }
851
SetImsConfig(int32_t slotId,ImsConfigItem item,int32_t value)852 int32_t CellularCallService::SetImsConfig(int32_t slotId, ImsConfigItem item, int32_t value)
853 {
854 if (!IsValidSlotId(slotId)) {
855 TELEPHONY_LOGE("CellularCallService::SetImsConfig return, invalid slot id");
856 return CALL_ERR_INVALID_SLOT_ID;
857 }
858 CellularCallConfig config;
859 return config.SetImsConfig(item, value);
860 }
861
GetImsConfig(int32_t slotId,ImsConfigItem item)862 int32_t CellularCallService::GetImsConfig(int32_t slotId, ImsConfigItem item)
863 {
864 if (!IsValidSlotId(slotId)) {
865 TELEPHONY_LOGE("CellularCallService::GetImsConfig return, invalid slot id");
866 return CALL_ERR_INVALID_SLOT_ID;
867 }
868 CellularCallConfig config;
869 return config.GetImsConfig(item);
870 }
871
SetImsFeatureValue(int32_t slotId,FeatureType type,int32_t value)872 int32_t CellularCallService::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
873 {
874 if (!IsValidSlotId(slotId)) {
875 TELEPHONY_LOGE("CellularCallService::SetImsFeatureValue return, invalid slot id");
876 return CALL_ERR_INVALID_SLOT_ID;
877 }
878 CellularCallConfig config;
879 return config.SetImsFeatureValue(type, value);
880 }
881
GetImsFeatureValue(int32_t slotId,FeatureType type)882 int32_t CellularCallService::GetImsFeatureValue(int32_t slotId, FeatureType type)
883 {
884 if (!IsValidSlotId(slotId)) {
885 TELEPHONY_LOGE("CellularCallService::GetImsFeatureValue return, invalid slot id");
886 return CALL_ERR_INVALID_SLOT_ID;
887 }
888 CellularCallConfig config;
889 return config.GetImsFeatureValue(type);
890 }
891
SetImsSwitchEnhanceMode(int32_t slotId,bool value)892 int32_t CellularCallService::SetImsSwitchEnhanceMode(int32_t slotId, bool value)
893 {
894 if (!IsValidSlotId(slotId)) {
895 TELEPHONY_LOGE("CellularCallService::SetImsSwitchEnhanceMode return, invalid slot id");
896 return CALL_ERR_INVALID_SLOT_ID;
897 }
898 CellularCallConfig config;
899 return config.SetImsSwitchEnhanceMode(value);
900 }
901
GetImsSwitchEnhanceMode(int32_t slotId)902 int32_t CellularCallService::GetImsSwitchEnhanceMode(int32_t slotId)
903 {
904 if (!IsValidSlotId(slotId)) {
905 TELEPHONY_LOGE("CellularCallService::GetImsSwitchEnhanceMode return, invalid slot id");
906 return CALL_ERR_INVALID_SLOT_ID;
907 }
908 CellularCallConfig config;
909 return config.GetImsSwitchEnhanceMode();
910 }
911
IsValidSlotId(int32_t slotId) const912 bool CellularCallService::IsValidSlotId(int32_t slotId) const
913 {
914 const int32_t slotSingle = 1;
915 const int32_t slotDouble = 2;
916 if (SIM_SLOT_COUNT == slotSingle) {
917 return slotId == DEFAULT_SIM_SLOT_ID;
918 } else if (SIM_SLOT_COUNT == slotDouble) {
919 return slotId == SIM_SLOT_0 || slotId == SIM_SLOT_1;
920 }
921 return false;
922 }
923
IsNeedIms(int32_t slotId) const924 bool CellularCallService::IsNeedIms(int32_t slotId) const
925 {
926 ModuleServiceUtils moduleUtils;
927 CellularCallConfig config;
928 bool imsRegState = moduleUtils.GetImsRegistrationState(slotId);
929 int32_t preferenceMode = config.GetPreferenceMode(slotId);
930 bool imsSwitchStatus = config.GetSwitchStatus(slotId);
931 TELEPHONY_LOGI("IsNeedIms state:%{public}d, mode:%{public}d, status:%{public}d", imsRegState, preferenceMode,
932 imsSwitchStatus);
933 if (imsRegState && preferenceMode != DomainPreferenceMode::CS_VOICE_ONLY && imsSwitchStatus) {
934 return true;
935 }
936 return false;
937 }
938
GetHandler(int32_t slotId)939 std::shared_ptr<CellularCallHandler> CellularCallService::GetHandler(int32_t slotId)
940 {
941 return handlerMap_[slotId];
942 }
943
CtrlCamera(const std::u16string & cameraId,int32_t callingUid,int32_t callingPid)944 int32_t CellularCallService::CtrlCamera(const std::u16string &cameraId, int32_t callingUid, int32_t callingPid)
945 {
946 CellularCallConfig config;
947 return config.CtrlCamera(cameraId, callingUid, callingPid);
948 }
949
SetPreviewWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)950 int32_t CellularCallService::SetPreviewWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
951 {
952 CellularCallConfig config;
953 return config.SetPreviewWindow(x, y, z, width, height);
954 }
955
SetDisplayWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)956 int32_t CellularCallService::SetDisplayWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
957 {
958 CellularCallConfig config;
959 return config.SetDisplayWindow(x, y, z, width, height);
960 }
961
SetCameraZoom(float zoomRatio)962 int32_t CellularCallService::SetCameraZoom(float zoomRatio)
963 {
964 CellularCallConfig config;
965 return config.SetCameraZoom(zoomRatio);
966 }
967
SetPauseImage(const std::u16string & path)968 int32_t CellularCallService::SetPauseImage(const std::u16string &path)
969 {
970 CellularCallConfig config;
971 return config.SetPauseImage(path);
972 }
973
SetDeviceDirection(int32_t rotation)974 int32_t CellularCallService::SetDeviceDirection(int32_t rotation)
975 {
976 CellularCallConfig config;
977 return config.SetDeviceDirection(rotation);
978 }
979
SetMute(int32_t slotId,int32_t mute)980 int32_t CellularCallService::SetMute(int32_t slotId, int32_t mute)
981 {
982 if (!IsValidSlotId(slotId)) {
983 TELEPHONY_LOGE("CellularCallService::SetMute return, invalid slot id");
984 return CALL_ERR_INVALID_SLOT_ID;
985 }
986 CellularCallConfig config;
987 return config.SetMute(slotId, mute);
988 }
989
GetMute(int32_t slotId)990 int32_t CellularCallService::GetMute(int32_t slotId)
991 {
992 if (!IsValidSlotId(slotId)) {
993 TELEPHONY_LOGE("CellularCallService::GetMute return, invalid slot id");
994 return CALL_ERR_INVALID_SLOT_ID;
995 }
996 CellularCallConfig config;
997 return config.GetMute(slotId);
998 }
999 } // namespace Telephony
1000 } // namespace OHOS