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_service.h"
17
18 #include "cellular_call_callback.h"
19 #include "cellular_call_dump_helper.h"
20 #include "cellular_call_hisysevent.h"
21 #include "common_event.h"
22 #include "common_event_manager.h"
23 #include "common_event_support.h"
24 #include "emergency_utils.h"
25 #include "ims_call_client.h"
26 #include "module_service_utils.h"
27 #include "radio_event.h"
28 #include "string_ex.h"
29 #include "system_ability_definition.h"
30 #include "telephony_permission.h"
31
32 namespace OHOS {
33 namespace Telephony {
34 const uint32_t CONNECT_MAX_TRY_COUNT = 20;
35 const uint32_t CONNECT_CORE_SERVICE_WAIT_TIME = 2000; // ms
36 bool g_registerResult =
37 SystemAbility::MakeAndRegisterAbility(DelayedSingleton<CellularCallService>::GetInstance().get());
38
CellularCallService()39 CellularCallService::CellularCallService() : SystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID, true)
40 {
41 state_ = ServiceRunningState::STATE_STOPPED;
42 }
43
~CellularCallService()44 CellularCallService::~CellularCallService()
45 {
46 state_ = ServiceRunningState::STATE_STOPPED;
47 if (statusChangeListener_ != nullptr) {
48 statusChangeListener_.clear();
49 statusChangeListener_ = nullptr;
50 }
51 }
52
Init()53 bool CellularCallService::Init()
54 {
55 TELEPHONY_LOGI("CellularCallService::Init start");
56 eventLoop_ = AppExecFwk::EventRunner::Create("CellularCallServiceLoop");
57 if (eventLoop_ == nullptr) {
58 TELEPHONY_LOGE("CellularCallService::Init return, failed to create EventRunner");
59 return false;
60 }
61 CreateHandler();
62 SendEventRegisterHandler();
63 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
64 callManagerListener_ = new (std::nothrow) SystemAbilityStatusChangeListener();
65 if (samgrProxy == nullptr || callManagerListener_ == nullptr) {
66 TELEPHONY_LOGE("samgrProxy or callManagerListener_ is nullptr");
67 } else {
68 int32_t ret = samgrProxy->SubscribeSystemAbility(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID, callManagerListener_);
69 TELEPHONY_LOGI("SubscribeSystemAbility TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID result:%{public}d", ret);
70 }
71 // connect ims_service
72 DelayedSingleton<ImsCallClient>::GetInstance()->Init();
73 TELEPHONY_LOGI("CellularCallService::Init, init success");
74 return true;
75 }
76
OnStart()77 void CellularCallService::OnStart()
78 {
79 TELEPHONY_LOGI("CellularCallService OnStart");
80 bindTime_ =
81 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
82 .count();
83 if (state_ == ServiceRunningState::STATE_RUNNING) {
84 TELEPHONY_LOGE("CellularCallService::OnStart return, has already started.");
85 return;
86 }
87 if (!Init()) {
88 TELEPHONY_LOGE("CellularCallService::OnStart return, failed to init service.");
89 return;
90 }
91 state_ = ServiceRunningState::STATE_RUNNING;
92 if (eventLoop_ != nullptr) {
93 eventLoop_->Run();
94 }
95 bool ret = Publish(DelayedSingleton<CellularCallService>::GetInstance().get());
96 if (!ret) {
97 TELEPHONY_LOGE("CellularCallService::OnStart Publish failed!");
98 }
99 endTime_ =
100 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
101 .count();
102 TELEPHONY_LOGI("CellularCallService start success.");
103 }
104
OnStop()105 void CellularCallService::OnStop()
106 {
107 TELEPHONY_LOGI("CellularCallService stop service");
108 if (eventLoop_ != nullptr) {
109 eventLoop_.reset();
110 }
111 DelayedSingleton<ImsCallClient>::GetInstance()->UnInit();
112 state_ = ServiceRunningState::STATE_STOPPED;
113 HandlerResetUnRegister();
114 }
115
RegisterHandler()116 void CellularCallService::RegisterHandler()
117 {
118 TELEPHONY_LOGI("connect core service Register Handler start");
119 networkSearchCallBack_ = (std::make_unique<CellularCallCallback>()).release();
120 for (uint32_t i = 0; i < CONNECT_MAX_TRY_COUNT; i++) {
121 std::this_thread::sleep_for(std::chrono::milliseconds(CONNECT_CORE_SERVICE_WAIT_TIME));
122 if (CoreManagerInner::GetInstance().IsInitFinishedForTelRil()) {
123 TELEPHONY_LOGI("connect core service Register Handler start");
124 RegisterCoreServiceHandler();
125 CoreManagerInner::GetInstance().RegisterCellularCallObject(networkSearchCallBack_);
126 break;
127 }
128 TELEPHONY_LOGW("connect core service Register Handler null or not init");
129 }
130 TELEPHONY_LOGI("connect core service Register Handler end");
131 }
132
CreateHandler()133 void CellularCallService::CreateHandler()
134 {
135 ModuleServiceUtils obtain;
136 std::vector<int32_t> slotVector = obtain.GetSlotInfo();
137 EventFwk::MatchingSkills matchingSkills;
138 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
139 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
140
141 for (const auto &it : slotVector) {
142 auto handler = std::make_shared<CellularCallHandler>(eventLoop_, subscriberInfo);
143 TELEPHONY_LOGI("setSlotId:%{public}d", it);
144 handler->SetSlotId(it);
145 handler->RegisterImsCallCallbackHandler();
146 handlerMap_.insert(std::make_pair(it, handler));
147 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
148 statusChangeListener_ = new (std::nothrow) SystemAbilityStatusChangeListener(handler);
149 if (samgrProxy == nullptr || statusChangeListener_ == nullptr) {
150 TELEPHONY_LOGE("samgrProxy or statusChangeListener_ is nullptr");
151 } else {
152 int32_t ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
153 TELEPHONY_LOGI("SubscribeSystemAbility COMMON_EVENT_SERVICE_ID result:%{public}d", ret);
154 }
155 }
156 }
157
HandlerResetUnRegister()158 void CellularCallService::HandlerResetUnRegister()
159 {
160 TELEPHONY_LOGI("HandlerResetUnRegister");
161 for (const auto &it : handlerMap_) {
162 int32_t slot = it.first;
163 auto handler = it.second;
164 if (handler != nullptr) {
165 handler.reset();
166 }
167 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_AVAIL);
168 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_NOT_AVAIL);
169 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_SIM_RECORDS_LOADED);
170 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_STATUS_INFO);
171 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_USSD_NOTICE);
172 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_SS_NOTICE);
173 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_RINGBACK_VOICE);
174 CoreManagerInner::GetInstance().UnRegisterCoreNotify(
175 slot, handler, RadioEvent::RADIO_CALL_EMERGENCY_NUMBER_REPORT);
176 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_SRVCC_STATUS);
177 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_RSRVCC_STATUS);
178 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
179 CoreManagerInner::GetInstance().UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_STATE_CHANGED);
180 #endif
181 if (GetCsControl(slot) != nullptr) {
182 GetCsControl(slot)->ReleaseAllConnection();
183 }
184 if (GetImsControl(slot) != nullptr) {
185 GetImsControl(slot)->ReleaseAllConnection();
186 }
187 }
188 }
189
RegisterCoreServiceHandler()190 void CellularCallService::RegisterCoreServiceHandler()
191 {
192 TELEPHONY_LOGI("RegisterCoreServiceHandle");
193 for (const auto &it : handlerMap_) {
194 int32_t slot = it.first;
195 auto handler = it.second;
196 if (handler != nullptr) {
197 CoreManagerInner::GetInstance().RegisterCoreNotify(slot, handler, RadioEvent::RADIO_AVAIL, nullptr);
198 CoreManagerInner::GetInstance().RegisterCoreNotify(slot, handler, RadioEvent::RADIO_NOT_AVAIL, nullptr);
199 CoreManagerInner::GetInstance().RegisterCoreNotify(
200 slot, handler, RadioEvent::RADIO_SIM_STATE_CHANGE, nullptr);
201 CoreManagerInner::GetInstance().RegisterCoreNotify(
202 slot, handler, RadioEvent::RADIO_SIM_RECORDS_LOADED, nullptr);
203 CoreManagerInner::GetInstance().RegisterCoreNotify(
204 slot, handler, RadioEvent::RADIO_CALL_STATUS_INFO, nullptr);
205 CoreManagerInner::GetInstance().RegisterCoreNotify(
206 slot, handler, RadioEvent::RADIO_CALL_USSD_NOTICE, nullptr);
207 CoreManagerInner::GetInstance().RegisterCoreNotify(
208 slot, handler, RadioEvent::RADIO_CALL_SS_NOTICE, nullptr);
209 CoreManagerInner::GetInstance().RegisterCoreNotify(
210 slot, handler, RadioEvent::RADIO_CALL_EMERGENCY_NUMBER_REPORT, nullptr);
211 CoreManagerInner::GetInstance().RegisterCoreNotify(
212 slot, handler, RadioEvent::RADIO_CALL_RINGBACK_VOICE, nullptr);
213 CoreManagerInner::GetInstance().RegisterCoreNotify(
214 slot, handler, RadioEvent::RADIO_CALL_SRVCC_STATUS, nullptr);
215 CoreManagerInner::GetInstance().RegisterCoreNotify(
216 slot, handler, RadioEvent::RADIO_CALL_RSRVCC_STATUS, nullptr);
217 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
218 CoreManagerInner::GetInstance().RegisterCoreNotify(slot, handler, RadioEvent::RADIO_STATE_CHANGED, nullptr);
219 #endif
220 }
221 CellularCallConfig config;
222 config.InitModeActive();
223 if (config.GetDomainPreferenceMode(slot) != TELEPHONY_SUCCESS) {
224 TELEPHONY_LOGW("RegisterCoreServiceHandler, GetDomainPreferenceMode request fail");
225 }
226 if (config.GetEmergencyCallList(it.first) != TELEPHONY_SUCCESS) {
227 TELEPHONY_LOGW("RegisterCoreServiceHandler, GetEmergencyCallList request fail");
228 }
229 }
230 }
231
SendEventRegisterHandler()232 void CellularCallService::SendEventRegisterHandler()
233 {
234 int64_t delayTime = 1000;
235 int32_t slot = DEFAULT_SIM_SLOT_ID;
236 auto handler = handlerMap_[slot];
237 if (handler == nullptr) {
238 TELEPHONY_LOGE("SendEventRegisterHandler return, handler is nullptr");
239 return;
240 }
241 handler->SendEvent(handler->REGISTER_HANDLER_ID, delayTime, CellularCallHandler::Priority::HIGH);
242 }
243
Dump(int32_t fd,const std::vector<std::u16string> & args)244 int32_t CellularCallService::Dump(int32_t fd, const std::vector<std::u16string> &args)
245 {
246 if (fd < 0) {
247 TELEPHONY_LOGE("dump fd invalid");
248 return TELEPHONY_ERR_FAIL;
249 }
250 std::vector<std::string> argsInStr;
251 for (const auto &arg : args) {
252 argsInStr.emplace_back(Str16ToStr8(arg));
253 }
254 std::string result;
255 CellularCallDumpHelper dumpHelper;
256 if (dumpHelper.Dump(argsInStr, result)) {
257 int32_t ret = dprintf(fd, "%s", result.c_str());
258 if (ret < 0) {
259 TELEPHONY_LOGE("dprintf to dump fd failed");
260 return TELEPHONY_ERR_FAIL;
261 }
262 return TELEPHONY_SUCCESS;
263 }
264 TELEPHONY_LOGW("dumpHelper failed");
265 return TELEPHONY_ERR_FAIL;
266 }
267
GetServiceRunningState()268 int32_t CellularCallService::GetServiceRunningState()
269 {
270 return static_cast<int32_t>(state_);
271 }
272
GetBindTime()273 std::string CellularCallService::GetBindTime()
274 {
275 std::ostringstream oss;
276 oss << bindTime_;
277 return oss.str();
278 }
279
GetEndTime()280 std::string CellularCallService::GetEndTime()
281 {
282 std::ostringstream oss;
283 oss << endTime_;
284 return oss.str();
285 }
286
GetSpendTime()287 std::string CellularCallService::GetSpendTime()
288 {
289 spendTime_ = endTime_ - bindTime_;
290 std::ostringstream oss;
291 oss << spendTime_;
292 return oss.str();
293 }
294
Dial(const CellularCallInfo & callInfo)295 int32_t CellularCallService::Dial(const CellularCallInfo &callInfo)
296 {
297 if (!TelephonyPermission::CheckPermission(Permission::PLACE_CALL)) {
298 TELEPHONY_LOGE("Check permission failed, no PLACE_CALL permisson.");
299 return TELEPHONY_ERR_PERMISSION_ERR;
300 }
301
302 if (!IsValidSlotId(callInfo.slotId)) {
303 TELEPHONY_LOGE("CellularCallService::Dial return, invalid slot id");
304 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.accountId, static_cast<int32_t>(callInfo.callType),
305 callInfo.videoState, CALL_ERR_INVALID_SLOT_ID, "invalid slot id");
306 return CALL_ERR_INVALID_SLOT_ID;
307 }
308 if (srvccState_ == SrvccState::STARTED) {
309 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.accountId, static_cast<int32_t>(callInfo.callType),
310 callInfo.videoState, static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE),
311 "srvccState_ is STARTED");
312 return TELEPHONY_ERR_FAIL;
313 }
314 bool useImsForEmergency = UseImsForEmergency(callInfo);
315 if (IsNeedIms(callInfo.slotId) || useImsForEmergency) {
316 auto imsControl = GetImsControl(callInfo.slotId);
317 if (imsControl == nullptr) {
318 TELEPHONY_LOGE("CellularCallService::Dial ims dial");
319 imsControl = std::make_shared<IMSControl>();
320 if (imsControl == nullptr) {
321 TELEPHONY_LOGE("CellularCallService::Dial return, imsControl create fail");
322 return TELEPHONY_ERR_LOCAL_PTR_NULL;
323 }
324 SetImsControl(callInfo.slotId, imsControl);
325 }
326 return imsControl->Dial(callInfo);
327 }
328
329 auto csControl = GetCsControl(callInfo.slotId);
330 if (csControl == nullptr) {
331 csControl = std::make_shared<CSControl>();
332 if (csControl == nullptr) {
333 TELEPHONY_LOGE("CellularCallService::Dial return, csControl create fail");
334 return TELEPHONY_ERR_LOCAL_PTR_NULL;
335 }
336 SetCsControl(callInfo.slotId, csControl);
337 }
338 return csControl->Dial(callInfo);
339 }
340
HangUp(const CellularCallInfo & callInfo,CallSupplementType type)341 int32_t CellularCallService::HangUp(const CellularCallInfo &callInfo, CallSupplementType type)
342 {
343 DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallParameterInfo(
344 callInfo.slotId, static_cast<int32_t>(callInfo.callType), callInfo.videoState);
345 if (!TelephonyPermission::CheckPermission(Permission::ANSWER_CALL)) {
346 TELEPHONY_LOGE("Check permission failed, no ANSWER_CALL permisson.");
347 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
348 TELEPHONY_ERR_PERMISSION_ERR, Permission::ANSWER_CALL);
349 return TELEPHONY_ERR_PERMISSION_ERR;
350 }
351 if (!IsValidSlotId(callInfo.slotId)) {
352 TELEPHONY_LOGE("CellularCallService::HangUp return, invalid slot id");
353 CellularCallHiSysEvent::WriteHangUpFaultEvent(
354 callInfo.slotId, callInfo.callId, CALL_ERR_INVALID_SLOT_ID, "HangUp invalid slot id");
355 return CALL_ERR_INVALID_SLOT_ID;
356 }
357 if (srvccState_ == SrvccState::STARTED) {
358 CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, callInfo.callId,
359 static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE), "HangUp srvccState_ is STARTED");
360 return TELEPHONY_ERR_FAIL;
361 }
362 if (CallType::TYPE_CS == callInfo.callType) {
363 auto csControl = GetCsControl(callInfo.slotId);
364 if (csControl == nullptr) {
365 TELEPHONY_LOGE("CellularCallService::HangUp return, csControl is nullptr");
366 CellularCallHiSysEvent::WriteHangUpFaultEvent(
367 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "HangUp csControl is nullptr");
368 return TELEPHONY_ERR_LOCAL_PTR_NULL;
369 }
370 return csControl->HangUp(callInfo, type);
371 } else if (CallType::TYPE_IMS == callInfo.callType) {
372 auto imsControl = GetImsControl(callInfo.slotId);
373 if (imsControl == nullptr) {
374 TELEPHONY_LOGE("CellularCallService::HangUp return, imsControl is nullptr");
375 CellularCallHiSysEvent::WriteHangUpFaultEvent(
376 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "HangUp imsControl is nullptr");
377 return TELEPHONY_ERR_LOCAL_PTR_NULL;
378 }
379 return imsControl->HangUp(callInfo, type);
380 }
381 TELEPHONY_LOGE("CellularCallService::HangUp return, call type error.");
382 CellularCallHiSysEvent::WriteHangUpFaultEvent(
383 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_ARGUMENT_INVALID, "HangUp call type error");
384 return TELEPHONY_ERR_ARGUMENT_INVALID;
385 }
386
Reject(const CellularCallInfo & callInfo)387 int32_t CellularCallService::Reject(const CellularCallInfo &callInfo)
388 {
389 DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallParameterInfo(
390 callInfo.slotId, static_cast<int32_t>(callInfo.callType), callInfo.videoState);
391 if (!TelephonyPermission::CheckPermission(Permission::ANSWER_CALL)) {
392 TELEPHONY_LOGE("Check permission failed, no ANSWER_CALL permisson.");
393 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
394 TELEPHONY_ERR_PERMISSION_ERR, Permission::ANSWER_CALL);
395 return TELEPHONY_ERR_PERMISSION_ERR;
396 }
397 if (!IsValidSlotId(callInfo.slotId)) {
398 TELEPHONY_LOGE("CellularCallService::Reject return, invalid slot id");
399 CellularCallHiSysEvent::WriteHangUpFaultEvent(
400 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_ARGUMENT_INVALID, "Reject call type error");
401 return CALL_ERR_INVALID_SLOT_ID;
402 }
403 if (srvccState_ == SrvccState::STARTED) {
404 CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, callInfo.callId,
405 static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE), "Reject srvccState_ is STARTED");
406 return TELEPHONY_ERR_FAIL;
407 }
408 if (CallType::TYPE_CS == callInfo.callType) {
409 auto csControl = GetCsControl(callInfo.slotId);
410 if (csControl == nullptr) {
411 TELEPHONY_LOGE("CellularCallService::Reject return, csControl is nullptr");
412 CellularCallHiSysEvent::WriteHangUpFaultEvent(
413 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "Reject csControl is nullptr");
414 return TELEPHONY_ERR_LOCAL_PTR_NULL;
415 }
416 return csControl->Reject(callInfo);
417 } else if (CallType::TYPE_IMS == callInfo.callType) {
418 auto imsControl = GetImsControl(callInfo.slotId);
419 if (imsControl == nullptr) {
420 TELEPHONY_LOGE("CellularCallService::Reject return, imsControl is nullptr");
421 CellularCallHiSysEvent::WriteHangUpFaultEvent(
422 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "Reject imsControl is nullptr");
423 return TELEPHONY_ERR_LOCAL_PTR_NULL;
424 }
425 return imsControl->Reject(callInfo);
426 }
427 TELEPHONY_LOGE("CellularCallService::Reject return, call type error.");
428 CellularCallHiSysEvent::WriteHangUpFaultEvent(
429 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_ARGUMENT_INVALID, "Reject call type error");
430 return TELEPHONY_ERR_ARGUMENT_INVALID;
431 }
432
Answer(const CellularCallInfo & callInfo)433 int32_t CellularCallService::Answer(const CellularCallInfo &callInfo)
434 {
435 DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallParameterInfo(
436 callInfo.slotId, static_cast<int32_t>(callInfo.callType), callInfo.videoState);
437 if (!TelephonyPermission::CheckPermission(Permission::ANSWER_CALL)) {
438 TELEPHONY_LOGE("Check permission failed, no ANSWER_CALL permisson.");
439 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
440 TELEPHONY_ERR_PERMISSION_ERR, Permission::ANSWER_CALL);
441 return TELEPHONY_ERR_PERMISSION_ERR;
442 }
443
444 if (!IsValidSlotId(callInfo.slotId)) {
445 TELEPHONY_LOGE("CellularCallService::Answer return, invalid slot id");
446 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(
447 callInfo.slotId, callInfo.callId, callInfo.videoState, CALL_ERR_INVALID_SLOT_ID, "invalid slot id");
448 return CALL_ERR_INVALID_SLOT_ID;
449 }
450 if (srvccState_ == SrvccState::STARTED) {
451 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
452 static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE), "srvccState_ is STARTED");
453 return TELEPHONY_ERR_FAIL;
454 }
455 if (CallType::TYPE_CS == callInfo.callType) {
456 auto csControl = GetCsControl(callInfo.slotId);
457 if (csControl == nullptr) {
458 TELEPHONY_LOGE("CellularCallService::Answer return, csControl is nullptr");
459 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
460 TELEPHONY_ERR_LOCAL_PTR_NULL, "csControl is nullptr");
461 return TELEPHONY_ERR_LOCAL_PTR_NULL;
462 }
463 return csControl->Answer(callInfo);
464 } else if (CallType::TYPE_IMS == callInfo.callType) {
465 auto imsControl = GetImsControl(callInfo.slotId);
466 if (imsControl == nullptr) {
467 TELEPHONY_LOGE("CellularCallService::Answer return, imsControl is nullptr");
468 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
469 TELEPHONY_ERR_LOCAL_PTR_NULL, "imsControl is nullptr");
470 return TELEPHONY_ERR_LOCAL_PTR_NULL;
471 }
472 return imsControl->Answer(callInfo);
473 }
474 TELEPHONY_LOGE("CellularCallService::Answer return, call type error.");
475 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(
476 callInfo.slotId, callInfo.callId, callInfo.videoState, TELEPHONY_ERR_LOCAL_PTR_NULL, "call type error");
477 return TELEPHONY_ERR_ARGUMENT_INVALID;
478 }
479
RegisterCallManagerCallBack(const sptr<ICallStatusCallback> & callback)480 int32_t CellularCallService::RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback)
481 {
482 if (!TelephonyPermission::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
483 TELEPHONY_LOGE("CellularCallService::RegisterCallManagerCallBack return, Permission denied!");
484 return TELEPHONY_ERR_PERMISSION_ERR;
485 }
486 if (DelayedSingleton<CellularCallRegister>::GetInstance() == nullptr) {
487 TELEPHONY_LOGE("CellularCallService::RegisterCallManagerCallBack return, instance is nullptr.");
488 return TELEPHONY_ERR_LOCAL_PTR_NULL;
489 }
490 return DelayedSingleton<CellularCallRegister>::GetInstance()->RegisterCallManagerCallBack(callback);
491 }
492
UnRegisterCallManagerCallBack()493 int32_t CellularCallService::UnRegisterCallManagerCallBack()
494 {
495 if (!TelephonyPermission::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
496 TELEPHONY_LOGE("CellularCallService::UnRegisterCallManagerCallBack return, Permission denied!");
497 return TELEPHONY_ERR_PERMISSION_ERR;
498 }
499 if (DelayedSingleton<CellularCallRegister>::GetInstance() == nullptr) {
500 TELEPHONY_LOGE("CellularCallService::UnRegisterCallManagerCallBack return, instance is nullptr.");
501 return TELEPHONY_ERR_LOCAL_PTR_NULL;
502 }
503 return DelayedSingleton<CellularCallRegister>::GetInstance()->UnRegisterCallManagerCallBack();
504 }
505
HoldCall(const CellularCallInfo & callInfo)506 int32_t CellularCallService::HoldCall(const CellularCallInfo &callInfo)
507 {
508 if (!TelephonyPermission::CheckPermission(Permission::ANSWER_CALL)) {
509 TELEPHONY_LOGE("Check permission failed, no ANSWER_CALL permisson.");
510 return TELEPHONY_ERR_PERMISSION_ERR;
511 }
512 if (!IsValidSlotId(callInfo.slotId)) {
513 TELEPHONY_LOGE("CellularCallService::HoldCall return, invalid slot id");
514 return CALL_ERR_INVALID_SLOT_ID;
515 }
516 if (srvccState_ == SrvccState::STARTED) {
517 return TELEPHONY_ERR_FAIL;
518 }
519 if (CallType::TYPE_IMS == callInfo.callType) {
520 auto imsControl = GetImsControl(callInfo.slotId);
521 if (imsControl == nullptr) {
522 TELEPHONY_LOGE("CellularCallService::HoldCall return, imsControl is nullptr");
523 return TELEPHONY_ERR_LOCAL_PTR_NULL;
524 }
525 return imsControl->HoldCall(callInfo.slotId);
526 } else if (CallType::TYPE_CS == callInfo.callType) {
527 auto csControl = GetCsControl(callInfo.slotId);
528 if (csControl == nullptr) {
529 TELEPHONY_LOGE("CellularCallService::HoldCall return, csControl is nullptr");
530 return TELEPHONY_ERR_LOCAL_PTR_NULL;
531 }
532 return csControl->HoldCall(callInfo.slotId);
533 }
534 TELEPHONY_LOGE("CellularCallService::HoldCall return, call type error.");
535 return TELEPHONY_ERR_ARGUMENT_INVALID;
536 }
537
UnHoldCall(const CellularCallInfo & callInfo)538 int32_t CellularCallService::UnHoldCall(const CellularCallInfo &callInfo)
539 {
540 if (!TelephonyPermission::CheckPermission(Permission::ANSWER_CALL)) {
541 TELEPHONY_LOGE("Check permission failed, no ANSWER_CALL permisson.");
542 return TELEPHONY_ERR_PERMISSION_ERR;
543 }
544 if (!IsValidSlotId(callInfo.slotId)) {
545 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, invalid slot id");
546 return CALL_ERR_INVALID_SLOT_ID;
547 }
548 if (srvccState_ == SrvccState::STARTED) {
549 return TELEPHONY_ERR_FAIL;
550 }
551 if (CallType::TYPE_IMS == callInfo.callType) {
552 auto imsControl = GetImsControl(callInfo.slotId);
553 if (imsControl == nullptr) {
554 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, imsControl is nullptr");
555 return TELEPHONY_ERR_LOCAL_PTR_NULL;
556 }
557 return imsControl->UnHoldCall(callInfo.slotId);
558 } else if (CallType::TYPE_CS == callInfo.callType) {
559 auto csControl = GetCsControl(callInfo.slotId);
560 if (csControl == nullptr) {
561 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, csControl is nullptr");
562 return TELEPHONY_ERR_LOCAL_PTR_NULL;
563 }
564 return csControl->UnHoldCall(callInfo.slotId);
565 }
566 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, call type error.");
567 return TELEPHONY_ERR_ARGUMENT_INVALID;
568 }
569
SwitchCall(const CellularCallInfo & callInfo)570 int32_t CellularCallService::SwitchCall(const CellularCallInfo &callInfo)
571 {
572 if (!TelephonyPermission::CheckPermission(Permission::ANSWER_CALL)) {
573 TELEPHONY_LOGE("Check permission failed, no ANSWER_CALL permisson.");
574 return TELEPHONY_ERR_PERMISSION_ERR;
575 }
576 if (!IsValidSlotId(callInfo.slotId)) {
577 TELEPHONY_LOGE("CellularCallService::SwitchCall return, invalid slot id");
578 return CALL_ERR_INVALID_SLOT_ID;
579 }
580 if (srvccState_ == SrvccState::STARTED) {
581 return TELEPHONY_ERR_FAIL;
582 }
583 if (CallType::TYPE_IMS == callInfo.callType) {
584 auto imsControl = GetImsControl(callInfo.slotId);
585 if (imsControl == nullptr) {
586 TELEPHONY_LOGE("CellularCallService::SwitchCall return, imsControl is nullptr");
587 return TELEPHONY_ERR_LOCAL_PTR_NULL;
588 }
589 return imsControl->SwitchCall(callInfo.slotId);
590 } else if (CallType::TYPE_CS == callInfo.callType) {
591 auto csControl = GetCsControl(callInfo.slotId);
592 if (csControl == nullptr) {
593 TELEPHONY_LOGE("CellularCallService::SwitchCall return, csControl is nullptr");
594 return TELEPHONY_ERR_LOCAL_PTR_NULL;
595 }
596 return csControl->SwitchCall(callInfo.slotId);
597 }
598 TELEPHONY_LOGE("CellularCallService::SwitchCall return, call type error.");
599 return TELEPHONY_ERR_ARGUMENT_INVALID;
600 }
601
CombineConference(const CellularCallInfo & callInfo)602 int32_t CellularCallService::CombineConference(const CellularCallInfo &callInfo)
603 {
604 if (!IsValidSlotId(callInfo.slotId)) {
605 TELEPHONY_LOGE("CellularCallService::CombineConference return, invalid slot id");
606 return CALL_ERR_INVALID_SLOT_ID;
607 }
608 if (srvccState_ == SrvccState::STARTED) {
609 return TELEPHONY_ERR_FAIL;
610 }
611 if (CallType::TYPE_IMS == callInfo.callType) {
612 auto imsControl = GetImsControl(callInfo.slotId);
613 if (imsControl == nullptr) {
614 TELEPHONY_LOGE("CellularCallService::CombineConference return, imsControl is nullptr");
615 return TELEPHONY_ERR_LOCAL_PTR_NULL;
616 }
617 return imsControl->CombineConference(callInfo.slotId);
618 } else if (CallType::TYPE_CS == callInfo.callType) {
619 auto csControl = GetCsControl(callInfo.slotId);
620 if (csControl == nullptr) {
621 TELEPHONY_LOGE("CellularCallService::CombineConference return, csControl is nullptr");
622 return TELEPHONY_ERR_LOCAL_PTR_NULL;
623 }
624 return csControl->CombineConference(callInfo.slotId);
625 }
626 TELEPHONY_LOGE("CellularCallService::CombineConference return, call type error.");
627 return TELEPHONY_ERR_ARGUMENT_INVALID;
628 }
629
SeparateConference(const CellularCallInfo & callInfo)630 int32_t CellularCallService::SeparateConference(const CellularCallInfo &callInfo)
631 {
632 if (!IsValidSlotId(callInfo.slotId)) {
633 TELEPHONY_LOGE("CellularCallService::SeparateConference return, invalid slot id");
634 return CALL_ERR_INVALID_SLOT_ID;
635 }
636 if (CallType::TYPE_IMS == callInfo.callType) {
637 auto imsControl = GetImsControl(callInfo.slotId);
638 if (imsControl == nullptr) {
639 TELEPHONY_LOGE("CellularCallService::SeparateConference return, imsControl is nullptr");
640 return TELEPHONY_ERR_LOCAL_PTR_NULL;
641 }
642 std::vector<std::string> numberList;
643 numberList.emplace_back(callInfo.phoneNum);
644 return imsControl->KickOutFromConference(callInfo.slotId, numberList);
645 } else if (CallType::TYPE_CS == callInfo.callType) {
646 auto csControl = GetCsControl(callInfo.slotId);
647 if (csControl == nullptr) {
648 TELEPHONY_LOGE("CellularCallService::SeparateConference return, csControl is nullptr");
649 return TELEPHONY_ERR_LOCAL_PTR_NULL;
650 }
651 return csControl->SeparateConference(callInfo.slotId, callInfo.phoneNum, callInfo.index);
652 }
653 TELEPHONY_LOGE("CellularCallService::SeparateConference return, call type error.");
654 return TELEPHONY_ERR_ARGUMENT_INVALID;
655 }
656
InviteToConference(int32_t slotId,const std::vector<std::string> & numberList)657 int32_t CellularCallService::InviteToConference(int32_t slotId, const std::vector<std::string> &numberList)
658 {
659 auto control = GetImsControl(slotId);
660 if (control == nullptr) {
661 TELEPHONY_LOGE("CellularCallService::InviteToConference return, control is nullptr");
662 return TELEPHONY_ERR_LOCAL_PTR_NULL;
663 }
664 return control->InviteToConference(slotId, numberList);
665 }
666
KickOutFromConference(int32_t slotId,const std::vector<std::string> & numberList)667 int32_t CellularCallService::KickOutFromConference(int32_t slotId, const std::vector<std::string> &numberList)
668 {
669 auto control = GetImsControl(slotId);
670 if (control == nullptr) {
671 TELEPHONY_LOGE("CellularCallService::KickOutFromConference return, control is nullptr");
672 return TELEPHONY_ERR_LOCAL_PTR_NULL;
673 }
674 return control->KickOutFromConference(slotId, numberList);
675 }
676
HangUpAllConnection()677 int32_t CellularCallService::HangUpAllConnection()
678 {
679 ModuleServiceUtils obtain;
680 std::vector<int32_t> slotVector = obtain.GetSlotInfo();
681 for (const auto &it : slotVector) {
682 if (GetCsControl(it)) {
683 GetCsControl(it)->HangUpAllConnection(it);
684 }
685 if (GetImsControl(it)) {
686 GetImsControl(it)->HangUpAllConnection(it);
687 }
688 }
689 return TELEPHONY_SUCCESS;
690 }
691
HangUpAllConnection(int32_t slotId)692 int32_t CellularCallService::HangUpAllConnection(int32_t slotId)
693 {
694 if (GetCsControl(slotId)) {
695 GetCsControl(slotId)->HangUpAllConnection(slotId);
696 }
697 if (GetImsControl(slotId)) {
698 GetImsControl(slotId)->HangUpAllConnection(slotId);
699 }
700 return TELEPHONY_SUCCESS;
701 }
702
UpdateImsCallMode(const CellularCallInfo & callInfo,ImsCallMode mode)703 int32_t CellularCallService::UpdateImsCallMode(const CellularCallInfo &callInfo, ImsCallMode mode)
704 {
705 auto control = GetImsControl(callInfo.slotId);
706 if (control == nullptr) {
707 TELEPHONY_LOGE("CellularCallService::UpdateImsCallMode return, control is nullptr");
708 return TELEPHONY_ERR_LOCAL_PTR_NULL;
709 }
710 return control->UpdateImsCallMode(callInfo, mode);
711 }
712
StartDtmf(char cDtmfCode,const CellularCallInfo & callInfo)713 int32_t CellularCallService::StartDtmf(char cDtmfCode, const CellularCallInfo &callInfo)
714 {
715 if (!IsValidSlotId(callInfo.slotId)) {
716 TELEPHONY_LOGE("CellularCallService::StartDtmf return, invalid slot id");
717 return CALL_ERR_INVALID_SLOT_ID;
718 }
719 if (srvccState_ == SrvccState::STARTED) {
720 return TELEPHONY_ERR_FAIL;
721 }
722 if (CallType::TYPE_IMS == callInfo.callType) {
723 auto imsControl = GetImsControl(callInfo.slotId);
724 if (imsControl == nullptr) {
725 TELEPHONY_LOGE("CellularCallService::StartDtmf return, imsControl is nullptr");
726 return TELEPHONY_ERR_LOCAL_PTR_NULL;
727 }
728 return imsControl->StartDtmf(imsControl->GetConnectionMap(), cDtmfCode, callInfo);
729 } else if (CallType::TYPE_CS == callInfo.callType) {
730 auto csControl = GetCsControl(callInfo.slotId);
731 if (csControl == nullptr) {
732 TELEPHONY_LOGE("CellularCallService::StartDtmf return, csControl is nullptr");
733 return TELEPHONY_ERR_LOCAL_PTR_NULL;
734 }
735 return csControl->StartDtmf(csControl->GetConnectionMap(), cDtmfCode, callInfo);
736 }
737 TELEPHONY_LOGE("CellularCallService::StartDtmf return, call type error.");
738 return TELEPHONY_ERR_ARGUMENT_INVALID;
739 }
740
StopDtmf(const CellularCallInfo & callInfo)741 int32_t CellularCallService::StopDtmf(const CellularCallInfo &callInfo)
742 {
743 if (!IsValidSlotId(callInfo.slotId)) {
744 TELEPHONY_LOGE("CellularCallService::StopDtmf return, invalid slot id");
745 return CALL_ERR_INVALID_SLOT_ID;
746 }
747 if (srvccState_ == SrvccState::STARTED) {
748 return TELEPHONY_ERR_FAIL;
749 }
750 if (CallType::TYPE_IMS == callInfo.callType) {
751 auto imsControl = GetImsControl(callInfo.slotId);
752 if (imsControl == nullptr) {
753 TELEPHONY_LOGE("CellularCallService::StopDtmf return, imsControl is nullptr");
754 return TELEPHONY_ERR_LOCAL_PTR_NULL;
755 }
756 return imsControl->StopDtmf(imsControl->GetConnectionMap(), callInfo);
757 } else if (CallType::TYPE_CS == callInfo.callType) {
758 auto csControl = GetCsControl(callInfo.slotId);
759 if (csControl == nullptr) {
760 TELEPHONY_LOGE("CellularCallService::StopDtmf return, csControl is nullptr");
761 return TELEPHONY_ERR_LOCAL_PTR_NULL;
762 }
763 return csControl->StopDtmf(csControl->GetConnectionMap(), callInfo);
764 }
765 TELEPHONY_LOGE("CellularCallService::StopDtmf return, call type error.");
766 return TELEPHONY_ERR_ARGUMENT_INVALID;
767 }
768
SendDtmf(char cDtmfCode,const CellularCallInfo & callInfo)769 int32_t CellularCallService::SendDtmf(char cDtmfCode, const CellularCallInfo &callInfo)
770 {
771 if (!IsValidSlotId(callInfo.slotId)) {
772 TELEPHONY_LOGE("CellularCallService::SendDtmf return, invalid slot id");
773 return CALL_ERR_INVALID_SLOT_ID;
774 }
775 if (srvccState_ == SrvccState::STARTED) {
776 return TELEPHONY_ERR_FAIL;
777 }
778 if (CallType::TYPE_IMS == callInfo.callType) {
779 auto imsControl = GetImsControl(callInfo.slotId);
780 if (imsControl == nullptr) {
781 TELEPHONY_LOGE("CellularCallService::SendDtmf return, imsControl is nullptr");
782 return TELEPHONY_ERR_LOCAL_PTR_NULL;
783 }
784 return imsControl->SendDtmf(imsControl->GetConnectionMap(), cDtmfCode, callInfo);
785 } else if (CallType::TYPE_CS == callInfo.callType) {
786 auto csControl = GetCsControl(callInfo.slotId);
787 if (csControl == nullptr) {
788 TELEPHONY_LOGE("CellularCallService::SendDtmf return, csControl is nullptr");
789 return TELEPHONY_ERR_LOCAL_PTR_NULL;
790 }
791 return csControl->SendDtmf(csControl->GetConnectionMap(), cDtmfCode, callInfo);
792 }
793 TELEPHONY_LOGE("CellularCallService::SendDtmf return, call type error.");
794 return TELEPHONY_ERR_ARGUMENT_INVALID;
795 }
796
StartRtt(int32_t slotId,const std::string & msg)797 int32_t CellularCallService::StartRtt(int32_t slotId, const std::string &msg)
798 {
799 auto control = GetImsControl(slotId);
800 if (control == nullptr) {
801 TELEPHONY_LOGE("CellularCallService::StartRtt return, control is nullptr");
802 return TELEPHONY_ERR_LOCAL_PTR_NULL;
803 }
804 return control->StartRtt(slotId, msg);
805 }
806
StopRtt(int32_t slotId)807 int32_t CellularCallService::StopRtt(int32_t slotId)
808 {
809 auto control = GetImsControl(slotId);
810 if (control == nullptr) {
811 TELEPHONY_LOGE("CellularCallService::StopRtt return, control is nullptr");
812 return TELEPHONY_ERR_LOCAL_PTR_NULL;
813 }
814 return control->StopRtt(slotId);
815 }
816
SetCallTransferInfo(int32_t slotId,const CallTransferInfo & cTInfo)817 int32_t CellularCallService::SetCallTransferInfo(int32_t slotId, const CallTransferInfo &cTInfo)
818 {
819 if (!TelephonyPermission::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
820 TELEPHONY_LOGE("CellularCallService::SetCallTransferInfo return, Permission denied!");
821 return TELEPHONY_ERR_PERMISSION_ERR;
822 }
823 if (!IsValidSlotId(slotId)) {
824 TELEPHONY_LOGE("CellularCallService::SetCallTransferInfo return, invalid slot id");
825 return CALL_ERR_INVALID_SLOT_ID;
826 }
827 CellularCallSupplement cellularCallSupplement;
828 return cellularCallSupplement.SetCallTransferInfo(slotId, cTInfo);
829 }
830
GetCallTransferInfo(int32_t slotId,CallTransferType type)831 int32_t CellularCallService::GetCallTransferInfo(int32_t slotId, CallTransferType type)
832 {
833 if (!TelephonyPermission::CheckPermission(Permission::GET_TELEPHONY_STATE)) {
834 TELEPHONY_LOGE("CellularCallService::GetCallTransferInfo return, Permission denied!");
835 return TELEPHONY_ERR_PERMISSION_ERR;
836 }
837 TELEPHONY_LOGI("CellularCallService::GetCallTransferInfo");
838 if (!IsValidSlotId(slotId)) {
839 TELEPHONY_LOGE("CellularCallService::GetCallTransferInfo return, invalid slot id");
840 return CALL_ERR_INVALID_SLOT_ID;
841 }
842 CellularCallSupplement cellularCallSupplement;
843 return cellularCallSupplement.GetCallTransferInfo(slotId, type);
844 }
845
GetCsControl(int32_t slotId)846 std::shared_ptr<CSControl> CellularCallService::GetCsControl(int32_t slotId)
847 {
848 return csControlMap_[slotId];
849 }
850
GetImsControl(int32_t slotId)851 std::shared_ptr<IMSControl> CellularCallService::GetImsControl(int32_t slotId)
852 {
853 return imsControlMap_[slotId];
854 }
855
SetCsControl(int32_t slotId,const std::shared_ptr<CSControl> & csControl)856 void CellularCallService::SetCsControl(int32_t slotId, const std::shared_ptr<CSControl> &csControl)
857 {
858 csControlMap_[slotId] = csControl;
859 }
860
SetImsControl(int32_t slotId,const std::shared_ptr<IMSControl> & imsControl)861 void CellularCallService::SetImsControl(int32_t slotId, const std::shared_ptr<IMSControl> &imsControl)
862 {
863 imsControlMap_[slotId] = imsControl;
864 }
865
SetCallWaiting(int32_t slotId,bool activate)866 int32_t CellularCallService::SetCallWaiting(int32_t slotId, bool activate)
867 {
868 if (!TelephonyPermission::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
869 TELEPHONY_LOGE("CellularCallService::SetCallWaiting return, Permission denied!");
870 return TELEPHONY_ERR_PERMISSION_ERR;
871 }
872 if (!IsValidSlotId(slotId)) {
873 TELEPHONY_LOGE("CellularCallService::SetCallWaiting return, invalid slot id");
874 return CALL_ERR_INVALID_SLOT_ID;
875 }
876 CellularCallSupplement cellularCallSupplement;
877 return cellularCallSupplement.SetCallWaiting(slotId, activate);
878 }
879
GetCallWaiting(int32_t slotId)880 int32_t CellularCallService::GetCallWaiting(int32_t slotId)
881 {
882 if (!TelephonyPermission::CheckPermission(Permission::GET_TELEPHONY_STATE)) {
883 TELEPHONY_LOGE("CellularCallService::GetCallWaiting return, Permission denied!");
884 return TELEPHONY_ERR_PERMISSION_ERR;
885 }
886 TELEPHONY_LOGI("CellularCallService::GetCallWaiting");
887 if (!IsValidSlotId(slotId)) {
888 TELEPHONY_LOGE("CellularCallService::GetCallWaiting return, invalid slot id");
889 return CALL_ERR_INVALID_SLOT_ID;
890 }
891 CellularCallSupplement cellularCallSupplement;
892 return cellularCallSupplement.GetCallWaiting(slotId);
893 }
894
SetCallRestriction(int32_t slotId,const CallRestrictionInfo & crInfo)895 int32_t CellularCallService::SetCallRestriction(int32_t slotId, const CallRestrictionInfo &crInfo)
896 {
897 if (!TelephonyPermission::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
898 TELEPHONY_LOGE("CellularCallService::SetCallRestriction return, Permission denied!");
899 return TELEPHONY_ERR_PERMISSION_ERR;
900 }
901 TELEPHONY_LOGI("CellularCallService::SetCallRestriction");
902 if (!IsValidSlotId(slotId)) {
903 TELEPHONY_LOGE("CellularCallService::SetCallRestriction return, invalid slot id");
904 return CALL_ERR_INVALID_SLOT_ID;
905 }
906 CellularCallSupplement cellularCallSupplement;
907 return cellularCallSupplement.SetCallRestriction(slotId, crInfo);
908 }
909
GetCallRestriction(int32_t slotId,CallRestrictionType facType)910 int32_t CellularCallService::GetCallRestriction(int32_t slotId, CallRestrictionType facType)
911 {
912 if (!TelephonyPermission::CheckPermission(Permission::GET_TELEPHONY_STATE)) {
913 TELEPHONY_LOGE("CellularCallService::GetCallRestriction return, Permission denied!");
914 return TELEPHONY_ERR_PERMISSION_ERR;
915 }
916 TELEPHONY_LOGI("CellularCallService::GetCallRestriction");
917 if (!IsValidSlotId(slotId)) {
918 TELEPHONY_LOGE("CellularCallService::GetCallRestriction return, invalid slot id");
919 return CALL_ERR_INVALID_SLOT_ID;
920 }
921 CellularCallSupplement cellularCallSupplement;
922 return cellularCallSupplement.GetCallRestriction(slotId, facType);
923 }
924
IsEmergencyPhoneNumber(int32_t slotId,const std::string & phoneNum,bool & enabled)925 int32_t CellularCallService::IsEmergencyPhoneNumber(int32_t slotId, const std::string &phoneNum, bool &enabled)
926 {
927 if (!IsValidSlotId(slotId)) {
928 TELEPHONY_LOGE("CellularCallService::IsEmergencyPhoneNumber return, invalid slot id");
929 return CALL_ERR_INVALID_SLOT_ID;
930 }
931 EmergencyUtils emergencyUtils;
932 return emergencyUtils.IsEmergencyCall(slotId, phoneNum, enabled);
933 }
934
SetEmergencyCallList(int32_t slotId,std::vector<EmergencyCall> & eccVec)935 int32_t CellularCallService::SetEmergencyCallList(int32_t slotId, std::vector<EmergencyCall> &eccVec)
936 {
937 TELEPHONY_LOGE("CellularCallService::SetEmergencyCallList start");
938 if (!IsValidSlotId(slotId)) {
939 TELEPHONY_LOGE("CellularCallService::SetMute return, invalid slot id");
940 return CALL_ERR_INVALID_SLOT_ID;
941 }
942 CellularCallConfig config;
943 return config.SetEmergencyCallList(slotId, eccVec);
944 }
945
SetDomainPreferenceMode(int32_t slotId,int32_t mode)946 int32_t CellularCallService::SetDomainPreferenceMode(int32_t slotId, int32_t mode)
947 {
948 if (!TelephonyPermission::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
949 TELEPHONY_LOGE("CellularCallService::SetDomainPreferenceMode return, Permission denied!");
950 return TELEPHONY_ERR_PERMISSION_ERR;
951 }
952 if (!IsValidSlotId(slotId)) {
953 TELEPHONY_LOGE("CellularCallService::SetDomainPreferenceMode return, invalid slot id");
954 return CALL_ERR_INVALID_SLOT_ID;
955 }
956 CellularCallConfig config;
957 return config.SetDomainPreferenceMode(slotId, mode);
958 }
959
GetDomainPreferenceMode(int32_t slotId)960 int32_t CellularCallService::GetDomainPreferenceMode(int32_t slotId)
961 {
962 if (!IsValidSlotId(slotId)) {
963 TELEPHONY_LOGE("CellularCallService::GetDomainPreferenceMode return, invalid slot id");
964 return CALL_ERR_INVALID_SLOT_ID;
965 }
966 CellularCallConfig config;
967 return config.GetDomainPreferenceMode(slotId);
968 }
969
SetImsSwitchStatus(int32_t slotId,bool active)970 int32_t CellularCallService::SetImsSwitchStatus(int32_t slotId, bool active)
971 {
972 if (!TelephonyPermission::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
973 TELEPHONY_LOGE("CellularCallService::SetImsSwitchStatus return, Permission denied!");
974 return TELEPHONY_ERR_PERMISSION_ERR;
975 }
976 if (!IsValidSlotId(slotId)) {
977 TELEPHONY_LOGE("CellularCallService::SetImsSwitchStatus return, invalid slot id");
978 return CALL_ERR_INVALID_SLOT_ID;
979 }
980 CellularCallConfig config;
981 return config.SetImsSwitchStatus(slotId, active);
982 }
983
GetImsSwitchStatus(int32_t slotId,bool & enabled)984 int32_t CellularCallService::GetImsSwitchStatus(int32_t slotId, bool &enabled)
985 {
986 if (!IsValidSlotId(slotId)) {
987 TELEPHONY_LOGE("CellularCallService::GetImsSwitchStatus return, invalid slot id");
988 return CALL_ERR_INVALID_SLOT_ID;
989 }
990 CellularCallConfig config;
991 return config.GetImsSwitchStatus(slotId, enabled);
992 }
993
SetImsConfig(int32_t slotId,ImsConfigItem item,const std::string & value)994 int32_t CellularCallService::SetImsConfig(int32_t slotId, ImsConfigItem item, const std::string &value)
995 {
996 if (!IsValidSlotId(slotId)) {
997 TELEPHONY_LOGE("CellularCallService::SetImsConfig return, invalid slot id");
998 return CALL_ERR_INVALID_SLOT_ID;
999 }
1000 CellularCallConfig config;
1001 return config.SetImsConfig(item, value);
1002 }
1003
SetImsConfig(int32_t slotId,ImsConfigItem item,int32_t value)1004 int32_t CellularCallService::SetImsConfig(int32_t slotId, ImsConfigItem item, int32_t value)
1005 {
1006 if (!IsValidSlotId(slotId)) {
1007 TELEPHONY_LOGE("CellularCallService::SetImsConfig return, invalid slot id");
1008 return CALL_ERR_INVALID_SLOT_ID;
1009 }
1010 CellularCallConfig config;
1011 return config.SetImsConfig(item, value);
1012 }
1013
GetImsConfig(int32_t slotId,ImsConfigItem item)1014 int32_t CellularCallService::GetImsConfig(int32_t slotId, ImsConfigItem item)
1015 {
1016 if (!IsValidSlotId(slotId)) {
1017 TELEPHONY_LOGE("CellularCallService::GetImsConfig return, invalid slot id");
1018 return CALL_ERR_INVALID_SLOT_ID;
1019 }
1020 CellularCallConfig config;
1021 return config.GetImsConfig(item);
1022 }
1023
SetImsFeatureValue(int32_t slotId,FeatureType type,int32_t value)1024 int32_t CellularCallService::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
1025 {
1026 if (!IsValidSlotId(slotId)) {
1027 TELEPHONY_LOGE("CellularCallService::SetImsFeatureValue return, invalid slot id");
1028 return CALL_ERR_INVALID_SLOT_ID;
1029 }
1030 CellularCallConfig config;
1031 return config.SetImsFeatureValue(type, value);
1032 }
1033
GetImsFeatureValue(int32_t slotId,FeatureType type)1034 int32_t CellularCallService::GetImsFeatureValue(int32_t slotId, FeatureType type)
1035 {
1036 if (!IsValidSlotId(slotId)) {
1037 TELEPHONY_LOGE("CellularCallService::GetImsFeatureValue return, invalid slot id");
1038 return CALL_ERR_INVALID_SLOT_ID;
1039 }
1040 CellularCallConfig config;
1041 return config.GetImsFeatureValue(type);
1042 }
1043
IsValidSlotId(int32_t slotId) const1044 bool CellularCallService::IsValidSlotId(int32_t slotId) const
1045 {
1046 const int32_t slotSingle = 1;
1047 const int32_t slotDouble = 2;
1048 if (SIM_SLOT_COUNT == slotSingle) {
1049 return slotId == DEFAULT_SIM_SLOT_ID;
1050 } else if (SIM_SLOT_COUNT == slotDouble) {
1051 return slotId == SIM_SLOT_0 || slotId == SIM_SLOT_1;
1052 }
1053 return false;
1054 }
1055
IsNeedIms(int32_t slotId) const1056 bool CellularCallService::IsNeedIms(int32_t slotId) const
1057 {
1058 ModuleServiceUtils moduleUtils;
1059 CellularCallConfig config;
1060 bool imsRegState = moduleUtils.GetImsRegistrationState(slotId);
1061 bool imsServiceConnected = moduleUtils.NeedCallImsService();
1062 int32_t preferenceMode = config.GetPreferenceMode(slotId);
1063 bool imsSwitchStatus = config.GetSwitchStatus(slotId);
1064 TELEPHONY_LOGI("IsNeedIms state:%{public}d, mode:%{public}d, status:%{public}d, connected:%{public}d", imsRegState,
1065 preferenceMode, imsSwitchStatus, imsServiceConnected);
1066 if (imsRegState && preferenceMode != DomainPreferenceMode::CS_VOICE_ONLY && imsSwitchStatus &&
1067 imsServiceConnected) {
1068 return true;
1069 }
1070 return false;
1071 }
1072
GetHandler(int32_t slotId)1073 std::shared_ptr<CellularCallHandler> CellularCallService::GetHandler(int32_t slotId)
1074 {
1075 return handlerMap_[slotId];
1076 }
1077
CtrlCamera(const std::u16string & cameraId,int32_t callingUid,int32_t callingPid)1078 int32_t CellularCallService::CtrlCamera(const std::u16string &cameraId, int32_t callingUid, int32_t callingPid)
1079 {
1080 CellularCallConfig config;
1081 return config.CtrlCamera(cameraId, callingUid, callingPid);
1082 }
1083
SetPreviewWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)1084 int32_t CellularCallService::SetPreviewWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
1085 {
1086 CellularCallConfig config;
1087 return config.SetPreviewWindow(x, y, z, width, height);
1088 }
1089
SetDisplayWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)1090 int32_t CellularCallService::SetDisplayWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
1091 {
1092 CellularCallConfig config;
1093 return config.SetDisplayWindow(x, y, z, width, height);
1094 }
1095
SetCameraZoom(float zoomRatio)1096 int32_t CellularCallService::SetCameraZoom(float zoomRatio)
1097 {
1098 CellularCallConfig config;
1099 return config.SetCameraZoom(zoomRatio);
1100 }
1101
SetPauseImage(const std::u16string & path)1102 int32_t CellularCallService::SetPauseImage(const std::u16string &path)
1103 {
1104 CellularCallConfig config;
1105 return config.SetPauseImage(path);
1106 }
1107
SetDeviceDirection(int32_t rotation)1108 int32_t CellularCallService::SetDeviceDirection(int32_t rotation)
1109 {
1110 CellularCallConfig config;
1111 return config.SetDeviceDirection(rotation);
1112 }
1113
SetMute(int32_t slotId,int32_t mute)1114 int32_t CellularCallService::SetMute(int32_t slotId, int32_t mute)
1115 {
1116 if (!IsValidSlotId(slotId)) {
1117 TELEPHONY_LOGE("CellularCallService::SetMute return, invalid slot id");
1118 return CALL_ERR_INVALID_SLOT_ID;
1119 }
1120 CellularCallConfig config;
1121 return config.SetMute(slotId, mute);
1122 }
1123
GetMute(int32_t slotId)1124 int32_t CellularCallService::GetMute(int32_t slotId)
1125 {
1126 if (!IsValidSlotId(slotId)) {
1127 TELEPHONY_LOGE("CellularCallService::GetMute return, invalid slot id");
1128 return CALL_ERR_INVALID_SLOT_ID;
1129 }
1130 CellularCallConfig config;
1131 return config.GetMute(slotId);
1132 }
1133
SetSrvccState(int32_t srvccState)1134 void CellularCallService::SetSrvccState(int32_t srvccState)
1135 {
1136 srvccState_ = srvccState;
1137 }
1138
GetSrvccState()1139 int32_t CellularCallService::GetSrvccState()
1140 {
1141 return srvccState_;
1142 }
1143
UseImsForEmergency(const CellularCallInfo & callInfo)1144 bool CellularCallService::UseImsForEmergency(const CellularCallInfo &callInfo)
1145 {
1146 ModuleServiceUtils moduleUtils;
1147 CellularCallConfig config;
1148 bool enabled = false;
1149 if (IsEmergencyPhoneNumber(callInfo.slotId, callInfo.phoneNum, enabled) != TELEPHONY_SUCCESS) {
1150 return false;
1151 }
1152 if (enabled && moduleUtils.NeedCallImsService() && config.GetImsPreferForEmergencyConfig(callInfo.slotId)) {
1153 return true;
1154 }
1155 return false;
1156 }
1157
HandleCallManagerException()1158 void CellularCallService::HandleCallManagerException()
1159 {
1160 ModuleServiceUtils obtain;
1161 std::vector<int32_t> slotVector = obtain.GetSlotInfo();
1162 for (const auto &it : slotVector) {
1163 auto csControl = GetCsControl(it);
1164 if (csControl != nullptr) {
1165 csControl->SetHangupReportIgnoredFlag(true);
1166 csControl->HangUpAllConnection(it);
1167 }
1168 auto imsControl = GetImsControl(it);
1169 if (imsControl != nullptr) {
1170 imsControl->SetHangupReportIgnoredFlag(true);
1171 imsControl->HangUpAllConnection(it);
1172 }
1173 }
1174 }
1175
SystemAbilityStatusChangeListener(std::shared_ptr<CellularCallHandler> & cellularCallHandler)1176 CellularCallService::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener(
1177 std::shared_ptr<CellularCallHandler> &cellularCallHandler)
1178 : cellularCallHandler_(cellularCallHandler)
1179 {}
1180
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1181 void CellularCallService::SystemAbilityStatusChangeListener::OnAddSystemAbility(
1182 int32_t systemAbilityId, const std::string &deviceId)
1183 {
1184 if (systemAbilityId != COMMON_EVENT_SERVICE_ID) {
1185 TELEPHONY_LOGE("systemAbilityId is not COMMON_EVENT_SERVICE_ID");
1186 return;
1187 }
1188 if (cellularCallHandler_ == nullptr) {
1189 TELEPHONY_LOGE("COMMON_EVENT_SERVICE_ID cellularCallHandler_ is nullptr");
1190 return;
1191 }
1192 bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(cellularCallHandler_);
1193 TELEPHONY_LOGI("subscribeResult = %{public}d", subscribeResult);
1194 }
1195
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1196 void CellularCallService::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
1197 int32_t systemAbilityId, const std::string &deviceId)
1198 {
1199 switch (systemAbilityId) {
1200 case TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID: {
1201 auto cellularCallRegister = DelayedSingleton<CellularCallRegister>::GetInstance();
1202 if (cellularCallRegister != nullptr) {
1203 cellularCallRegister->UnRegisterCallManagerCallBack();
1204 }
1205 auto cellularCallService = DelayedSingleton<CellularCallService>::GetInstance();
1206 if (cellularCallService == nullptr) {
1207 TELEPHONY_LOGE("cellularCallService is nullptr");
1208 return;
1209 }
1210 cellularCallService->HandleCallManagerException();
1211 count_++;
1212 CellularCallHiSysEvent::WriteFoundationRestartFaultEvent(count_);
1213 break;
1214 }
1215 case COMMON_EVENT_SERVICE_ID: {
1216 if (cellularCallHandler_ == nullptr) {
1217 TELEPHONY_LOGE("cellularCallHandler_ is nullptr");
1218 return;
1219 }
1220 bool unSubscribeResult = EventFwk::CommonEventManager::UnSubscribeCommonEvent(cellularCallHandler_);
1221 TELEPHONY_LOGI("unSubscribeResult = %{public}d", unSubscribeResult);
1222 break;
1223 }
1224 default:
1225 TELEPHONY_LOGE("systemAbilityId is invalid");
1226 break;
1227 }
1228 }
1229
1230 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
StartCallManagerService()1231 void CellularCallService::StartCallManagerService()
1232 {
1233 sptr<ISystemAbilityManager> managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1234 if (managerPtr == nullptr) {
1235 TELEPHONY_LOGE("GetSystemAbilityManager failed!");
1236 return;
1237 }
1238
1239 sptr<IRemoteObject> iRemoteObjectPtr = managerPtr->GetSystemAbility(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID);
1240 if (iRemoteObjectPtr == nullptr) {
1241 TELEPHONY_LOGE("GetSystemAbility failed!");
1242 }
1243 }
1244 #endif
1245 } // namespace Telephony
1246 } // namespace OHOS
1247