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 "ims_video_call_control.h"
27 #include "module_service_utils.h"
28 #include "radio_event.h"
29 #include "satellite_call_client.h"
30 #include "securec.h"
31 #include "string_ex.h"
32 #include "system_ability_definition.h"
33 #include "telephony_ext_wrapper.h"
34
35 namespace OHOS {
36 namespace Telephony {
37 const uint32_t CONNECT_MAX_TRY_COUNT = 20;
38 const uint32_t CONNECT_CORE_SERVICE_WAIT_TIME = 2000; // ms
39 const uint32_t TELEPHONY_SATELLITE_SYS_ABILITY_ID = 4012;
40 bool g_registerResult =
41 SystemAbility::MakeAndRegisterAbility(DelayedSingleton<CellularCallService>::GetInstance().get());
42
CellularCallService()43 CellularCallService::CellularCallService() : SystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID, true)
44 {
45 state_ = ServiceRunningState::STATE_STOPPED;
46 }
47
~CellularCallService()48 CellularCallService::~CellularCallService()
49 {
50 state_ = ServiceRunningState::STATE_STOPPED;
51 if (statusChangeListener_ != nullptr) {
52 statusChangeListener_.clear();
53 statusChangeListener_ = nullptr;
54 }
55 }
56
Init()57 bool CellularCallService::Init()
58 {
59 TELEPHONY_LOGD("CellularCallService::Init start");
60 #ifdef OHOS_BUILD_ENABLE_TELEPHONY_EXT
61 TELEPHONY_EXT_WRAPPER.InitTelephonyExtWrapper();
62 #endif
63 CreateHandler();
64 SendEventRegisterHandler();
65 for (int32_t i = DEFAULT_SIM_SLOT_ID; i < SIM_SLOT_COUNT; ++i) {
66 isRadioOn_.insert(std::pair<int, bool>(i, false));
67 }
68 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
69 callManagerListener_ = new (std::nothrow) SystemAbilityStatusChangeListener();
70 if (samgrProxy == nullptr || callManagerListener_ == nullptr) {
71 TELEPHONY_LOGE("samgrProxy or callManagerListener_ is nullptr");
72 } else {
73 int32_t ret = samgrProxy->SubscribeSystemAbility(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID, callManagerListener_);
74 TELEPHONY_LOGI("SubscribeSystemAbility TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID result:%{public}d", ret);
75 }
76 // connect ims_service
77 DelayedSingleton<ImsCallClient>::GetInstance()->Init();
78 TELEPHONY_LOGD("CellularCallService::Init, init success");
79 return true;
80 }
81
OnStart()82 void CellularCallService::OnStart()
83 {
84 TELEPHONY_LOGD("CellularCallService OnStart");
85 bindTime_ =
86 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
87 .count();
88 if (state_ == ServiceRunningState::STATE_RUNNING) {
89 TELEPHONY_LOGE("CellularCallService::OnStart return, has already started.");
90 return;
91 }
92 if (!Init()) {
93 TELEPHONY_LOGE("CellularCallService::OnStart return, failed to init service.");
94 return;
95 }
96 state_ = ServiceRunningState::STATE_RUNNING;
97 bool ret = Publish(DelayedSingleton<CellularCallService>::GetInstance().get());
98 if (!ret) {
99 TELEPHONY_LOGE("CellularCallService::OnStart Publish failed!");
100 }
101 endTime_ =
102 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
103 .count();
104 TELEPHONY_LOGD("CellularCallService start success.");
105 }
106
OnStop()107 void CellularCallService::OnStop()
108 {
109 TELEPHONY_LOGD("CellularCallService stop service");
110 DelayedSingleton<ImsCallClient>::GetInstance()->UnInit();
111 state_ = ServiceRunningState::STATE_STOPPED;
112 HandlerResetUnRegister();
113 }
114
RegisterHandler()115 void CellularCallService::RegisterHandler()
116 {
117 TELEPHONY_LOGI("connect core service Register Handler start");
118 networkSearchCallBack_ = (std::make_unique<CellularCallCallback>()).release();
119 for (uint32_t i = 0; i < CONNECT_MAX_TRY_COUNT; i++) {
120 std::this_thread::sleep_for(std::chrono::milliseconds(CONNECT_CORE_SERVICE_WAIT_TIME));
121 if (CoreManagerInner::GetInstance().IsInitFinished()) {
122 TELEPHONY_LOGI("connect core service Register Handler start");
123 RegisterCoreServiceHandler();
124 CoreManagerInner::GetInstance().RegisterCellularCallObject(networkSearchCallBack_);
125 break;
126 }
127 TELEPHONY_LOGW("connect core service Register Handler null or not init");
128 }
129 TELEPHONY_LOGI("connect core service Register Handler end");
130 }
131
CreateHandler()132 void CellularCallService::CreateHandler()
133 {
134 ModuleServiceUtils obtain;
135 std::vector<int32_t> slotVector = obtain.GetSlotInfo();
136 EventFwk::MatchingSkills matchingSkills;
137 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
138 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_NETWORK_STATE_CHANGED);
139 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
140 subscriberInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
141 for (const auto &it : slotVector) {
142 auto handler = std::make_shared<CellularCallHandler>(subscriberInfo);
143 TELEPHONY_LOGI("setSlotId:%{public}d", it);
144 handler->SetSlotId(it);
145 handler->RegisterImsCallCallbackHandler();
146 {
147 std::unique_lock<std::mutex> lock(handlerMapMutex_);
148 handlerMap_.insert(std::make_pair(it, handler));
149 }
150 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
151 statusChangeListener_ = new (std::nothrow) SystemAbilityStatusChangeListener(handler);
152 if (samgrProxy == nullptr || statusChangeListener_ == nullptr) {
153 TELEPHONY_LOGE("samgrProxy or statusChangeListener_ is nullptr");
154 } else {
155 int32_t retSubCommnetEvent =
156 samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
157 TELEPHONY_LOGI("SubscribeSystemAbility COMMON_EVENT_SERVICE_ID result:%{public}d", retSubCommnetEvent);
158 int32_t retSubSateEvent =
159 samgrProxy->SubscribeSystemAbility(TELEPHONY_SATELLITE_SYS_ABILITY_ID, statusChangeListener_);
160 TELEPHONY_LOGI(
161 "SubscribeSystemAbility TELEPHONY_SATELLITE_SYS_ABILITY_ID result:%{public}d", retSubSateEvent);
162 }
163 }
164 }
165
HandlerResetUnRegister()166 void CellularCallService::HandlerResetUnRegister()
167 {
168 TELEPHONY_LOGI("HandlerResetUnRegister");
169 std::unique_lock<std::mutex> lock(handlerMapMutex_);
170 for (const auto &it : handlerMap_) {
171 int32_t slot = it.first;
172 auto handler = it.second;
173 if (handler != nullptr) {
174 handler.reset();
175 }
176 CoreManagerInner &coreInner = CoreManagerInner::GetInstance();
177 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_AVAIL);
178 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_NOT_AVAIL);
179 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_SIM_RECORDS_LOADED);
180 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_SIM_ACCOUNT_LOADED);
181 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_STATUS_INFO);
182 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_USSD_NOTICE);
183 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_SS_NOTICE);
184 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_RINGBACK_VOICE);
185 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_EMERGENCY_NUMBER_REPORT);
186 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_SRVCC_STATUS);
187 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_RSRVCC_STATUS);
188 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_RESIDENT_NETWORK_CHANGE);
189 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_RIL_ADAPTER_HOST_DIED);
190 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_FACTORY_RESET);
191 coreInner.UnRegisterCoreNotify(slot, handler, RadioEvent::RADIO_STATE_CHANGED);
192 if (GetCsControl(slot) != nullptr) {
193 GetCsControl(slot)->ReleaseAllConnection();
194 }
195 if (GetImsControl(slot) != nullptr) {
196 GetImsControl(slot)->ReleaseAllConnection();
197 }
198 }
199 }
200
RegisterCoreServiceHandler()201 void CellularCallService::RegisterCoreServiceHandler()
202 {
203 TELEPHONY_LOGI("RegisterCoreServiceHandle");
204 std::unique_lock<std::mutex> lock(handlerMapMutex_, std::defer_lock);
205 lock.lock();
206 for (const auto &it : handlerMap_) {
207 int32_t slot = it.first;
208 auto handler = it.second;
209 if (handler != nullptr) {
210 CoreManagerInner &coreInner = CoreManagerInner::GetInstance();
211 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_AVAIL, nullptr);
212 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_NOT_AVAIL, nullptr);
213 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_SIM_STATE_CHANGE, nullptr);
214 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_SIM_RECORDS_LOADED, nullptr);
215 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_SIM_ACCOUNT_LOADED, nullptr);
216 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_STATUS_INFO, nullptr);
217 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_USSD_NOTICE, nullptr);
218 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_SS_NOTICE, nullptr);
219 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_EMERGENCY_NUMBER_REPORT, nullptr);
220 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_RINGBACK_VOICE, nullptr);
221 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_SRVCC_STATUS, nullptr);
222 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_CALL_RSRVCC_STATUS, nullptr);
223 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_RESIDENT_NETWORK_CHANGE, nullptr);
224 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_RIL_ADAPTER_HOST_DIED, nullptr);
225 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_FACTORY_RESET, nullptr);
226 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_NV_REFRESH_FINISHED, nullptr);
227 coreInner.RegisterCoreNotify(slot, handler, RadioEvent::RADIO_STATE_CHANGED, nullptr);
228 coreInner.GetRadioState(slot, RadioEvent::RADIO_GET_STATUS, handler);
229 }
230 lock.unlock();
231 CellularCallConfig config;
232 config.InitModeActive();
233 if (config.GetDomainPreferenceMode(slot) != TELEPHONY_SUCCESS) {
234 TELEPHONY_LOGW("RegisterCoreServiceHandler, GetDomainPreferenceMode request fail");
235 }
236 if (config.GetEmergencyCallList(it.first) != TELEPHONY_SUCCESS) {
237 TELEPHONY_LOGW("RegisterCoreServiceHandler, GetEmergencyCallList request fail");
238 }
239 lock.lock();
240 }
241 }
242
SendEventRegisterHandler()243 void CellularCallService::SendEventRegisterHandler()
244 {
245 int64_t delayTime = 1000;
246 int32_t slot = DEFAULT_SIM_SLOT_ID;
247 std::unique_lock<std::mutex> lock(handlerMapMutex_);
248 auto handler = handlerMap_[slot];
249 if (handler == nullptr) {
250 TELEPHONY_LOGE("SendEventRegisterHandler return, handler is nullptr");
251 return;
252 }
253 handler->SendEvent(handler->REGISTER_HANDLER_ID, delayTime, CellularCallHandler::Priority::HIGH);
254 }
255
Dump(int32_t fd,const std::vector<std::u16string> & args)256 int32_t CellularCallService::Dump(int32_t fd, const std::vector<std::u16string> &args)
257 {
258 if (fd < 0) {
259 TELEPHONY_LOGE("dump fd invalid");
260 return TELEPHONY_ERR_FAIL;
261 }
262 std::vector<std::string> argsInStr;
263 for (const auto &arg : args) {
264 argsInStr.emplace_back(Str16ToStr8(arg));
265 }
266 std::string result;
267 CellularCallDumpHelper dumpHelper;
268 if (dumpHelper.Dump(argsInStr, result)) {
269 int32_t ret = dprintf(fd, "%s", result.c_str());
270 if (ret < 0) {
271 TELEPHONY_LOGE("dprintf to dump fd failed");
272 return TELEPHONY_ERR_FAIL;
273 }
274 return TELEPHONY_SUCCESS;
275 }
276 TELEPHONY_LOGW("dumpHelper failed");
277 return TELEPHONY_ERR_FAIL;
278 }
279
GetServiceRunningState()280 int32_t CellularCallService::GetServiceRunningState()
281 {
282 return static_cast<int32_t>(state_);
283 }
284
GetBindTime()285 std::string CellularCallService::GetBindTime()
286 {
287 std::ostringstream oss;
288 oss << bindTime_;
289 return oss.str();
290 }
291
GetEndTime()292 std::string CellularCallService::GetEndTime()
293 {
294 std::ostringstream oss;
295 oss << endTime_;
296 return oss.str();
297 }
298
GetSpendTime()299 std::string CellularCallService::GetSpendTime()
300 {
301 spendTime_ = endTime_ - bindTime_;
302 std::ostringstream oss;
303 oss << spendTime_;
304 return oss.str();
305 }
306
Dial(const CellularCallInfo & callInfo)307 int32_t CellularCallService::Dial(const CellularCallInfo &callInfo)
308 {
309 if (!IsValidSlotId(callInfo.slotId)) {
310 TELEPHONY_LOGE("CellularCallService::Dial return, invalid slot id");
311 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.accountId, static_cast<int32_t>(callInfo.callType),
312 callInfo.videoState, CALL_ERR_INVALID_SLOT_ID, "invalid slot id");
313 return CALL_ERR_INVALID_SLOT_ID;
314 }
315 if (srvccState_ == SrvccState::STARTED) {
316 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.accountId, static_cast<int32_t>(callInfo.callType),
317 callInfo.videoState, static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE),
318 "srvccState_ is STARTED");
319 return TELEPHONY_ERR_FAIL;
320 }
321 bool isEcc = false;
322 IsEmergencyPhoneNumber(callInfo.slotId, callInfo.phoneNum, isEcc);
323 ModuleServiceUtils moduleServiceUtils;
324 bool satelliteStatusOn = moduleServiceUtils.GetSatelliteStatus();
325 if (satelliteStatusOn) {
326 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
327 if (satelliteControl == nullptr) {
328 TELEPHONY_LOGI("CellularCallService::Dial satelliteControl dial");
329 satelliteControl = std::make_shared<SatelliteControl>();
330 if (satelliteControl == nullptr) {
331 TELEPHONY_LOGE("CellularCallService::Dial return, satelliteControl create fail");
332 return TELEPHONY_ERR_LOCAL_PTR_NULL;
333 }
334 SetSatelliteControl(callInfo.slotId, satelliteControl);
335 }
336 return satelliteControl->Dial(callInfo, isEcc);
337 }
338 return DialNormalCall(callInfo, isEcc);
339 }
340
DialNormalCall(const CellularCallInfo & callInfo,bool isEcc)341 int32_t CellularCallService::DialNormalCall(const CellularCallInfo &callInfo, bool isEcc)
342 {
343 bool useImsForEmergency = UseImsForEmergency(callInfo, isEcc);
344 if (IsNeedIms(callInfo.slotId) || useImsForEmergency) {
345 auto imsControl = GetImsControl(callInfo.slotId);
346 if (imsControl == nullptr) {
347 TELEPHONY_LOGI("CellularCallService::Dial ims dial");
348 imsControl = std::make_shared<IMSControl>();
349 if (imsControl == nullptr) {
350 TELEPHONY_LOGE("CellularCallService::Dial return, imsControl create fail");
351 return TELEPHONY_ERR_LOCAL_PTR_NULL;
352 }
353 SetImsControl(callInfo.slotId, imsControl);
354 }
355 return imsControl->Dial(callInfo, isEcc);
356 }
357
358 auto csControl = GetCsControl(callInfo.slotId);
359 if (csControl == nullptr) {
360 csControl = std::make_shared<CSControl>();
361 if (csControl == nullptr) {
362 TELEPHONY_LOGE("CellularCallService::Dial return, csControl create fail");
363 return TELEPHONY_ERR_LOCAL_PTR_NULL;
364 }
365 SetCsControl(callInfo.slotId, csControl);
366 }
367 return csControl->Dial(callInfo, isEcc);
368 }
369
IsMmiCode(int32_t slotId,std::string & number)370 bool CellularCallService::IsMmiCode(int32_t slotId, std::string &number)
371 {
372 if (!IsValidSlotId(slotId)) {
373 TELEPHONY_LOGE("invalid slot id");
374 return false;
375 }
376 if (TELEPHONY_EXT_WRAPPER.isMmiCode_ != nullptr) {
377 bool isMmiCode = TELEPHONY_EXT_WRAPPER.isMmiCode_(slotId, number);
378 if (!isMmiCode) {
379 TELEPHONY_LOGI("don't need to execute mmi");
380 return false;
381 }
382 }
383 std::unique_ptr<MMICodeUtils> mmiCodeUtils = std::make_unique<MMICodeUtils>();
384 if (mmiCodeUtils == nullptr) {
385 TELEPHONY_LOGE("mmiCodeUtils is nullptr");
386 return false;
387 }
388 if (!mmiCodeUtils->IsNeedExecuteMmi(number, false)) {
389 return false;
390 }
391 // In temporary mode, to supress CLIR for a single call, enter:
392 // "*31#[called number] SEND"
393 // In temporary mode, to invoke CLIR for a single call, enter:
394 // "#31#[called number] SEND"
395 MMIData mmiData = mmiCodeUtils->GetMMIData();
396 if (!mmiData.serviceCode.empty() && !mmiData.dialString.empty() &&
397 (mmiData.actionString == "*" || mmiData.actionString == "#")) {
398 return false;
399 }
400 return true;
401 }
402
HangUp(const CellularCallInfo & callInfo,CallSupplementType type)403 int32_t CellularCallService::HangUp(const CellularCallInfo &callInfo, CallSupplementType type)
404 {
405 DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallParameterInfo(
406 callInfo.slotId, static_cast<int32_t>(callInfo.callType), callInfo.videoState);
407 if (!IsValidSlotId(callInfo.slotId)) {
408 TELEPHONY_LOGE("CellularCallService::HangUp return, invalid slot id");
409 CellularCallHiSysEvent::WriteHangUpFaultEvent(
410 callInfo.slotId, callInfo.callId, CALL_ERR_INVALID_SLOT_ID, "HangUp invalid slot id");
411 return CALL_ERR_INVALID_SLOT_ID;
412 }
413 if (srvccState_ == SrvccState::STARTED) {
414 CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, callInfo.callId,
415 static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE), "HangUp srvccState_ is STARTED");
416 return TELEPHONY_ERR_FAIL;
417 }
418 if (CallType::TYPE_SATELLITE == callInfo.callType) {
419 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
420 if (satelliteControl == nullptr) {
421 TELEPHONY_LOGE("CellularCallService::HangUp return, satelliteControl is nullptr");
422 CellularCallHiSysEvent::WriteHangUpFaultEvent(
423 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "HangUp satelliteControl is nullptr");
424 HandleCellularControlException(callInfo);
425 return TELEPHONY_ERR_LOCAL_PTR_NULL;
426 }
427 return satelliteControl->HangUp(callInfo, type);
428 } else if (CallType::TYPE_CS == callInfo.callType) {
429 auto csControl = GetCsControl(callInfo.slotId);
430 if (csControl == nullptr) {
431 TELEPHONY_LOGE("CellularCallService::HangUp return, csControl is nullptr");
432 CellularCallHiSysEvent::WriteHangUpFaultEvent(
433 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "HangUp csControl is nullptr");
434 HandleCellularControlException(callInfo);
435 return TELEPHONY_ERR_LOCAL_PTR_NULL;
436 }
437 return csControl->HangUp(callInfo, type);
438 } else if (CallType::TYPE_IMS == callInfo.callType) {
439 auto imsControl = GetImsControl(callInfo.slotId);
440 if (imsControl == nullptr) {
441 TELEPHONY_LOGE("CellularCallService::HangUp return, imsControl is nullptr");
442 CellularCallHiSysEvent::WriteHangUpFaultEvent(
443 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "HangUp imsControl is nullptr");
444 HandleCellularControlException(callInfo);
445 return TELEPHONY_ERR_LOCAL_PTR_NULL;
446 }
447 return imsControl->HangUp(callInfo, type);
448 }
449 TELEPHONY_LOGE("CellularCallService::HangUp return, call type error.");
450 CellularCallHiSysEvent::WriteHangUpFaultEvent(
451 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_ARGUMENT_INVALID, "HangUp call type error");
452 return TELEPHONY_ERR_ARGUMENT_INVALID;
453 }
454
Reject(const CellularCallInfo & callInfo)455 int32_t CellularCallService::Reject(const CellularCallInfo &callInfo)
456 {
457 DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallParameterInfo(
458 callInfo.slotId, static_cast<int32_t>(callInfo.callType), callInfo.videoState);
459 if (!IsValidSlotId(callInfo.slotId)) {
460 TELEPHONY_LOGE("CellularCallService::Reject return, invalid slot id");
461 CellularCallHiSysEvent::WriteHangUpFaultEvent(
462 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_ARGUMENT_INVALID, "Reject call type error");
463 return CALL_ERR_INVALID_SLOT_ID;
464 }
465 if (srvccState_ == SrvccState::STARTED) {
466 CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, callInfo.callId,
467 static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE), "Reject srvccState_ is STARTED");
468 return TELEPHONY_ERR_FAIL;
469 }
470 if (CallType::TYPE_SATELLITE == callInfo.callType) {
471 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
472 if (satelliteControl == nullptr) {
473 TELEPHONY_LOGE("CellularCallService::Reject return, satelliteControl is nullptr");
474 CellularCallHiSysEvent::WriteHangUpFaultEvent(
475 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "Reject satelliteControl is nullptr");
476 HandleCellularControlException(callInfo);
477 return TELEPHONY_ERR_LOCAL_PTR_NULL;
478 }
479 return satelliteControl->Reject(callInfo);
480 } else if (CallType::TYPE_CS == callInfo.callType) {
481 auto csControl = GetCsControl(callInfo.slotId);
482 if (csControl == nullptr) {
483 TELEPHONY_LOGE("CellularCallService::Reject return, csControl is nullptr");
484 CellularCallHiSysEvent::WriteHangUpFaultEvent(
485 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "Reject csControl is nullptr");
486 HandleCellularControlException(callInfo);
487 return TELEPHONY_ERR_LOCAL_PTR_NULL;
488 }
489 return csControl->Reject(callInfo);
490 } else if (CallType::TYPE_IMS == callInfo.callType) {
491 auto imsControl = GetImsControl(callInfo.slotId);
492 if (imsControl == nullptr) {
493 TELEPHONY_LOGE("CellularCallService::Reject return, imsControl is nullptr");
494 CellularCallHiSysEvent::WriteHangUpFaultEvent(
495 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "Reject imsControl is nullptr");
496 HandleCellularControlException(callInfo);
497 return TELEPHONY_ERR_LOCAL_PTR_NULL;
498 }
499 return imsControl->Reject(callInfo);
500 }
501 TELEPHONY_LOGE("CellularCallService::Reject return, call type error.");
502 CellularCallHiSysEvent::WriteHangUpFaultEvent(
503 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_ARGUMENT_INVALID, "Reject call type error");
504 return TELEPHONY_ERR_ARGUMENT_INVALID;
505 }
506
Answer(const CellularCallInfo & callInfo)507 int32_t CellularCallService::Answer(const CellularCallInfo &callInfo)
508 {
509 DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallParameterInfo(
510 callInfo.slotId, static_cast<int32_t>(callInfo.callType), callInfo.videoState);
511
512 if (!IsValidSlotId(callInfo.slotId)) {
513 TELEPHONY_LOGE("CellularCallService::Answer return, invalid slot id");
514 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(
515 callInfo.slotId, callInfo.callId, callInfo.videoState, CALL_ERR_INVALID_SLOT_ID, "invalid slot id");
516 return CALL_ERR_INVALID_SLOT_ID;
517 }
518 if (srvccState_ == SrvccState::STARTED) {
519 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
520 static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE), "srvccState_ is STARTED");
521 return TELEPHONY_ERR_FAIL;
522 }
523 if (CallType::TYPE_SATELLITE == callInfo.callType) {
524 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
525 if (satelliteControl == nullptr) {
526 TELEPHONY_LOGE("CellularCallService::Answer return, satelliteControl is nullptr");
527 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
528 TELEPHONY_ERR_LOCAL_PTR_NULL, "satelliteControl is nullptr");
529 HandleCellularControlException(callInfo);
530 return TELEPHONY_ERR_LOCAL_PTR_NULL;
531 }
532 return satelliteControl->Answer(callInfo);
533 } else if (CallType::TYPE_CS == callInfo.callType) {
534 auto csControl = GetCsControl(callInfo.slotId);
535 if (csControl == nullptr) {
536 TELEPHONY_LOGE("CellularCallService::Answer return, csControl is nullptr");
537 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
538 TELEPHONY_ERR_LOCAL_PTR_NULL, "csControl is nullptr");
539 HandleCellularControlException(callInfo);
540 return TELEPHONY_ERR_LOCAL_PTR_NULL;
541 }
542 return csControl->Answer(callInfo);
543 } else if (CallType::TYPE_IMS == callInfo.callType) {
544 auto imsControl = GetImsControl(callInfo.slotId);
545 if (imsControl == nullptr) {
546 TELEPHONY_LOGE("CellularCallService::Answer return, imsControl is nullptr");
547 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
548 TELEPHONY_ERR_LOCAL_PTR_NULL, "imsControl is nullptr");
549 HandleCellularControlException(callInfo);
550 return TELEPHONY_ERR_LOCAL_PTR_NULL;
551 }
552 return imsControl->Answer(callInfo);
553 }
554 TELEPHONY_LOGE("CellularCallService::Answer return, call type error.");
555 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(
556 callInfo.slotId, callInfo.callId, callInfo.videoState, TELEPHONY_ERR_LOCAL_PTR_NULL, "call type error");
557 return TELEPHONY_ERR_ARGUMENT_INVALID;
558 }
559
RegisterCallManagerCallBack(const sptr<ICallStatusCallback> & callback)560 int32_t CellularCallService::RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback)
561 {
562 if (DelayedSingleton<CellularCallRegister>::GetInstance() == nullptr) {
563 TELEPHONY_LOGE("CellularCallService::RegisterCallManagerCallBack return, instance is nullptr.");
564 return TELEPHONY_ERR_LOCAL_PTR_NULL;
565 }
566 TELEPHONY_LOGI("CellularCallService::RegisterCallManagerCallBack");
567 return DelayedSingleton<CellularCallRegister>::GetInstance()->RegisterCallManagerCallBack(callback);
568 }
569
UnRegisterCallManagerCallBack()570 int32_t CellularCallService::UnRegisterCallManagerCallBack()
571 {
572 if (DelayedSingleton<CellularCallRegister>::GetInstance() == nullptr) {
573 TELEPHONY_LOGE("CellularCallService::UnRegisterCallManagerCallBack return, instance is nullptr.");
574 return TELEPHONY_ERR_LOCAL_PTR_NULL;
575 }
576 TELEPHONY_LOGI("CellularCallService::UnRegisterCallManagerCallBack");
577 return DelayedSingleton<CellularCallRegister>::GetInstance()->UnRegisterCallManagerCallBack();
578 }
579
HoldCall(const CellularCallInfo & callInfo)580 int32_t CellularCallService::HoldCall(const CellularCallInfo &callInfo)
581 {
582 if (!IsValidSlotId(callInfo.slotId)) {
583 TELEPHONY_LOGE("CellularCallService::HoldCall return, invalid slot id");
584 return CALL_ERR_INVALID_SLOT_ID;
585 }
586 if (srvccState_ == SrvccState::STARTED) {
587 return TELEPHONY_ERR_FAIL;
588 }
589 if (CallType::TYPE_SATELLITE == callInfo.callType) {
590 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
591 if (satelliteControl == nullptr) {
592 TELEPHONY_LOGE("CellularCallService::HoldCall return, satelliteControl is nullptr");
593 return TELEPHONY_ERR_LOCAL_PTR_NULL;
594 }
595 return satelliteControl->HoldCall(callInfo.slotId);
596 } else if (CallType::TYPE_IMS == callInfo.callType) {
597 auto imsControl = GetImsControl(callInfo.slotId);
598 if (imsControl == nullptr) {
599 TELEPHONY_LOGE("CellularCallService::HoldCall return, imsControl is nullptr");
600 return TELEPHONY_ERR_LOCAL_PTR_NULL;
601 }
602 return imsControl->HoldCall(callInfo.slotId);
603 } else if (CallType::TYPE_CS == callInfo.callType) {
604 auto csControl = GetCsControl(callInfo.slotId);
605 if (csControl == nullptr) {
606 TELEPHONY_LOGE("CellularCallService::HoldCall return, csControl is nullptr");
607 return TELEPHONY_ERR_LOCAL_PTR_NULL;
608 }
609 return csControl->HoldCall(callInfo.slotId);
610 }
611 TELEPHONY_LOGE("CellularCallService::HoldCall return, call type error.");
612 return TELEPHONY_ERR_ARGUMENT_INVALID;
613 }
614
UnHoldCall(const CellularCallInfo & callInfo)615 int32_t CellularCallService::UnHoldCall(const CellularCallInfo &callInfo)
616 {
617 if (!IsValidSlotId(callInfo.slotId)) {
618 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, invalid slot id");
619 return CALL_ERR_INVALID_SLOT_ID;
620 }
621 if (srvccState_ == SrvccState::STARTED) {
622 return TELEPHONY_ERR_FAIL;
623 }
624 if (CallType::TYPE_SATELLITE == callInfo.callType) {
625 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
626 if (satelliteControl == nullptr) {
627 TELEPHONY_LOGE("CellularCallService::HoldCall return, satelliteControl is nullptr");
628 return TELEPHONY_ERR_LOCAL_PTR_NULL;
629 }
630 return satelliteControl->UnHoldCall(callInfo.slotId);
631 } else if (CallType::TYPE_IMS == callInfo.callType) {
632 auto imsControl = GetImsControl(callInfo.slotId);
633 if (imsControl == nullptr) {
634 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, imsControl is nullptr");
635 return TELEPHONY_ERR_LOCAL_PTR_NULL;
636 }
637 return imsControl->UnHoldCall(callInfo.slotId);
638 } else if (CallType::TYPE_CS == callInfo.callType) {
639 auto csControl = GetCsControl(callInfo.slotId);
640 if (csControl == nullptr) {
641 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, csControl is nullptr");
642 return TELEPHONY_ERR_LOCAL_PTR_NULL;
643 }
644 return csControl->UnHoldCall(callInfo.slotId);
645 }
646 TELEPHONY_LOGE("CellularCallService::UnHoldCall return, call type error.");
647 return TELEPHONY_ERR_ARGUMENT_INVALID;
648 }
649
SwitchCall(const CellularCallInfo & callInfo)650 int32_t CellularCallService::SwitchCall(const CellularCallInfo &callInfo)
651 {
652 if (!IsValidSlotId(callInfo.slotId)) {
653 TELEPHONY_LOGE("CellularCallService::SwitchCall return, invalid slot id");
654 return CALL_ERR_INVALID_SLOT_ID;
655 }
656 if (srvccState_ == SrvccState::STARTED) {
657 return TELEPHONY_ERR_FAIL;
658 }
659 if (CallType::TYPE_SATELLITE == callInfo.callType) {
660 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
661 if (satelliteControl == nullptr) {
662 TELEPHONY_LOGE("CellularCallService::HoldCall return, satelliteControl is nullptr");
663 return TELEPHONY_ERR_LOCAL_PTR_NULL;
664 }
665 return satelliteControl->UnHoldCall(callInfo.slotId);
666 } else if (CallType::TYPE_IMS == callInfo.callType) {
667 auto imsControl = GetImsControl(callInfo.slotId);
668 if (imsControl == nullptr) {
669 TELEPHONY_LOGE("CellularCallService::SwitchCall return, imsControl is nullptr");
670 return TELEPHONY_ERR_LOCAL_PTR_NULL;
671 }
672 return imsControl->SwitchCall(callInfo.slotId);
673 } else if (CallType::TYPE_CS == callInfo.callType) {
674 auto csControl = GetCsControl(callInfo.slotId);
675 if (csControl == nullptr) {
676 TELEPHONY_LOGE("CellularCallService::SwitchCall return, csControl is nullptr");
677 return TELEPHONY_ERR_LOCAL_PTR_NULL;
678 }
679 return csControl->SwitchCall(callInfo.slotId);
680 }
681 TELEPHONY_LOGE("CellularCallService::SwitchCall return, call type error.");
682 return TELEPHONY_ERR_ARGUMENT_INVALID;
683 }
684
CombineConference(const CellularCallInfo & callInfo)685 int32_t CellularCallService::CombineConference(const CellularCallInfo &callInfo)
686 {
687 if (!IsValidSlotId(callInfo.slotId)) {
688 TELEPHONY_LOGE("CellularCallService::CombineConference return, invalid slot id");
689 return CALL_ERR_INVALID_SLOT_ID;
690 }
691 if (srvccState_ == SrvccState::STARTED) {
692 return TELEPHONY_ERR_FAIL;
693 }
694 if (CallType::TYPE_IMS == callInfo.callType) {
695 auto imsControl = GetImsControl(callInfo.slotId);
696 if (imsControl == nullptr) {
697 TELEPHONY_LOGE("CellularCallService::CombineConference return, imsControl is nullptr");
698 return TELEPHONY_ERR_LOCAL_PTR_NULL;
699 }
700 return imsControl->CombineConference(callInfo.slotId);
701 } else if (CallType::TYPE_CS == callInfo.callType) {
702 auto csControl = GetCsControl(callInfo.slotId);
703 if (csControl == nullptr) {
704 TELEPHONY_LOGE("CellularCallService::CombineConference return, csControl is nullptr");
705 return TELEPHONY_ERR_LOCAL_PTR_NULL;
706 }
707 return csControl->CombineConference(callInfo.slotId);
708 }
709 TELEPHONY_LOGE("CellularCallService::CombineConference return, call type error.");
710 return TELEPHONY_ERR_ARGUMENT_INVALID;
711 }
712
SeparateConference(const CellularCallInfo & callInfo)713 int32_t CellularCallService::SeparateConference(const CellularCallInfo &callInfo)
714 {
715 if (!IsValidSlotId(callInfo.slotId)) {
716 TELEPHONY_LOGE("CellularCallService::SeparateConference return, invalid slot id");
717 return CALL_ERR_INVALID_SLOT_ID;
718 }
719 if (CallType::TYPE_CS == callInfo.callType) {
720 auto csControl = GetCsControl(callInfo.slotId);
721 if (csControl == nullptr) {
722 TELEPHONY_LOGE("CellularCallService::SeparateConference return, csControl is nullptr");
723 return TELEPHONY_ERR_LOCAL_PTR_NULL;
724 }
725 return csControl->SeparateConference(callInfo.slotId, callInfo.phoneNum, callInfo.index);
726 }
727 TELEPHONY_LOGE("CellularCallService::SeparateConference return, call type error.");
728 return TELEPHONY_ERR_ARGUMENT_INVALID;
729 }
730
InviteToConference(int32_t slotId,const std::vector<std::string> & numberList)731 int32_t CellularCallService::InviteToConference(int32_t slotId, const std::vector<std::string> &numberList)
732 {
733 auto control = GetImsControl(slotId);
734 if (control == nullptr) {
735 TELEPHONY_LOGE("CellularCallService::InviteToConference return, control is nullptr");
736 return TELEPHONY_ERR_LOCAL_PTR_NULL;
737 }
738 return control->InviteToConference(slotId, numberList);
739 }
740
KickOutFromConference(const CellularCallInfo & callInfo)741 int32_t CellularCallService::KickOutFromConference(const CellularCallInfo &callInfo)
742 {
743 if (!IsValidSlotId(callInfo.slotId)) {
744 TELEPHONY_LOGE("CellularCallService::KickOutFromConference return, invalid slot id");
745 return CALL_ERR_INVALID_SLOT_ID;
746 }
747 if (CallType::TYPE_IMS == callInfo.callType) {
748 auto imsControl = GetImsControl(callInfo.slotId);
749 if (imsControl == nullptr) {
750 TELEPHONY_LOGE("CellularCallService::KickOutFromConference return, imsControl is nullptr");
751 return TELEPHONY_ERR_LOCAL_PTR_NULL;
752 }
753 return imsControl->KickOutFromConference(callInfo.slotId, callInfo.phoneNum, callInfo.index);
754 } else if (CallType::TYPE_CS == callInfo.callType) {
755 auto csControl = GetCsControl(callInfo.slotId);
756 if (csControl == nullptr) {
757 TELEPHONY_LOGE("CellularCallService::KickOutFromConference return, csControl is nullptr");
758 return TELEPHONY_ERR_LOCAL_PTR_NULL;
759 }
760 return csControl->HangUp(callInfo, CallSupplementType::TYPE_DEFAULT);
761 }
762 TELEPHONY_LOGE("CellularCallService::KickOutFromConference return, call type error.");
763 return TELEPHONY_ERR_ARGUMENT_INVALID;
764 }
765
HangUpAllConnection()766 int32_t CellularCallService::HangUpAllConnection()
767 {
768 ModuleServiceUtils obtain;
769 std::vector<int32_t> slotVector = obtain.GetSlotInfo();
770 for (const auto &it : slotVector) {
771 if (GetCsControl(it)) {
772 GetCsControl(it)->HangUpAllConnection(it);
773 }
774 if (GetImsControl(it)) {
775 #ifdef BASE_POWER_IMPROVEMENT_FEATURE
776 if (GetImsControl(it)->isPendingEmcFlag()) {
777 return TELEPHONY_SUCCESS;
778 }
779 #endif
780 GetImsControl(it)->HangUpAllConnection(it);
781 }
782 }
783 return TELEPHONY_SUCCESS;
784 }
785
SetReadyToCall(int32_t slotId,int32_t callType,bool isReadyToCall)786 int32_t CellularCallService::SetReadyToCall(int32_t slotId, int32_t callType, bool isReadyToCall)
787 {
788 TELEPHONY_LOGI("slotId = %{public}d, callType = %{public}d, isReadyToCall = %{public}d",
789 slotId, callType, isReadyToCall);
790 if (!IsValidSlotId(slotId)) {
791 TELEPHONY_LOGE("CellularCallService::SetReadyToCall return, invalid slot id");
792 return CALL_ERR_INVALID_SLOT_ID;
793 }
794 if (GetCsControl(slotId) != nullptr) {
795 GetCsControl(slotId)->SetReadyToCall(slotId, isReadyToCall);
796 }
797 if (GetImsControl(slotId) != nullptr) {
798 GetImsControl(slotId)->SetReadyToCall(slotId, isReadyToCall);
799 }
800 if (GetSatelliteControl(slotId) != nullptr) {
801 GetSatelliteControl(slotId)->SetReadyToCall(slotId, isReadyToCall);
802 }
803 return TELEPHONY_SUCCESS;
804 }
805
HangUpAllConnection(int32_t slotId)806 int32_t CellularCallService::HangUpAllConnection(int32_t slotId)
807 {
808 if (GetCsControl(slotId)) {
809 GetCsControl(slotId)->HangUpAllConnection(slotId);
810 }
811 if (GetImsControl(slotId)) {
812 GetImsControl(slotId)->HangUpAllConnection(slotId);
813 }
814 if (GetSatelliteControl(slotId)) {
815 GetSatelliteControl(slotId)->HangUpAllConnection(slotId);
816 }
817 return TELEPHONY_SUCCESS;
818 }
819
SendUpdateCallMediaModeRequest(const CellularCallInfo & callInfo,ImsCallMode mode)820 int32_t CellularCallService::SendUpdateCallMediaModeRequest(const CellularCallInfo &callInfo, ImsCallMode mode)
821 {
822 auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
823 if (videoCallControl == nullptr) {
824 TELEPHONY_LOGE("videoCallControl is nullptr");
825 return TELEPHONY_ERR_LOCAL_PTR_NULL;
826 }
827 return videoCallControl->SendUpdateCallMediaModeRequest(callInfo, mode);
828 }
829
SendUpdateCallMediaModeResponse(const CellularCallInfo & callInfo,ImsCallMode mode)830 int32_t CellularCallService::SendUpdateCallMediaModeResponse(const CellularCallInfo &callInfo, ImsCallMode mode)
831 {
832 auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
833 if (videoCallControl == nullptr) {
834 TELEPHONY_LOGE("videoCallControl is nullptr");
835 return TELEPHONY_ERR_LOCAL_PTR_NULL;
836 }
837 return videoCallControl->SendUpdateCallMediaModeResponse(callInfo, mode);
838 }
839
CancelCallUpgrade(int32_t slotId,int32_t callIndex)840 int32_t CellularCallService::CancelCallUpgrade(int32_t slotId, int32_t callIndex)
841 {
842 auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
843 if (videoCallControl == nullptr) {
844 TELEPHONY_LOGE("videoCallControl is nullptr");
845 return TELEPHONY_ERR_LOCAL_PTR_NULL;
846 }
847 return videoCallControl->CancelCallUpgrade(slotId, callIndex);
848 }
849
RequestCameraCapabilities(int32_t slotId,int32_t callIndex)850 int32_t CellularCallService::RequestCameraCapabilities(int32_t slotId, int32_t callIndex)
851 {
852 auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
853 if (videoCallControl == nullptr) {
854 TELEPHONY_LOGE("videoCallControl is nullptr");
855 return TELEPHONY_ERR_LOCAL_PTR_NULL;
856 }
857 return videoCallControl->RequestCameraCapabilities(slotId, callIndex);
858 }
859
StartDtmf(char cDtmfCode,const CellularCallInfo & callInfo)860 int32_t CellularCallService::StartDtmf(char cDtmfCode, const CellularCallInfo &callInfo)
861 {
862 if (!IsValidSlotId(callInfo.slotId)) {
863 TELEPHONY_LOGE("CellularCallService::StartDtmf return, invalid slot id");
864 return CALL_ERR_INVALID_SLOT_ID;
865 }
866 if (srvccState_ == SrvccState::STARTED) {
867 return TELEPHONY_ERR_FAIL;
868 }
869 if (CallType::TYPE_IMS == callInfo.callType) {
870 auto imsControl = GetImsControl(callInfo.slotId);
871 if (imsControl == nullptr) {
872 TELEPHONY_LOGE("CellularCallService::StartDtmf return, imsControl is nullptr");
873 return TELEPHONY_ERR_LOCAL_PTR_NULL;
874 }
875 return imsControl->StartDtmf(imsControl->GetConnectionMap(), cDtmfCode, callInfo);
876 } else if (CallType::TYPE_CS == callInfo.callType) {
877 auto csControl = GetCsControl(callInfo.slotId);
878 if (csControl == nullptr) {
879 TELEPHONY_LOGE("CellularCallService::StartDtmf return, csControl is nullptr");
880 return TELEPHONY_ERR_LOCAL_PTR_NULL;
881 }
882 return csControl->StartDtmf(csControl->GetConnectionMap(), cDtmfCode, callInfo);
883 } else if (CallType::TYPE_SATELLITE == callInfo.callType) {
884 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
885 if (satelliteControl == nullptr) {
886 TELEPHONY_LOGE("CellularCallService::StartDtmf return, satelliteControl is nullptr");
887 return TELEPHONY_ERR_LOCAL_PTR_NULL;
888 }
889 return satelliteControl->StartDtmf(satelliteControl->GetConnectionMap(), cDtmfCode, callInfo);
890 }
891 TELEPHONY_LOGE("CellularCallService::StartDtmf return, call type error.");
892 return TELEPHONY_ERR_ARGUMENT_INVALID;
893 }
894
StopDtmf(const CellularCallInfo & callInfo)895 int32_t CellularCallService::StopDtmf(const CellularCallInfo &callInfo)
896 {
897 if (!IsValidSlotId(callInfo.slotId)) {
898 TELEPHONY_LOGE("CellularCallService::StopDtmf return, invalid slot id");
899 return CALL_ERR_INVALID_SLOT_ID;
900 }
901 if (srvccState_ == SrvccState::STARTED) {
902 return TELEPHONY_ERR_FAIL;
903 }
904 if (CallType::TYPE_IMS == callInfo.callType) {
905 auto imsControl = GetImsControl(callInfo.slotId);
906 if (imsControl == nullptr) {
907 TELEPHONY_LOGE("CellularCallService::StopDtmf return, imsControl is nullptr");
908 return TELEPHONY_ERR_LOCAL_PTR_NULL;
909 }
910 return imsControl->StopDtmf(imsControl->GetConnectionMap(), callInfo);
911 } else if (CallType::TYPE_CS == callInfo.callType) {
912 auto csControl = GetCsControl(callInfo.slotId);
913 if (csControl == nullptr) {
914 TELEPHONY_LOGE("CellularCallService::StopDtmf return, csControl is nullptr");
915 return TELEPHONY_ERR_LOCAL_PTR_NULL;
916 }
917 return csControl->StopDtmf(csControl->GetConnectionMap(), callInfo);
918 } else if (CallType::TYPE_SATELLITE == callInfo.callType) {
919 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
920 if (satelliteControl == nullptr) {
921 TELEPHONY_LOGE("CellularCallService::StopDtmf return, satelliteControl is nullptr");
922 return TELEPHONY_ERR_LOCAL_PTR_NULL;
923 }
924 return satelliteControl->StopDtmf(satelliteControl->GetConnectionMap(), callInfo);
925 }
926 TELEPHONY_LOGE("CellularCallService::StopDtmf return, call type error.");
927 return TELEPHONY_ERR_ARGUMENT_INVALID;
928 }
929
PostDialProceed(const CellularCallInfo & callInfo,const bool proceed)930 int32_t CellularCallService::PostDialProceed(const CellularCallInfo &callInfo, const bool proceed)
931 {
932 if (!IsValidSlotId(callInfo.slotId)) {
933 TELEPHONY_LOGE("CellularCallService::PostDialProceed return, invalid slot id");
934 return CALL_ERR_INVALID_SLOT_ID;
935 }
936 if (srvccState_ == SrvccState::STARTED) {
937 TELEPHONY_LOGE("CellularCallService::PostDialProceed srvccState_ is started");
938 return TELEPHONY_ERR_FAIL;
939 }
940 if (callInfo.callType == CallType::TYPE_IMS) {
941 auto imsControl = GetImsControl(callInfo.slotId);
942 if (imsControl == nullptr) {
943 TELEPHONY_LOGE("CellularCallService::PostDialProceed return, imsControl is nullptr");
944 return TELEPHONY_ERR_LOCAL_PTR_NULL;
945 }
946 return imsControl->PostDialProceed(callInfo, proceed);
947 } else if (callInfo.callType == CallType::TYPE_CS) {
948 auto csControl = GetCsControl(callInfo.slotId);
949 if (csControl == nullptr) {
950 TELEPHONY_LOGE("CellularCallService::PostDialProceed return, csControl is nullptr");
951 return TELEPHONY_ERR_LOCAL_PTR_NULL;
952 }
953 return csControl->PostDialProceed(callInfo, proceed);
954 } else if (CallType::TYPE_SATELLITE == callInfo.callType) {
955 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
956 if (satelliteControl == nullptr) {
957 TELEPHONY_LOGE("CellularCallService::PostDialProceed return, satelliteControl is nullptr");
958 return TELEPHONY_ERR_LOCAL_PTR_NULL;
959 }
960 return satelliteControl->PostDialProceed(callInfo, proceed);
961 }
962 TELEPHONY_LOGE("CellularCallService::PostDialProceed return, call type error.");
963 return TELEPHONY_ERR_ARGUMENT_INVALID;
964 }
965
SendDtmf(char cDtmfCode,const CellularCallInfo & callInfo)966 int32_t CellularCallService::SendDtmf(char cDtmfCode, const CellularCallInfo &callInfo)
967 {
968 if (!IsValidSlotId(callInfo.slotId)) {
969 TELEPHONY_LOGE("CellularCallService::SendDtmf return, invalid slot id");
970 return CALL_ERR_INVALID_SLOT_ID;
971 }
972 if (srvccState_ == SrvccState::STARTED) {
973 return TELEPHONY_ERR_FAIL;
974 }
975 if (CallType::TYPE_IMS == callInfo.callType) {
976 auto imsControl = GetImsControl(callInfo.slotId);
977 if (imsControl == nullptr) {
978 TELEPHONY_LOGE("CellularCallService::SendDtmf return, imsControl is nullptr");
979 return TELEPHONY_ERR_LOCAL_PTR_NULL;
980 }
981 return imsControl->SendDtmf(imsControl->GetConnectionMap(), cDtmfCode, callInfo);
982 } else if (CallType::TYPE_CS == callInfo.callType) {
983 auto csControl = GetCsControl(callInfo.slotId);
984 if (csControl == nullptr) {
985 TELEPHONY_LOGE("CellularCallService::SendDtmf return, csControl is nullptr");
986 return TELEPHONY_ERR_LOCAL_PTR_NULL;
987 }
988 return csControl->SendDtmf(csControl->GetConnectionMap(), cDtmfCode, callInfo);
989 } else if (CallType::TYPE_SATELLITE == callInfo.callType) {
990 auto satelliteControl = GetSatelliteControl(callInfo.slotId);
991 if (satelliteControl == nullptr) {
992 TELEPHONY_LOGE("CellularCallService::SendDtmf return, satelliteControl is nullptr");
993 return TELEPHONY_ERR_LOCAL_PTR_NULL;
994 }
995 return satelliteControl->SendDtmf(satelliteControl->GetConnectionMap(), cDtmfCode, callInfo);
996 }
997 TELEPHONY_LOGE("CellularCallService::SendDtmf return, call type error.");
998 return TELEPHONY_ERR_ARGUMENT_INVALID;
999 }
1000
StartRtt(int32_t slotId,const std::string & msg)1001 int32_t CellularCallService::StartRtt(int32_t slotId, const std::string &msg)
1002 {
1003 auto control = GetImsControl(slotId);
1004 if (control == nullptr) {
1005 TELEPHONY_LOGE("CellularCallService::StartRtt return, control is nullptr");
1006 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1007 }
1008 return control->StartRtt(slotId, msg);
1009 }
1010
StopRtt(int32_t slotId)1011 int32_t CellularCallService::StopRtt(int32_t slotId)
1012 {
1013 auto control = GetImsControl(slotId);
1014 if (control == nullptr) {
1015 TELEPHONY_LOGE("CellularCallService::StopRtt return, control is nullptr");
1016 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1017 }
1018 return control->StopRtt(slotId);
1019 }
1020
SetCallTransferInfo(int32_t slotId,const CallTransferInfo & cTInfo)1021 int32_t CellularCallService::SetCallTransferInfo(int32_t slotId, const CallTransferInfo &cTInfo)
1022 {
1023 if (!IsValidSlotId(slotId)) {
1024 TELEPHONY_LOGE("CellularCallService::SetCallTransferInfo return, invalid slot id");
1025 return CALL_ERR_INVALID_SLOT_ID;
1026 }
1027 CellularCallSupplement cellularCallSupplement;
1028 if (cTInfo.settingType == CallTransferSettingType::CALL_TRANSFER_DISABLE) {
1029 DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallForwardingInfo(
1030 slotId, false, cTInfo.transferNum);
1031 } else if (cTInfo.settingType == CallTransferSettingType::CALL_TRANSFER_ENABLE) {
1032 DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallForwardingInfo(
1033 slotId, true, cTInfo.transferNum);
1034 }
1035 return cellularCallSupplement.SetCallTransferInfo(slotId, cTInfo);
1036 }
1037
CanSetCallTransferTime(int32_t slotId,bool & result)1038 int32_t CellularCallService::CanSetCallTransferTime(int32_t slotId, bool &result)
1039 {
1040 if (!IsValidSlotId(slotId)) {
1041 TELEPHONY_LOGE("invalid slot id");
1042 return CALL_ERR_INVALID_SLOT_ID;
1043 }
1044 CellularCallSupplement cellularCallSupplement;
1045 return cellularCallSupplement.CanSetCallTransferTime(slotId, result);
1046 }
1047
GetCallTransferInfo(int32_t slotId,CallTransferType type)1048 int32_t CellularCallService::GetCallTransferInfo(int32_t slotId, CallTransferType type)
1049 {
1050 TELEPHONY_LOGD("CellularCallService::GetCallTransferInfo");
1051 if (!IsValidSlotId(slotId)) {
1052 TELEPHONY_LOGE("CellularCallService::GetCallTransferInfo return, invalid slot id");
1053 return CALL_ERR_INVALID_SLOT_ID;
1054 }
1055 CellularCallSupplement cellularCallSupplement;
1056 return cellularCallSupplement.GetCallTransferInfo(slotId, type);
1057 }
1058
GetCsControl(int32_t slotId)1059 std::shared_ptr<CSControl> CellularCallService::GetCsControl(int32_t slotId)
1060 {
1061 std::lock_guard<std::mutex> lock(mutex_);
1062 if (!IsValidSlotId(slotId)) {
1063 TELEPHONY_LOGE("return nullptr, invalid slot id");
1064 return nullptr;
1065 }
1066 return csControlMap_[slotId];
1067 }
1068
GetImsControl(int32_t slotId)1069 std::shared_ptr<IMSControl> CellularCallService::GetImsControl(int32_t slotId)
1070 {
1071 std::lock_guard<std::mutex> lock(mutex_);
1072 if (!IsValidSlotId(slotId)) {
1073 TELEPHONY_LOGE("return nullptr, invalid slot id");
1074 return nullptr;
1075 }
1076 return imsControlMap_[slotId];
1077 }
1078
GetSatelliteControl(int32_t slotId)1079 std::shared_ptr<SatelliteControl> CellularCallService::GetSatelliteControl(int32_t slotId)
1080 {
1081 std::lock_guard<std::mutex> lock(mutex_);
1082 return satelliteControlMap_[slotId];
1083 }
1084
SetCsControl(int32_t slotId,const std::shared_ptr<CSControl> & csControl)1085 void CellularCallService::SetCsControl(int32_t slotId, const std::shared_ptr<CSControl> &csControl)
1086 {
1087 std::lock_guard<std::mutex> lock(mutex_);
1088 if (!IsValidSlotId(slotId)) {
1089 TELEPHONY_LOGE("invalid slot id, return");
1090 return;
1091 }
1092 csControlMap_[slotId] = csControl;
1093 }
1094
SetImsControl(int32_t slotId,const std::shared_ptr<IMSControl> & imsControl)1095 void CellularCallService::SetImsControl(int32_t slotId, const std::shared_ptr<IMSControl> &imsControl)
1096 {
1097 std::lock_guard<std::mutex> lock(mutex_);
1098 if (!IsValidSlotId(slotId)) {
1099 TELEPHONY_LOGE("invalid slot id, return");
1100 return;
1101 }
1102 imsControlMap_[slotId] = imsControl;
1103 }
1104
SetSatelliteControl(int32_t slotId,const std::shared_ptr<SatelliteControl> & satelliteControl)1105 void CellularCallService::SetSatelliteControl(int32_t slotId, const std::shared_ptr<SatelliteControl> &satelliteControl)
1106 {
1107 std::lock_guard<std::mutex> lock(mutex_);
1108 if (!IsValidSlotId(slotId)) {
1109 TELEPHONY_LOGE("invalid slot id, return");
1110 return;
1111 }
1112 satelliteControlMap_[slotId] = satelliteControl;
1113 }
1114
SetCallWaiting(int32_t slotId,bool activate)1115 int32_t CellularCallService::SetCallWaiting(int32_t slotId, bool activate)
1116 {
1117 if (!IsValidSlotId(slotId)) {
1118 TELEPHONY_LOGE("CellularCallService::SetCallWaiting return, invalid slot id");
1119 return CALL_ERR_INVALID_SLOT_ID;
1120 }
1121 CellularCallSupplement cellularCallSupplement;
1122 return cellularCallSupplement.SetCallWaiting(slotId, activate);
1123 }
1124
GetCallWaiting(int32_t slotId)1125 int32_t CellularCallService::GetCallWaiting(int32_t slotId)
1126 {
1127 TELEPHONY_LOGD("CellularCallService::GetCallWaiting");
1128 if (!IsValidSlotId(slotId)) {
1129 TELEPHONY_LOGE("CellularCallService::GetCallWaiting return, invalid slot id");
1130 return CALL_ERR_INVALID_SLOT_ID;
1131 }
1132 CellularCallSupplement cellularCallSupplement;
1133 return cellularCallSupplement.GetCallWaiting(slotId);
1134 }
1135
GetVideoCallWaiting(int32_t slotId,bool & enabled)1136 int32_t CellularCallService::GetVideoCallWaiting(int32_t slotId, bool &enabled)
1137 {
1138 TELEPHONY_LOGD("CellularCallService::GetVideoCallWaiting");
1139 if (!IsValidSlotId(slotId)) {
1140 TELEPHONY_LOGE("CellularCallService::GetVideoCallWaiting return, invalid slot id");
1141 return CALL_ERR_INVALID_SLOT_ID;
1142 }
1143 CellularCallConfig cellularCallConfig;
1144 return cellularCallConfig.GetVideoCallWaiting(slotId, enabled);
1145 }
1146
SetCallRestriction(int32_t slotId,const CallRestrictionInfo & crInfo)1147 int32_t CellularCallService::SetCallRestriction(int32_t slotId, const CallRestrictionInfo &crInfo)
1148 {
1149 TELEPHONY_LOGD("CellularCallService::SetCallRestriction");
1150 if (!IsValidSlotId(slotId)) {
1151 TELEPHONY_LOGE("CellularCallService::SetCallRestriction return, invalid slot id");
1152 return CALL_ERR_INVALID_SLOT_ID;
1153 }
1154 CellularCallSupplement cellularCallSupplement;
1155 return cellularCallSupplement.SetCallRestriction(slotId, crInfo);
1156 }
1157
GetCallRestriction(int32_t slotId,CallRestrictionType facType)1158 int32_t CellularCallService::GetCallRestriction(int32_t slotId, CallRestrictionType facType)
1159 {
1160 TELEPHONY_LOGD("CellularCallService::GetCallRestriction");
1161 if (!IsValidSlotId(slotId)) {
1162 TELEPHONY_LOGE("CellularCallService::GetCallRestriction return, invalid slot id");
1163 return CALL_ERR_INVALID_SLOT_ID;
1164 }
1165 CellularCallSupplement cellularCallSupplement;
1166 return cellularCallSupplement.GetCallRestriction(slotId, facType);
1167 }
1168
SetCallRestrictionPassword(int32_t slotId,CallRestrictionType facType,const char * oldPassword,const char * newPassword)1169 int32_t CellularCallService::SetCallRestrictionPassword(
1170 int32_t slotId, CallRestrictionType facType, const char *oldPassword, const char *newPassword)
1171 {
1172 if (!IsValidSlotId(slotId)) {
1173 TELEPHONY_LOGE("invalid slot id");
1174 return CALL_ERR_INVALID_SLOT_ID;
1175 }
1176 CellularCallSupplement cellularCallSupplement;
1177 return cellularCallSupplement.SetBarringPassword(slotId, facType, oldPassword, newPassword);
1178 }
1179
IsEmergencyPhoneNumber(int32_t slotId,const std::string & phoneNum,bool & enabled)1180 int32_t CellularCallService::IsEmergencyPhoneNumber(int32_t slotId, const std::string &phoneNum, bool &enabled)
1181 {
1182 if (!IsValidSlotId(slotId)) {
1183 TELEPHONY_LOGE("CellularCallService::IsEmergencyPhoneNumber return, invalid slot id");
1184 return CALL_ERR_INVALID_SLOT_ID;
1185 }
1186 EmergencyUtils emergencyUtils;
1187 return emergencyUtils.IsEmergencyCall(slotId, phoneNum, enabled);
1188 }
1189
SetEmergencyCallList(int32_t slotId,std::vector<EmergencyCall> & eccVec)1190 int32_t CellularCallService::SetEmergencyCallList(int32_t slotId, std::vector<EmergencyCall> &eccVec)
1191 {
1192 TELEPHONY_LOGD("CellularCallService::SetEmergencyCallList start");
1193 if (!IsValidSlotId(slotId)) {
1194 TELEPHONY_LOGE("CellularCallService::SetMute return, invalid slot id");
1195 return CALL_ERR_INVALID_SLOT_ID;
1196 }
1197 CellularCallConfig config;
1198 return config.SetEmergencyCallList(slotId, eccVec);
1199 }
1200
SetDomainPreferenceMode(int32_t slotId,int32_t mode)1201 int32_t CellularCallService::SetDomainPreferenceMode(int32_t slotId, int32_t mode)
1202 {
1203 if (!IsValidSlotId(slotId)) {
1204 TELEPHONY_LOGE("CellularCallService::SetDomainPreferenceMode return, invalid slot id");
1205 return CALL_ERR_INVALID_SLOT_ID;
1206 }
1207 CellularCallConfig config;
1208 return config.SetDomainPreferenceMode(slotId, mode);
1209 }
1210
GetDomainPreferenceMode(int32_t slotId)1211 int32_t CellularCallService::GetDomainPreferenceMode(int32_t slotId)
1212 {
1213 if (!IsValidSlotId(slotId)) {
1214 TELEPHONY_LOGE("CellularCallService::GetDomainPreferenceMode return, invalid slot id");
1215 return CALL_ERR_INVALID_SLOT_ID;
1216 }
1217 CellularCallConfig config;
1218 return config.GetDomainPreferenceMode(slotId);
1219 }
1220
GetCarrierVtConfig(int32_t slotId,bool & enabled)1221 int32_t CellularCallService::GetCarrierVtConfig(int32_t slotId, bool &enabled)
1222 {
1223 if (!IsValidSlotId(slotId)) {
1224 TELEPHONY_LOGE("CellularCallService::GetDomainPreferenceMode return, invalid slot id");
1225 return CALL_ERR_INVALID_SLOT_ID;
1226 }
1227 CellularCallConfig config;
1228 return config.GetCarrierVtConfig(slotId, enabled);
1229 }
1230
SetImsSwitchStatus(int32_t slotId,bool active)1231 int32_t CellularCallService::SetImsSwitchStatus(int32_t slotId, bool active)
1232 {
1233 if (!IsValidSlotId(slotId)) {
1234 TELEPHONY_LOGE("CellularCallService::SetImsSwitchStatus return, invalid slot id");
1235 return CALL_ERR_INVALID_SLOT_ID;
1236 }
1237 CellularCallConfig config;
1238 return config.SetImsSwitchStatus(slotId, active);
1239 }
1240
GetImsSwitchStatus(int32_t slotId,bool & enabled)1241 int32_t CellularCallService::GetImsSwitchStatus(int32_t slotId, bool &enabled)
1242 {
1243 if (!IsValidSlotId(slotId)) {
1244 TELEPHONY_LOGE("CellularCallService::GetImsSwitchStatus return, invalid slot id");
1245 return CALL_ERR_INVALID_SLOT_ID;
1246 }
1247 CellularCallConfig config;
1248 return config.GetImsSwitchStatus(slotId, enabled);
1249 }
1250
SetVoNRState(int32_t slotId,int32_t state)1251 int32_t CellularCallService::SetVoNRState(int32_t slotId, int32_t state)
1252 {
1253 if (!IsValidSlotId(slotId)) {
1254 TELEPHONY_LOGE("CellularCallService::SetVoNRState return, invalid slot id");
1255 return CALL_ERR_INVALID_SLOT_ID;
1256 }
1257 CellularCallConfig config;
1258 return config.SetVoNRSwitchStatus(slotId, state);
1259 }
1260
GetVoNRState(int32_t slotId,int32_t & state)1261 int32_t CellularCallService::GetVoNRState(int32_t slotId, int32_t &state)
1262 {
1263 if (!IsValidSlotId(slotId)) {
1264 TELEPHONY_LOGE("CellularCallService::GetVoNRState return, invalid slot id");
1265 return CALL_ERR_INVALID_SLOT_ID;
1266 }
1267 CellularCallConfig config;
1268 return config.GetVoNRSwitchStatus(slotId, state);
1269 }
1270
SetImsConfig(int32_t slotId,ImsConfigItem item,const std::string & value)1271 int32_t CellularCallService::SetImsConfig(int32_t slotId, ImsConfigItem item, const std::string &value)
1272 {
1273 if (!IsValidSlotId(slotId)) {
1274 TELEPHONY_LOGE("CellularCallService::SetImsConfig return, invalid slot id");
1275 return CALL_ERR_INVALID_SLOT_ID;
1276 }
1277 CellularCallConfig config;
1278 return config.SetImsConfig(item, value);
1279 }
1280
SetImsConfig(int32_t slotId,ImsConfigItem item,int32_t value)1281 int32_t CellularCallService::SetImsConfig(int32_t slotId, ImsConfigItem item, int32_t value)
1282 {
1283 if (!IsValidSlotId(slotId)) {
1284 TELEPHONY_LOGE("CellularCallService::SetImsConfig return, invalid slot id");
1285 return CALL_ERR_INVALID_SLOT_ID;
1286 }
1287 CellularCallConfig config;
1288 return config.SetImsConfig(item, value);
1289 }
1290
GetImsConfig(int32_t slotId,ImsConfigItem item)1291 int32_t CellularCallService::GetImsConfig(int32_t slotId, ImsConfigItem item)
1292 {
1293 if (!IsValidSlotId(slotId)) {
1294 TELEPHONY_LOGE("CellularCallService::GetImsConfig return, invalid slot id");
1295 return CALL_ERR_INVALID_SLOT_ID;
1296 }
1297 CellularCallConfig config;
1298 return config.GetImsConfig(item);
1299 }
1300
SetImsFeatureValue(int32_t slotId,FeatureType type,int32_t value)1301 int32_t CellularCallService::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
1302 {
1303 if (!IsValidSlotId(slotId)) {
1304 TELEPHONY_LOGE("CellularCallService::SetImsFeatureValue return, invalid slot id");
1305 return CALL_ERR_INVALID_SLOT_ID;
1306 }
1307 CellularCallConfig config;
1308 return config.SetImsFeatureValue(type, value);
1309 }
1310
GetImsFeatureValue(int32_t slotId,FeatureType type)1311 int32_t CellularCallService::GetImsFeatureValue(int32_t slotId, FeatureType type)
1312 {
1313 if (!IsValidSlotId(slotId)) {
1314 TELEPHONY_LOGE("CellularCallService::GetImsFeatureValue return, invalid slot id");
1315 return CALL_ERR_INVALID_SLOT_ID;
1316 }
1317 CellularCallConfig config;
1318 return config.GetImsFeatureValue(type);
1319 }
1320
IsValidSlotId(int32_t slotId) const1321 bool CellularCallService::IsValidSlotId(int32_t slotId) const
1322 {
1323 const int32_t slotSingle = 1;
1324 const int32_t slotDouble = 2;
1325 if (SIM_SLOT_COUNT == slotSingle) {
1326 return slotId == DEFAULT_SIM_SLOT_ID;
1327 } else if (SIM_SLOT_COUNT == slotDouble) {
1328 return slotId == SIM_SLOT_0 || slotId == SIM_SLOT_1;
1329 }
1330 return false;
1331 }
1332
IsNeedIms(int32_t slotId) const1333 bool CellularCallService::IsNeedIms(int32_t slotId) const
1334 {
1335 ModuleServiceUtils moduleUtils;
1336 CellularCallConfig config;
1337 bool imsRegState = moduleUtils.GetImsRegistrationState(slotId);
1338 bool imsServiceConnected = moduleUtils.NeedCallImsService();
1339 int32_t preferenceMode = config.GetPreferenceMode(slotId);
1340 TELEPHONY_LOGI("IsNeedIms state:%{public}d, mode:%{public}d, connected:%{public}d", imsRegState,
1341 preferenceMode, imsServiceConnected);
1342 if (imsRegState && preferenceMode != DomainPreferenceMode::CS_VOICE_ONLY && imsServiceConnected) {
1343 return true;
1344 }
1345 return false;
1346 }
1347
GetHandler(int32_t slotId)1348 std::shared_ptr<CellularCallHandler> CellularCallService::GetHandler(int32_t slotId)
1349 {
1350 std::unique_lock<std::mutex> lock(handlerMapMutex_);
1351 return handlerMap_[slotId];
1352 }
1353
ControlCamera(int32_t slotId,int32_t index,const std::string & cameraId)1354 int32_t CellularCallService::ControlCamera(int32_t slotId, int32_t index, const std::string &cameraId)
1355 {
1356 auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1357 if (videoCallControl == nullptr) {
1358 TELEPHONY_LOGE("videoCallControl is nullptr");
1359 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1360 }
1361 return videoCallControl->ControlCamera(slotId, index, cameraId);
1362 }
1363
SetPreviewWindow(int32_t slotId,int32_t index,const std::string & surfaceId,sptr<Surface> surface)1364 int32_t CellularCallService::SetPreviewWindow(
1365 int32_t slotId, int32_t index, const std::string &surfaceId, sptr<Surface> surface)
1366 {
1367 auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1368 if (videoCallControl == nullptr) {
1369 TELEPHONY_LOGE("videoCallControl is nullptr");
1370 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1371 }
1372 return videoCallControl->SetPreviewWindow(slotId, index, surfaceId, surface);
1373 }
1374
SetDisplayWindow(int32_t slotId,int32_t index,const std::string & surfaceId,sptr<Surface> surface)1375 int32_t CellularCallService::SetDisplayWindow(
1376 int32_t slotId, int32_t index, const std::string &surfaceId, sptr<Surface> surface)
1377 {
1378 auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1379 if (videoCallControl == nullptr) {
1380 TELEPHONY_LOGE("videoCallControl is nullptr");
1381 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1382 }
1383 return videoCallControl->SetDisplayWindow(slotId, index, surfaceId, surface);
1384 }
1385
SetCameraZoom(float zoomRatio)1386 int32_t CellularCallService::SetCameraZoom(float zoomRatio)
1387 {
1388 auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1389 if (videoCallControl == nullptr) {
1390 TELEPHONY_LOGE("videoCallControl is nullptr");
1391 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1392 }
1393 return videoCallControl->SetCameraZoom(zoomRatio);
1394 }
1395
SetPausePicture(int32_t slotId,int32_t index,const std::string & path)1396 int32_t CellularCallService::SetPausePicture(int32_t slotId, int32_t index, const std::string &path)
1397 {
1398 auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1399 if (videoCallControl == nullptr) {
1400 TELEPHONY_LOGE("videoCallControl is nullptr");
1401 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1402 }
1403 return videoCallControl->SetPausePicture(slotId, index, path);
1404 }
1405
SetDeviceDirection(int32_t slotId,int32_t callIndex,int32_t rotation)1406 int32_t CellularCallService::SetDeviceDirection(int32_t slotId, int32_t callIndex, int32_t rotation)
1407 {
1408 auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1409 if (videoCallControl == nullptr) {
1410 TELEPHONY_LOGE("videoCallControl is nullptr");
1411 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1412 }
1413 return videoCallControl->SetDeviceDirection(slotId, callIndex, rotation);
1414 }
1415
SetMute(int32_t slotId,int32_t mute)1416 int32_t CellularCallService::SetMute(int32_t slotId, int32_t mute)
1417 {
1418 if (!IsValidSlotId(slotId)) {
1419 TELEPHONY_LOGE("CellularCallService::SetMute return, invalid slot id");
1420 return CALL_ERR_INVALID_SLOT_ID;
1421 }
1422 CellularCallConfig config;
1423 return config.SetMute(slotId, mute);
1424 }
1425
GetMute(int32_t slotId)1426 int32_t CellularCallService::GetMute(int32_t slotId)
1427 {
1428 if (!IsValidSlotId(slotId)) {
1429 TELEPHONY_LOGE("CellularCallService::GetMute return, invalid slot id");
1430 return CALL_ERR_INVALID_SLOT_ID;
1431 }
1432 CellularCallConfig config;
1433 return config.GetMute(slotId);
1434 }
1435
CloseUnFinishedUssd(int32_t slotId)1436 int32_t CellularCallService::CloseUnFinishedUssd(int32_t slotId)
1437 {
1438 if (!IsValidSlotId(slotId)) {
1439 TELEPHONY_LOGE("CellularCallService::CloseUnFinishedUssd return, invalid slot id");
1440 return CALL_ERR_INVALID_SLOT_ID;
1441 }
1442 CellularCallSupplement cellularCallSupplement;
1443 return cellularCallSupplement.CloseUnFinishedUssd(slotId);
1444 }
1445
SetControl(const CellularCallInfo & info)1446 int32_t CellularCallService::SetControl(const CellularCallInfo &info)
1447 {
1448 if (info.callType == CallType::TYPE_CS) {
1449 auto csControl = GetCsControl(info.slotId);
1450 if (csControl == nullptr) {
1451 TELEPHONY_LOGI("GetCsControl csControl is nullptr");
1452 csControl = std::make_shared<CSControl>();
1453 if (csControl == nullptr) {
1454 TELEPHONY_LOGE("csControl is nullptr");
1455 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1456 }
1457 SetCsControl(info.slotId, csControl);
1458 }
1459 }
1460 if (info.callType == CallType::TYPE_IMS) {
1461 auto imsControl = GetImsControl(info.slotId);
1462 if (imsControl == nullptr) {
1463 TELEPHONY_LOGI("GetImsControl imsControl is nullptr");
1464 imsControl = std::make_shared<IMSControl>();
1465 if (imsControl == nullptr) {
1466 TELEPHONY_LOGE("imsControl is nullptr");
1467 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1468 }
1469 SetImsControl(info.slotId, imsControl);
1470 }
1471 }
1472 return TELEPHONY_SUCCESS;
1473 }
1474
ClearAllCalls(const std::vector<CellularCallInfo> & infos)1475 int32_t CellularCallService::ClearAllCalls(const std::vector<CellularCallInfo> &infos)
1476 {
1477 if (infos.empty()) {
1478 TELEPHONY_LOGE("CellularCallService::ClearAllCalls infos is empty");
1479 return TELEPHONY_ERR_ARGUMENT_INVALID;
1480 }
1481 for (auto &info : infos) {
1482 if (SetControl(info) != TELEPHONY_SUCCESS) {
1483 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1484 }
1485 }
1486 HangUpWithCellularCallRestart(infos);
1487 return TELEPHONY_SUCCESS;
1488 }
1489
SetSrvccState(int32_t srvccState)1490 void CellularCallService::SetSrvccState(int32_t srvccState)
1491 {
1492 srvccState_ = srvccState;
1493 }
1494
GetSrvccState()1495 int32_t CellularCallService::GetSrvccState()
1496 {
1497 return srvccState_;
1498 }
1499
UseImsForEmergency(const CellularCallInfo & callInfo,bool isEcc)1500 bool CellularCallService::UseImsForEmergency(const CellularCallInfo &callInfo, bool isEcc)
1501 {
1502 ModuleServiceUtils moduleUtils;
1503 CellularCallConfig config;
1504 if (isEcc && moduleUtils.NeedCallImsService() && config.GetImsPreferForEmergencyConfig(callInfo.slotId)) {
1505 return true;
1506 }
1507 return false;
1508 }
1509
HandleCallManagerException()1510 void CellularCallService::HandleCallManagerException()
1511 {
1512 ModuleServiceUtils obtain;
1513 std::vector<int32_t> slotVector = obtain.GetSlotInfo();
1514 for (const auto &it : slotVector) {
1515 auto csControl = GetCsControl(it);
1516 if (csControl != nullptr) {
1517 csControl->HangUpAllConnection(it);
1518 }
1519 auto imsControl = GetImsControl(it);
1520 if (imsControl != nullptr) {
1521 imsControl->HangUpAllConnection(it);
1522 }
1523 }
1524 }
1525
HangUpWithCellularCallRestart(const std::vector<CellularCallInfo> & infos)1526 void CellularCallService::HangUpWithCellularCallRestart(const std::vector<CellularCallInfo> &infos)
1527 {
1528 ModuleServiceUtils obtain;
1529 std::vector<int32_t> slotVector = obtain.GetSlotInfo();
1530 for (const auto &it : slotVector) {
1531 auto csControl = GetCsControl(it);
1532 if (csControl != nullptr) {
1533 csControl->ReportHangUp(infos, it);
1534 csControl->HangUpAllConnection(it);
1535 }
1536 auto imsControl = GetImsControl(it);
1537 if (imsControl != nullptr) {
1538 imsControl->ReportHangUp(infos, it);
1539 imsControl->RestoreConnection(infos, it);
1540 imsControl->HangUpAllConnection(it);
1541 imsControl->ReleaseAllConnection();
1542 }
1543 }
1544 }
1545
HandleCellularControlException(const CellularCallInfo & callInfo)1546 void CellularCallService::HandleCellularControlException(const CellularCallInfo &callInfo)
1547 {
1548 TELEPHONY_LOGI("HandleCellularControlException entry");
1549 CallsReportInfo callsReportInfo;
1550 CallReportInfo reportInfo = EncapsulationCallReportInfo(callInfo);
1551 callsReportInfo.callVec.push_back(reportInfo);
1552 if (DelayedSingleton<CellularCallRegister>::GetInstance() == nullptr) {
1553 TELEPHONY_LOGE("HandleCellularControlException return, GetInstance() is nullptr.");
1554 return;
1555 }
1556 callsReportInfo.slotId = callInfo.slotId;
1557 DelayedSingleton<CellularCallRegister>::GetInstance()->ReportCallsInfo(callsReportInfo);
1558 }
1559
EncapsulationCallReportInfo(const CellularCallInfo & callInfo)1560 CallReportInfo CellularCallService::EncapsulationCallReportInfo(const CellularCallInfo &callInfo)
1561 {
1562 TELEPHONY_LOGD("EncapsulationCallReportInfo entry");
1563 CallReportInfo callReportInfo;
1564 if (memset_s(&callReportInfo, sizeof(callReportInfo), 0, sizeof(callReportInfo)) != EOK) {
1565 TELEPHONY_LOGE("EncapsulationCallReportInfo return, memset_s fail.");
1566 return callReportInfo;
1567 }
1568
1569 size_t cpyLen = strlen(callInfo.phoneNum) + 1;
1570 if (cpyLen > static_cast<size_t>(kMaxNumberLen + 1)) {
1571 TELEPHONY_LOGE("EncapsulationCallReportInfo return, strcpy_s fail.");
1572 return callReportInfo;
1573 }
1574 if (strcpy_s(callReportInfo.accountNum, cpyLen, callInfo.phoneNum) != EOK) {
1575 TELEPHONY_LOGE("EncapsulationCallReportInfo return, strcpy_s fail.");
1576 return callReportInfo;
1577 }
1578 callReportInfo.index = callInfo.index;
1579 callReportInfo.accountId = callInfo.slotId;
1580 callReportInfo.state = TelCallState::CALL_STATUS_DISCONNECTED;
1581 callReportInfo.callType = callInfo.callType;
1582 return callReportInfo;
1583 }
1584
SystemAbilityStatusChangeListener(std::shared_ptr<CellularCallHandler> & cellularCallHandler)1585 CellularCallService::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener(
1586 std::shared_ptr<CellularCallHandler> &cellularCallHandler)
1587 : cellularCallHandler_(cellularCallHandler)
1588 {}
1589
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1590 void CellularCallService::SystemAbilityStatusChangeListener::OnAddSystemAbility(
1591 int32_t systemAbilityId, const std::string &deviceId)
1592 {
1593 if (systemAbilityId != COMMON_EVENT_SERVICE_ID && systemAbilityId != TELEPHONY_SATELLITE_SYS_ABILITY_ID) {
1594 TELEPHONY_LOGE("systemAbilityId is not COMMON_EVENT_SERVICE_ID or TELEPHONY_SATELLITE_SYS_ABILITY_ID");
1595 return;
1596 }
1597 if (cellularCallHandler_ == nullptr) {
1598 TELEPHONY_LOGE("COMMON_EVENT_SERVICE_ID cellularCallHandler_ is nullptr");
1599 return;
1600 }
1601 if (systemAbilityId == COMMON_EVENT_SERVICE_ID) {
1602 bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(cellularCallHandler_);
1603 TELEPHONY_LOGI("subscribeResult = %{public}d", subscribeResult);
1604 } else if (systemAbilityId == TELEPHONY_SATELLITE_SYS_ABILITY_ID) {
1605 DelayedSingleton<SatelliteCallClient>::GetInstance()->Init();
1606 cellularCallHandler_->RegisterSatelliteCallCallbackHandler();
1607 }
1608 }
1609
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1610 void CellularCallService::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
1611 int32_t systemAbilityId, const std::string &deviceId)
1612 {
1613 switch (systemAbilityId) {
1614 case TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID: {
1615 auto cellularCallService = DelayedSingleton<CellularCallService>::GetInstance();
1616 if (cellularCallService == nullptr) {
1617 TELEPHONY_LOGE("cellularCallService is nullptr");
1618 return;
1619 }
1620 cellularCallService->HandleCallManagerException();
1621 count_++;
1622 CellularCallHiSysEvent::WriteFoundationRestartFaultEvent(count_);
1623 break;
1624 }
1625 case COMMON_EVENT_SERVICE_ID: {
1626 if (cellularCallHandler_ == nullptr) {
1627 TELEPHONY_LOGE("cellularCallHandler_ is nullptr");
1628 return;
1629 }
1630 bool unSubscribeResult = EventFwk::CommonEventManager::UnSubscribeCommonEvent(cellularCallHandler_);
1631 TELEPHONY_LOGI("unSubscribeResult = %{public}d", unSubscribeResult);
1632 break;
1633 }
1634 case TELEPHONY_SATELLITE_SYS_ABILITY_ID: {
1635 DelayedSingleton<SatelliteCallClient>::GetInstance()->UnInit();
1636 break;
1637 }
1638 default:
1639 TELEPHONY_LOGE("systemAbilityId is invalid");
1640 break;
1641 }
1642 }
1643
1644 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
StartCallManagerService()1645 void CellularCallService::StartCallManagerService()
1646 {
1647 sptr<ISystemAbilityManager> managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1648 if (managerPtr == nullptr) {
1649 TELEPHONY_LOGE("GetSystemAbilityManager failed!");
1650 return;
1651 }
1652
1653 sptr<IRemoteObject> iRemoteObjectPtr = managerPtr->GetSystemAbility(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID);
1654 if (iRemoteObjectPtr == nullptr) {
1655 TELEPHONY_LOGE("GetSystemAbility failed!");
1656 }
1657 }
1658 #endif
1659
setRadioOnFlag(bool flag,int32_t slotId)1660 void CellularCallService::setRadioOnFlag(bool flag, int32_t slotId)
1661 {
1662 isRadioOn_[slotId] = flag;
1663 }
1664
isRadioOnFlag(int32_t slotId)1665 bool CellularCallService::isRadioOnFlag(int32_t slotId)
1666 {
1667 return isRadioOn_[slotId];
1668 }
1669
SendUssdResponse(int32_t slotId,const std::string & content)1670 int32_t CellularCallService::SendUssdResponse(int32_t slotId, const std::string &content)
1671 {
1672 if (!IsValidSlotId(slotId)) {
1673 TELEPHONY_LOGE("CellularCallService::SendUssdResponse return, invalid slot id");
1674 return CALL_ERR_INVALID_SLOT_ID;
1675 }
1676 CellularCallSupplement supplement;
1677 return supplement.SendUssd(slotId, content);
1678 }
1679 } // namespace Telephony
1680 } // namespace OHOS
1681