• 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_handler.h"
17 
18 #include "cellular_call_config.h"
19 #include "cellular_call_hisysevent.h"
20 #include "cellular_call_service.h"
21 #include "hitrace_meter.h"
22 #include "hril_call_parcel.h"
23 #include "hril_types.h"
24 #include "ims_call_client.h"
25 #include "operator_config_types.h"
26 #include "radio_event.h"
27 #include "resource_utils.h"
28 #include "securec.h"
29 
30 namespace OHOS {
31 namespace Telephony {
32 const uint32_t GET_CS_CALL_DATA_ID = 10001;
33 const uint32_t GET_IMS_CALL_DATA_ID = 10002;
34 const uint32_t OPERATOR_CONFIG_CHANGED_ID = 10004;
35 const int64_t DELAY_TIME = 100;
36 const int32_t MAX_REQUEST_COUNT = 50;
37 // message was null, mean report the default message to user which have been define at CellularCallSupplement
38 const std::string DEFAULT_NULL_MESSAGE = "";
39 
CellularCallHandler(const std::shared_ptr<AppExecFwk::EventRunner> & runner,const EventFwk::CommonEventSubscribeInfo & subscriberInfo)40 CellularCallHandler::CellularCallHandler(
41     const std::shared_ptr<AppExecFwk::EventRunner> &runner, const EventFwk::CommonEventSubscribeInfo &subscriberInfo)
42     : AppExecFwk::EventHandler(runner), CommonEventSubscriber(subscriberInfo)
43 {
44     InitBasicFuncMap();
45     InitConfigFuncMap();
46     InitSupplementFuncMap();
47     InitActiveReportFuncMap();
48 }
49 
InitBasicFuncMap()50 void CellularCallHandler::InitBasicFuncMap()
51 {
52     requestFuncMap_[RadioEvent::RADIO_DIAL] = &CellularCallHandler::DialResponse;
53     requestFuncMap_[RadioEvent::RADIO_HANGUP_CONNECT] = &CellularCallHandler::CommonResultResponse;
54     requestFuncMap_[RadioEvent::RADIO_REJECT_CALL] = &CellularCallHandler::CommonResultResponse;
55     requestFuncMap_[RadioEvent::RADIO_ACCEPT_CALL] = &CellularCallHandler::CommonResultResponse;
56     requestFuncMap_[RadioEvent::RADIO_HOLD_CALL] = &CellularCallHandler::CommonResultResponse;
57     requestFuncMap_[RadioEvent::RADIO_ACTIVE_CALL] = &CellularCallHandler::CommonResultResponse;
58     requestFuncMap_[RadioEvent::RADIO_SWAP_CALL] = &CellularCallHandler::CommonResultResponse;
59     requestFuncMap_[RadioEvent::RADIO_COMBINE_CALL] = &CellularCallHandler::CommonResultResponse;
60     requestFuncMap_[RadioEvent::RADIO_JOIN_CALL] = &CellularCallHandler::CommonResultResponse;
61     requestFuncMap_[RadioEvent::RADIO_SPLIT_CALL] = &CellularCallHandler::CommonResultResponse;
62     requestFuncMap_[RadioEvent::RADIO_CALL_SUPPLEMENT] = &CellularCallHandler::CommonResultResponse;
63     requestFuncMap_[RadioEvent::RADIO_SEND_DTMF] = &CellularCallHandler::SendDtmfResponse;
64     requestFuncMap_[RadioEvent::RADIO_START_DTMF] = &CellularCallHandler::StartDtmfResponse;
65     requestFuncMap_[RadioEvent::RADIO_STOP_DTMF] = &CellularCallHandler::StopDtmfResponse;
66     requestFuncMap_[RadioEvent::RADIO_CURRENT_CALLS] = &CellularCallHandler::GetCsCallsDataResponse;
67     requestFuncMap_[RadioEvent::RADIO_GET_CALL_FAIL_REASON] = &CellularCallHandler::GetCallFailReasonResponse;
68 
69     requestFuncMap_[GET_CS_CALL_DATA_ID] = &CellularCallHandler::GetCsCallsDataRequest;
70     requestFuncMap_[GET_IMS_CALL_DATA_ID] = &CellularCallHandler::GetImsCallsDataRequest;
71     requestFuncMap_[REGISTER_HANDLER_ID] = &CellularCallHandler::RegisterHandler;
72     requestFuncMap_[MMIHandlerId::EVENT_MMI_Id] = &CellularCallHandler::GetMMIResponse;
73     requestFuncMap_[DtmfHandlerId::EVENT_EXECUTE_POST_DIAL] = &CellularCallHandler::ExecutePostDial;
74 
75     requestFuncMap_[RadioEvent::RADIO_IMS_GET_CALL_DATA] = &CellularCallHandler::GetImsCallsDataResponse;
76 }
77 
InitConfigFuncMap()78 void CellularCallHandler::InitConfigFuncMap()
79 {
80     requestFuncMap_[RadioEvent::RADIO_SET_CMUT] = &CellularCallHandler::SetMuteResponse;
81     requestFuncMap_[RadioEvent::RADIO_GET_CMUT] = &CellularCallHandler::GetMuteResponse;
82     requestFuncMap_[RadioEvent::RADIO_SET_CALL_PREFERENCE_MODE] = &CellularCallHandler::SetDomainPreferenceModeResponse;
83     requestFuncMap_[RadioEvent::RADIO_GET_CALL_PREFERENCE_MODE] = &CellularCallHandler::GetDomainPreferenceModeResponse;
84     requestFuncMap_[RadioEvent::RADIO_SET_IMS_SWITCH_STATUS] = &CellularCallHandler::SetImsSwitchStatusResponse;
85     requestFuncMap_[RadioEvent::RADIO_GET_IMS_SWITCH_STATUS] = &CellularCallHandler::GetImsSwitchStatusResponse;
86     requestFuncMap_[RadioEvent::RADIO_SET_VONR_SWITCH_STATUS] = &CellularCallHandler::SetVoNRSwitchStatusResponse;
87     requestFuncMap_[RadioEvent::RADIO_SET_EMERGENCY_CALL_LIST] = &CellularCallHandler::SetEmergencyCallListResponse;
88     requestFuncMap_[RadioEvent::RADIO_GET_EMERGENCY_CALL_LIST] = &CellularCallHandler::GetEmergencyCallListResponse;
89     requestFuncMap_[OPERATOR_CONFIG_CHANGED_ID] = &CellularCallHandler::HandleOperatorConfigChanged;
90 }
91 
InitSupplementFuncMap()92 void CellularCallHandler::InitSupplementFuncMap()
93 {
94     requestFuncMap_[RadioEvent::RADIO_GET_CALL_WAIT] = &CellularCallHandler::GetCallWaitingResponse;
95     requestFuncMap_[RadioEvent::RADIO_SET_CALL_WAIT] = &CellularCallHandler::SetCallWaitingResponse;
96     requestFuncMap_[RadioEvent::RADIO_GET_CALL_FORWARD] = &CellularCallHandler::GetCallTransferResponse;
97     requestFuncMap_[RadioEvent::RADIO_SET_CALL_FORWARD] = &CellularCallHandler::SetCallTransferInfoResponse;
98     requestFuncMap_[RadioEvent::RADIO_GET_CALL_CLIP] = &CellularCallHandler::GetClipResponse;
99     requestFuncMap_[RadioEvent::RADIO_SET_CALL_CLIP] = &CellularCallHandler::SetClipResponse;
100     requestFuncMap_[RadioEvent::RADIO_GET_CALL_CLIR] = &CellularCallHandler::GetClirResponse;
101     requestFuncMap_[RadioEvent::RADIO_SET_CALL_CLIR] = &CellularCallHandler::SetClirResponse;
102     requestFuncMap_[RadioEvent::RADIO_IMS_GET_COLR] = &CellularCallHandler::GetColrResponse;
103     requestFuncMap_[RadioEvent::RADIO_IMS_SET_COLR] = &CellularCallHandler::SetColrResponse;
104     requestFuncMap_[RadioEvent::RADIO_IMS_GET_COLP] = &CellularCallHandler::GetColpResponse;
105     requestFuncMap_[RadioEvent::RADIO_IMS_SET_COLP] = &CellularCallHandler::SetColpResponse;
106     requestFuncMap_[RadioEvent::RADIO_GET_CALL_RESTRICTION] = &CellularCallHandler::GetCallRestrictionResponse;
107     requestFuncMap_[RadioEvent::RADIO_SET_CALL_RESTRICTION] = &CellularCallHandler::SetCallRestrictionResponse;
108     requestFuncMap_[RadioEvent::RADIO_SET_CALL_RESTRICTION_PWD] = &CellularCallHandler::SetBarringPasswordResponse;
109     requestFuncMap_[RadioEvent::RADIO_SET_USSD] = &CellularCallHandler::SendUssdResponse;
110     requestFuncMap_[MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID] = &CellularCallHandler::SendUnlockPinPukResponse;
111     requestFuncMap_[RadioEvent::RADIO_CLOSE_UNFINISHED_USSD] = &CellularCallHandler::CloseUnFinishedUssdResponse;
112 }
113 
InitActiveReportFuncMap()114 void CellularCallHandler::InitActiveReportFuncMap()
115 {
116     requestFuncMap_[RadioEvent::RADIO_CALL_STATUS_INFO] = &CellularCallHandler::CsCallStatusInfoReport;
117     requestFuncMap_[RadioEvent::RADIO_IMS_CALL_STATUS_INFO] = &CellularCallHandler::ImsCallStatusInfoReport;
118     requestFuncMap_[RadioEvent::RADIO_AVAIL] = &CellularCallHandler::GetCsCallData;
119     requestFuncMap_[RadioEvent::RADIO_NOT_AVAIL] = &CellularCallHandler::GetCsCallData;
120     requestFuncMap_[RadioEvent::RADIO_CALL_USSD_NOTICE] = &CellularCallHandler::UssdNotifyResponse;
121     requestFuncMap_[RadioEvent::RADIO_CALL_RINGBACK_VOICE] = &CellularCallHandler::CallRingBackVoiceResponse;
122     requestFuncMap_[RadioEvent::RADIO_CALL_SRVCC_STATUS] = &CellularCallHandler::UpdateSrvccStateReport;
123     requestFuncMap_[RadioEvent::RADIO_CALL_SS_NOTICE] = &CellularCallHandler::SsNotifyResponse;
124     requestFuncMap_[RadioEvent::RADIO_CALL_EMERGENCY_NUMBER_REPORT] = &CellularCallHandler::ReportEccChanged;
125     requestFuncMap_[RadioEvent::RADIO_SIM_STATE_CHANGE] = &CellularCallHandler::SimStateChangeReport;
126     requestFuncMap_[RadioEvent::RADIO_SIM_RECORDS_LOADED] = &CellularCallHandler::SimRecordsLoadedReport;
127     requestFuncMap_[RadioEvent::RADIO_CALL_RSRVCC_STATUS] = &CellularCallHandler::UpdateRsrvccStateReport;
128 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
129     requestFuncMap_[RadioEvent::RADIO_GET_STATUS] = &CellularCallHandler::GetRadioStateProcess;
130     requestFuncMap_[RadioEvent::RADIO_STATE_CHANGED] = &CellularCallHandler::RadioStateChangeProcess;
131 #endif
132 }
133 
RegisterImsCallCallbackHandler()134 void CellularCallHandler::RegisterImsCallCallbackHandler()
135 {
136     // Register IMS
137     std::shared_ptr<ImsCallClient> imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
138     if (imsCallClient != nullptr) {
139         imsCallClient->RegisterImsCallCallbackHandler(slotId_, shared_from_this());
140     }
141 }
142 
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)143 void CellularCallHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
144 {
145     if (event == nullptr) {
146         TELEPHONY_LOGE("[slot%{public}d] event is null", slotId_);
147         return;
148     }
149 
150     uint32_t eventId = event->GetInnerEventId();
151     TELEPHONY_LOGD("[slot%{public}d] eventId = %{public}d", slotId_, eventId);
152 
153     auto itFunc = requestFuncMap_.find(event->GetInnerEventId());
154     if (itFunc != requestFuncMap_.end()) {
155         auto requestFunc = itFunc->second;
156         if (requestFunc != nullptr) {
157             return (this->*requestFunc)(event);
158         }
159     }
160     TELEPHONY_LOGI("[slot%{public}d] Function not found, need check.", slotId_);
161 }
162 
OnReceiveEvent(const EventFwk::CommonEventData & data)163 void CellularCallHandler::OnReceiveEvent(const EventFwk::CommonEventData &data)
164 {
165     EventFwk::Want want = data.GetWant();
166     std::string action = want.GetAction();
167     TELEPHONY_LOGI("[slot%{public}d] action=%{public}s code=%{public}d", slotId_, action.c_str(), data.GetCode());
168     if (action == EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED) {
169         int32_t slotId = want.GetIntParam(BROADCAST_ARG_SLOT_ID, DEFAULT_SIM_SLOT_ID);
170         if (slotId_ != slotId) {
171             return;
172         }
173         this->SendEvent(OPERATOR_CONFIG_CHANGED_ID, DELAY_TIME, Priority::HIGH);
174     }
175 }
176 
GetCsCallData(const AppExecFwk::InnerEvent::Pointer & event)177 void CellularCallHandler::GetCsCallData(const AppExecFwk::InnerEvent::Pointer &event)
178 {
179     this->SendEvent(GET_CS_CALL_DATA_ID, 0, Priority::HIGH);
180 }
181 
GetImsCallData(const AppExecFwk::InnerEvent::Pointer & event)182 void CellularCallHandler::GetImsCallData(const AppExecFwk::InnerEvent::Pointer &event)
183 {
184     this->SendEvent(GET_IMS_CALL_DATA_ID, 0, Priority::HIGH);
185 }
186 
CellularCallIncomingStartTrace(const int32_t state)187 void CellularCallHandler::CellularCallIncomingStartTrace(const int32_t state)
188 {
189     if (state == static_cast<int32_t>(TelCallState::CALL_STATUS_INCOMING)) {
190         StartAsyncTrace(HITRACE_TAG_OHOS, "CellularCallIncoming", getpid());
191     }
192 }
193 
CellularCallIncomingFinishTrace(const int32_t state)194 void CellularCallHandler::CellularCallIncomingFinishTrace(const int32_t state)
195 {
196     if (state == static_cast<int32_t>(TelCallState::CALL_STATUS_INCOMING)) {
197         FinishAsyncTrace(HITRACE_TAG_OHOS, "CellularCallIncoming", getpid());
198     }
199 }
200 
ReportCsCallsData(const CallInfoList & callInfoList)201 void CellularCallHandler::ReportCsCallsData(const CallInfoList &callInfoList)
202 {
203     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
204     if (serviceInstance == nullptr) {
205         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
206         return;
207     }
208     auto csControl = serviceInstance->GetCsControl(slotId_);
209     CallInfo callInfo;
210     std::vector<CallInfo>::const_iterator it = callInfoList.calls.begin();
211     for (; it != callInfoList.calls.end(); ++it) {
212         callInfo.state = (*it).state;
213     }
214     TELEPHONY_LOGI("[slot%{public}d] callInfoList.callSize:%{public}d", slotId_, callInfoList.callSize);
215     CellularCallIncomingStartTrace(callInfo.state);
216     if (callInfoList.callSize == 0) {
217         if (isInCsRedial_) {
218             TELEPHONY_LOGI("[slot%{public}d] Ignore hangup during cs redial", slotId_);
219             isInCsRedial_ = false;
220             return;
221         }
222         if (csControl == nullptr) {
223             TELEPHONY_LOGE("[slot%{public}d] cs_control is null", slotId_);
224             CellularCallIncomingFinishTrace(callInfo.state);
225             return;
226         }
227         if (csControl->ReportCallsData(slotId_, callInfoList) != TELEPHONY_SUCCESS) {
228             CellularCallIncomingFinishTrace(callInfo.state);
229         }
230         serviceInstance->SetCsControl(slotId_, nullptr);
231         return;
232     }
233     if (isInCsRedial_) {
234         TELEPHONY_LOGI("[slot%{public}d] Ignore cs call state change during cs redial", slotId_);
235         return;
236     }
237     if (callInfoList.callSize == 1) {
238         if (csControl == nullptr) {
239             csControl = std::make_shared<CSControl>();
240             serviceInstance->SetCsControl(slotId_, csControl);
241         }
242     }
243     if (csControl == nullptr) {
244         TELEPHONY_LOGE("[slot%{public}d] cs_control is null", slotId_);
245         CellularCallIncomingFinishTrace(callInfo.state);
246         return;
247     }
248     if (csControl->ReportCallsData(slotId_, callInfoList) != TELEPHONY_SUCCESS) {
249         CellularCallIncomingFinishTrace(callInfo.state);
250     }
251 }
252 
ReportImsCallsData(const ImsCurrentCallList & imsCallInfoList)253 void CellularCallHandler::ReportImsCallsData(const ImsCurrentCallList &imsCallInfoList)
254 {
255     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
256     if (serviceInstance == nullptr) {
257         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
258         return;
259     }
260     ImsCurrentCall imsCallInfo;
261     std::vector<ImsCurrentCall>::const_iterator it = imsCallInfoList.calls.begin();
262     for (; it != imsCallInfoList.calls.end(); ++it) {
263         imsCallInfo.state = (*it).state;
264     }
265     TELEPHONY_LOGI("[slot%{public}d] imsCallInfoList.callSize:%{public}d", slotId_, imsCallInfoList.callSize);
266     CellularCallIncomingStartTrace(imsCallInfo.state);
267     auto imsControl = serviceInstance->GetImsControl(slotId_);
268     if (imsCallInfoList.callSize == 0) {
269         if (imsControl == nullptr) {
270             TELEPHONY_LOGE("[slot%{public}d] ims_control is null", slotId_);
271             return;
272         }
273         if (imsControl->ReportImsCallsData(slotId_, imsCallInfoList) != TELEPHONY_SUCCESS) {
274             CellularCallIncomingFinishTrace(imsCallInfo.state);
275         }
276         serviceInstance->SetImsControl(slotId_, nullptr);
277         return;
278     }
279     if (imsCallInfoList.callSize == 1) {
280         if (imsControl == nullptr) {
281             imsControl = std::make_shared<IMSControl>();
282             serviceInstance->SetImsControl(slotId_, imsControl);
283         }
284     }
285     if (imsControl == nullptr) {
286         TELEPHONY_LOGE("[slot%{public}d] ims_control is null", slotId_);
287         CellularCallIncomingFinishTrace(imsCallInfo.state);
288         return;
289     }
290     if (imsControl->ReportImsCallsData(slotId_, imsCallInfoList) != TELEPHONY_SUCCESS) {
291         CellularCallIncomingFinishTrace(imsCallInfo.state);
292     }
293 }
294 
GetCsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer & event)295 void CellularCallHandler::GetCsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event)
296 {
297     // Returns list of current calls of ME. If command succeeds but no calls are available,
298     // no information response is sent to TE. Refer subclause 9.2 for possible <err> values.
299     auto callInfoList = event->GetSharedObject<CallInfoList>();
300     if (callInfoList == nullptr) {
301         TELEPHONY_LOGE("[slot%{public}d] Cannot get the callInfoList, need to get rilResponseInfo", slotId_);
302         auto rilResponseInfo = event->GetSharedObject<HRilRadioResponseInfo>();
303         if (rilResponseInfo == nullptr) {
304             TELEPHONY_LOGE("[slot%{public}d] callInfoList and rilResponseInfo are null", slotId_);
305             return;
306         }
307         if (rilResponseInfo->error == HRilErrType::NONE) {
308             TELEPHONY_LOGE("[slot%{public}d] Failed to query the call list but no reason!", slotId_);
309             return;
310         }
311         CellularCallEventInfo eventInfo;
312         eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
313         eventInfo.eventId = RequestResultEventId::RESULT_GET_CURRENT_CALLS_FAILED;
314         if (registerInstance_ == nullptr) {
315             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
316             return;
317         }
318         registerInstance_->ReportEventResultInfo(eventInfo);
319         return;
320     }
321     ReportCsCallsData(*callInfoList);
322 }
323 
GetImsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer & event)324 void CellularCallHandler::GetImsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event)
325 {
326     // Returns list of current calls of ME. If command succeeds but no calls are available,
327     // no information response is sent to TE. Refer subclause 9.2 for possible <err> values.
328     auto imsCallInfoList = event->GetSharedObject<ImsCurrentCallList>();
329     if (imsCallInfoList == nullptr) {
330         TELEPHONY_LOGE("[slot%{public}d] Cannot get the imsCallInfoList, need to get rilResponseInfo", slotId_);
331         auto rilResponseInfo = event->GetSharedObject<HRilRadioResponseInfo>();
332         if (rilResponseInfo == nullptr) {
333             TELEPHONY_LOGE("[slot%{public}d] callInfoList and rilResponseInfo are null", slotId_);
334             return;
335         }
336         if (rilResponseInfo->error == HRilErrType::NONE) {
337             TELEPHONY_LOGE("[slot%{public}d] Failed to query the call list but no reason!", slotId_);
338             return;
339         }
340         if (registerInstance_ == nullptr) {
341             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
342             return;
343         }
344         registerInstance_->ReportGetCallDataResult(static_cast<int32_t>(rilResponseInfo->error));
345         return;
346     }
347     ReportImsCallsData(*imsCallInfoList);
348 }
349 
DialResponse(const AppExecFwk::InnerEvent::Pointer & event)350 void CellularCallHandler::DialResponse(const AppExecFwk::InnerEvent::Pointer &event)
351 {
352     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
353     if (result == nullptr) {
354         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
355         return;
356     }
357     struct CallBehaviorParameterInfo info = { 0 };
358     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
359     if (callHiSysEvent == nullptr) {
360         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
361         return;
362     }
363     callHiSysEvent->GetCallParameterInfo(info);
364     if (result->error != HRilErrType::NONE) {
365         TELEPHONY_LOGE("[slot%{public}d] dial error:%{public}d", slotId_, result->error);
366         CellularCallEventInfo eventInfo;
367         eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
368 
369         /*
370          * 3GPP TS 27.007 V3.9.0 (2001-06)
371          * If ME has succeeded in establishing a logical link between application protocols and external interface,
372          * it will send CONNECT message to the TE. Otherwise, the NO CARRIER response will be returned.
373          */
374         if (result->error == HRilErrType::HRIL_ERR_CMD_NO_CARRIER) {
375             eventInfo.eventId = RequestResultEventId::RESULT_DIAL_NO_CARRIER;
376         } else {
377             eventInfo.eventId = RequestResultEventId::RESULT_DIAL_SEND_FAILED;
378         }
379         if (registerInstance_ == nullptr) {
380             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
381             return;
382         }
383         registerInstance_->ReportEventResultInfo(eventInfo);
384         CellularCallHiSysEvent::WriteDialCallBehaviorEvent(info, CallResponseResult::COMMAND_FAILURE);
385     } else {
386         CellularCallHiSysEvent::WriteDialCallBehaviorEvent(info, CallResponseResult::COMMAND_SUCCESS);
387     }
388 }
389 
CommonResultEventHandling(const AppExecFwk::InnerEvent::Pointer & event,CellularCallEventInfo & eventInfo)390 void CellularCallHandler::CommonResultEventHandling(
391     const AppExecFwk::InnerEvent::Pointer &event, CellularCallEventInfo &eventInfo)
392 {
393     eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
394     switch (event->GetInnerEventId()) {
395         case RadioEvent::RADIO_HANGUP_CONNECT:
396             eventInfo.eventId = RequestResultEventId::RESULT_END_SEND_FAILED;
397             break;
398         case RadioEvent::RADIO_REJECT_CALL:
399             eventInfo.eventId = RequestResultEventId::RESULT_REJECT_SEND_FAILED;
400             break;
401         case RadioEvent::RADIO_ACCEPT_CALL:
402             eventInfo.eventId = RequestResultEventId::RESULT_ACCEPT_SEND_FAILED;
403             break;
404         case RadioEvent::RADIO_HOLD_CALL:
405             eventInfo.eventId = RequestResultEventId::RESULT_HOLD_SEND_FAILED;
406             break;
407         case RadioEvent::RADIO_ACTIVE_CALL:
408             eventInfo.eventId = RequestResultEventId::RESULT_ACTIVE_SEND_FAILED;
409             break;
410         case RadioEvent::RADIO_SWAP_CALL:
411             eventInfo.eventId = RequestResultEventId::RESULT_SWAP_SEND_FAILED;
412             break;
413         case RadioEvent::RADIO_COMBINE_CALL:
414             eventInfo.eventId = RequestResultEventId::RESULT_COMBINE_SEND_FAILED;
415             break;
416         case RadioEvent::RADIO_JOIN_CALL:
417             eventInfo.eventId = RequestResultEventId::RESULT_JOIN_SEND_FAILED;
418             break;
419         case RadioEvent::RADIO_SPLIT_CALL:
420             eventInfo.eventId = RequestResultEventId::RESULT_SPLIT_SEND_FAILED;
421             break;
422         case RadioEvent::RADIO_CALL_SUPPLEMENT:
423             eventInfo.eventId = RequestResultEventId::RESULT_SUPPLEMENT_SEND_FAILED;
424             break;
425         default:
426             break;
427     }
428 }
429 
CommonResultResponse(const AppExecFwk::InnerEvent::Pointer & event)430 void CellularCallHandler::CommonResultResponse(const AppExecFwk::InnerEvent::Pointer &event)
431 {
432     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
433     if (result == nullptr) {
434         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
435         return;
436     }
437     struct CallBehaviorParameterInfo info = { 0 };
438     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
439     if (callHiSysEvent == nullptr) {
440         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
441         return;
442     }
443     callHiSysEvent->GetCallParameterInfo(info);
444     if (result->error != HRilErrType::NONE) {
445         CellularCallEventInfo eventInfo;
446         eventInfo.eventId = RequestResultEventId::INVALID_REQUEST_RESULT_EVENT_ID;
447         CommonResultEventHandling(event, eventInfo);
448         if (eventInfo.eventId == RequestResultEventId::RESULT_END_SEND_FAILED ||
449             eventInfo.eventId == RequestResultEventId::RESULT_REJECT_SEND_FAILED) {
450             CellularCallHiSysEvent::WriteHangUpCallBehaviorEvent(info, CallResponseResult::COMMAND_FAILURE);
451         } else if (eventInfo.eventId == RequestResultEventId::RESULT_ACCEPT_SEND_FAILED) {
452             CellularCallHiSysEvent::WriteAnswerCallBehaviorEvent(info, CallResponseResult::COMMAND_FAILURE);
453         } else {
454             TELEPHONY_LOGW("[slot%{public}d] eventId is:%{public}d, not within the scope of processing", slotId_,
455                 eventInfo.eventId);
456         }
457         if (registerInstance_ == nullptr) {
458             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
459             return;
460         }
461         registerInstance_->ReportEventResultInfo(eventInfo);
462         return;
463     }
464     uint32_t id = event->GetInnerEventId();
465     if (id == RadioEvent::RADIO_HANGUP_CONNECT || id == RadioEvent::RADIO_REJECT_CALL) {
466         CellularCallHiSysEvent::WriteHangUpCallBehaviorEvent(info, CallResponseResult::COMMAND_SUCCESS);
467     } else if (id == RadioEvent::RADIO_ACCEPT_CALL) {
468         CellularCallHiSysEvent::WriteAnswerCallBehaviorEvent(info, CallResponseResult::COMMAND_SUCCESS);
469     } else {
470         TELEPHONY_LOGW("[slot%{public}d] id is:%{public}d, not within the scope of processing", slotId_, id);
471     }
472 }
473 
ExecutePostDial(const AppExecFwk::InnerEvent::Pointer & event)474 void CellularCallHandler::ExecutePostDial(const AppExecFwk::InnerEvent::Pointer &event)
475 {
476     auto postDialData = event->GetSharedObject<PostDialData>();
477     if (postDialData == nullptr) {
478         TELEPHONY_LOGE("[slot%{public}d] postDialData is null", slotId_);
479         return;
480     }
481     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
482     if (serviceInstance == nullptr) {
483         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
484         return;
485     }
486     int64_t callId = postDialData->callId;
487     if (postDialData->isIms) {
488         auto imsControl = serviceInstance->GetImsControl(slotId_);
489         imsControl->ExecutePostDial(slotId_, callId);
490     } else {
491         auto csControl = serviceInstance->GetCsControl(slotId_);
492         csControl->ExecutePostDial(slotId_, callId);
493     }
494 }
495 
SendDtmfResponse(const AppExecFwk::InnerEvent::Pointer & event)496 void CellularCallHandler::SendDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event)
497 {
498     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
499     if (result == nullptr) {
500         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
501         return;
502     }
503 
504     std::shared_ptr<PostDialData> postDial = std::make_shared<PostDialData>();
505     postDial->callId = result->flag;
506     postDial->isIms = event->GetParam() == static_cast<int32_t>(CallType::TYPE_IMS);
507     this->SendEvent(EVENT_EXECUTE_POST_DIAL, postDial, DELAY_TIME);
508 
509     CellularCallEventInfo eventInfo;
510     eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
511     if (result->error != HRilErrType::NONE) {
512         eventInfo.eventId = RequestResultEventId::RESULT_SEND_DTMF_FAILED;
513     } else {
514         eventInfo.eventId = RequestResultEventId::RESULT_SEND_DTMF_SUCCESS;
515     }
516     if (registerInstance_ == nullptr) {
517         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
518         return;
519     }
520     registerInstance_->ReportEventResultInfo(eventInfo);
521 }
522 
StartDtmfResponse(const AppExecFwk::InnerEvent::Pointer & event)523 void CellularCallHandler::StartDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event)
524 {
525     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
526     if (result == nullptr) {
527         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
528         return;
529     }
530     if (registerInstance_ == nullptr) {
531         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
532         return;
533     }
534     registerInstance_->ReportStartDtmfResult(static_cast<int32_t>(result->error));
535 }
536 
SimStateChangeReport(const AppExecFwk::InnerEvent::Pointer & event)537 void CellularCallHandler::SimStateChangeReport(const AppExecFwk::InnerEvent::Pointer &event)
538 {
539     CellularCallConfig config;
540     config.HandleSimStateChanged(slotId_);
541 }
542 
SimRecordsLoadedReport(const AppExecFwk::InnerEvent::Pointer & event)543 void CellularCallHandler::SimRecordsLoadedReport(const AppExecFwk::InnerEvent::Pointer &event)
544 {
545     CellularCallConfig config;
546     config.HandleSimRecordsLoaded(slotId_);
547 }
548 
StopDtmfResponse(const AppExecFwk::InnerEvent::Pointer & event)549 void CellularCallHandler::StopDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event)
550 {
551     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
552     if (result == nullptr) {
553         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
554         return;
555     }
556     if (registerInstance_ == nullptr) {
557         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
558         return;
559     }
560     registerInstance_->ReportStopDtmfResult(static_cast<int32_t>(result->error));
561 }
562 
SetSlotId(int32_t id)563 void CellularCallHandler::SetSlotId(int32_t id)
564 {
565     slotId_ = id;
566 }
567 
GetSlotId()568 int32_t CellularCallHandler::GetSlotId()
569 {
570     return slotId_;
571 }
572 
CurrentTimeMillis()573 int64_t CellularCallHandler::CurrentTimeMillis()
574 {
575     int64_t timems =
576         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
577             .count();
578     return timems;
579 }
580 
GetCsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer & event)581 void CellularCallHandler::GetCsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event)
582 {
583     lastCallsDataFlag_ = CurrentTimeMillis();
584     CellularCallConnectionCS connectionCs;
585     connectionCs.GetCsCallsDataRequest(slotId_, lastCallsDataFlag_);
586 }
587 
GetImsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer & event)588 void CellularCallHandler::GetImsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event)
589 {
590     lastCallsDataFlag_ = CurrentTimeMillis();
591     CellularCallConnectionIMS connectionIms;
592     connectionIms.GetImsCallsDataRequest(slotId_, lastCallsDataFlag_);
593 }
594 
RegisterHandler(const AppExecFwk::InnerEvent::Pointer & event)595 void CellularCallHandler::RegisterHandler(const AppExecFwk::InnerEvent::Pointer &event)
596 {
597     CellularCallConnectionCS connectionCs;
598     connectionCs.RegisterHandler();
599 }
600 
SetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer & event)601 void CellularCallHandler::SetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
602 {
603     auto info = event->GetSharedObject<HRilRadioResponseInfo>();
604     if (info == nullptr) {
605         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
606         return;
607     }
608     CellularCallEventInfo eventInfo;
609     eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
610     if (info->error != HRilErrType::NONE) {
611         eventInfo.eventId = RequestResultEventId::RESULT_SET_CALL_PREFERENCE_MODE_FAILED;
612     } else {
613         eventInfo.eventId = RequestResultEventId::RESULT_SET_CALL_PREFERENCE_MODE_SUCCESS;
614 
615         CellularCallConfig config;
616         config.SetTempMode(slotId_);
617     }
618     if (registerInstance_ == nullptr) {
619         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
620         return;
621     }
622     registerInstance_->ReportEventResultInfo(eventInfo);
623 }
624 
GetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer & event)625 void CellularCallHandler::GetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
626 {
627     auto mode = event->GetSharedObject<int32_t>();
628     if (mode == nullptr) {
629         TELEPHONY_LOGI("[slot%{public}d] mode is null", slotId_);
630         return;
631     }
632     CellularCallConfig config;
633     config.GetDomainPreferenceModeResponse(slotId_, *mode);
634 }
635 
SetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer & event)636 void CellularCallHandler::SetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event)
637 {
638     auto info = event->GetSharedObject<HRilRadioResponseInfo>();
639     if (info == nullptr) {
640         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
641         return;
642     }
643     if (registerInstance_ == nullptr) {
644         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
645         return;
646     }
647     CellularCallConfig config;
648     config.HandleSetLteImsSwitchResult(slotId_, info->error);
649 }
650 
GetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer & event)651 void CellularCallHandler::GetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event) {}
652 
SetVoNRSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer & event)653 void CellularCallHandler::SetVoNRSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event)
654 {
655     auto info = event->GetSharedObject<HRilRadioResponseInfo>();
656     if (info == nullptr) {
657         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
658         return;
659     }
660     CellularCallConfig config;
661     config.HandleSetVoNRSwitchResult(slotId_, info->error);
662 }
663 
CsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer & event)664 void CellularCallHandler::CsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event)
665 {
666     if (srvccState_ == SrvccState::STARTED) {
667         TELEPHONY_LOGI("[slot%{public}d] Ignore to report cs call state change cause by srvcc started", slotId_);
668         return;
669     }
670     GetCsCallData(event);
671 }
672 
ImsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer & event)673 void CellularCallHandler::ImsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event)
674 {
675     if (srvccState_ == SrvccState::STARTED) {
676         TELEPHONY_LOGI("[slot%{public}d] Ignore to report ims call state change cause by srvcc started", slotId_);
677         return;
678     }
679     GetImsCallData(event);
680 }
681 
UssdNotifyResponse(const AppExecFwk::InnerEvent::Pointer & event)682 void CellularCallHandler::UssdNotifyResponse(const AppExecFwk::InnerEvent::Pointer &event)
683 {
684     auto result = event->GetSharedObject<UssdNoticeInfo>();
685     if (result == nullptr) {
686         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
687         return;
688     }
689     CellularCallSupplement supplement;
690     supplement.EventUssdNotify(*result);
691 }
692 
SetMuteResponse(const AppExecFwk::InnerEvent::Pointer & event)693 void CellularCallHandler::SetMuteResponse(const AppExecFwk::InnerEvent::Pointer &event)
694 {
695     auto info = event->GetSharedObject<HRilRadioResponseInfo>();
696     if (info == nullptr) {
697         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
698         return;
699     }
700     MuteControlResponse response;
701     if (registerInstance_ == nullptr) {
702         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
703         return;
704     }
705     response.result = static_cast<int32_t>(info->error);
706     registerInstance_->ReportSetMuteResult(response);
707 }
708 
GetMuteResponse(const AppExecFwk::InnerEvent::Pointer & event)709 void CellularCallHandler::GetMuteResponse(const AppExecFwk::InnerEvent::Pointer &event)
710 {
711     MuteControlResponse response;
712     auto mute = event->GetSharedObject<int32_t>();
713     if (mute == nullptr) {
714         TELEPHONY_LOGI("[slot%{public}d] mute is null", slotId_);
715         auto info = event->GetSharedObject<HRilRadioResponseInfo>();
716         if (info == nullptr) {
717             TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
718             return;
719         }
720         response.result = static_cast<int32_t>(info->error);
721     } else {
722         response.result = static_cast<int32_t>(HRilErrType::NONE);
723         response.value = *mute;
724     }
725     if (registerInstance_ == nullptr) {
726         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
727         return;
728     }
729     registerInstance_->ReportGetMuteResult(response);
730 }
731 
GetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer & event)732 void CellularCallHandler::GetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer &event)
733 {
734     auto eccList = event->GetSharedObject<EmergencyInfoList>();
735     if (eccList == nullptr) {
736         TELEPHONY_LOGE("[slot%{public}d] eccList is null", slotId_);
737         return;
738     }
739     CellularCallConfig config;
740     config.UpdateEmergencyCallFromRadio(slotId_, *eccList);
741 }
742 
SetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer & event)743 void CellularCallHandler::SetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer &event)
744 {
745     auto info = event->GetSharedObject<HRilRadioResponseInfo>();
746     if (info == nullptr) {
747         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
748         return;
749     }
750     if (registerInstance_ == nullptr) {
751         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
752         return;
753     }
754     SetEccListResponse response;
755     response.result = static_cast<int32_t>(info->error);
756     registerInstance_->ReportSetEmergencyCallListResponse(response);
757 }
758 
CallRingBackVoiceResponse(const AppExecFwk::InnerEvent::Pointer & event)759 void CellularCallHandler::CallRingBackVoiceResponse(const AppExecFwk::InnerEvent::Pointer &event)
760 {
761     auto ringBackVoice = event->GetSharedObject<RingbackVoice>();
762     if (ringBackVoice == nullptr) {
763         TELEPHONY_LOGE("[slot%{public}d] ringBackVoice is null", slotId_);
764         return;
765     }
766     if (registerInstance_ == nullptr) {
767         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
768         return;
769     }
770     registerInstance_->ReportCallRingBackResult(ringBackVoice->status);
771 }
772 
GetCallFailReasonResponse(const AppExecFwk::InnerEvent::Pointer & event)773 void CellularCallHandler::GetCallFailReasonResponse(const AppExecFwk::InnerEvent::Pointer &event)
774 {
775     if (registerInstance_ == nullptr) {
776         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
777         return;
778     }
779     auto reason = event->GetSharedObject<int32_t>();
780     DisconnectedDetails details;
781     if (reason == nullptr) {
782         auto info = event->GetSharedObject<DisconnectedDetails>();
783         if (info == nullptr) {
784             TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
785             return;
786         }
787         details.reason = static_cast<DisconnectedReason>(info->reason);
788         details.message = (info->message.c_str() == nullptr) ? "" : info->message;
789     } else {
790         details.reason = static_cast<DisconnectedReason>(*reason);
791         details.message = "";
792     }
793 
794     if (details.message.empty()) {
795         std::string callFailedMessageName = "";
796         bool ret =
797             ResourceUtils::Get().GetCallFailedMessageName(static_cast<int32_t>(details.reason), callFailedMessageName);
798         if (!ret) {
799             TELEPHONY_LOGE("[slot%{public}d] Get call failed message failed!", slotId_);
800             return;
801         }
802         ResourceUtils::Get().GetStringValueByName(callFailedMessageName, details.message);
803     }
804     CellularCallHiSysEvent::WriteCallEndBehaviorEvent(slotId_, static_cast<int32_t>(details.reason));
805     registerInstance_->ReportCallFailReason(details);
806 }
807 
UpdateSrvccStateReport(const AppExecFwk::InnerEvent::Pointer & event)808 void CellularCallHandler::UpdateSrvccStateReport(const AppExecFwk::InnerEvent::Pointer &event)
809 {
810     auto srvccStatus = event->GetSharedObject<SrvccStatus>();
811     if (srvccStatus == nullptr) {
812         TELEPHONY_LOGE("[slot%{public}d] srvccStatus is null", slotId_);
813         return;
814     }
815     TELEPHONY_LOGI("[slot%{public}d] srvccStatus is %{public}d", slotId_, srvccStatus->status);
816     srvccState_ = srvccStatus->status;
817     auto serviceInstance_ = DelayedSingleton<CellularCallService>::GetInstance();
818     if (registerInstance_ == nullptr) {
819         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
820         return;
821     }
822     serviceInstance_->SetSrvccState(srvccState_);
823     if (srvccState_ != SrvccState::COMPLETED) {
824         TELEPHONY_LOGE("[slot%{public}d] srvccState_ != SrvccState::COMPLETED", slotId_);
825         return;
826     }
827     SrvccStateCompleted();
828 }
829 
ReportEccChanged(const AppExecFwk::InnerEvent::Pointer & event)830 void CellularCallHandler::ReportEccChanged(const AppExecFwk::InnerEvent::Pointer &event)
831 {
832     auto emergencyInfoList = event->GetSharedObject<EmergencyInfoList>();
833     if (emergencyInfoList == nullptr) {
834         TELEPHONY_LOGE("[slot%{public}d] emergencyInfoList is null", slotId_);
835         return;
836     }
837     CellularCallConfig config;
838     auto calls = emergencyInfoList->calls;
839     if (calls.size() > 0 && static_cast<uint32_t>(calls.back().total) != calls.size()) {
840         TELEPHONY_LOGE("[slot%{public}d] data error", slotId_);
841         auto endCall = calls.back();
842         if (endCall.index < endCall.total) {
843             return;
844         }
845         TELEPHONY_LOGI("[slot%{public}d] try query", slotId_);
846         config.GetEmergencyCallList(slotId_);
847         return;
848     }
849     config.UpdateEmergencyCallFromRadio(slotId_, *emergencyInfoList);
850 }
851 
SrvccStateCompleted()852 void CellularCallHandler::SrvccStateCompleted()
853 {
854     if (srvccState_ != SrvccState::COMPLETED) {
855         TELEPHONY_LOGE("[slot%{public}d] srvccState_ != SrvccState::COMPLETED", slotId_);
856         return;
857     }
858     auto serviceInstance_ = DelayedSingleton<CellularCallService>::GetInstance();
859     if (serviceInstance_ == nullptr) {
860         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
861         return;
862     }
863     auto csControl = serviceInstance_->GetCsControl(slotId_);
864     if (csControl != nullptr) {
865         TELEPHONY_LOGI("[slot%{public}d] CsControl ReleaseAllConnection", slotId_);
866         csControl->ReleaseAllConnection();
867         serviceInstance_->SetCsControl(slotId_, nullptr);
868     } else {
869         TELEPHONY_LOGI("[slot%{public}d] CsControl is null", slotId_);
870         csControl = std::make_shared<CSControl>();
871         serviceInstance_->SetCsControl(slotId_, csControl);
872     }
873     auto imsControl = serviceInstance_->GetImsControl(slotId_);
874     if (imsControl != nullptr) {
875         TELEPHONY_LOGI("[slot%{public}d] ImsControl ReleaseAllConnection", slotId_);
876         imsControl->ReleaseAllConnection();
877         serviceInstance_->SetImsControl(slotId_, nullptr);
878     } else {
879         TELEPHONY_LOGI("[slot%{public}d] imsControl is null", slotId_);
880     }
881     srvccState_ = SrvccState::SRVCC_NONE;
882 }
883 
GetMMIResponse(const AppExecFwk::InnerEvent::Pointer & event)884 void CellularCallHandler::GetMMIResponse(const AppExecFwk::InnerEvent::Pointer &event)
885 {
886     std::unique_ptr<MMICodeUtils> mmiCodeUtils = event->GetUniqueObject<MMICodeUtils>();
887     if (mmiCodeUtils == nullptr) {
888         TELEPHONY_LOGE("[slot%{public}d] mmiCodeUtils is null", slotId_);
889         return;
890     }
891     mmiCodeUtils->ExecuteMmiCode(slotId_);
892 }
893 
GetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer & event)894 void CellularCallHandler::GetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer &event)
895 {
896     auto result = event->GetSharedObject<CallWaitResult>();
897     if (result == nullptr) {
898         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
899         return;
900     }
901     int32_t flag = SS_FROM_MMI_CODE;
902     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->result.index, flag);
903     if (ret != TELEPHONY_SUCCESS) {
904         return;
905     }
906     CellularCallSupplement supplement;
907     supplement.EventGetCallWaiting(*result, result->result.message, flag);
908 }
909 
SetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer & event)910 void CellularCallHandler::SetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer &event)
911 {
912     auto result = event->GetSharedObject<SsBaseResult>();
913     if (result == nullptr) {
914         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
915         return;
916     }
917     int32_t flag = SS_FROM_MMI_CODE;
918     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
919     if (ret != TELEPHONY_SUCCESS) {
920         return;
921     }
922     CellularCallSupplement supplement;
923     if (result->result != TELEPHONY_SUCCESS) {
924         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
925     }
926     supplement.EventSetCallWaiting(result->result, result->message, flag);
927 }
928 
GetClirResponse(const AppExecFwk::InnerEvent::Pointer & event)929 void CellularCallHandler::GetClirResponse(const AppExecFwk::InnerEvent::Pointer &event)
930 {
931     auto getClirResult = event->GetSharedObject<GetClirResult>();
932     if (getClirResult == nullptr) {
933         TELEPHONY_LOGE("[slot%{public}d] getClirResult is null", slotId_);
934         return;
935     }
936     int32_t flag = SS_FROM_MMI_CODE;
937     int32_t ret = ConfirmAndRemoveSsRequestCommand(getClirResult->result.index, flag);
938     if (ret != TELEPHONY_SUCCESS) {
939         return;
940     }
941     CellularCallSupplement supplement;
942     supplement.EventGetClir(*getClirResult, getClirResult->result.message, flag);
943 }
944 
SetClirResponse(const AppExecFwk::InnerEvent::Pointer & event)945 void CellularCallHandler::SetClirResponse(const AppExecFwk::InnerEvent::Pointer &event)
946 {
947     auto result = event->GetSharedObject<SsBaseResult>();
948     if (result == nullptr) {
949         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
950         return;
951     }
952     int32_t flag = SS_FROM_MMI_CODE;
953     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
954     if (ret != TELEPHONY_SUCCESS) {
955         return;
956     }
957     CellularCallSupplement supplement;
958     supplement.EventSetClir(result->result, result->message, flag);
959 }
960 
GetClipResponse(const AppExecFwk::InnerEvent::Pointer & event)961 void CellularCallHandler::GetClipResponse(const AppExecFwk::InnerEvent::Pointer &event)
962 {
963     auto getClipResult = event->GetSharedObject<GetClipResult>();
964     if (getClipResult == nullptr) {
965         TELEPHONY_LOGE("[slot%{public}d] getClipResult is null", slotId_);
966         return;
967     }
968     int32_t flag = SS_FROM_MMI_CODE;
969     int32_t ret = ConfirmAndRemoveSsRequestCommand(getClipResult->result.index, flag);
970     if (ret != TELEPHONY_SUCCESS) {
971         return;
972     }
973     CellularCallSupplement supplement;
974     supplement.EventGetClip(*getClipResult, getClipResult->result.message, flag);
975 }
976 
SetClipResponse(const AppExecFwk::InnerEvent::Pointer & event)977 void CellularCallHandler::SetClipResponse(const AppExecFwk::InnerEvent::Pointer &event)
978 {
979     auto result = event->GetSharedObject<SsBaseResult>();
980     if (result == nullptr) {
981         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
982         return;
983     }
984     int32_t flag = SS_FROM_MMI_CODE;
985     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
986     if (ret != TELEPHONY_SUCCESS) {
987         return;
988     }
989     CellularCallSupplement supplement;
990     supplement.EventSetClip(result->result, result->message, flag);
991 }
992 
GetColrResponse(const AppExecFwk::InnerEvent::Pointer & event)993 void CellularCallHandler::GetColrResponse(const AppExecFwk::InnerEvent::Pointer &event)
994 {
995     auto colrResult = event->GetSharedObject<GetColrResult>();
996     if (colrResult == nullptr) {
997         TELEPHONY_LOGE("[slot%{public}d] colrResult is null", slotId_);
998         return;
999     }
1000     int32_t flag = SS_FROM_MMI_CODE;
1001     int32_t ret = ConfirmAndRemoveSsRequestCommand(colrResult->result.index, flag);
1002     if (ret != TELEPHONY_SUCCESS) {
1003         return;
1004     }
1005     CellularCallSupplement supplement;
1006     supplement.EventGetColr(*colrResult, colrResult->result.message, flag);
1007 }
1008 
SetColrResponse(const AppExecFwk::InnerEvent::Pointer & event)1009 void CellularCallHandler::SetColrResponse(const AppExecFwk::InnerEvent::Pointer &event)
1010 {
1011     auto result = event->GetSharedObject<SsBaseResult>();
1012     if (result == nullptr) {
1013         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1014         return;
1015     }
1016     int32_t flag = SS_FROM_MMI_CODE;
1017     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1018     if (ret != TELEPHONY_SUCCESS) {
1019         return;
1020     }
1021     CellularCallSupplement supplement;
1022     supplement.EventSetColr(result->result, result->message, flag);
1023 }
1024 
GetColpResponse(const AppExecFwk::InnerEvent::Pointer & event)1025 void CellularCallHandler::GetColpResponse(const AppExecFwk::InnerEvent::Pointer &event)
1026 {
1027     auto colpResult = event->GetSharedObject<GetColpResult>();
1028     if (colpResult == nullptr) {
1029         TELEPHONY_LOGE("[slot%{public}d] colpResult is null", slotId_);
1030         return;
1031     }
1032     int32_t flag = SS_FROM_MMI_CODE;
1033     int32_t ret = ConfirmAndRemoveSsRequestCommand(colpResult->result.index, flag);
1034     if (ret != TELEPHONY_SUCCESS) {
1035         return;
1036     }
1037     CellularCallSupplement supplement;
1038     supplement.EventGetColp(*colpResult, colpResult->result.message, flag);
1039 }
1040 
SetColpResponse(const AppExecFwk::InnerEvent::Pointer & event)1041 void CellularCallHandler::SetColpResponse(const AppExecFwk::InnerEvent::Pointer &event)
1042 {
1043     auto result = event->GetSharedObject<SsBaseResult>();
1044     if (result == nullptr) {
1045         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1046         return;
1047     }
1048     int32_t flag = SS_FROM_MMI_CODE;
1049     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1050     if (ret != TELEPHONY_SUCCESS) {
1051         return;
1052     }
1053     CellularCallSupplement supplement;
1054     supplement.EventSetColp(result->result, result->message, flag);
1055 }
1056 
GetCallTransferResponse(const AppExecFwk::InnerEvent::Pointer & event)1057 void CellularCallHandler::GetCallTransferResponse(const AppExecFwk::InnerEvent::Pointer &event)
1058 {
1059     auto cFQueryList = event->GetSharedObject<CallForwardQueryInfoList>();
1060     if (cFQueryList == nullptr) {
1061         TELEPHONY_LOGE("[slot%{public}d] cFQueryList is null", slotId_);
1062         return;
1063     }
1064     int32_t flag = SS_FROM_MMI_CODE;
1065     int32_t ret = ConfirmAndRemoveSsRequestCommand(cFQueryList->result.index, flag);
1066     if (ret != TELEPHONY_SUCCESS) {
1067         return;
1068     }
1069     CellularCallSupplement supplement;
1070     supplement.EventGetCallTransferInfo(*cFQueryList, cFQueryList->result.message, flag);
1071 }
1072 
SetCallTransferInfoResponse(const AppExecFwk::InnerEvent::Pointer & event)1073 void CellularCallHandler::SetCallTransferInfoResponse(const AppExecFwk::InnerEvent::Pointer &event)
1074 {
1075     auto result = event->GetSharedObject<SsBaseResult>();
1076     if (result == nullptr) {
1077         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1078         return;
1079     }
1080     int32_t flag = SS_FROM_MMI_CODE;
1081     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1082     if (ret != TELEPHONY_SUCCESS) {
1083         return;
1084     }
1085     CellularCallSupplement supplement;
1086     CallForwardingInfo info;
1087     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
1088     if (callHiSysEvent == nullptr) {
1089         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
1090         return;
1091     }
1092     callHiSysEvent->GetCallForwardingInfo(info);
1093     if (result->result == TELEPHONY_SUCCESS) {
1094         CoreManagerInner::GetInstance().SetVoiceCallForwarding(info.slotId, info.enable, info.number);
1095     } else {
1096         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1097     }
1098     supplement.EventSetCallTransferInfo(result->result, result->message, flag);
1099 }
1100 
GetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer & event)1101 void CellularCallHandler::GetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer &event)
1102 {
1103     auto result = event->GetSharedObject<CallRestrictionResult>();
1104     if (result == nullptr) {
1105         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1106         return;
1107     }
1108     int32_t flag = SS_FROM_MMI_CODE;
1109     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->result.index, flag);
1110     if (ret != TELEPHONY_SUCCESS) {
1111         return;
1112     }
1113     CellularCallSupplement supplement;
1114     supplement.EventGetCallRestriction(*result, result->result.message, flag);
1115 }
1116 
SetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer & event)1117 void CellularCallHandler::SetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer &event)
1118 {
1119     auto result = event->GetSharedObject<SsBaseResult>();
1120     if (result == nullptr) {
1121         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1122         return;
1123     }
1124     int32_t flag = SS_FROM_MMI_CODE;
1125     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1126     if (ret != TELEPHONY_SUCCESS) {
1127         return;
1128     }
1129     CellularCallSupplement supplement;
1130     if (result->result != TELEPHONY_SUCCESS) {
1131         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1132     }
1133     supplement.EventSetCallRestriction(result->result, result->message, flag);
1134 }
1135 
SetBarringPasswordResponse(const AppExecFwk::InnerEvent::Pointer & event)1136 void CellularCallHandler::SetBarringPasswordResponse(const AppExecFwk::InnerEvent::Pointer &event)
1137 {
1138     auto result = event->GetSharedObject<SsBaseResult>();
1139     if (result == nullptr) {
1140         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1141         return;
1142     }
1143     int32_t flag = SS_FROM_MMI_CODE;
1144     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1145     if (ret != TELEPHONY_SUCCESS) {
1146         return;
1147     }
1148     CellularCallSupplement supplement;
1149     if (result->result != TELEPHONY_SUCCESS) {
1150         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1151     }
1152     supplement.EventSetBarringPassword(result->result, result->message, flag);
1153 }
1154 
SendUssdResponse(const AppExecFwk::InnerEvent::Pointer & event)1155 void CellularCallHandler::SendUssdResponse(const AppExecFwk::InnerEvent::Pointer &event)
1156 {
1157     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
1158     if (result == nullptr) {
1159         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1160         return;
1161     }
1162     CellularCallSupplement supplement;
1163     supplement.EventSendUssd(*result);
1164 }
1165 
SsNotifyResponse(const AppExecFwk::InnerEvent::Pointer & event)1166 void CellularCallHandler::SsNotifyResponse(const AppExecFwk::InnerEvent::Pointer &event)
1167 {
1168     auto result = event->GetSharedObject<SsNoticeInfo>();
1169     if (result == nullptr) {
1170         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1171         return;
1172     }
1173     CellularCallSupplement supplement;
1174     supplement.EventSsNotify(*result);
1175 }
1176 
SendUnlockPinPukResponse(const AppExecFwk::InnerEvent::Pointer & event)1177 void CellularCallHandler::SendUnlockPinPukResponse(const AppExecFwk::InnerEvent::Pointer &event)
1178 {
1179     auto result = event->GetSharedObject<PinPukResponse>();
1180     if (result == nullptr) {
1181         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1182         return;
1183     }
1184     CellularCallSupplement supplement;
1185     supplement.EventSetPinPuk(*result);
1186 }
1187 
HandleOperatorConfigChanged(const AppExecFwk::InnerEvent::Pointer & event)1188 void CellularCallHandler::HandleOperatorConfigChanged(const AppExecFwk::InnerEvent::Pointer &event)
1189 {
1190     CellularCallConfig config;
1191     config.HandleOperatorConfigChanged(slotId_);
1192 }
1193 
UpdateRsrvccStateReport(const AppExecFwk::InnerEvent::Pointer & event)1194 void CellularCallHandler::UpdateRsrvccStateReport(const AppExecFwk::InnerEvent::Pointer &event)
1195 {
1196     isInCsRedial_ = true;
1197     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
1198     if (serviceInstance == nullptr) {
1199         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
1200         return;
1201     }
1202     serviceInstance->SetCsControl(slotId_, nullptr);
1203 }
1204 
RequestSsRequestCommandIndex(int32_t & index)1205 void CellularCallHandler::RequestSsRequestCommandIndex(int32_t &index)
1206 {
1207     if (indexCommand_ >= MAX_REQUEST_COUNT) {
1208         indexCommand_ = 0;
1209     } else {
1210         indexCommand_++;
1211     }
1212     index = indexCommand_;
1213 }
1214 
SaveSsRequestCommand(const std::shared_ptr<SsRequestCommand> & utCommand,int32_t index)1215 void CellularCallHandler::SaveSsRequestCommand(const std::shared_ptr<SsRequestCommand> &utCommand, int32_t index)
1216 {
1217     if (utCommand == nullptr) {
1218         TELEPHONY_LOGE("[slot%{public}d] utCommand is null", slotId_);
1219         return;
1220     }
1221     std::lock_guard<std::mutex> lock(mutex_);
1222     utCommandMap_.insert(std::make_pair(indexCommand_, utCommand));
1223 }
1224 
ConfirmAndRemoveSsRequestCommand(int32_t index,int32_t & flag)1225 int32_t CellularCallHandler::ConfirmAndRemoveSsRequestCommand(int32_t index, int32_t &flag)
1226 {
1227     if (index == INVALID_INDEX) {
1228         // -1 mean this command index wasn't come from app, so don't need report result
1229         TELEPHONY_LOGI("[slot%{public}d] index is invalid, nothing need to do", slotId_);
1230         return TELEPHONY_ERROR;
1231     }
1232     std::lock_guard<std::mutex> lock(mutex_);
1233     auto itor = utCommandMap_.find(index);
1234     if (itor == utCommandMap_.end()) {
1235         TELEPHONY_LOGE("[slot%{public}d] the index(%{public}d) in utCommandMap_ haven't been found", slotId_, index);
1236         return TELEPHONY_ERROR;
1237     }
1238     flag = itor->second->flag;
1239     utCommandMap_.erase(index);
1240     return TELEPHONY_SUCCESS;
1241 }
1242 
GetSsRequestCommand(int32_t index,SsRequestCommand & ss)1243 int32_t CellularCallHandler::GetSsRequestCommand(int32_t index, SsRequestCommand &ss)
1244 {
1245     std::lock_guard<std::mutex> lock(mutex_);
1246     auto itor = utCommandMap_.find(index);
1247     if (itor == utCommandMap_.end()) {
1248         TELEPHONY_LOGE("[slot%{public}d] the index in utCommandMap_ haven't been found", slotId_);
1249         return TELEPHONY_ERROR;
1250     }
1251 
1252     ss.cfAction = itor->second->cfAction;
1253     ss.cfReason = itor->second->cfReason;
1254     ss.number = itor->second->number;
1255     ss.enable = itor->second->enable;
1256     ss.clirAction = itor->second->clirAction;
1257     ss.facility = itor->second->facility;
1258     if (strcpy_s(ss.password, sizeof(ss.password), itor->second->password) != EOK) {
1259         TELEPHONY_LOGE("password strcpy_s fail.");
1260         return TELEPHONY_ERR_STRCPY_FAIL;
1261     }
1262     ss.classType = itor->second->classType;
1263     ss.action = itor->second->action;
1264     ss.flag = itor->second->flag;
1265     return TELEPHONY_SUCCESS;
1266 }
1267 
CloseUnFinishedUssdResponse(const AppExecFwk::InnerEvent::Pointer & event)1268 void CellularCallHandler::CloseUnFinishedUssdResponse(const AppExecFwk::InnerEvent::Pointer &event)
1269 {
1270     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
1271     if (result == nullptr) {
1272         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1273         return;
1274     }
1275     CellularCallSupplement supplement;
1276     supplement.EventCloseUnFinishedUssd(*result);
1277 }
1278 
1279 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
StartCallManagerService()1280 void CellularCallHandler::StartCallManagerService()
1281 {
1282     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
1283     if (serviceInstance == nullptr) {
1284         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
1285         return;
1286     }
1287     serviceInstance->StartCallManagerService();
1288 }
1289 
RadioStateChangeProcess(const AppExecFwk::InnerEvent::Pointer & event)1290 void CellularCallHandler::RadioStateChangeProcess(const AppExecFwk::InnerEvent::Pointer &event)
1291 {
1292     std::shared_ptr<HRilInt32Parcel> object = event->GetSharedObject<HRilInt32Parcel>();
1293     if (object == nullptr) {
1294         TELEPHONY_LOGE("[slot%{public}d] object is null", slotId_);
1295         return;
1296     }
1297     TELEPHONY_LOGI("[slot%{public}d] Radio changed with state: %{public}d", slotId_, object->data);
1298     if (object->data == CORE_SERVICE_POWER_ON) {
1299         StartCallManagerService();
1300     }
1301 }
1302 
GetRadioStateProcess(const AppExecFwk::InnerEvent::Pointer & event)1303 void CellularCallHandler::GetRadioStateProcess(const AppExecFwk::InnerEvent::Pointer &event)
1304 {
1305     auto object = event->GetUniqueObject<HRilRadioStateInfo>();
1306     if (object == nullptr) {
1307         TELEPHONY_LOGE("object is null");
1308         return;
1309     }
1310     TELEPHONY_LOGI("GetRadioStateProcess [slot%{public}d], state=%{public}d", slotId_, object->state);
1311     if (object->state == CORE_SERVICE_POWER_ON) {
1312         StartCallManagerService();
1313     }
1314 }
1315 #endif
1316 } // namespace Telephony
1317 } // namespace OHOS
1318