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