• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
HangUp(const CellularCallInfo & callInfo,CallSupplementType type)370 int32_t CellularCallService::HangUp(const CellularCallInfo &callInfo, CallSupplementType type)
371 {
372     DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallParameterInfo(
373         callInfo.slotId, static_cast<int32_t>(callInfo.callType), callInfo.videoState);
374     if (!IsValidSlotId(callInfo.slotId)) {
375         TELEPHONY_LOGE("CellularCallService::HangUp return, invalid slot id");
376         CellularCallHiSysEvent::WriteHangUpFaultEvent(
377             callInfo.slotId, callInfo.callId, CALL_ERR_INVALID_SLOT_ID, "HangUp invalid slot id");
378         return CALL_ERR_INVALID_SLOT_ID;
379     }
380     if (srvccState_ == SrvccState::STARTED) {
381         CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, callInfo.callId,
382             static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE), "HangUp srvccState_ is STARTED");
383         return TELEPHONY_ERR_FAIL;
384     }
385     if (CallType::TYPE_SATELLITE == callInfo.callType) {
386         auto satelliteControl = GetSatelliteControl(callInfo.slotId);
387         if (satelliteControl == nullptr) {
388             TELEPHONY_LOGE("CellularCallService::HangUp return, satelliteControl is nullptr");
389             CellularCallHiSysEvent::WriteHangUpFaultEvent(
390                 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "HangUp satelliteControl is nullptr");
391             HandleCellularControlException(callInfo);
392             return TELEPHONY_ERR_LOCAL_PTR_NULL;
393         }
394         return satelliteControl->HangUp(callInfo, type);
395     } else if (CallType::TYPE_CS == callInfo.callType) {
396         auto csControl = GetCsControl(callInfo.slotId);
397         if (csControl == nullptr) {
398             TELEPHONY_LOGE("CellularCallService::HangUp return, csControl is nullptr");
399             CellularCallHiSysEvent::WriteHangUpFaultEvent(
400                 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "HangUp csControl is nullptr");
401             HandleCellularControlException(callInfo);
402             return TELEPHONY_ERR_LOCAL_PTR_NULL;
403         }
404         return csControl->HangUp(callInfo, type);
405     } else if (CallType::TYPE_IMS == callInfo.callType) {
406         auto imsControl = GetImsControl(callInfo.slotId);
407         if (imsControl == nullptr) {
408             TELEPHONY_LOGE("CellularCallService::HangUp return, imsControl is nullptr");
409             CellularCallHiSysEvent::WriteHangUpFaultEvent(
410                 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "HangUp imsControl is nullptr");
411             HandleCellularControlException(callInfo);
412             return TELEPHONY_ERR_LOCAL_PTR_NULL;
413         }
414         return imsControl->HangUp(callInfo, type);
415     }
416     TELEPHONY_LOGE("CellularCallService::HangUp return, call type error.");
417     CellularCallHiSysEvent::WriteHangUpFaultEvent(
418         callInfo.slotId, callInfo.callId, TELEPHONY_ERR_ARGUMENT_INVALID, "HangUp call type error");
419     return TELEPHONY_ERR_ARGUMENT_INVALID;
420 }
421 
Reject(const CellularCallInfo & callInfo)422 int32_t CellularCallService::Reject(const CellularCallInfo &callInfo)
423 {
424     DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallParameterInfo(
425         callInfo.slotId, static_cast<int32_t>(callInfo.callType), callInfo.videoState);
426     if (!IsValidSlotId(callInfo.slotId)) {
427         TELEPHONY_LOGE("CellularCallService::Reject return, invalid slot id");
428         CellularCallHiSysEvent::WriteHangUpFaultEvent(
429             callInfo.slotId, callInfo.callId, TELEPHONY_ERR_ARGUMENT_INVALID, "Reject call type error");
430         return CALL_ERR_INVALID_SLOT_ID;
431     }
432     if (srvccState_ == SrvccState::STARTED) {
433         CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, callInfo.callId,
434             static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE), "Reject srvccState_ is STARTED");
435         return TELEPHONY_ERR_FAIL;
436     }
437     if (CallType::TYPE_SATELLITE == callInfo.callType) {
438         auto satelliteControl = GetSatelliteControl(callInfo.slotId);
439         if (satelliteControl == nullptr) {
440             TELEPHONY_LOGE("CellularCallService::Reject return, satelliteControl is nullptr");
441             CellularCallHiSysEvent::WriteHangUpFaultEvent(
442                 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "Reject satelliteControl is nullptr");
443             HandleCellularControlException(callInfo);
444             return TELEPHONY_ERR_LOCAL_PTR_NULL;
445         }
446         return satelliteControl->Reject(callInfo);
447     } else if (CallType::TYPE_CS == callInfo.callType) {
448         auto csControl = GetCsControl(callInfo.slotId);
449         if (csControl == nullptr) {
450             TELEPHONY_LOGE("CellularCallService::Reject return, csControl is nullptr");
451             CellularCallHiSysEvent::WriteHangUpFaultEvent(
452                 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "Reject csControl is nullptr");
453             HandleCellularControlException(callInfo);
454             return TELEPHONY_ERR_LOCAL_PTR_NULL;
455         }
456         return csControl->Reject(callInfo);
457     } else if (CallType::TYPE_IMS == callInfo.callType) {
458         auto imsControl = GetImsControl(callInfo.slotId);
459         if (imsControl == nullptr) {
460             TELEPHONY_LOGE("CellularCallService::Reject return, imsControl is nullptr");
461             CellularCallHiSysEvent::WriteHangUpFaultEvent(
462                 callInfo.slotId, callInfo.callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "Reject imsControl is nullptr");
463             HandleCellularControlException(callInfo);
464             return TELEPHONY_ERR_LOCAL_PTR_NULL;
465         }
466         return imsControl->Reject(callInfo);
467     }
468     TELEPHONY_LOGE("CellularCallService::Reject return, call type error.");
469     CellularCallHiSysEvent::WriteHangUpFaultEvent(
470         callInfo.slotId, callInfo.callId, TELEPHONY_ERR_ARGUMENT_INVALID, "Reject call type error");
471     return TELEPHONY_ERR_ARGUMENT_INVALID;
472 }
473 
Answer(const CellularCallInfo & callInfo)474 int32_t CellularCallService::Answer(const CellularCallInfo &callInfo)
475 {
476     DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallParameterInfo(
477         callInfo.slotId, static_cast<int32_t>(callInfo.callType), callInfo.videoState);
478 
479     if (!IsValidSlotId(callInfo.slotId)) {
480         TELEPHONY_LOGE("CellularCallService::Answer return, invalid slot id");
481         CellularCallHiSysEvent::WriteAnswerCallFaultEvent(
482             callInfo.slotId, callInfo.callId, callInfo.videoState, CALL_ERR_INVALID_SLOT_ID, "invalid slot id");
483         return CALL_ERR_INVALID_SLOT_ID;
484     }
485     if (srvccState_ == SrvccState::STARTED) {
486         CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
487             static_cast<int32_t>(CallErrorCode::CALL_ERROR_UNEXPECTED_SRVCC_STATE), "srvccState_ is STARTED");
488         return TELEPHONY_ERR_FAIL;
489     }
490     if (CallType::TYPE_SATELLITE == callInfo.callType) {
491         auto satelliteControl = GetSatelliteControl(callInfo.slotId);
492         if (satelliteControl == nullptr) {
493             TELEPHONY_LOGE("CellularCallService::Answer return, satelliteControl is nullptr");
494             CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
495                 TELEPHONY_ERR_LOCAL_PTR_NULL, "satelliteControl is nullptr");
496             HandleCellularControlException(callInfo);
497             return TELEPHONY_ERR_LOCAL_PTR_NULL;
498         }
499         return satelliteControl->Answer(callInfo);
500     } else if (CallType::TYPE_CS == callInfo.callType) {
501         auto csControl = GetCsControl(callInfo.slotId);
502         if (csControl == nullptr) {
503             TELEPHONY_LOGE("CellularCallService::Answer return, csControl is nullptr");
504             CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
505                 TELEPHONY_ERR_LOCAL_PTR_NULL, "csControl is nullptr");
506             HandleCellularControlException(callInfo);
507             return TELEPHONY_ERR_LOCAL_PTR_NULL;
508         }
509         return csControl->Answer(callInfo);
510     } else if (CallType::TYPE_IMS == callInfo.callType) {
511         auto imsControl = GetImsControl(callInfo.slotId);
512         if (imsControl == nullptr) {
513             TELEPHONY_LOGE("CellularCallService::Answer return, imsControl is nullptr");
514             CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, callInfo.callId, callInfo.videoState,
515                 TELEPHONY_ERR_LOCAL_PTR_NULL, "imsControl is nullptr");
516             HandleCellularControlException(callInfo);
517             return TELEPHONY_ERR_LOCAL_PTR_NULL;
518         }
519         return imsControl->Answer(callInfo);
520     }
521     TELEPHONY_LOGE("CellularCallService::Answer return, call type error.");
522     CellularCallHiSysEvent::WriteAnswerCallFaultEvent(
523         callInfo.slotId, callInfo.callId, callInfo.videoState, TELEPHONY_ERR_LOCAL_PTR_NULL, "call type error");
524     return TELEPHONY_ERR_ARGUMENT_INVALID;
525 }
526 
RegisterCallManagerCallBack(const sptr<ICallStatusCallback> & callback)527 int32_t CellularCallService::RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback)
528 {
529     if (DelayedSingleton<CellularCallRegister>::GetInstance() == nullptr) {
530         TELEPHONY_LOGE("CellularCallService::RegisterCallManagerCallBack return, instance is nullptr.");
531         return TELEPHONY_ERR_LOCAL_PTR_NULL;
532     }
533     TELEPHONY_LOGI("CellularCallService::RegisterCallManagerCallBack");
534     return DelayedSingleton<CellularCallRegister>::GetInstance()->RegisterCallManagerCallBack(callback);
535 }
536 
UnRegisterCallManagerCallBack()537 int32_t CellularCallService::UnRegisterCallManagerCallBack()
538 {
539     if (DelayedSingleton<CellularCallRegister>::GetInstance() == nullptr) {
540         TELEPHONY_LOGE("CellularCallService::UnRegisterCallManagerCallBack return, instance is nullptr.");
541         return TELEPHONY_ERR_LOCAL_PTR_NULL;
542     }
543     TELEPHONY_LOGI("CellularCallService::UnRegisterCallManagerCallBack");
544     return DelayedSingleton<CellularCallRegister>::GetInstance()->UnRegisterCallManagerCallBack();
545 }
546 
HoldCall(const CellularCallInfo & callInfo)547 int32_t CellularCallService::HoldCall(const CellularCallInfo &callInfo)
548 {
549     if (!IsValidSlotId(callInfo.slotId)) {
550         TELEPHONY_LOGE("CellularCallService::HoldCall return, invalid slot id");
551         return CALL_ERR_INVALID_SLOT_ID;
552     }
553     if (srvccState_ == SrvccState::STARTED) {
554         return TELEPHONY_ERR_FAIL;
555     }
556     if (CallType::TYPE_SATELLITE == callInfo.callType) {
557         auto satelliteControl = GetSatelliteControl(callInfo.slotId);
558         if (satelliteControl == nullptr) {
559             TELEPHONY_LOGE("CellularCallService::HoldCall return, satelliteControl is nullptr");
560             return TELEPHONY_ERR_LOCAL_PTR_NULL;
561         }
562         return satelliteControl->HoldCall(callInfo.slotId);
563     } else if (CallType::TYPE_IMS == callInfo.callType) {
564         auto imsControl = GetImsControl(callInfo.slotId);
565         if (imsControl == nullptr) {
566             TELEPHONY_LOGE("CellularCallService::HoldCall return, imsControl is nullptr");
567             return TELEPHONY_ERR_LOCAL_PTR_NULL;
568         }
569         return imsControl->HoldCall(callInfo.slotId);
570     } else if (CallType::TYPE_CS == callInfo.callType) {
571         auto csControl = GetCsControl(callInfo.slotId);
572         if (csControl == nullptr) {
573             TELEPHONY_LOGE("CellularCallService::HoldCall return, csControl is nullptr");
574             return TELEPHONY_ERR_LOCAL_PTR_NULL;
575         }
576         return csControl->HoldCall(callInfo.slotId);
577     }
578     TELEPHONY_LOGE("CellularCallService::HoldCall return, call type error.");
579     return TELEPHONY_ERR_ARGUMENT_INVALID;
580 }
581 
UnHoldCall(const CellularCallInfo & callInfo)582 int32_t CellularCallService::UnHoldCall(const CellularCallInfo &callInfo)
583 {
584     if (!IsValidSlotId(callInfo.slotId)) {
585         TELEPHONY_LOGE("CellularCallService::UnHoldCall return, invalid slot id");
586         return CALL_ERR_INVALID_SLOT_ID;
587     }
588     if (srvccState_ == SrvccState::STARTED) {
589         return TELEPHONY_ERR_FAIL;
590     }
591     if (CallType::TYPE_SATELLITE == callInfo.callType) {
592         auto satelliteControl = GetSatelliteControl(callInfo.slotId);
593         if (satelliteControl == nullptr) {
594             TELEPHONY_LOGE("CellularCallService::HoldCall return, satelliteControl is nullptr");
595             return TELEPHONY_ERR_LOCAL_PTR_NULL;
596         }
597         return satelliteControl->UnHoldCall(callInfo.slotId);
598     } else if (CallType::TYPE_IMS == callInfo.callType) {
599         auto imsControl = GetImsControl(callInfo.slotId);
600         if (imsControl == nullptr) {
601             TELEPHONY_LOGE("CellularCallService::UnHoldCall return, imsControl is nullptr");
602             return TELEPHONY_ERR_LOCAL_PTR_NULL;
603         }
604         return imsControl->UnHoldCall(callInfo.slotId);
605     } else if (CallType::TYPE_CS == callInfo.callType) {
606         auto csControl = GetCsControl(callInfo.slotId);
607         if (csControl == nullptr) {
608             TELEPHONY_LOGE("CellularCallService::UnHoldCall return, csControl is nullptr");
609             return TELEPHONY_ERR_LOCAL_PTR_NULL;
610         }
611         return csControl->UnHoldCall(callInfo.slotId);
612     }
613     TELEPHONY_LOGE("CellularCallService::UnHoldCall return, call type error.");
614     return TELEPHONY_ERR_ARGUMENT_INVALID;
615 }
616 
SwitchCall(const CellularCallInfo & callInfo)617 int32_t CellularCallService::SwitchCall(const CellularCallInfo &callInfo)
618 {
619     if (!IsValidSlotId(callInfo.slotId)) {
620         TELEPHONY_LOGE("CellularCallService::SwitchCall return, invalid slot id");
621         return CALL_ERR_INVALID_SLOT_ID;
622     }
623     if (srvccState_ == SrvccState::STARTED) {
624         return TELEPHONY_ERR_FAIL;
625     }
626     if (CallType::TYPE_SATELLITE == callInfo.callType) {
627         auto satelliteControl = GetSatelliteControl(callInfo.slotId);
628         if (satelliteControl == nullptr) {
629             TELEPHONY_LOGE("CellularCallService::HoldCall return, satelliteControl is nullptr");
630             return TELEPHONY_ERR_LOCAL_PTR_NULL;
631         }
632         return satelliteControl->UnHoldCall(callInfo.slotId);
633     } else if (CallType::TYPE_IMS == callInfo.callType) {
634         auto imsControl = GetImsControl(callInfo.slotId);
635         if (imsControl == nullptr) {
636             TELEPHONY_LOGE("CellularCallService::SwitchCall return, imsControl is nullptr");
637             return TELEPHONY_ERR_LOCAL_PTR_NULL;
638         }
639         return imsControl->SwitchCall(callInfo.slotId);
640     } else if (CallType::TYPE_CS == callInfo.callType) {
641         auto csControl = GetCsControl(callInfo.slotId);
642         if (csControl == nullptr) {
643             TELEPHONY_LOGE("CellularCallService::SwitchCall return, csControl is nullptr");
644             return TELEPHONY_ERR_LOCAL_PTR_NULL;
645         }
646         return csControl->SwitchCall(callInfo.slotId);
647     }
648     TELEPHONY_LOGE("CellularCallService::SwitchCall return, call type error.");
649     return TELEPHONY_ERR_ARGUMENT_INVALID;
650 }
651 
CombineConference(const CellularCallInfo & callInfo)652 int32_t CellularCallService::CombineConference(const CellularCallInfo &callInfo)
653 {
654     if (!IsValidSlotId(callInfo.slotId)) {
655         TELEPHONY_LOGE("CellularCallService::CombineConference return, invalid slot id");
656         return CALL_ERR_INVALID_SLOT_ID;
657     }
658     if (srvccState_ == SrvccState::STARTED) {
659         return TELEPHONY_ERR_FAIL;
660     }
661     if (CallType::TYPE_IMS == callInfo.callType) {
662         auto imsControl = GetImsControl(callInfo.slotId);
663         if (imsControl == nullptr) {
664             TELEPHONY_LOGE("CellularCallService::CombineConference return, imsControl is nullptr");
665             return TELEPHONY_ERR_LOCAL_PTR_NULL;
666         }
667         return imsControl->CombineConference(callInfo.slotId);
668     } else if (CallType::TYPE_CS == callInfo.callType) {
669         auto csControl = GetCsControl(callInfo.slotId);
670         if (csControl == nullptr) {
671             TELEPHONY_LOGE("CellularCallService::CombineConference return, csControl is nullptr");
672             return TELEPHONY_ERR_LOCAL_PTR_NULL;
673         }
674         return csControl->CombineConference(callInfo.slotId);
675     }
676     TELEPHONY_LOGE("CellularCallService::CombineConference return, call type error.");
677     return TELEPHONY_ERR_ARGUMENT_INVALID;
678 }
679 
SeparateConference(const CellularCallInfo & callInfo)680 int32_t CellularCallService::SeparateConference(const CellularCallInfo &callInfo)
681 {
682     if (!IsValidSlotId(callInfo.slotId)) {
683         TELEPHONY_LOGE("CellularCallService::SeparateConference return, invalid slot id");
684         return CALL_ERR_INVALID_SLOT_ID;
685     }
686     if (CallType::TYPE_CS == callInfo.callType) {
687         auto csControl = GetCsControl(callInfo.slotId);
688         if (csControl == nullptr) {
689             TELEPHONY_LOGE("CellularCallService::SeparateConference return, csControl is nullptr");
690             return TELEPHONY_ERR_LOCAL_PTR_NULL;
691         }
692         return csControl->SeparateConference(callInfo.slotId, callInfo.phoneNum, callInfo.index);
693     }
694     TELEPHONY_LOGE("CellularCallService::SeparateConference return, call type error.");
695     return TELEPHONY_ERR_ARGUMENT_INVALID;
696 }
697 
InviteToConference(int32_t slotId,const std::vector<std::string> & numberList)698 int32_t CellularCallService::InviteToConference(int32_t slotId, const std::vector<std::string> &numberList)
699 {
700     auto control = GetImsControl(slotId);
701     if (control == nullptr) {
702         TELEPHONY_LOGE("CellularCallService::InviteToConference return, control is nullptr");
703         return TELEPHONY_ERR_LOCAL_PTR_NULL;
704     }
705     return control->InviteToConference(slotId, numberList);
706 }
707 
KickOutFromConference(const CellularCallInfo & callInfo)708 int32_t CellularCallService::KickOutFromConference(const CellularCallInfo &callInfo)
709 {
710     if (!IsValidSlotId(callInfo.slotId)) {
711         TELEPHONY_LOGE("CellularCallService::KickOutFromConference return, invalid slot id");
712         return CALL_ERR_INVALID_SLOT_ID;
713     }
714     if (CallType::TYPE_IMS == callInfo.callType) {
715         auto imsControl = GetImsControl(callInfo.slotId);
716         if (imsControl == nullptr) {
717             TELEPHONY_LOGE("CellularCallService::KickOutFromConference return, imsControl is nullptr");
718             return TELEPHONY_ERR_LOCAL_PTR_NULL;
719         }
720         return imsControl->KickOutFromConference(callInfo.slotId, callInfo.phoneNum, callInfo.index);
721     } else if (CallType::TYPE_CS == callInfo.callType) {
722         auto csControl = GetCsControl(callInfo.slotId);
723         if (csControl == nullptr) {
724             TELEPHONY_LOGE("CellularCallService::KickOutFromConference return, csControl is nullptr");
725             return TELEPHONY_ERR_LOCAL_PTR_NULL;
726         }
727         return csControl->HangUp(callInfo, CallSupplementType::TYPE_DEFAULT);
728     }
729     TELEPHONY_LOGE("CellularCallService::KickOutFromConference return, call type error.");
730     return TELEPHONY_ERR_ARGUMENT_INVALID;
731 }
732 
HangUpAllConnection()733 int32_t CellularCallService::HangUpAllConnection()
734 {
735     ModuleServiceUtils obtain;
736     std::vector<int32_t> slotVector = obtain.GetSlotInfo();
737     for (const auto &it : slotVector) {
738         if (GetCsControl(it)) {
739             GetCsControl(it)->HangUpAllConnection(it);
740         }
741         if (GetImsControl(it)) {
742 #ifdef BASE_POWER_IMPROVEMENT_FEATURE
743             if (GetImsControl(it)->isPendingEmcFlag()) {
744                 return TELEPHONY_SUCCESS;
745             }
746 #endif
747             GetImsControl(it)->HangUpAllConnection(it);
748         }
749     }
750     return TELEPHONY_SUCCESS;
751 }
752 
SetReadyToCall(int32_t slotId,int32_t callType,bool isReadyToCall)753 int32_t CellularCallService::SetReadyToCall(int32_t slotId, int32_t callType, bool isReadyToCall)
754 {
755     TELEPHONY_LOGI("slotId = %{public}d, callType = %{public}d, isReadyToCall = %{public}d",
756         slotId, callType, isReadyToCall);
757     if (!IsValidSlotId(slotId)) {
758         TELEPHONY_LOGE("CellularCallService::SetReadyToCall return, invalid slot id");
759         return CALL_ERR_INVALID_SLOT_ID;
760     }
761     if (GetCsControl(slotId) != nullptr) {
762         GetCsControl(slotId)->SetReadyToCall(slotId, isReadyToCall);
763     }
764     if (GetImsControl(slotId) != nullptr) {
765         GetImsControl(slotId)->SetReadyToCall(slotId, isReadyToCall);
766     }
767     if (GetSatelliteControl(slotId) != nullptr) {
768         GetSatelliteControl(slotId)->SetReadyToCall(slotId, isReadyToCall);
769     }
770     return TELEPHONY_SUCCESS;
771 }
772 
HangUpAllConnection(int32_t slotId)773 int32_t CellularCallService::HangUpAllConnection(int32_t slotId)
774 {
775     if (GetCsControl(slotId)) {
776         GetCsControl(slotId)->HangUpAllConnection(slotId);
777     }
778     if (GetImsControl(slotId)) {
779         GetImsControl(slotId)->HangUpAllConnection(slotId);
780     }
781     if (GetSatelliteControl(slotId)) {
782         GetSatelliteControl(slotId)->HangUpAllConnection(slotId);
783     }
784     return TELEPHONY_SUCCESS;
785 }
786 
SendUpdateCallMediaModeRequest(const CellularCallInfo & callInfo,ImsCallMode mode)787 int32_t CellularCallService::SendUpdateCallMediaModeRequest(const CellularCallInfo &callInfo, ImsCallMode mode)
788 {
789     auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
790     if (videoCallControl == nullptr) {
791         TELEPHONY_LOGE("videoCallControl is nullptr");
792         return TELEPHONY_ERR_LOCAL_PTR_NULL;
793     }
794     return videoCallControl->SendUpdateCallMediaModeRequest(callInfo, mode);
795 }
796 
SendUpdateCallMediaModeResponse(const CellularCallInfo & callInfo,ImsCallMode mode)797 int32_t CellularCallService::SendUpdateCallMediaModeResponse(const CellularCallInfo &callInfo, ImsCallMode mode)
798 {
799     auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
800     if (videoCallControl == nullptr) {
801         TELEPHONY_LOGE("videoCallControl is nullptr");
802         return TELEPHONY_ERR_LOCAL_PTR_NULL;
803     }
804     return videoCallControl->SendUpdateCallMediaModeResponse(callInfo, mode);
805 }
806 
CancelCallUpgrade(int32_t slotId,int32_t callIndex)807 int32_t CellularCallService::CancelCallUpgrade(int32_t slotId, int32_t callIndex)
808 {
809     auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
810     if (videoCallControl == nullptr) {
811         TELEPHONY_LOGE("videoCallControl is nullptr");
812         return TELEPHONY_ERR_LOCAL_PTR_NULL;
813     }
814     return videoCallControl->CancelCallUpgrade(slotId, callIndex);
815 }
816 
RequestCameraCapabilities(int32_t slotId,int32_t callIndex)817 int32_t CellularCallService::RequestCameraCapabilities(int32_t slotId, int32_t callIndex)
818 {
819     auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
820     if (videoCallControl == nullptr) {
821         TELEPHONY_LOGE("videoCallControl is nullptr");
822         return TELEPHONY_ERR_LOCAL_PTR_NULL;
823     }
824     return videoCallControl->RequestCameraCapabilities(slotId, callIndex);
825 }
826 
StartDtmf(char cDtmfCode,const CellularCallInfo & callInfo)827 int32_t CellularCallService::StartDtmf(char cDtmfCode, const CellularCallInfo &callInfo)
828 {
829     if (!IsValidSlotId(callInfo.slotId)) {
830         TELEPHONY_LOGE("CellularCallService::StartDtmf return, invalid slot id");
831         return CALL_ERR_INVALID_SLOT_ID;
832     }
833     if (srvccState_ == SrvccState::STARTED) {
834         return TELEPHONY_ERR_FAIL;
835     }
836     if (CallType::TYPE_IMS == callInfo.callType) {
837         auto imsControl = GetImsControl(callInfo.slotId);
838         if (imsControl == nullptr) {
839             TELEPHONY_LOGE("CellularCallService::StartDtmf return, imsControl is nullptr");
840             return TELEPHONY_ERR_LOCAL_PTR_NULL;
841         }
842         return imsControl->StartDtmf(imsControl->GetConnectionMap(), cDtmfCode, callInfo);
843     } else if (CallType::TYPE_CS == callInfo.callType) {
844         auto csControl = GetCsControl(callInfo.slotId);
845         if (csControl == nullptr) {
846             TELEPHONY_LOGE("CellularCallService::StartDtmf return, csControl is nullptr");
847             return TELEPHONY_ERR_LOCAL_PTR_NULL;
848         }
849         return csControl->StartDtmf(csControl->GetConnectionMap(), cDtmfCode, callInfo);
850     } else if (CallType::TYPE_SATELLITE == callInfo.callType) {
851         auto satelliteControl = GetSatelliteControl(callInfo.slotId);
852         if (satelliteControl == nullptr) {
853             TELEPHONY_LOGE("CellularCallService::StartDtmf return, satelliteControl is nullptr");
854             return TELEPHONY_ERR_LOCAL_PTR_NULL;
855         }
856         return satelliteControl->StartDtmf(satelliteControl->GetConnectionMap(), cDtmfCode, callInfo);
857     }
858     TELEPHONY_LOGE("CellularCallService::StartDtmf return, call type error.");
859     return TELEPHONY_ERR_ARGUMENT_INVALID;
860 }
861 
StopDtmf(const CellularCallInfo & callInfo)862 int32_t CellularCallService::StopDtmf(const CellularCallInfo &callInfo)
863 {
864     if (!IsValidSlotId(callInfo.slotId)) {
865         TELEPHONY_LOGE("CellularCallService::StopDtmf return, invalid slot id");
866         return CALL_ERR_INVALID_SLOT_ID;
867     }
868     if (srvccState_ == SrvccState::STARTED) {
869         return TELEPHONY_ERR_FAIL;
870     }
871     if (CallType::TYPE_IMS == callInfo.callType) {
872         auto imsControl = GetImsControl(callInfo.slotId);
873         if (imsControl == nullptr) {
874             TELEPHONY_LOGE("CellularCallService::StopDtmf return, imsControl is nullptr");
875             return TELEPHONY_ERR_LOCAL_PTR_NULL;
876         }
877         return imsControl->StopDtmf(imsControl->GetConnectionMap(), callInfo);
878     } else if (CallType::TYPE_CS == callInfo.callType) {
879         auto csControl = GetCsControl(callInfo.slotId);
880         if (csControl == nullptr) {
881             TELEPHONY_LOGE("CellularCallService::StopDtmf return, csControl is nullptr");
882             return TELEPHONY_ERR_LOCAL_PTR_NULL;
883         }
884         return csControl->StopDtmf(csControl->GetConnectionMap(), callInfo);
885     } else if (CallType::TYPE_SATELLITE == callInfo.callType) {
886         auto satelliteControl = GetSatelliteControl(callInfo.slotId);
887         if (satelliteControl == nullptr) {
888             TELEPHONY_LOGE("CellularCallService::StopDtmf return, satelliteControl is nullptr");
889             return TELEPHONY_ERR_LOCAL_PTR_NULL;
890         }
891         return satelliteControl->StopDtmf(satelliteControl->GetConnectionMap(), callInfo);
892     }
893     TELEPHONY_LOGE("CellularCallService::StopDtmf return, call type error.");
894     return TELEPHONY_ERR_ARGUMENT_INVALID;
895 }
896 
PostDialProceed(const CellularCallInfo & callInfo,const bool proceed)897 int32_t CellularCallService::PostDialProceed(const CellularCallInfo &callInfo, const bool proceed)
898 {
899     if (!IsValidSlotId(callInfo.slotId)) {
900         TELEPHONY_LOGE("CellularCallService::PostDialProceed return, invalid slot id");
901         return CALL_ERR_INVALID_SLOT_ID;
902     }
903     if (srvccState_ == SrvccState::STARTED) {
904         TELEPHONY_LOGE("CellularCallService::PostDialProceed srvccState_ is started");
905         return TELEPHONY_ERR_FAIL;
906     }
907     if (callInfo.callType == CallType::TYPE_IMS) {
908         auto imsControl = GetImsControl(callInfo.slotId);
909         if (imsControl == nullptr) {
910             TELEPHONY_LOGE("CellularCallService::PostDialProceed return, imsControl is nullptr");
911             return TELEPHONY_ERR_LOCAL_PTR_NULL;
912         }
913         return imsControl->PostDialProceed(callInfo, proceed);
914     } else if (callInfo.callType == CallType::TYPE_CS) {
915         auto csControl = GetCsControl(callInfo.slotId);
916         if (csControl == nullptr) {
917             TELEPHONY_LOGE("CellularCallService::PostDialProceed return, csControl is nullptr");
918             return TELEPHONY_ERR_LOCAL_PTR_NULL;
919         }
920         return csControl->PostDialProceed(callInfo, proceed);
921     } else if (CallType::TYPE_SATELLITE == callInfo.callType) {
922         auto satelliteControl = GetSatelliteControl(callInfo.slotId);
923         if (satelliteControl == nullptr) {
924             TELEPHONY_LOGE("CellularCallService::PostDialProceed return, satelliteControl is nullptr");
925             return TELEPHONY_ERR_LOCAL_PTR_NULL;
926         }
927         return satelliteControl->PostDialProceed(callInfo, proceed);
928     }
929     TELEPHONY_LOGE("CellularCallService::PostDialProceed return, call type error.");
930     return TELEPHONY_ERR_ARGUMENT_INVALID;
931 }
932 
SendDtmf(char cDtmfCode,const CellularCallInfo & callInfo)933 int32_t CellularCallService::SendDtmf(char cDtmfCode, const CellularCallInfo &callInfo)
934 {
935     if (!IsValidSlotId(callInfo.slotId)) {
936         TELEPHONY_LOGE("CellularCallService::SendDtmf return, invalid slot id");
937         return CALL_ERR_INVALID_SLOT_ID;
938     }
939     if (srvccState_ == SrvccState::STARTED) {
940         return TELEPHONY_ERR_FAIL;
941     }
942     if (CallType::TYPE_IMS == callInfo.callType) {
943         auto imsControl = GetImsControl(callInfo.slotId);
944         if (imsControl == nullptr) {
945             TELEPHONY_LOGE("CellularCallService::SendDtmf return, imsControl is nullptr");
946             return TELEPHONY_ERR_LOCAL_PTR_NULL;
947         }
948         return imsControl->SendDtmf(imsControl->GetConnectionMap(), cDtmfCode, callInfo);
949     } else if (CallType::TYPE_CS == callInfo.callType) {
950         auto csControl = GetCsControl(callInfo.slotId);
951         if (csControl == nullptr) {
952             TELEPHONY_LOGE("CellularCallService::SendDtmf return, csControl is nullptr");
953             return TELEPHONY_ERR_LOCAL_PTR_NULL;
954         }
955         return csControl->SendDtmf(csControl->GetConnectionMap(), cDtmfCode, callInfo);
956     } else if (CallType::TYPE_SATELLITE == callInfo.callType) {
957         auto satelliteControl = GetSatelliteControl(callInfo.slotId);
958         if (satelliteControl == nullptr) {
959             TELEPHONY_LOGE("CellularCallService::SendDtmf return, satelliteControl is nullptr");
960             return TELEPHONY_ERR_LOCAL_PTR_NULL;
961         }
962         return satelliteControl->SendDtmf(satelliteControl->GetConnectionMap(), cDtmfCode, callInfo);
963     }
964     TELEPHONY_LOGE("CellularCallService::SendDtmf return, call type error.");
965     return TELEPHONY_ERR_ARGUMENT_INVALID;
966 }
967 
StartRtt(int32_t slotId,const std::string & msg)968 int32_t CellularCallService::StartRtt(int32_t slotId, const std::string &msg)
969 {
970     auto control = GetImsControl(slotId);
971     if (control == nullptr) {
972         TELEPHONY_LOGE("CellularCallService::StartRtt return, control is nullptr");
973         return TELEPHONY_ERR_LOCAL_PTR_NULL;
974     }
975     return control->StartRtt(slotId, msg);
976 }
977 
StopRtt(int32_t slotId)978 int32_t CellularCallService::StopRtt(int32_t slotId)
979 {
980     auto control = GetImsControl(slotId);
981     if (control == nullptr) {
982         TELEPHONY_LOGE("CellularCallService::StopRtt return, control is nullptr");
983         return TELEPHONY_ERR_LOCAL_PTR_NULL;
984     }
985     return control->StopRtt(slotId);
986 }
987 
SetCallTransferInfo(int32_t slotId,const CallTransferInfo & cTInfo)988 int32_t CellularCallService::SetCallTransferInfo(int32_t slotId, const CallTransferInfo &cTInfo)
989 {
990     if (!IsValidSlotId(slotId)) {
991         TELEPHONY_LOGE("CellularCallService::SetCallTransferInfo return, invalid slot id");
992         return CALL_ERR_INVALID_SLOT_ID;
993     }
994     CellularCallSupplement cellularCallSupplement;
995     if (cTInfo.settingType == CallTransferSettingType::CALL_TRANSFER_DISABLE) {
996         DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallForwardingInfo(
997             slotId, false, cTInfo.transferNum);
998     } else if (cTInfo.settingType == CallTransferSettingType::CALL_TRANSFER_ENABLE) {
999         DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetCallForwardingInfo(
1000             slotId, true, cTInfo.transferNum);
1001     }
1002     return cellularCallSupplement.SetCallTransferInfo(slotId, cTInfo);
1003 }
1004 
CanSetCallTransferTime(int32_t slotId,bool & result)1005 int32_t CellularCallService::CanSetCallTransferTime(int32_t slotId, bool &result)
1006 {
1007     if (!IsValidSlotId(slotId)) {
1008         TELEPHONY_LOGE("invalid slot id");
1009         return CALL_ERR_INVALID_SLOT_ID;
1010     }
1011     CellularCallSupplement cellularCallSupplement;
1012     return cellularCallSupplement.CanSetCallTransferTime(slotId, result);
1013 }
1014 
GetCallTransferInfo(int32_t slotId,CallTransferType type)1015 int32_t CellularCallService::GetCallTransferInfo(int32_t slotId, CallTransferType type)
1016 {
1017     TELEPHONY_LOGD("CellularCallService::GetCallTransferInfo");
1018     if (!IsValidSlotId(slotId)) {
1019         TELEPHONY_LOGE("CellularCallService::GetCallTransferInfo return, invalid slot id");
1020         return CALL_ERR_INVALID_SLOT_ID;
1021     }
1022     CellularCallSupplement cellularCallSupplement;
1023     return cellularCallSupplement.GetCallTransferInfo(slotId, type);
1024 }
1025 
GetCsControl(int32_t slotId)1026 std::shared_ptr<CSControl> CellularCallService::GetCsControl(int32_t slotId)
1027 {
1028     std::lock_guard<std::mutex> lock(mutex_);
1029     if (!IsValidSlotId(slotId)) {
1030         TELEPHONY_LOGE("return nullptr, invalid slot id");
1031         return nullptr;
1032     }
1033     return csControlMap_[slotId];
1034 }
1035 
GetImsControl(int32_t slotId)1036 std::shared_ptr<IMSControl> CellularCallService::GetImsControl(int32_t slotId)
1037 {
1038     std::lock_guard<std::mutex> lock(mutex_);
1039     if (!IsValidSlotId(slotId)) {
1040         TELEPHONY_LOGE("return nullptr, invalid slot id");
1041         return nullptr;
1042     }
1043     return imsControlMap_[slotId];
1044 }
1045 
GetSatelliteControl(int32_t slotId)1046 std::shared_ptr<SatelliteControl> CellularCallService::GetSatelliteControl(int32_t slotId)
1047 {
1048     std::lock_guard<std::mutex> lock(mutex_);
1049     return satelliteControlMap_[slotId];
1050 }
1051 
SetCsControl(int32_t slotId,const std::shared_ptr<CSControl> & csControl)1052 void CellularCallService::SetCsControl(int32_t slotId, const std::shared_ptr<CSControl> &csControl)
1053 {
1054     std::lock_guard<std::mutex> lock(mutex_);
1055     if (!IsValidSlotId(slotId)) {
1056         TELEPHONY_LOGE("invalid slot id, return");
1057         return;
1058     }
1059     csControlMap_[slotId] = csControl;
1060 }
1061 
SetImsControl(int32_t slotId,const std::shared_ptr<IMSControl> & imsControl)1062 void CellularCallService::SetImsControl(int32_t slotId, const std::shared_ptr<IMSControl> &imsControl)
1063 {
1064     std::lock_guard<std::mutex> lock(mutex_);
1065     if (!IsValidSlotId(slotId)) {
1066         TELEPHONY_LOGE("invalid slot id, return");
1067         return;
1068     }
1069     imsControlMap_[slotId] = imsControl;
1070 }
1071 
SetSatelliteControl(int32_t slotId,const std::shared_ptr<SatelliteControl> & satelliteControl)1072 void CellularCallService::SetSatelliteControl(int32_t slotId, const std::shared_ptr<SatelliteControl> &satelliteControl)
1073 {
1074     std::lock_guard<std::mutex> lock(mutex_);
1075     if (!IsValidSlotId(slotId)) {
1076         TELEPHONY_LOGE("invalid slot id, return");
1077         return;
1078     }
1079     satelliteControlMap_[slotId] = satelliteControl;
1080 }
1081 
SetCallWaiting(int32_t slotId,bool activate)1082 int32_t CellularCallService::SetCallWaiting(int32_t slotId, bool activate)
1083 {
1084     if (!IsValidSlotId(slotId)) {
1085         TELEPHONY_LOGE("CellularCallService::SetCallWaiting return, invalid slot id");
1086         return CALL_ERR_INVALID_SLOT_ID;
1087     }
1088     CellularCallSupplement cellularCallSupplement;
1089     return cellularCallSupplement.SetCallWaiting(slotId, activate);
1090 }
1091 
GetCallWaiting(int32_t slotId)1092 int32_t CellularCallService::GetCallWaiting(int32_t slotId)
1093 {
1094     TELEPHONY_LOGD("CellularCallService::GetCallWaiting");
1095     if (!IsValidSlotId(slotId)) {
1096         TELEPHONY_LOGE("CellularCallService::GetCallWaiting return, invalid slot id");
1097         return CALL_ERR_INVALID_SLOT_ID;
1098     }
1099     CellularCallSupplement cellularCallSupplement;
1100     return cellularCallSupplement.GetCallWaiting(slotId);
1101 }
1102 
GetVideoCallWaiting(int32_t slotId,bool & enabled)1103 int32_t CellularCallService::GetVideoCallWaiting(int32_t slotId, bool &enabled)
1104 {
1105     TELEPHONY_LOGD("CellularCallService::GetVideoCallWaiting");
1106     if (!IsValidSlotId(slotId)) {
1107         TELEPHONY_LOGE("CellularCallService::GetVideoCallWaiting return, invalid slot id");
1108         return CALL_ERR_INVALID_SLOT_ID;
1109     }
1110     CellularCallConfig cellularCallConfig;
1111     return cellularCallConfig.GetVideoCallWaiting(slotId, enabled);
1112 }
1113 
SetCallRestriction(int32_t slotId,const CallRestrictionInfo & crInfo)1114 int32_t CellularCallService::SetCallRestriction(int32_t slotId, const CallRestrictionInfo &crInfo)
1115 {
1116     TELEPHONY_LOGD("CellularCallService::SetCallRestriction");
1117     if (!IsValidSlotId(slotId)) {
1118         TELEPHONY_LOGE("CellularCallService::SetCallRestriction return, invalid slot id");
1119         return CALL_ERR_INVALID_SLOT_ID;
1120     }
1121     CellularCallSupplement cellularCallSupplement;
1122     return cellularCallSupplement.SetCallRestriction(slotId, crInfo);
1123 }
1124 
GetCallRestriction(int32_t slotId,CallRestrictionType facType)1125 int32_t CellularCallService::GetCallRestriction(int32_t slotId, CallRestrictionType facType)
1126 {
1127     TELEPHONY_LOGD("CellularCallService::GetCallRestriction");
1128     if (!IsValidSlotId(slotId)) {
1129         TELEPHONY_LOGE("CellularCallService::GetCallRestriction return, invalid slot id");
1130         return CALL_ERR_INVALID_SLOT_ID;
1131     }
1132     CellularCallSupplement cellularCallSupplement;
1133     return cellularCallSupplement.GetCallRestriction(slotId, facType);
1134 }
1135 
SetCallRestrictionPassword(int32_t slotId,CallRestrictionType facType,const char * oldPassword,const char * newPassword)1136 int32_t CellularCallService::SetCallRestrictionPassword(
1137     int32_t slotId, CallRestrictionType facType, const char *oldPassword, const char *newPassword)
1138 {
1139     if (!IsValidSlotId(slotId)) {
1140         TELEPHONY_LOGE("invalid slot id");
1141         return CALL_ERR_INVALID_SLOT_ID;
1142     }
1143     CellularCallSupplement cellularCallSupplement;
1144     return cellularCallSupplement.SetBarringPassword(slotId, facType, oldPassword, newPassword);
1145 }
1146 
IsEmergencyPhoneNumber(int32_t slotId,const std::string & phoneNum,bool & enabled)1147 int32_t CellularCallService::IsEmergencyPhoneNumber(int32_t slotId, const std::string &phoneNum, bool &enabled)
1148 {
1149     if (!IsValidSlotId(slotId)) {
1150         TELEPHONY_LOGE("CellularCallService::IsEmergencyPhoneNumber return, invalid slot id");
1151         return CALL_ERR_INVALID_SLOT_ID;
1152     }
1153     EmergencyUtils emergencyUtils;
1154     return emergencyUtils.IsEmergencyCall(slotId, phoneNum, enabled);
1155 }
1156 
SetEmergencyCallList(int32_t slotId,std::vector<EmergencyCall> & eccVec)1157 int32_t CellularCallService::SetEmergencyCallList(int32_t slotId, std::vector<EmergencyCall> &eccVec)
1158 {
1159     TELEPHONY_LOGD("CellularCallService::SetEmergencyCallList start");
1160     if (!IsValidSlotId(slotId)) {
1161         TELEPHONY_LOGE("CellularCallService::SetMute return, invalid slot id");
1162         return CALL_ERR_INVALID_SLOT_ID;
1163     }
1164     CellularCallConfig config;
1165     return config.SetEmergencyCallList(slotId, eccVec);
1166 }
1167 
SetDomainPreferenceMode(int32_t slotId,int32_t mode)1168 int32_t CellularCallService::SetDomainPreferenceMode(int32_t slotId, int32_t mode)
1169 {
1170     if (!IsValidSlotId(slotId)) {
1171         TELEPHONY_LOGE("CellularCallService::SetDomainPreferenceMode return, invalid slot id");
1172         return CALL_ERR_INVALID_SLOT_ID;
1173     }
1174     CellularCallConfig config;
1175     return config.SetDomainPreferenceMode(slotId, mode);
1176 }
1177 
GetDomainPreferenceMode(int32_t slotId)1178 int32_t CellularCallService::GetDomainPreferenceMode(int32_t slotId)
1179 {
1180     if (!IsValidSlotId(slotId)) {
1181         TELEPHONY_LOGE("CellularCallService::GetDomainPreferenceMode return, invalid slot id");
1182         return CALL_ERR_INVALID_SLOT_ID;
1183     }
1184     CellularCallConfig config;
1185     return config.GetDomainPreferenceMode(slotId);
1186 }
1187 
GetCarrierVtConfig(int32_t slotId,bool & enabled)1188 int32_t CellularCallService::GetCarrierVtConfig(int32_t slotId, bool &enabled)
1189 {
1190     if (!IsValidSlotId(slotId)) {
1191         TELEPHONY_LOGE("CellularCallService::GetDomainPreferenceMode return, invalid slot id");
1192         return CALL_ERR_INVALID_SLOT_ID;
1193     }
1194     CellularCallConfig config;
1195     return config.GetCarrierVtConfig(slotId, enabled);
1196 }
1197 
SetImsSwitchStatus(int32_t slotId,bool active)1198 int32_t CellularCallService::SetImsSwitchStatus(int32_t slotId, bool active)
1199 {
1200     if (!IsValidSlotId(slotId)) {
1201         TELEPHONY_LOGE("CellularCallService::SetImsSwitchStatus return, invalid slot id");
1202         return CALL_ERR_INVALID_SLOT_ID;
1203     }
1204     CellularCallConfig config;
1205     return config.SetImsSwitchStatus(slotId, active);
1206 }
1207 
GetImsSwitchStatus(int32_t slotId,bool & enabled)1208 int32_t CellularCallService::GetImsSwitchStatus(int32_t slotId, bool &enabled)
1209 {
1210     if (!IsValidSlotId(slotId)) {
1211         TELEPHONY_LOGE("CellularCallService::GetImsSwitchStatus return, invalid slot id");
1212         return CALL_ERR_INVALID_SLOT_ID;
1213     }
1214     CellularCallConfig config;
1215     return config.GetImsSwitchStatus(slotId, enabled);
1216 }
1217 
SetVoNRState(int32_t slotId,int32_t state)1218 int32_t CellularCallService::SetVoNRState(int32_t slotId, int32_t state)
1219 {
1220     if (!IsValidSlotId(slotId)) {
1221         TELEPHONY_LOGE("CellularCallService::SetVoNRState return, invalid slot id");
1222         return CALL_ERR_INVALID_SLOT_ID;
1223     }
1224     CellularCallConfig config;
1225     return config.SetVoNRSwitchStatus(slotId, state);
1226 }
1227 
GetVoNRState(int32_t slotId,int32_t & state)1228 int32_t CellularCallService::GetVoNRState(int32_t slotId, int32_t &state)
1229 {
1230     if (!IsValidSlotId(slotId)) {
1231         TELEPHONY_LOGE("CellularCallService::GetVoNRState return, invalid slot id");
1232         return CALL_ERR_INVALID_SLOT_ID;
1233     }
1234     CellularCallConfig config;
1235     return config.GetVoNRSwitchStatus(slotId, state);
1236 }
1237 
SetImsConfig(int32_t slotId,ImsConfigItem item,const std::string & value)1238 int32_t CellularCallService::SetImsConfig(int32_t slotId, ImsConfigItem item, const std::string &value)
1239 {
1240     if (!IsValidSlotId(slotId)) {
1241         TELEPHONY_LOGE("CellularCallService::SetImsConfig return, invalid slot id");
1242         return CALL_ERR_INVALID_SLOT_ID;
1243     }
1244     CellularCallConfig config;
1245     return config.SetImsConfig(item, value);
1246 }
1247 
SetImsConfig(int32_t slotId,ImsConfigItem item,int32_t value)1248 int32_t CellularCallService::SetImsConfig(int32_t slotId, ImsConfigItem item, int32_t value)
1249 {
1250     if (!IsValidSlotId(slotId)) {
1251         TELEPHONY_LOGE("CellularCallService::SetImsConfig return, invalid slot id");
1252         return CALL_ERR_INVALID_SLOT_ID;
1253     }
1254     CellularCallConfig config;
1255     return config.SetImsConfig(item, value);
1256 }
1257 
GetImsConfig(int32_t slotId,ImsConfigItem item)1258 int32_t CellularCallService::GetImsConfig(int32_t slotId, ImsConfigItem item)
1259 {
1260     if (!IsValidSlotId(slotId)) {
1261         TELEPHONY_LOGE("CellularCallService::GetImsConfig return, invalid slot id");
1262         return CALL_ERR_INVALID_SLOT_ID;
1263     }
1264     CellularCallConfig config;
1265     return config.GetImsConfig(item);
1266 }
1267 
SetImsFeatureValue(int32_t slotId,FeatureType type,int32_t value)1268 int32_t CellularCallService::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
1269 {
1270     if (!IsValidSlotId(slotId)) {
1271         TELEPHONY_LOGE("CellularCallService::SetImsFeatureValue return, invalid slot id");
1272         return CALL_ERR_INVALID_SLOT_ID;
1273     }
1274     CellularCallConfig config;
1275     return config.SetImsFeatureValue(type, value);
1276 }
1277 
GetImsFeatureValue(int32_t slotId,FeatureType type)1278 int32_t CellularCallService::GetImsFeatureValue(int32_t slotId, FeatureType type)
1279 {
1280     if (!IsValidSlotId(slotId)) {
1281         TELEPHONY_LOGE("CellularCallService::GetImsFeatureValue return, invalid slot id");
1282         return CALL_ERR_INVALID_SLOT_ID;
1283     }
1284     CellularCallConfig config;
1285     return config.GetImsFeatureValue(type);
1286 }
1287 
IsValidSlotId(int32_t slotId) const1288 bool CellularCallService::IsValidSlotId(int32_t slotId) const
1289 {
1290     const int32_t slotSingle = 1;
1291     const int32_t slotDouble = 2;
1292     if (SIM_SLOT_COUNT == slotSingle) {
1293         return slotId == DEFAULT_SIM_SLOT_ID;
1294     } else if (SIM_SLOT_COUNT == slotDouble) {
1295         return slotId == SIM_SLOT_0 || slotId == SIM_SLOT_1;
1296     }
1297     return false;
1298 }
1299 
IsNeedIms(int32_t slotId) const1300 bool CellularCallService::IsNeedIms(int32_t slotId) const
1301 {
1302     ModuleServiceUtils moduleUtils;
1303     CellularCallConfig config;
1304     bool imsRegState = moduleUtils.GetImsRegistrationState(slotId);
1305     bool imsServiceConnected = moduleUtils.NeedCallImsService();
1306     int32_t preferenceMode = config.GetPreferenceMode(slotId);
1307     bool imsSwitchStatus = false;
1308     config.GetImsSwitchStatus(slotId, imsSwitchStatus);
1309     TELEPHONY_LOGI("IsNeedIms state:%{public}d, mode:%{public}d, status:%{public}d, connected:%{public}d", imsRegState,
1310         preferenceMode, imsSwitchStatus, imsServiceConnected);
1311     if (imsRegState && preferenceMode != DomainPreferenceMode::CS_VOICE_ONLY && imsSwitchStatus &&
1312         imsServiceConnected) {
1313         return true;
1314     }
1315     return false;
1316 }
1317 
GetHandler(int32_t slotId)1318 std::shared_ptr<CellularCallHandler> CellularCallService::GetHandler(int32_t slotId)
1319 {
1320     std::unique_lock<std::mutex> lock(handlerMapMutex_);
1321     return handlerMap_[slotId];
1322 }
1323 
ControlCamera(int32_t slotId,int32_t index,const std::string & cameraId)1324 int32_t CellularCallService::ControlCamera(int32_t slotId, int32_t index, const std::string &cameraId)
1325 {
1326     auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1327     if (videoCallControl == nullptr) {
1328         TELEPHONY_LOGE("videoCallControl is nullptr");
1329         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1330     }
1331     return videoCallControl->ControlCamera(slotId, index, cameraId);
1332 }
1333 
SetPreviewWindow(int32_t slotId,int32_t index,const std::string & surfaceId,sptr<Surface> surface)1334 int32_t CellularCallService::SetPreviewWindow(
1335     int32_t slotId, int32_t index, const std::string &surfaceId, sptr<Surface> surface)
1336 {
1337     auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1338     if (videoCallControl == nullptr) {
1339         TELEPHONY_LOGE("videoCallControl is nullptr");
1340         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1341     }
1342     return videoCallControl->SetPreviewWindow(slotId, index, surfaceId, surface);
1343 }
1344 
SetDisplayWindow(int32_t slotId,int32_t index,const std::string & surfaceId,sptr<Surface> surface)1345 int32_t CellularCallService::SetDisplayWindow(
1346     int32_t slotId, int32_t index, const std::string &surfaceId, sptr<Surface> surface)
1347 {
1348     auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1349     if (videoCallControl == nullptr) {
1350         TELEPHONY_LOGE("videoCallControl is nullptr");
1351         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1352     }
1353     return videoCallControl->SetDisplayWindow(slotId, index, surfaceId, surface);
1354 }
1355 
SetCameraZoom(float zoomRatio)1356 int32_t CellularCallService::SetCameraZoom(float zoomRatio)
1357 {
1358     auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1359     if (videoCallControl == nullptr) {
1360         TELEPHONY_LOGE("videoCallControl is nullptr");
1361         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1362     }
1363     return videoCallControl->SetCameraZoom(zoomRatio);
1364 }
1365 
SetPausePicture(int32_t slotId,int32_t index,const std::string & path)1366 int32_t CellularCallService::SetPausePicture(int32_t slotId, int32_t index, const std::string &path)
1367 {
1368     auto videoCallControl = DelayedSingleton<ImsVideoCallControl>::GetInstance();
1369     if (videoCallControl == nullptr) {
1370         TELEPHONY_LOGE("videoCallControl is nullptr");
1371         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1372     }
1373     return videoCallControl->SetPausePicture(slotId, index, path);
1374 }
1375 
SetDeviceDirection(int32_t slotId,int32_t callIndex,int32_t rotation)1376 int32_t CellularCallService::SetDeviceDirection(int32_t slotId, int32_t callIndex, int32_t rotation)
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->SetDeviceDirection(slotId, callIndex, rotation);
1384 }
1385 
SetMute(int32_t slotId,int32_t mute)1386 int32_t CellularCallService::SetMute(int32_t slotId, int32_t mute)
1387 {
1388     if (!IsValidSlotId(slotId)) {
1389         TELEPHONY_LOGE("CellularCallService::SetMute return, invalid slot id");
1390         return CALL_ERR_INVALID_SLOT_ID;
1391     }
1392     CellularCallConfig config;
1393     return config.SetMute(slotId, mute);
1394 }
1395 
GetMute(int32_t slotId)1396 int32_t CellularCallService::GetMute(int32_t slotId)
1397 {
1398     if (!IsValidSlotId(slotId)) {
1399         TELEPHONY_LOGE("CellularCallService::GetMute return, invalid slot id");
1400         return CALL_ERR_INVALID_SLOT_ID;
1401     }
1402     CellularCallConfig config;
1403     return config.GetMute(slotId);
1404 }
1405 
CloseUnFinishedUssd(int32_t slotId)1406 int32_t CellularCallService::CloseUnFinishedUssd(int32_t slotId)
1407 {
1408     if (!IsValidSlotId(slotId)) {
1409         TELEPHONY_LOGE("CellularCallService::CloseUnFinishedUssd return, invalid slot id");
1410         return CALL_ERR_INVALID_SLOT_ID;
1411     }
1412     CellularCallSupplement cellularCallSupplement;
1413     return cellularCallSupplement.CloseUnFinishedUssd(slotId);
1414 }
1415 
SetControl(const CellularCallInfo & info)1416 int32_t CellularCallService::SetControl(const CellularCallInfo &info)
1417 {
1418     if (info.callType == CallType::TYPE_CS) {
1419         auto csControl = GetCsControl(info.slotId);
1420         if (csControl == nullptr) {
1421             TELEPHONY_LOGI("GetCsControl csControl is nullptr");
1422             csControl = std::make_shared<CSControl>();
1423             if (csControl == nullptr) {
1424                 TELEPHONY_LOGE("csControl is nullptr");
1425                 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1426             }
1427             SetCsControl(info.slotId, csControl);
1428         }
1429     }
1430     if (info.callType == CallType::TYPE_IMS) {
1431         auto imsControl = GetImsControl(info.slotId);
1432         if (imsControl == nullptr) {
1433             TELEPHONY_LOGI("GetImsControl imsControl is nullptr");
1434             imsControl = std::make_shared<IMSControl>();
1435             if (imsControl == nullptr) {
1436                 TELEPHONY_LOGE("imsControl is nullptr");
1437                 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1438             }
1439             SetImsControl(info.slotId, imsControl);
1440         }
1441     }
1442     return TELEPHONY_SUCCESS;
1443 }
1444 
ClearAllCalls(const std::vector<CellularCallInfo> & infos)1445 int32_t CellularCallService::ClearAllCalls(const std::vector<CellularCallInfo> &infos)
1446 {
1447     if (infos.empty()) {
1448         TELEPHONY_LOGE("CellularCallService::ClearAllCalls infos is empty");
1449         return TELEPHONY_ERR_ARGUMENT_INVALID;
1450     }
1451     for (auto &info : infos) {
1452         if (SetControl(info) != TELEPHONY_SUCCESS) {
1453             return TELEPHONY_ERR_LOCAL_PTR_NULL;
1454         }
1455     }
1456     HangUpWithCellularCallRestart(infos);
1457     return TELEPHONY_SUCCESS;
1458 }
1459 
SetSrvccState(int32_t srvccState)1460 void CellularCallService::SetSrvccState(int32_t srvccState)
1461 {
1462     srvccState_ = srvccState;
1463 }
1464 
GetSrvccState()1465 int32_t CellularCallService::GetSrvccState()
1466 {
1467     return srvccState_;
1468 }
1469 
UseImsForEmergency(const CellularCallInfo & callInfo,bool isEcc)1470 bool CellularCallService::UseImsForEmergency(const CellularCallInfo &callInfo, bool isEcc)
1471 {
1472     ModuleServiceUtils moduleUtils;
1473     CellularCallConfig config;
1474     if (isEcc && moduleUtils.NeedCallImsService() && config.GetImsPreferForEmergencyConfig(callInfo.slotId)) {
1475         return true;
1476     }
1477     return false;
1478 }
1479 
HandleCallManagerException()1480 void CellularCallService::HandleCallManagerException()
1481 {
1482     ModuleServiceUtils obtain;
1483     std::vector<int32_t> slotVector = obtain.GetSlotInfo();
1484     for (const auto &it : slotVector) {
1485         auto csControl = GetCsControl(it);
1486         if (csControl != nullptr) {
1487             csControl->HangUpAllConnection(it);
1488         }
1489         auto imsControl = GetImsControl(it);
1490         if (imsControl != nullptr) {
1491             imsControl->HangUpAllConnection(it);
1492         }
1493     }
1494 }
1495 
HangUpWithCellularCallRestart(const std::vector<CellularCallInfo> & infos)1496 void CellularCallService::HangUpWithCellularCallRestart(const std::vector<CellularCallInfo> &infos)
1497 {
1498     ModuleServiceUtils obtain;
1499     std::vector<int32_t> slotVector = obtain.GetSlotInfo();
1500     for (const auto &it : slotVector) {
1501         auto csControl = GetCsControl(it);
1502         if (csControl != nullptr) {
1503             csControl->ReportHangUp(infos, it);
1504             csControl->HangUpAllConnection(it);
1505         }
1506         auto imsControl = GetImsControl(it);
1507         if (imsControl != nullptr) {
1508             imsControl->ReportHangUp(infos, it);
1509             imsControl->RestoreConnection(infos, it);
1510             imsControl->HangUpAllConnection(it);
1511             imsControl->ReleaseAllConnection();
1512         }
1513     }
1514 }
1515 
HandleCellularControlException(const CellularCallInfo & callInfo)1516 void CellularCallService::HandleCellularControlException(const CellularCallInfo &callInfo)
1517 {
1518     TELEPHONY_LOGI("HandleCellularControlException entry");
1519     CallsReportInfo callsReportInfo;
1520     CallReportInfo reportInfo = EncapsulationCallReportInfo(callInfo);
1521     callsReportInfo.callVec.push_back(reportInfo);
1522     if (DelayedSingleton<CellularCallRegister>::GetInstance() == nullptr) {
1523         TELEPHONY_LOGE("HandleCellularControlException return, GetInstance() is nullptr.");
1524         return;
1525     }
1526     callsReportInfo.slotId = callInfo.slotId;
1527     DelayedSingleton<CellularCallRegister>::GetInstance()->ReportCallsInfo(callsReportInfo);
1528 }
1529 
EncapsulationCallReportInfo(const CellularCallInfo & callInfo)1530 CallReportInfo CellularCallService::EncapsulationCallReportInfo(const CellularCallInfo &callInfo)
1531 {
1532     TELEPHONY_LOGD("EncapsulationCallReportInfo entry");
1533     CallReportInfo callReportInfo;
1534     if (memset_s(&callReportInfo, sizeof(callReportInfo), 0, sizeof(callReportInfo)) != EOK) {
1535         TELEPHONY_LOGE("EncapsulationCallReportInfo return, memset_s fail.");
1536         return callReportInfo;
1537     }
1538 
1539     size_t cpyLen = strlen(callInfo.phoneNum) + 1;
1540     if (cpyLen > static_cast<size_t>(kMaxNumberLen + 1)) {
1541         TELEPHONY_LOGE("EncapsulationCallReportInfo return, strcpy_s fail.");
1542         return callReportInfo;
1543     }
1544     if (strcpy_s(callReportInfo.accountNum, cpyLen, callInfo.phoneNum) != EOK) {
1545         TELEPHONY_LOGE("EncapsulationCallReportInfo return, strcpy_s fail.");
1546         return callReportInfo;
1547     }
1548     callReportInfo.index = callInfo.index;
1549     callReportInfo.accountId = callInfo.slotId;
1550     callReportInfo.state = TelCallState::CALL_STATUS_DISCONNECTED;
1551     callReportInfo.callType = callInfo.callType;
1552     return callReportInfo;
1553 }
1554 
SystemAbilityStatusChangeListener(std::shared_ptr<CellularCallHandler> & cellularCallHandler)1555 CellularCallService::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener(
1556     std::shared_ptr<CellularCallHandler> &cellularCallHandler)
1557     : cellularCallHandler_(cellularCallHandler)
1558 {}
1559 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1560 void CellularCallService::SystemAbilityStatusChangeListener::OnAddSystemAbility(
1561     int32_t systemAbilityId, const std::string &deviceId)
1562 {
1563     if (systemAbilityId != COMMON_EVENT_SERVICE_ID && systemAbilityId != TELEPHONY_SATELLITE_SYS_ABILITY_ID) {
1564         TELEPHONY_LOGE("systemAbilityId is not COMMON_EVENT_SERVICE_ID or TELEPHONY_SATELLITE_SYS_ABILITY_ID");
1565         return;
1566     }
1567     if (cellularCallHandler_ == nullptr) {
1568         TELEPHONY_LOGE("COMMON_EVENT_SERVICE_ID cellularCallHandler_ is nullptr");
1569         return;
1570     }
1571     if (systemAbilityId == COMMON_EVENT_SERVICE_ID) {
1572         bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(cellularCallHandler_);
1573         TELEPHONY_LOGI("subscribeResult = %{public}d", subscribeResult);
1574     } else if (systemAbilityId == TELEPHONY_SATELLITE_SYS_ABILITY_ID) {
1575         DelayedSingleton<SatelliteCallClient>::GetInstance()->Init();
1576         cellularCallHandler_->RegisterSatelliteCallCallbackHandler();
1577     }
1578 }
1579 
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1580 void CellularCallService::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
1581     int32_t systemAbilityId, const std::string &deviceId)
1582 {
1583     switch (systemAbilityId) {
1584         case TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID: {
1585             auto cellularCallService = DelayedSingleton<CellularCallService>::GetInstance();
1586             if (cellularCallService == nullptr) {
1587                 TELEPHONY_LOGE("cellularCallService is nullptr");
1588                 return;
1589             }
1590             cellularCallService->HandleCallManagerException();
1591             count_++;
1592             CellularCallHiSysEvent::WriteFoundationRestartFaultEvent(count_);
1593             break;
1594         }
1595         case COMMON_EVENT_SERVICE_ID: {
1596             if (cellularCallHandler_ == nullptr) {
1597                 TELEPHONY_LOGE("cellularCallHandler_ is nullptr");
1598                 return;
1599             }
1600             bool unSubscribeResult = EventFwk::CommonEventManager::UnSubscribeCommonEvent(cellularCallHandler_);
1601             TELEPHONY_LOGI("unSubscribeResult = %{public}d", unSubscribeResult);
1602             break;
1603         }
1604         case TELEPHONY_SATELLITE_SYS_ABILITY_ID: {
1605             DelayedSingleton<SatelliteCallClient>::GetInstance()->UnInit();
1606             break;
1607         }
1608         default:
1609             TELEPHONY_LOGE("systemAbilityId is invalid");
1610             break;
1611     }
1612 }
1613 
1614 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
StartCallManagerService()1615 void CellularCallService::StartCallManagerService()
1616 {
1617     sptr<ISystemAbilityManager> managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1618     if (managerPtr == nullptr) {
1619         TELEPHONY_LOGE("GetSystemAbilityManager failed!");
1620         return;
1621     }
1622 
1623     sptr<IRemoteObject> iRemoteObjectPtr = managerPtr->GetSystemAbility(TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID);
1624     if (iRemoteObjectPtr == nullptr) {
1625         TELEPHONY_LOGE("GetSystemAbility failed!");
1626     }
1627 }
1628 #endif
1629 
setRadioOnFlag(bool flag,int32_t slotId)1630 void CellularCallService::setRadioOnFlag(bool flag, int32_t slotId)
1631 {
1632     isRadioOn_[slotId] = flag;
1633 }
1634 
isRadioOnFlag(int32_t slotId)1635 bool CellularCallService::isRadioOnFlag(int32_t slotId)
1636 {
1637     return isRadioOn_[slotId];
1638 }
1639 
SendUssdResponse(int32_t slotId,const std::string & content)1640 int32_t CellularCallService::SendUssdResponse(int32_t slotId, const std::string &content)
1641 {
1642     if (!IsValidSlotId(slotId)) {
1643         TELEPHONY_LOGE("CellularCallService::SendUssdResponse return, invalid slot id");
1644         return CALL_ERR_INVALID_SLOT_ID;
1645     }
1646     CellularCallSupplement supplement;
1647     return supplement.SendUssd(slotId, content);
1648 }
1649 } // namespace Telephony
1650 } // namespace OHOS
1651