• 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 "tel_ril_call_parcel.h"
23 #include "tel_ril_types.h"
24 #include "ims_call_client.h"
25 #include "operator_config_types.h"
26 #include "parameters.h"
27 #include "radio_event.h"
28 #include "resource_utils.h"
29 #include "satellite_call_client.h"
30 #include "satellite_radio_event.h"
31 #include "securec.h"
32 #include "call_manager_info.h"
33 
34 namespace OHOS {
35 namespace Telephony {
36 const std::string CN_INTERNATIONAL_NUMBER_PREFIX = "+86";
37 const std::string DUPLICATIVE_CN_INTERNATIONAL_NUMBER_PREFIX_FORMAT = "^\\+8686(13[0-9]|14[5-9]|15[0-9]|166|17[0-9]"
38         "|18[0-9]|19[0-9])\\d{8}$";
39 const uint32_t GET_CS_CALL_DATA_ID = 10001;
40 const uint32_t GET_IMS_CALL_DATA_ID = 10002;
41 const uint32_t OPERATOR_CONFIG_CHANGED_ID = 10004;
42 const uint32_t GET_SATELLITE_CALL_DATA_ID = 10005;
43 const uint32_t NETWORK_STATE_CHANGED = 10006;
44 const int64_t DELAY_TIME = 100;
45 const int32_t MAX_REQUEST_COUNT = 50;
46 // message was null, mean report the default message to user which have been define at CellularCallSupplement
47 const std::string DEFAULT_NULL_MESSAGE = "";
48 // NV refresh state
49 constexpr int32_t STATE_NV_REFRESH_FINISHED = 1;
50 constexpr int32_t STATE_NV_REFRESH_ALREADY_FINISHED = 4;
51 
CellularCallHandler(const EventFwk::CommonEventSubscribeInfo & subscriberInfo)52 CellularCallHandler::CellularCallHandler(const EventFwk::CommonEventSubscribeInfo &subscriberInfo)
53     : TelEventHandler("CellularCallHandler"), CommonEventSubscriber(subscriberInfo)
54 {
55     InitBasicFuncMap();
56     InitConfigFuncMap();
57     InitSupplementFuncMap();
58     InitActiveReportFuncMap();
59     InitSatelliteCallFuncMap();
60     InitAdditionalFuncMap();
61 }
62 
InitBasicFuncMap()63 void CellularCallHandler::InitBasicFuncMap()
64 {
65     requestFuncMap_[RadioEvent::RADIO_DIAL] =
66         [this](const AppExecFwk::InnerEvent::Pointer &event) { DialResponse(event); };
67     requestFuncMap_[RadioEvent::RADIO_HANGUP_CONNECT] =
68         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
69     requestFuncMap_[RadioEvent::RADIO_REJECT_CALL] =
70         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
71     requestFuncMap_[RadioEvent::RADIO_ACCEPT_CALL] =
72         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
73     requestFuncMap_[RadioEvent::RADIO_HOLD_CALL] =
74         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
75     requestFuncMap_[RadioEvent::RADIO_ACTIVE_CALL] =
76         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
77     requestFuncMap_[RadioEvent::RADIO_SWAP_CALL] =
78         [this](const AppExecFwk::InnerEvent::Pointer &event) { SwapCallResponse(event); };
79     requestFuncMap_[RadioEvent::RADIO_COMBINE_CALL] =
80         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
81     requestFuncMap_[RadioEvent::RADIO_JOIN_CALL] =
82         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
83     requestFuncMap_[RadioEvent::RADIO_SPLIT_CALL] =
84         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
85     requestFuncMap_[RadioEvent::RADIO_CALL_SUPPLEMENT] =
86         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
87     requestFuncMap_[RadioEvent::RADIO_SEND_DTMF] =
88         [this](const AppExecFwk::InnerEvent::Pointer &event) { SendDtmfResponse(event); };
89     requestFuncMap_[RadioEvent::RADIO_START_DTMF] =
90         [this](const AppExecFwk::InnerEvent::Pointer &event) { StartDtmfResponse(event); };
91     requestFuncMap_[RadioEvent::RADIO_STOP_DTMF] =
92         [this](const AppExecFwk::InnerEvent::Pointer &event) { StopDtmfResponse(event); };
93     requestFuncMap_[RadioEvent::RADIO_CURRENT_CALLS] =
94         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetCsCallsDataResponse(event); };
95     requestFuncMap_[RadioEvent::RADIO_GET_CALL_FAIL_REASON] =
96         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetCallFailReasonResponse(event); };
97     requestFuncMap_[RadioEvent::RADIO_RECV_CALL_MEDIA_MODE_REQUEST] =
98         [this](const AppExecFwk::InnerEvent::Pointer &event) { ReceiveUpdateCallMediaModeRequest(event); };
99     requestFuncMap_[RadioEvent::RADIO_RECV_CALL_MEDIA_MODE_RESPONSE] =
100         [this](const AppExecFwk::InnerEvent::Pointer &event) { ReceiveUpdateCallMediaModeResponse(event); };
101     requestFuncMap_[RadioEvent::RADIO_CALL_SESSION_EVENT_CHANGED] =
102         [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleCallSessionEventChanged(event); };
103     requestFuncMap_[RadioEvent::RADIO_CALL_PEER_DIMENSIONS_CHANGED] =
104         [this](const AppExecFwk::InnerEvent::Pointer &event) { HandlePeerDimensionsChanged(event); };
105     requestFuncMap_[RadioEvent::RADIO_CALL_DATA_USAGE_CHANGED] =
106         [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleCallDataUsageChanged(event); };
107     requestFuncMap_[RadioEvent::RADIO_CAMERA_CAPABILITIES_CHANGED] =
108         [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleCameraCapabilitiesChanged(event); };
109     requestFuncMap_[RadioEvent::RADIO_IMS_GET_CALL_DATA] =
110         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetImsCallsDataResponse(event); };
111 }
112 
InitConfigFuncMap()113 void CellularCallHandler::InitConfigFuncMap()
114 {
115     requestFuncMap_[RadioEvent::RADIO_SET_CMUT] =
116         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetMuteResponse(event); };
117     requestFuncMap_[RadioEvent::RADIO_GET_CMUT] =
118         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetMuteResponse(event); };
119     requestFuncMap_[RadioEvent::RADIO_SET_CALL_PREFERENCE_MODE] =
120         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetDomainPreferenceModeResponse(event); };
121     requestFuncMap_[RadioEvent::RADIO_GET_CALL_PREFERENCE_MODE] =
122         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetDomainPreferenceModeResponse(event); };
123     requestFuncMap_[RadioEvent::RADIO_SET_IMS_SWITCH_STATUS] =
124         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetImsSwitchStatusResponse(event); };
125     requestFuncMap_[RadioEvent::RADIO_GET_IMS_SWITCH_STATUS] =
126         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetImsSwitchStatusResponse(event); };
127     requestFuncMap_[RadioEvent::RADIO_SET_VONR_SWITCH_STATUS] =
128         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetVoNRSwitchStatusResponse(event); };
129     requestFuncMap_[RadioEvent::RADIO_SET_EMERGENCY_CALL_LIST] =
130         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetEmergencyCallListResponse(event); };
131     requestFuncMap_[RadioEvent::RADIO_GET_EMERGENCY_CALL_LIST] =
132         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetEmergencyCallListResponse(event); };
133     requestFuncMap_[OPERATOR_CONFIG_CHANGED_ID] =
134         [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleOperatorConfigChanged(event); };
135     requestFuncMap_[RadioEvent::RADIO_GET_IMS_CAPABILITY_FINISHED] =
136         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetImsCapResponse(event); };
137 }
138 
InitSupplementFuncMap()139 void CellularCallHandler::InitSupplementFuncMap()
140 {
141     requestFuncMap_[RadioEvent::RADIO_GET_CALL_WAIT] =
142         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetCallWaitingResponse(event); };
143     requestFuncMap_[RadioEvent::RADIO_SET_CALL_WAIT] =
144         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetCallWaitingResponse(event); };
145     requestFuncMap_[RadioEvent::RADIO_GET_CALL_FORWARD] =
146         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetCallTransferResponse(event); };
147     requestFuncMap_[RadioEvent::RADIO_SET_CALL_FORWARD] =
148         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetCallTransferInfoResponse(event); };
149     requestFuncMap_[RadioEvent::RADIO_GET_CALL_CLIP] =
150         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetClipResponse(event); };
151     requestFuncMap_[RadioEvent::RADIO_SET_CALL_CLIP] =
152         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetClipResponse(event); };
153     requestFuncMap_[RadioEvent::RADIO_GET_CALL_CLIR] =
154         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetClirResponse(event); };
155     requestFuncMap_[RadioEvent::RADIO_SET_CALL_CLIR] =
156         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetClirResponse(event); };
157     requestFuncMap_[RadioEvent::RADIO_IMS_GET_COLR] =
158         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetColrResponse(event); };
159     requestFuncMap_[RadioEvent::RADIO_IMS_SET_COLR] =
160         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetColrResponse(event); };
161     requestFuncMap_[RadioEvent::RADIO_IMS_GET_COLP] =
162         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetColpResponse(event); };
163     requestFuncMap_[RadioEvent::RADIO_IMS_SET_COLP] =
164         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetColpResponse(event); };
165     requestFuncMap_[RadioEvent::RADIO_GET_CALL_RESTRICTION] =
166         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetCallRestrictionResponse(event); };
167     requestFuncMap_[RadioEvent::RADIO_SET_CALL_RESTRICTION] =
168         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetCallRestrictionResponse(event); };
169     requestFuncMap_[RadioEvent::RADIO_SET_CALL_RESTRICTION_PWD] =
170         [this](const AppExecFwk::InnerEvent::Pointer &event) { SetBarringPasswordResponse(event); };
171     requestFuncMap_[RadioEvent::RADIO_SET_USSD] =
172         [this](const AppExecFwk::InnerEvent::Pointer &event) { SendUssdResponse(event); };
173     requestFuncMap_[MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID] =
174         [this](const AppExecFwk::InnerEvent::Pointer &event) { SendUnlockPinPukResponse(event); };
175     requestFuncMap_[RadioEvent::RADIO_CLOSE_UNFINISHED_USSD] =
176         [this](const AppExecFwk::InnerEvent::Pointer &event) { CloseUnFinishedUssdResponse(event); };
177 }
178 
InitActiveReportFuncMap()179 void CellularCallHandler::InitActiveReportFuncMap()
180 {
181     requestFuncMap_[RadioEvent::RADIO_CALL_STATUS_INFO] =
182         [this](const AppExecFwk::InnerEvent::Pointer &event) { CsCallStatusInfoReport(event); };
183     requestFuncMap_[RadioEvent::RADIO_IMS_CALL_STATUS_INFO] =
184         [this](const AppExecFwk::InnerEvent::Pointer &event) { ImsCallStatusInfoReport(event); };
185     requestFuncMap_[RadioEvent::RADIO_AVAIL] =
186         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetCsCallData(event); };
187     requestFuncMap_[RadioEvent::RADIO_NOT_AVAIL] =
188         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetCsCallData(event); };
189     requestFuncMap_[RadioEvent::RADIO_CALL_USSD_NOTICE] =
190         [this](const AppExecFwk::InnerEvent::Pointer &event) { UssdNotifyResponse(event); };
191     requestFuncMap_[RadioEvent::RADIO_CALL_RINGBACK_VOICE] =
192         [this](const AppExecFwk::InnerEvent::Pointer &event) { CallRingBackVoiceResponse(event); };
193     requestFuncMap_[RadioEvent::RADIO_CALL_SRVCC_STATUS] =
194         [this](const AppExecFwk::InnerEvent::Pointer &event) { UpdateSrvccStateReport(event); };
195     requestFuncMap_[RadioEvent::RADIO_CALL_SS_NOTICE] =
196         [this](const AppExecFwk::InnerEvent::Pointer &event) { SsNotifyResponse(event); };
197     requestFuncMap_[RadioEvent::RADIO_CALL_EMERGENCY_NUMBER_REPORT] =
198         [this](const AppExecFwk::InnerEvent::Pointer &event) { ReportEccChanged(event); };
199     requestFuncMap_[RadioEvent::RADIO_SIM_STATE_CHANGE] =
200         [this](const AppExecFwk::InnerEvent::Pointer &event) { SimStateChangeReport(event); };
201     requestFuncMap_[RadioEvent::RADIO_SIM_RECORDS_LOADED] =
202         [this](const AppExecFwk::InnerEvent::Pointer &event) { SimRecordsLoadedReport(event); };
203     requestFuncMap_[RadioEvent::RADIO_SIM_ACCOUNT_LOADED] =
204         [this](const AppExecFwk::InnerEvent::Pointer &event) { SimAccountLoadedReport(event); };
205     requestFuncMap_[RadioEvent::RADIO_CALL_RSRVCC_STATUS] =
206         [this](const AppExecFwk::InnerEvent::Pointer &event) { UpdateRsrvccStateReport(event); };
207     requestFuncMap_[RadioEvent::RADIO_RESIDENT_NETWORK_CHANGE] =
208         [this](const AppExecFwk::InnerEvent::Pointer &event) { ResidentNetworkChangeReport(event); };
209     requestFuncMap_[NETWORK_STATE_CHANGED] =
210         [this](const AppExecFwk::InnerEvent::Pointer &event) { NetworkStateChangeReport(event); };
211     requestFuncMap_[RadioEvent::RADIO_RIL_ADAPTER_HOST_DIED] =
212         [this](const AppExecFwk::InnerEvent::Pointer &event) { OnRilAdapterHostDied(event); };
213     requestFuncMap_[RadioEvent::RADIO_FACTORY_RESET] =
214         [this](const AppExecFwk::InnerEvent::Pointer &event) { FactoryReset(event); };
215     requestFuncMap_[RadioEvent::RADIO_NV_REFRESH_FINISHED] =
216         [this](const AppExecFwk::InnerEvent::Pointer &event) { NvCfgFinishedIndication(event); };
217     requestFuncMap_[RadioEvent::RADIO_GET_STATUS] =
218         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetRadioStateProcess(event); };
219     requestFuncMap_[RadioEvent::RADIO_STATE_CHANGED] =
220         [this](const AppExecFwk::InnerEvent::Pointer &event) { RadioStateChangeProcess(event); };
221 }
222 
InitSatelliteCallFuncMap()223 void CellularCallHandler::InitSatelliteCallFuncMap()
224 {
225     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_CALL_STATE_CHANGED] =
226         [this](const AppExecFwk::InnerEvent::Pointer &event) { SatelliteCallStatusInfoReport(event); };
227     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_DIAL] =
228         [this](const AppExecFwk::InnerEvent::Pointer &event) { DialSatelliteResponse(event); };
229     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_HANGUP] =
230         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
231     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_ANSWER] =
232         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
233     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_REJECT] =
234         [this](const AppExecFwk::InnerEvent::Pointer &event) { CommonResultResponse(event); };
235     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_GET_CALL_DATA] =
236         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetSatelliteCallsDataResponse(event); };
237     requestFuncMap_[GET_SATELLITE_CALL_DATA_ID] =
238         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetSatelliteCallsDataRequest(event); };
239 }
240 
InitAdditionalFuncMap()241 void CellularCallHandler::InitAdditionalFuncMap()
242 {
243     requestFuncMap_[GET_CS_CALL_DATA_ID] =
244         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetCsCallsDataRequest(event); };
245     requestFuncMap_[GET_IMS_CALL_DATA_ID] =
246         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetImsCallsDataRequest(event); };
247     requestFuncMap_[REGISTER_HANDLER_ID] =
248         [this](const AppExecFwk::InnerEvent::Pointer &event) { RegisterHandler(event); };
249     requestFuncMap_[MMIHandlerId::EVENT_MMI_Id] =
250         [this](const AppExecFwk::InnerEvent::Pointer &event) { GetMMIResponse(event); };
251     requestFuncMap_[DtmfHandlerId::EVENT_EXECUTE_POST_DIAL] =
252         [this](const AppExecFwk::InnerEvent::Pointer &event) { ExecutePostDial(event); };
253 }
254 
RegisterImsCallCallbackHandler()255 void CellularCallHandler::RegisterImsCallCallbackHandler()
256 {
257     // Register IMS
258     std::shared_ptr<ImsCallClient> imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
259     if (imsCallClient != nullptr) {
260         imsCallClient->RegisterImsCallCallbackHandler(slotId_, shared_from_this());
261     }
262 }
263 
RegisterSatelliteCallCallbackHandler()264 void CellularCallHandler::RegisterSatelliteCallCallbackHandler()
265 {
266     // Register Satellite
267     std::shared_ptr<SatelliteCallClient> satelliteCallClient = DelayedSingleton<SatelliteCallClient>::GetInstance();
268     if (satelliteCallClient != nullptr) {
269         satelliteCallClient->RegisterSatelliteCallCallbackHandler(slotId_, shared_from_this());
270     }
271 }
272 
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)273 void CellularCallHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
274 {
275     if (event == nullptr) {
276         TELEPHONY_LOGE("[slot%{public}d] event is null", slotId_);
277         return;
278     }
279 
280     uint32_t eventId = event->GetInnerEventId();
281     TELEPHONY_LOGD("[slot%{public}d] eventId = %{public}d", slotId_, eventId);
282 
283     auto itFunc = requestFuncMap_.find(event->GetInnerEventId());
284     if (itFunc != requestFuncMap_.end()) {
285         auto requestFunc = itFunc->second;
286         if (requestFunc != nullptr) {
287             return requestFunc(event);
288         }
289     }
290     TELEPHONY_LOGI("[slot%{public}d] Function not found, need check.", slotId_);
291 }
292 
OnReceiveEvent(const EventFwk::CommonEventData & data)293 void CellularCallHandler::OnReceiveEvent(const EventFwk::CommonEventData &data)
294 {
295     EventFwk::Want want = data.GetWant();
296     std::string action = want.GetAction();
297     auto operatorState = std::make_shared<int32_t>();
298     TELEPHONY_LOGI("[slot%{public}d] action=%{public}s code=%{public}d", slotId_, action.c_str(), data.GetCode());
299     if (action == EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED) {
300         int32_t slotId = want.GetIntParam(BROADCAST_ARG_SLOT_ID, DEFAULT_SIM_SLOT_ID);
301         int32_t state = want.GetIntParam(BROADCAST_ARG_OPERATOR_STATE, DEFAULT_OPERATOR_STATE);
302         if (slotId_ != slotId) {
303             return;
304         }
305         *operatorState = state;
306         TELEPHONY_LOGI("[slot%{public}d] state=%{public}d", slotId_, *operatorState);
307         this->SendEvent(OPERATOR_CONFIG_CHANGED_ID, operatorState, DELAY_TIME);
308     }
309     if (action == EventFwk::CommonEventSupport::COMMON_EVENT_NETWORK_STATE_CHANGED) {
310         int32_t slotId = want.GetIntParam(BROADCAST_ARG_SLOT_ID, DEFAULT_SIM_SLOT_ID);
311         if (slotId_ != slotId) {
312             return;
313         }
314         this->SendEvent(NETWORK_STATE_CHANGED, 0, Priority::HIGH);
315     }
316 }
317 
GetCsCallData(const AppExecFwk::InnerEvent::Pointer & event)318 void CellularCallHandler::GetCsCallData(const AppExecFwk::InnerEvent::Pointer &event)
319 {
320     this->SendEvent(GET_CS_CALL_DATA_ID, 0, Priority::HIGH);
321 }
322 
GetImsCallData(const AppExecFwk::InnerEvent::Pointer & event)323 void CellularCallHandler::GetImsCallData(const AppExecFwk::InnerEvent::Pointer &event)
324 {
325     this->SendEvent(GET_IMS_CALL_DATA_ID, 0, Priority::HIGH);
326 }
327 
GetSatelliteCallData(const AppExecFwk::InnerEvent::Pointer & event)328 void CellularCallHandler::GetSatelliteCallData(const AppExecFwk::InnerEvent::Pointer &event)
329 {
330     this->SendEvent(GET_SATELLITE_CALL_DATA_ID, 0, Priority::HIGH);
331 }
332 
CellularCallIncomingStartTrace(const int32_t state)333 void CellularCallHandler::CellularCallIncomingStartTrace(const int32_t state)
334 {
335     if (state == static_cast<int32_t>(TelCallState::CALL_STATUS_INCOMING)) {
336         StartAsyncTrace(HITRACE_TAG_OHOS, "CellularCallIncoming", getpid());
337     }
338 }
339 
CellularCallIncomingFinishTrace(const int32_t state)340 void CellularCallHandler::CellularCallIncomingFinishTrace(const int32_t state)
341 {
342     if (state == static_cast<int32_t>(TelCallState::CALL_STATUS_INCOMING)) {
343         FinishAsyncTrace(HITRACE_TAG_OHOS, "CellularCallIncoming", getpid());
344     }
345 }
346 
ReportCsCallsData(const CallInfoList & callInfoList)347 void CellularCallHandler::ReportCsCallsData(const CallInfoList &callInfoList)
348 {
349     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
350     if (serviceInstance == nullptr) {
351         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
352         return;
353     }
354     CallInfo callInfo;
355     std::vector<CallInfo>::const_iterator it = callInfoList.calls.begin();
356     for (; it != callInfoList.calls.end(); ++it) {
357         callInfo.state = (*it).state;
358     }
359     TELEPHONY_LOGI("[slot%{public}d] callInfoList.callSize:%{public}d", slotId_, callInfoList.callSize);
360     CellularCallIncomingStartTrace(callInfo.state);
361     auto csControl = serviceInstance->GetCsControl(slotId_);
362     currentCsCallInfoList_ = callInfoList;
363     if (callInfoList.callSize == 0) {
364         ReportNoCsCallsData(callInfoList, callInfo.state, csControl);
365         return;
366     }
367     if (isInCsRedial_) {
368         TELEPHONY_LOGI("[slot%{public}d] Ignore cs call state change during cs redial", slotId_);
369         return;
370     }
371     if (callInfoList.callSize == 1) {
372         if (csControl == nullptr) {
373             csControl = std::make_shared<CSControl>();
374             serviceInstance->SetCsControl(slotId_, csControl);
375         }
376     }
377     if (csControl == nullptr) {
378         TELEPHONY_LOGE("[slot%{public}d] cs_control is null", slotId_);
379         CellularCallIncomingFinishTrace(callInfo.state);
380         return;
381     }
382     if (csControl->ReportCsCallsData(slotId_, callInfoList) != TELEPHONY_SUCCESS) {
383         CellularCallIncomingFinishTrace(callInfo.state);
384     }
385 }
386 
ReportNoCsCallsData(const CallInfoList & callInfoList,const int32_t state,const std::shared_ptr<CSControl> & csControl)387 void CellularCallHandler::ReportNoCsCallsData(const CallInfoList &callInfoList, const int32_t state,
388     const std::shared_ptr<CSControl> &csControl)
389 {
390     if (isInCsRedial_) {
391         TELEPHONY_LOGI("[slot%{public}d] Ignore hangup during cs redial", slotId_);
392         isInCsRedial_ = false;
393         return;
394     }
395     if (csControl == nullptr) {
396         TELEPHONY_LOGE("[slot%{public}d] cs_control is null", slotId_);
397         CellularCallIncomingFinishTrace(state);
398         return;
399     }
400     if (csControl->ReportCsCallsData(slotId_, callInfoList) != TELEPHONY_SUCCESS) {
401         CellularCallIncomingFinishTrace(state);
402     }
403     if (!csControl->HasEndCallWithoutReason(callInfoList)) {
404         DelayedSingleton<CellularCallService>::GetInstance()->SetCsControl(slotId_, nullptr);
405     }
406 }
407 
ReportImsCallsData(const ImsCurrentCallList & imsCallInfoList)408 void CellularCallHandler::ReportImsCallsData(const ImsCurrentCallList &imsCallInfoList)
409 {
410     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
411     if (serviceInstance == nullptr) {
412         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
413         return;
414     }
415     ImsCurrentCall imsCallInfo;
416     std::vector<ImsCurrentCall>::const_iterator it = imsCallInfoList.calls.begin();
417     for (; it != imsCallInfoList.calls.end(); ++it) {
418         imsCallInfo.state = (*it).state;
419     }
420     TELEPHONY_LOGI("[slot%{public}d] imsCallInfoList.callSize:%{public}d", slotId_, imsCallInfoList.callSize);
421     CellularCallIncomingStartTrace(imsCallInfo.state);
422     auto imsControl = serviceInstance->GetImsControl(slotId_);
423     currentCallList_ = imsCallInfoList;
424     if (imsCallInfoList.callSize == 0) {
425         if (imsControl == nullptr) {
426             TELEPHONY_LOGE("[slot%{public}d] ims_control is null", slotId_);
427             return;
428         }
429         bool hasEndCallWithoutReason = imsControl->HasEndCallWithoutReason(imsCallInfoList);
430         if (imsControl->ReportImsCallsData(slotId_, imsCallInfoList, hasEndCallWithoutReason) != TELEPHONY_SUCCESS) {
431             CellularCallIncomingFinishTrace(imsCallInfo.state);
432         }
433         if (!hasEndCallWithoutReason) {
434             serviceInstance->SetImsControl(slotId_, nullptr);
435         }
436         return;
437     }
438     if (srvccState_ == SrvccState::STARTED) {
439         TELEPHONY_LOGI("[slot%{public}d] Ignore to report ims call state change during srvcc", slotId_);
440         return;
441     }
442     if (imsCallInfoList.callSize == 1) {
443         if (imsControl == nullptr) {
444             imsControl = std::make_shared<IMSControl>();
445             serviceInstance->SetImsControl(slotId_, imsControl);
446         }
447     }
448     if (imsControl == nullptr) {
449         TELEPHONY_LOGE("[slot%{public}d] ims_control is null", slotId_);
450         CellularCallIncomingFinishTrace(imsCallInfo.state);
451         return;
452     }
453     bool hasEndCallWithoutReason = imsControl->HasEndCallWithoutReason(imsCallInfoList);
454     if (imsControl->ReportImsCallsData(slotId_, imsCallInfoList, hasEndCallWithoutReason) != TELEPHONY_SUCCESS) {
455         CellularCallIncomingFinishTrace(imsCallInfo.state);
456     }
457 }
458 
GetCsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer & event)459 void CellularCallHandler::GetCsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event)
460 {
461     // Returns list of current calls of ME. If command succeeds but no calls are available,
462     // no information response is sent to TE. Refer subclause 9.2 for possible <err> values.
463     TELEPHONY_LOGI("[slot%{public}d] GetCsCallsDataResponse entry", slotId_);
464     auto callInfoList = event->GetSharedObject<CallInfoList>();
465     if (callInfoList == nullptr) {
466         TELEPHONY_LOGE("[slot%{public}d] Cannot get the callInfoList, need to get rilResponseInfo", slotId_);
467         auto rilResponseInfo = event->GetSharedObject<RadioResponseInfo>();
468         if (rilResponseInfo == nullptr) {
469             TELEPHONY_LOGE("[slot%{public}d] callInfoList and rilResponseInfo are null", slotId_);
470             return;
471         }
472         if (rilResponseInfo->error == ErrType::NONE) {
473             TELEPHONY_LOGE("[slot%{public}d] Failed to query the call list but no reason!", slotId_);
474             return;
475         }
476         CellularCallEventInfo eventInfo;
477         eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
478         eventInfo.eventId = RequestResultEventId::RESULT_GET_CURRENT_CALLS_FAILED;
479         if (registerInstance_ == nullptr) {
480             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
481             return;
482         }
483         registerInstance_->ReportEventResultInfo(eventInfo);
484         return;
485     }
486     ProcessCsPhoneNumber(*callInfoList);
487     ProcessRedundantCode(*callInfoList);
488     ReportCsCallsData(*callInfoList);
489 }
490 
GetImsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer & event)491 void CellularCallHandler::GetImsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event)
492 {
493     // Returns list of current calls of ME. If command succeeds but no calls are available,
494     // no information response is sent to TE. Refer subclause 9.2 for possible <err> values.
495     auto imsCallInfoList = event->GetSharedObject<ImsCurrentCallList>();
496     if (imsCallInfoList == nullptr) {
497         TELEPHONY_LOGE("[slot%{public}d] Cannot get the imsCallInfoList, need to get rilResponseInfo", slotId_);
498         auto rilResponseInfo = event->GetSharedObject<RadioResponseInfo>();
499         if (rilResponseInfo == nullptr) {
500             TELEPHONY_LOGE("[slot%{public}d] callInfoList and rilResponseInfo are null", slotId_);
501             return;
502         }
503         if (rilResponseInfo->error == ErrType::NONE) {
504             TELEPHONY_LOGE("[slot%{public}d] Failed to query the call list but no reason!", slotId_);
505             return;
506         }
507         if (registerInstance_ == nullptr) {
508             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
509             return;
510         }
511         registerInstance_->ReportGetCallDataResult(static_cast<int32_t>(rilResponseInfo->error));
512         return;
513     }
514     ProcessImsPhoneNumber(*imsCallInfoList);
515     ReportImsCallsData(*imsCallInfoList);
516 }
517 
DialResponse(const AppExecFwk::InnerEvent::Pointer & event)518 void CellularCallHandler::DialResponse(const AppExecFwk::InnerEvent::Pointer &event)
519 {
520     auto result = event->GetSharedObject<RadioResponseInfo>();
521     if (result == nullptr) {
522         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
523         return;
524     }
525     struct CallBehaviorParameterInfo info = { 0 };
526     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
527     if (callHiSysEvent == nullptr) {
528         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
529         return;
530     }
531     callHiSysEvent->GetCallParameterInfo(info);
532     if (result->error != ErrType::NONE) {
533         TELEPHONY_LOGE("[slot%{public}d] dial error:%{public}d", slotId_, result->error);
534         CellularCallEventInfo eventInfo;
535         eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
536 
537         /*
538          * 3GPP TS 27.007 V3.9.0 (2001-06)
539          * If ME has succeeded in establishing a logical link between application protocols and external interface,
540          * it will send CONNECT message to the TE. Otherwise, the NO CARRIER response will be returned.
541          */
542         if (result->error == ErrType::ERR_CMD_NO_CARRIER) {
543             eventInfo.eventId = RequestResultEventId::RESULT_DIAL_NO_CARRIER;
544         } else {
545             eventInfo.eventId = RequestResultEventId::RESULT_DIAL_SEND_FAILED;
546         }
547         if (registerInstance_ == nullptr) {
548             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
549             return;
550         }
551         registerInstance_->ReportEventResultInfo(eventInfo);
552         CellularCallHiSysEvent::WriteDialCallBehaviorEvent(info, CallResponseResult::COMMAND_FAILURE);
553     } else {
554         CellularCallHiSysEvent::WriteDialCallBehaviorEvent(info, CallResponseResult::COMMAND_SUCCESS);
555     }
556 }
557 
DialSatelliteResponse(const AppExecFwk::InnerEvent::Pointer & event)558 void CellularCallHandler::DialSatelliteResponse(const AppExecFwk::InnerEvent::Pointer &event)
559 {
560     auto result = event->GetSharedObject<RadioResponseInfo>();
561     if (result == nullptr) {
562         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
563         return;
564     }
565     struct CallBehaviorParameterInfo satelliteCallInfo = { 0 };
566     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
567     if (callHiSysEvent == nullptr) {
568         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
569         return;
570     }
571     callHiSysEvent->GetCallParameterInfo(satelliteCallInfo);
572     if (result->error != ErrType::NONE) {
573         TELEPHONY_LOGE("[slot%{public}d] dial error:%{public}d", slotId_, result->error);
574         CellularCallEventInfo eventInfo;
575         eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
576 
577         if (result->error == ErrType::ERR_CMD_NO_CARRIER) {
578             eventInfo.eventId = RequestResultEventId::RESULT_DIAL_NO_CARRIER;
579         } else {
580             eventInfo.eventId = RequestResultEventId::RESULT_DIAL_SEND_FAILED;
581         }
582         if (registerInstance_ == nullptr) {
583             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
584             return;
585         }
586         registerInstance_->ReportEventResultInfo(eventInfo);
587         CellularCallHiSysEvent::WriteDialCallBehaviorEvent(satelliteCallInfo, CallResponseResult::COMMAND_FAILURE);
588     } else {
589         CellularCallHiSysEvent::WriteDialCallBehaviorEvent(satelliteCallInfo, CallResponseResult::COMMAND_SUCCESS);
590     }
591 }
592 
GetSatelliteCallsDataResponse(const AppExecFwk::InnerEvent::Pointer & event)593 void CellularCallHandler::GetSatelliteCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event)
594 {
595     auto satelliteCallInfoList = event->GetSharedObject<SatelliteCurrentCallList>();
596     if (satelliteCallInfoList == nullptr) {
597         TELEPHONY_LOGE(
598             "[slot%{public}d] Cannot get the SatelliteCurrentCallList, need to create satelliteCallInfoList", slotId_);
599         satelliteCallInfoList = std::make_shared<SatelliteCurrentCallList>();
600     }
601     ReportSatelliteCallsData(*satelliteCallInfoList);
602 }
603 
ReportSatelliteCallsData(const SatelliteCurrentCallList & callInfoList)604 void CellularCallHandler::ReportSatelliteCallsData(const SatelliteCurrentCallList &callInfoList)
605 {
606     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
607     if (serviceInstance == nullptr) {
608         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
609         return;
610     }
611     auto satelliteControl = serviceInstance->GetSatelliteControl(slotId_);
612     SatelliteCurrentCall callInfo;
613     std::vector<SatelliteCurrentCall>::const_iterator it = callInfoList.calls.begin();
614     for (; it != callInfoList.calls.end(); ++it) {
615         callInfo.state = (*it).state;
616     }
617     TELEPHONY_LOGI("[slot%{public}d] callInfoList.callSize:%{public}d", slotId_, callInfoList.callSize);
618     CellularCallIncomingStartTrace(callInfo.state);
619     if (callInfoList.callSize == 0) {
620         if (satelliteControl == nullptr) {
621             TELEPHONY_LOGE("[slot%{public}d] satelliteControl is null", slotId_);
622             CellularCallIncomingFinishTrace(callInfo.state);
623             return;
624         }
625         if (satelliteControl->ReportSatelliteCallsData(slotId_, callInfoList) != TELEPHONY_SUCCESS) {
626             CellularCallIncomingFinishTrace(callInfo.state);
627         }
628         serviceInstance->SetSatelliteControl(slotId_, nullptr);
629         return;
630     }
631     if (callInfoList.callSize == 1) {
632         if (satelliteControl == nullptr) {
633             satelliteControl = std::make_shared<SatelliteControl>();
634             serviceInstance->SetSatelliteControl(slotId_, satelliteControl);
635         }
636     }
637     if (satelliteControl == nullptr) {
638         TELEPHONY_LOGE("[slot%{public}d] satelliteControl is null", slotId_);
639         CellularCallIncomingFinishTrace(callInfo.state);
640         return;
641     }
642     if (satelliteControl->ReportSatelliteCallsData(slotId_, callInfoList) != TELEPHONY_SUCCESS) {
643         CellularCallIncomingFinishTrace(callInfo.state);
644     }
645 }
646 
CommonResultEventHandling(const AppExecFwk::InnerEvent::Pointer & event,CellularCallEventInfo & eventInfo)647 void CellularCallHandler::CommonResultEventHandling(
648     const AppExecFwk::InnerEvent::Pointer &event, CellularCallEventInfo &eventInfo)
649 {
650     eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
651     switch (event->GetInnerEventId()) {
652         case RadioEvent::RADIO_HANGUP_CONNECT:
653             eventInfo.eventId = RequestResultEventId::RESULT_END_SEND_FAILED;
654             break;
655         case RadioEvent::RADIO_REJECT_CALL:
656             eventInfo.eventId = RequestResultEventId::RESULT_REJECT_SEND_FAILED;
657             break;
658         case RadioEvent::RADIO_ACCEPT_CALL:
659             eventInfo.eventId = RequestResultEventId::RESULT_ACCEPT_SEND_FAILED;
660             break;
661         case RadioEvent::RADIO_HOLD_CALL:
662             eventInfo.eventId = RequestResultEventId::RESULT_HOLD_SEND_FAILED;
663             break;
664         case RadioEvent::RADIO_ACTIVE_CALL:
665             eventInfo.eventId = RequestResultEventId::RESULT_ACTIVE_SEND_FAILED;
666             break;
667         case RadioEvent::RADIO_SWAP_CALL:
668             eventInfo.eventId = RequestResultEventId::RESULT_SWAP_SEND_FAILED;
669             break;
670         case RadioEvent::RADIO_COMBINE_CALL:
671         case RadioEvent::RADIO_JOIN_CALL:
672             eventInfo.eventId = RequestResultEventId::RESULT_COMBINE_SEND_FAILED;
673             break;
674         case RadioEvent::RADIO_SPLIT_CALL:
675             eventInfo.eventId = RequestResultEventId::RESULT_SPLIT_SEND_FAILED;
676             break;
677         case RadioEvent::RADIO_CALL_SUPPLEMENT:
678             eventInfo.eventId = RequestResultEventId::RESULT_SUPPLEMENT_SEND_FAILED;
679             break;
680         default:
681             break;
682     }
683 }
684 
CommonResultResponse(const AppExecFwk::InnerEvent::Pointer & event)685 void CellularCallHandler::CommonResultResponse(const AppExecFwk::InnerEvent::Pointer &event)
686 {
687     auto result = event->GetSharedObject<RadioResponseInfo>();
688     if (result == nullptr) {
689         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
690         return;
691     }
692     struct CallBehaviorParameterInfo info = { 0 };
693     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
694     if (callHiSysEvent == nullptr) {
695         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
696         return;
697     }
698     callHiSysEvent->GetCallParameterInfo(info);
699     if (result->error != ErrType::NONE) {
700         CellularCallEventInfo eventInfo;
701         eventInfo.eventId = RequestResultEventId::INVALID_REQUEST_RESULT_EVENT_ID;
702         CommonResultEventHandling(event, eventInfo);
703         if (eventInfo.eventId == RequestResultEventId::RESULT_END_SEND_FAILED ||
704             eventInfo.eventId == RequestResultEventId::RESULT_REJECT_SEND_FAILED) {
705             CellularCallHiSysEvent::WriteHangUpCallBehaviorEvent(info, CallResponseResult::COMMAND_FAILURE);
706         } else if (eventInfo.eventId == RequestResultEventId::RESULT_ACCEPT_SEND_FAILED) {
707             CellularCallHiSysEvent::WriteAnswerCallBehaviorEvent(info, CallResponseResult::COMMAND_FAILURE);
708         } else {
709             TELEPHONY_LOGW("[slot%{public}d] eventId is:%{public}d, not within the scope of processing", slotId_,
710                 eventInfo.eventId);
711         }
712         if (registerInstance_ == nullptr) {
713             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
714             return;
715         }
716         registerInstance_->ReportEventResultInfo(eventInfo);
717         return;
718     }
719     uint32_t id = event->GetInnerEventId();
720     if (id == RadioEvent::RADIO_HANGUP_CONNECT || id == RadioEvent::RADIO_REJECT_CALL) {
721         CellularCallHiSysEvent::WriteHangUpCallBehaviorEvent(info, CallResponseResult::COMMAND_SUCCESS);
722     } else if (id == RadioEvent::RADIO_ACCEPT_CALL) {
723         CellularCallHiSysEvent::WriteAnswerCallBehaviorEvent(info, CallResponseResult::COMMAND_SUCCESS);
724     } else {
725         TELEPHONY_LOGW("[slot%{public}d] id is:%{public}d, not within the scope of processing", slotId_, id);
726     }
727 }
728 
ExecutePostDial(const AppExecFwk::InnerEvent::Pointer & event)729 void CellularCallHandler::ExecutePostDial(const AppExecFwk::InnerEvent::Pointer &event)
730 {
731     auto postDialData = event->GetSharedObject<PostDialData>();
732     if (postDialData == nullptr) {
733         TELEPHONY_LOGE("[slot%{public}d] postDialData is null", slotId_);
734         return;
735     }
736     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
737     if (serviceInstance == nullptr) {
738         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
739         return;
740     }
741     int64_t callId = postDialData->callId;
742     if (postDialData->isIms) {
743         auto imsControl = serviceInstance->GetImsControl(slotId_);
744         if (imsControl == nullptr) {
745             TELEPHONY_LOGE("[slot%{public}d] imsControl is null", slotId_);
746             return;
747         }
748         imsControl->ExecutePostDial(slotId_, callId);
749     } else {
750         auto csControl = serviceInstance->GetCsControl(slotId_);
751         if (csControl == nullptr) {
752             TELEPHONY_LOGE("[slot%{public}d] csControl is null", slotId_);
753             return;
754         }
755         csControl->ExecutePostDial(slotId_, callId);
756     }
757 }
758 
SwapCallResponse(const AppExecFwk::InnerEvent::Pointer & event)759 void CellularCallHandler::SwapCallResponse(const AppExecFwk::InnerEvent::Pointer &event)
760 {
761     auto serviceInstence = DelayedSingleton<CellularCallService>::GetInstance();
762     if (serviceInstence == nullptr) {
763         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
764         return;
765     }
766     auto callType = event->GetParam();
767     std::shared_ptr<IMSControl> imsControl = nullptr;
768     if (callType == static_cast<int32_t>(CallType::TYPE_IMS)) {
769         imsControl = serviceInstence->GetImsControl(slotId_);
770         if (imsControl == nullptr) {
771             TELEPHONY_LOGE("[slot%{public}d] imsControl is null", slotId_);
772             return;
773         }
774         imsControl->RecoverPendingHold();
775     }
776     auto result = event->GetSharedObject<RadioResponseInfo>();
777     if (result == nullptr) {
778         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
779         return;
780     }
781     if (result->error != ErrType::NONE) {
782         CellularCallEventInfo eventInfo;
783         eventInfo.eventId = RequestResultEventId::INVALID_REQUEST_RESULT_EVENT_ID;
784         CommonResultEventHandling(event, eventInfo);
785         if (registerInstance_ == nullptr) {
786             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
787             return;
788         }
789         registerInstance_->ReportEventResultInfo(eventInfo);
790         return;
791     }
792     if (imsControl != nullptr) {
793         imsControl->DialAfterHold(slotId_);
794     }
795 }
796 
SendDtmfResponse(const AppExecFwk::InnerEvent::Pointer & event)797 void CellularCallHandler::SendDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event)
798 {
799     auto result = event->GetSharedObject<RadioResponseInfo>();
800     if (result == nullptr) {
801         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
802         return;
803     }
804 
805     std::shared_ptr<PostDialData> postDial = std::make_shared<PostDialData>();
806     postDial->callId = result->flag;
807     postDial->isIms = event->GetParam() == static_cast<int32_t>(CallType::TYPE_IMS);
808     this->SendEvent(EVENT_EXECUTE_POST_DIAL, postDial, DELAY_TIME);
809 
810     CellularCallEventInfo eventInfo;
811     eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
812     if (result->error != ErrType::NONE) {
813         eventInfo.eventId = RequestResultEventId::RESULT_SEND_DTMF_FAILED;
814     } else {
815         eventInfo.eventId = RequestResultEventId::RESULT_SEND_DTMF_SUCCESS;
816     }
817     if (registerInstance_ == nullptr) {
818         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
819         return;
820     }
821     registerInstance_->ReportEventResultInfo(eventInfo);
822 }
823 
StartDtmfResponse(const AppExecFwk::InnerEvent::Pointer & event)824 void CellularCallHandler::StartDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event)
825 {
826     auto result = event->GetSharedObject<RadioResponseInfo>();
827     if (result == nullptr) {
828         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
829         return;
830     }
831     if (registerInstance_ == nullptr) {
832         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
833         return;
834     }
835     registerInstance_->ReportStartDtmfResult(static_cast<int32_t>(result->error));
836 }
837 
SimStateChangeReport(const AppExecFwk::InnerEvent::Pointer & event)838 void CellularCallHandler::SimStateChangeReport(const AppExecFwk::InnerEvent::Pointer &event)
839 {
840     CellularCallConfig config;
841     config.HandleSimStateChanged(slotId_);
842 }
843 
FactoryReset(const AppExecFwk::InnerEvent::Pointer & event)844 void CellularCallHandler::FactoryReset(const AppExecFwk::InnerEvent::Pointer &event)
845 {
846     CellularCallConfig config;
847     config.HandleFactoryReset(slotId_);
848 }
849 
SimRecordsLoadedReport(const AppExecFwk::InnerEvent::Pointer & event)850 void CellularCallHandler::SimRecordsLoadedReport(const AppExecFwk::InnerEvent::Pointer &event)
851 {
852     CellularCallConfig config;
853     config.HandleSimRecordsLoaded(slotId_);
854 }
855 
SimAccountLoadedReport(const AppExecFwk::InnerEvent::Pointer & event)856 void CellularCallHandler::SimAccountLoadedReport(const AppExecFwk::InnerEvent::Pointer &event)
857 {
858     CellularCallConfig config;
859     config.HandleSimAccountLoaded(slotId_);
860 }
861 
ResidentNetworkChangeReport(const AppExecFwk::InnerEvent::Pointer & event)862 void CellularCallHandler::ResidentNetworkChangeReport(const AppExecFwk::InnerEvent::Pointer &event)
863 {
864     if (event == nullptr) {
865         TELEPHONY_LOGE("ResidentNetworkChangeReport event is nullptr slotId:%{public}d!", slotId_);
866         return;
867     }
868     auto result = event->GetSharedObject<std::string>();
869     if (result == nullptr) {
870         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
871         return;
872     }
873     CellularCallConfig config;
874     config.HandleResidentNetworkChange(slotId_, *result);
875 }
876 
NetworkStateChangeReport(const AppExecFwk::InnerEvent::Pointer & event)877 void CellularCallHandler::NetworkStateChangeReport(const AppExecFwk::InnerEvent::Pointer &event)
878 {
879     if (event == nullptr) {
880         TELEPHONY_LOGE("NetworkStateChangeReport event is nullptr slotId:%{public}d!", slotId_);
881         return;
882     }
883     CellularCallConfig config;
884     config.HandleNetworkStateChange(slotId_);
885 }
886 
StopDtmfResponse(const AppExecFwk::InnerEvent::Pointer & event)887 void CellularCallHandler::StopDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event)
888 {
889     auto result = event->GetSharedObject<RadioResponseInfo>();
890     if (result == nullptr) {
891         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
892         return;
893     }
894     if (registerInstance_ == nullptr) {
895         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
896         return;
897     }
898     registerInstance_->ReportStopDtmfResult(static_cast<int32_t>(result->error));
899 }
900 
ReceiveUpdateCallMediaModeRequest(const AppExecFwk::InnerEvent::Pointer & event)901 void CellularCallHandler::ReceiveUpdateCallMediaModeRequest(const AppExecFwk::InnerEvent::Pointer &event)
902 {
903     struct CallBehaviorParameterInfo info = { 0 };
904     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
905     if (callHiSysEvent == nullptr) {
906         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
907         return;
908     }
909     callHiSysEvent->GetCallParameterInfo(info);
910     auto result = event->GetSharedObject<ImsCallModeReceiveInfo>();
911     if (result == nullptr) {
912         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
913         return;
914     }
915     if (registerInstance_ == nullptr) {
916         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
917         return;
918     }
919     registerInstance_->ReceiveUpdateCallMediaModeRequest(slotId_, *result);
920     int32_t requestResult = static_cast<ImsCallModeRequestResult>(result->result);
921     CellularCallHiSysEvent::WriteImsCallModeBehaviorEvent(
922         CallModeBehaviorType::RECEIVE_REQUEST_EVENT, info, requestResult);
923 }
924 
ReceiveUpdateCallMediaModeResponse(const AppExecFwk::InnerEvent::Pointer & event)925 void CellularCallHandler::ReceiveUpdateCallMediaModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
926 {
927     struct CallBehaviorParameterInfo info = { 0 };
928     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
929     if (callHiSysEvent == nullptr) {
930         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
931         return;
932     }
933     callHiSysEvent->GetCallParameterInfo(info);
934     auto result = event->GetSharedObject<ImsCallModeReceiveInfo>();
935     if (result == nullptr) {
936         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
937         return;
938     }
939     if (registerInstance_ == nullptr) {
940         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
941         return;
942     }
943     registerInstance_->ReceiveUpdateCallMediaModeResponse(slotId_, *result);
944     info.videoState = static_cast<ImsCallType>(result->callType);
945     int32_t requestResult = static_cast<ImsCallModeRequestResult>(result->result);
946     CellularCallHiSysEvent::WriteImsCallModeBehaviorEvent(
947         CallModeBehaviorType::RECEIVE_RESPONSE_EVENT, info, requestResult);
948 }
949 
HandleCallSessionEventChanged(const AppExecFwk::InnerEvent::Pointer & event)950 void CellularCallHandler::HandleCallSessionEventChanged(const AppExecFwk::InnerEvent::Pointer &event)
951 {
952     auto result = event->GetSharedObject<ImsCallSessionEventInfo>();
953     if (result == nullptr) {
954         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
955         return;
956     }
957     if (registerInstance_ == nullptr) {
958         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
959         return;
960     }
961     registerInstance_->HandleCallSessionEventChanged(*result);
962 }
963 
HandlePeerDimensionsChanged(const AppExecFwk::InnerEvent::Pointer & event)964 void CellularCallHandler::HandlePeerDimensionsChanged(const AppExecFwk::InnerEvent::Pointer &event)
965 {
966     auto result = event->GetSharedObject<ImsCallPeerDimensionsInfo>();
967     if (result == nullptr) {
968         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
969         return;
970     }
971     if (registerInstance_ == nullptr) {
972         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
973         return;
974     }
975     registerInstance_->HandlePeerDimensionsChanged(*result);
976 }
977 
HandleCallDataUsageChanged(const AppExecFwk::InnerEvent::Pointer & event)978 void CellularCallHandler::HandleCallDataUsageChanged(const AppExecFwk::InnerEvent::Pointer &event)
979 {
980     auto result = event->GetSharedObject<ImsCallDataUsageInfo>();
981     if (result == nullptr) {
982         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
983         return;
984     }
985     if (registerInstance_ == nullptr) {
986         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
987         return;
988     }
989     registerInstance_->HandleCallDataUsageChanged(*result);
990 }
991 
HandleCameraCapabilitiesChanged(const AppExecFwk::InnerEvent::Pointer & event)992 void CellularCallHandler::HandleCameraCapabilitiesChanged(const AppExecFwk::InnerEvent::Pointer &event)
993 {
994     auto result = event->GetSharedObject<CameraCapabilitiesInfo>();
995     if (result == nullptr) {
996         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
997         return;
998     }
999     if (registerInstance_ == nullptr) {
1000         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1001         return;
1002     }
1003     registerInstance_->HandleCameraCapabilitiesChanged(*result);
1004 }
1005 
SetSlotId(int32_t id)1006 void CellularCallHandler::SetSlotId(int32_t id)
1007 {
1008     slotId_ = id;
1009 }
1010 
GetSlotId()1011 int32_t CellularCallHandler::GetSlotId()
1012 {
1013     return slotId_;
1014 }
1015 
CurrentTimeMillis()1016 int64_t CellularCallHandler::CurrentTimeMillis()
1017 {
1018     int64_t timems =
1019         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
1020             .count();
1021     return timems;
1022 }
1023 
GetCsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer & event)1024 void CellularCallHandler::GetCsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event)
1025 {
1026     lastCallsDataFlag_ = CurrentTimeMillis();
1027     CellularCallConnectionCS connectionCs;
1028     connectionCs.GetCsCallsDataRequest(slotId_, lastCallsDataFlag_);
1029 }
1030 
GetImsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer & event)1031 void CellularCallHandler::GetImsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event)
1032 {
1033     lastCallsDataFlag_ = CurrentTimeMillis();
1034     CellularCallConnectionIMS connectionIms;
1035     connectionIms.GetImsCallsDataRequest(slotId_, lastCallsDataFlag_);
1036 }
1037 
GetSatelliteCallsDataRequest(const AppExecFwk::InnerEvent::Pointer & event)1038 void CellularCallHandler::GetSatelliteCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event)
1039 {
1040     lastCallsDataFlag_ = CurrentTimeMillis();
1041     CellularCallConnectionSatellite connectionSatellite;
1042     connectionSatellite.GetSatelliteCallsDataRequest(slotId_, lastCallsDataFlag_);
1043 }
1044 
RegisterHandler(const AppExecFwk::InnerEvent::Pointer & event)1045 void CellularCallHandler::RegisterHandler(const AppExecFwk::InnerEvent::Pointer &event)
1046 {
1047     CellularCallConnectionCS connectionCs;
1048     connectionCs.RegisterHandler();
1049 }
1050 
SetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer & event)1051 void CellularCallHandler::SetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
1052 {
1053     auto info = event->GetSharedObject<RadioResponseInfo>();
1054     if (info == nullptr) {
1055         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1056         return;
1057     }
1058     CellularCallEventInfo eventInfo;
1059     eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
1060     if (info->error != ErrType::NONE) {
1061         eventInfo.eventId = RequestResultEventId::RESULT_SET_CALL_PREFERENCE_MODE_FAILED;
1062     } else {
1063         eventInfo.eventId = RequestResultEventId::RESULT_SET_CALL_PREFERENCE_MODE_SUCCESS;
1064 
1065         CellularCallConfig config;
1066         config.SetTempMode(slotId_);
1067     }
1068     if (registerInstance_ == nullptr) {
1069         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1070         return;
1071     }
1072     registerInstance_->ReportEventResultInfo(eventInfo);
1073 }
1074 
GetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer & event)1075 void CellularCallHandler::GetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
1076 {
1077     auto mode = event->GetSharedObject<int32_t>();
1078     if (mode == nullptr) {
1079         TELEPHONY_LOGI("[slot%{public}d] mode is null", slotId_);
1080         return;
1081     }
1082     CellularCallConfig config;
1083     config.GetDomainPreferenceModeResponse(slotId_, *mode);
1084 }
1085 
SetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer & event)1086 void CellularCallHandler::SetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event)
1087 {
1088     auto info = event->GetSharedObject<RadioResponseInfo>();
1089     if (info == nullptr) {
1090         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1091         return;
1092     }
1093     if (registerInstance_ == nullptr) {
1094         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1095         return;
1096     }
1097     CellularCallConfig config;
1098     config.HandleSetLteImsSwitchResult(slotId_, info->error);
1099 }
1100 
GetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer & event)1101 void CellularCallHandler::GetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event)
1102 {
1103     // get imsswitch from modem. maybe response error, the error will be in RadioResponseInfo
1104     auto info = event->GetSharedObject<RadioResponseInfo>();
1105     if (info == nullptr) {
1106         // if dont have modem error, the response just contain the imsswitch active state.
1107         auto active = event->GetSharedObject<int32_t>();
1108         if (active == nullptr) {
1109             return;
1110         }
1111         CellularCallConfig config;
1112         bool isVolteSupport = config.IsVolteSupport(slotId_);
1113         TELEPHONY_LOGI("[slot%{public}d] GetImsSwitchStatusResponse active %{public}d, isVolteSupport %{public}d",
1114             slotId_, *active, isVolteSupport);
1115         if (static_cast<int>(*active) != static_cast<int>(isVolteSupport)) {
1116             UpdateImsConfiguration();
1117         }
1118         return;
1119     }
1120     UpdateImsConfiguration();
1121 }
1122 
SetVoNRSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer & event)1123 void CellularCallHandler::SetVoNRSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event)
1124 {
1125     auto info = event->GetSharedObject<RadioResponseInfo>();
1126     if (info == nullptr) {
1127         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1128         return;
1129     }
1130     CellularCallConfig config;
1131     config.HandleSetVoNRSwitchResult(slotId_, info->error);
1132 }
1133 
CsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer & event)1134 void CellularCallHandler::CsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event)
1135 {
1136     TELEPHONY_LOGI("[slot%{public}d] CsCallStatusInfoReport entry", slotId_);
1137     if (srvccState_ == SrvccState::STARTED) {
1138         TELEPHONY_LOGI("[slot%{public}d] Ignore to report cs call state change cause by srvcc started", slotId_);
1139         return;
1140     }
1141     GetCsCallData(event);
1142 }
1143 
ImsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer & event)1144 void CellularCallHandler::ImsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event)
1145 {
1146     GetImsCallData(event);
1147 }
1148 
SatelliteCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer & event)1149 void CellularCallHandler::SatelliteCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event)
1150 {
1151     if (srvccState_ == SrvccState::STARTED) {
1152         TELEPHONY_LOGI("[slot%{public}d] Ignore to report satellite call state change cause by srvcc started", slotId_);
1153         return;
1154     }
1155     GetSatelliteCallData(event);
1156 }
1157 
UssdNotifyResponse(const AppExecFwk::InnerEvent::Pointer & event)1158 void CellularCallHandler::UssdNotifyResponse(const AppExecFwk::InnerEvent::Pointer &event)
1159 {
1160     auto result = event->GetSharedObject<UssdNoticeInfo>();
1161     if (result == nullptr) {
1162         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1163         return;
1164     }
1165     CellularCallSupplement supplement;
1166     supplement.EventUssdNotify(*result, slotId_);
1167 }
1168 
SetMuteResponse(const AppExecFwk::InnerEvent::Pointer & event)1169 void CellularCallHandler::SetMuteResponse(const AppExecFwk::InnerEvent::Pointer &event)
1170 {
1171     auto info = event->GetSharedObject<RadioResponseInfo>();
1172     if (info == nullptr) {
1173         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1174         return;
1175     }
1176     MuteControlResponse response;
1177     if (registerInstance_ == nullptr) {
1178         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1179         return;
1180     }
1181     response.result = static_cast<int32_t>(info->error);
1182     registerInstance_->ReportSetMuteResult(response);
1183 }
1184 
GetMuteResponse(const AppExecFwk::InnerEvent::Pointer & event)1185 void CellularCallHandler::GetMuteResponse(const AppExecFwk::InnerEvent::Pointer &event)
1186 {
1187     MuteControlResponse response;
1188     auto mute = event->GetSharedObject<int32_t>();
1189     if (mute == nullptr) {
1190         TELEPHONY_LOGI("[slot%{public}d] mute is null", slotId_);
1191         auto info = event->GetSharedObject<RadioResponseInfo>();
1192         if (info == nullptr) {
1193             TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1194             return;
1195         }
1196         response.result = static_cast<int32_t>(info->error);
1197     } else {
1198         response.result = static_cast<int32_t>(ErrType::NONE);
1199         response.value = *mute;
1200     }
1201     if (registerInstance_ == nullptr) {
1202         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1203         return;
1204     }
1205     registerInstance_->ReportGetMuteResult(response);
1206 }
1207 
GetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer & event)1208 void CellularCallHandler::GetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer &event)
1209 {
1210     auto eccList = event->GetSharedObject<EmergencyInfoList>();
1211     if (eccList == nullptr) {
1212         TELEPHONY_LOGE("[slot%{public}d] eccList is null", slotId_);
1213         return;
1214     }
1215     CellularCallConfig config;
1216     config.UpdateEmergencyCallFromRadio(slotId_, *eccList);
1217 }
1218 
SetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer & event)1219 void CellularCallHandler::SetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer &event)
1220 {
1221     auto info = event->GetSharedObject<RadioResponseInfo>();
1222     if (info == nullptr) {
1223         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1224         return;
1225     }
1226     if (registerInstance_ == nullptr) {
1227         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1228         return;
1229     }
1230     SetEccListResponse response;
1231     response.result = static_cast<int32_t>(info->error);
1232     registerInstance_->ReportSetEmergencyCallListResponse(response);
1233 }
1234 
CallRingBackVoiceResponse(const AppExecFwk::InnerEvent::Pointer & event)1235 void CellularCallHandler::CallRingBackVoiceResponse(const AppExecFwk::InnerEvent::Pointer &event)
1236 {
1237     auto ringBackVoice = event->GetSharedObject<RingbackVoice>();
1238     if (ringBackVoice == nullptr) {
1239         TELEPHONY_LOGE("[slot%{public}d] ringBackVoice is null", slotId_);
1240         return;
1241     }
1242     if (registerInstance_ == nullptr) {
1243         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1244         return;
1245     }
1246     registerInstance_->ReportCallRingBackResult(ringBackVoice->status);
1247 }
1248 
GetCallFailReasonResponse(const AppExecFwk::InnerEvent::Pointer & event)1249 void CellularCallHandler::GetCallFailReasonResponse(const AppExecFwk::InnerEvent::Pointer &event)
1250 {
1251     auto reason = event->GetSharedObject<int32_t>();
1252     DisconnectedDetails details;
1253     if (reason == nullptr) {
1254         auto info = event->GetSharedObject<DisconnectedDetails>();
1255         if (info == nullptr) {
1256             TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1257             HandleCallDisconnectReason(RilDisconnectedReason::DISCONNECTED_REASON_NORMAL, "");
1258             return;
1259         }
1260         details.reason = static_cast<DisconnectedReason>(info->reason);
1261         details.message = (info->message.c_str() == nullptr) ? "" : info->message;
1262     } else {
1263         details.reason = static_cast<DisconnectedReason>(*reason);
1264         details.message = "";
1265     }
1266 
1267     if (details.message.empty()) {
1268         std::string callFailedMessageName = "";
1269         bool ret =
1270             ResourceUtils::Get().GetCallFailedMessageName(static_cast<int32_t>(details.reason), callFailedMessageName);
1271         if (!ret) {
1272             TELEPHONY_LOGE("[slot%{public}d] Get call failed message failed!", slotId_);
1273             HandleCallDisconnectReason(RilDisconnectedReason::DISCONNECTED_REASON_NORMAL, "");
1274             return;
1275         }
1276         ResourceUtils::Get().GetStringValueByName(callFailedMessageName, details.message);
1277     }
1278     CellularCallHiSysEvent::WriteCallEndBehaviorEvent(slotId_, static_cast<int32_t>(details.reason));
1279     if (registerInstance_ != nullptr) {
1280         registerInstance_->ReportCallFailReason(details);
1281     }
1282     TELEPHONY_LOGI("GetCallFailReasonResponse reason[%{public}d], message[%{public}s]",
1283         static_cast<int32_t>(details.reason), details.message.c_str());
1284     HandleCallDisconnectReason(static_cast<RilDisconnectedReason>(details.reason), details.message);
1285 }
1286 
UpdateSrvccStateReport(const AppExecFwk::InnerEvent::Pointer & event)1287 void CellularCallHandler::UpdateSrvccStateReport(const AppExecFwk::InnerEvent::Pointer &event)
1288 {
1289     auto srvccStatus = event->GetSharedObject<SrvccStatus>();
1290     if (srvccStatus == nullptr) {
1291         TELEPHONY_LOGE("[slot%{public}d] srvccStatus is null", slotId_);
1292         return;
1293     }
1294     TELEPHONY_LOGI("[slot%{public}d] srvccStatus is %{public}d", slotId_, srvccStatus->status);
1295     srvccState_ = srvccStatus->status;
1296     auto serviceInstance_ = DelayedSingleton<CellularCallService>::GetInstance();
1297     if (registerInstance_ == nullptr) {
1298         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1299         return;
1300     }
1301     serviceInstance_->SetSrvccState(srvccState_);
1302     if (srvccState_ != SrvccState::COMPLETED) {
1303         TELEPHONY_LOGE("[slot%{public}d] srvccState_ != SrvccState::COMPLETED", slotId_);
1304         return;
1305     }
1306     SrvccStateCompleted();
1307 }
1308 
ReportEccChanged(const AppExecFwk::InnerEvent::Pointer & event)1309 void CellularCallHandler::ReportEccChanged(const AppExecFwk::InnerEvent::Pointer &event)
1310 {
1311     auto emergencyInfoList = event->GetSharedObject<EmergencyInfoList>();
1312     if (emergencyInfoList == nullptr) {
1313         TELEPHONY_LOGE("[slot%{public}d] emergencyInfoList is null", slotId_);
1314         return;
1315     }
1316     CellularCallConfig config;
1317     auto calls = emergencyInfoList->calls;
1318     if (calls.size() > 0 && static_cast<uint32_t>(calls.back().total) != calls.size()) {
1319         TELEPHONY_LOGE("[slot%{public}d] data error", slotId_);
1320         auto endCall = calls.back();
1321         if (endCall.index < endCall.total) {
1322             return;
1323         }
1324         TELEPHONY_LOGI("[slot%{public}d] try query", slotId_);
1325         config.GetEmergencyCallList(slotId_);
1326         return;
1327     }
1328     config.UpdateEmergencyCallFromRadio(slotId_, *emergencyInfoList);
1329 }
1330 
SrvccStateCompleted()1331 void CellularCallHandler::SrvccStateCompleted()
1332 {
1333     if (srvccState_ != SrvccState::COMPLETED) {
1334         TELEPHONY_LOGE("[slot%{public}d] srvccState_ != SrvccState::COMPLETED", slotId_);
1335         return;
1336     }
1337     auto serviceInstance_ = DelayedSingleton<CellularCallService>::GetInstance();
1338     if (serviceInstance_ == nullptr) {
1339         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1340         return;
1341     }
1342     auto csControl = serviceInstance_->GetCsControl(slotId_);
1343     if (csControl != nullptr) {
1344         TELEPHONY_LOGI("[slot%{public}d] CsControl ReleaseAllConnection", slotId_);
1345         csControl->ReleaseAllConnection();
1346         serviceInstance_->SetCsControl(slotId_, nullptr);
1347     } else {
1348         TELEPHONY_LOGI("[slot%{public}d] CsControl is null", slotId_);
1349         csControl = std::make_shared<CSControl>();
1350         serviceInstance_->SetCsControl(slotId_, csControl);
1351     }
1352     auto imsControl = serviceInstance_->GetImsControl(slotId_);
1353     if (imsControl != nullptr) {
1354         TELEPHONY_LOGI("[slot%{public}d] ImsControl ReleaseAllConnection", slotId_);
1355         imsControl->ReleaseAllConnection();
1356         serviceInstance_->SetImsControl(slotId_, nullptr);
1357     } else {
1358         TELEPHONY_LOGI("[slot%{public}d] imsControl is null", slotId_);
1359     }
1360     srvccState_ = SrvccState::SRVCC_NONE;
1361 }
1362 
GetMMIResponse(const AppExecFwk::InnerEvent::Pointer & event)1363 void CellularCallHandler::GetMMIResponse(const AppExecFwk::InnerEvent::Pointer &event)
1364 {
1365     std::unique_ptr<MMICodeUtils> mmiCodeUtils = event->GetUniqueObject<MMICodeUtils>();
1366     if (mmiCodeUtils == nullptr) {
1367         TELEPHONY_LOGE("[slot%{public}d] mmiCodeUtils is null", slotId_);
1368         return;
1369     }
1370     mmiCodeUtils->ExecuteMmiCode(slotId_);
1371 }
1372 
GetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer & event)1373 void CellularCallHandler::GetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer &event)
1374 {
1375     auto result = event->GetSharedObject<CallWaitResult>();
1376     if (result == nullptr) {
1377         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1378         return;
1379     }
1380     int32_t flag = SS_FROM_MMI_CODE;
1381     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->result.index, flag);
1382     if (ret != TELEPHONY_SUCCESS) {
1383         return;
1384     }
1385     CellularCallSupplement supplement;
1386     supplement.EventGetCallWaiting(*result, result->result.message, flag);
1387 }
1388 
ProcessRedundantCode(CallInfoList & callInfoList)1389 void CellularCallHandler::ProcessRedundantCode(CallInfoList &callInfoList)
1390 {
1391     if (callInfoList.callSize == 0 || callInfoList.calls.empty()) {
1392         return;
1393     }
1394 
1395     for (uint64_t i = 0; i < callInfoList.calls.size(); i++) {
1396         CallInfo callInfo = callInfoList.calls[i];
1397         std::regex phoneContextPattern(DUPLICATIVE_CN_INTERNATIONAL_NUMBER_PREFIX_FORMAT);
1398         if (callInfo.type == INTERNATION_CODE && std::regex_match(callInfo.number, phoneContextPattern)) {
1399             callInfoList.calls[i].number = callInfo.number.substr(0, 1) +
1400                 callInfo.number.substr(CN_INTERNATIONAL_NUMBER_PREFIX.length());
1401         }
1402     }
1403 }
1404 
replacePrefix(std::string & number)1405 void CellularCallHandler::replacePrefix(std::string &number)
1406 {
1407     std::u16string imsi;
1408     CoreManagerInner::GetInstance().GetIMSI(slotId_, imsi);
1409     if (imsi.empty()) {
1410         return;
1411     }
1412     // only 460 country code need replace prefix
1413     if (imsi.substr(0, 3) != u"460") {
1414         return;
1415     }
1416     std::string prefix1 = "0086";
1417     std::string prefix2 = "086";
1418     if (number.length() > prefix1.length() && number.compare(0, prefix1.length(), prefix1) == 0) {
1419         number.replace(0, prefix1.length(), CN_INTERNATIONAL_NUMBER_PREFIX);
1420         return;
1421     }
1422     if (number.length() > prefix2.length() && number.compare(0, prefix2.length(), prefix2) == 0) {
1423         number.replace(0, prefix2.length(), CN_INTERNATIONAL_NUMBER_PREFIX);
1424         return;
1425     }
1426 }
1427 
ProcessCsPhoneNumber(CallInfoList & list)1428 void CellularCallHandler::ProcessCsPhoneNumber(CallInfoList &list)
1429 {
1430     if (list.callSize == 0 || list.calls.empty()) {
1431         return;
1432     }
1433     for (uint64_t i = 0; i < list.calls.size(); i++) {
1434         replacePrefix(list.calls[i].number);
1435     }
1436 }
1437 
ProcessImsPhoneNumber(ImsCurrentCallList & list)1438 void CellularCallHandler::ProcessImsPhoneNumber(ImsCurrentCallList &list)
1439 {
1440     if (list.callSize == 0 || list.calls.empty()) {
1441         return;
1442     }
1443     for (uint64_t i = 0; i < list.calls.size(); i++) {
1444         replacePrefix(list.calls[i].number);
1445     }
1446 }
1447 
SetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer & event)1448 void CellularCallHandler::SetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer &event)
1449 {
1450     auto result = event->GetSharedObject<SsBaseResult>();
1451     if (result == nullptr) {
1452         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1453         return;
1454     }
1455     int32_t flag = SS_FROM_MMI_CODE;
1456     int32_t action = INVALID_INDEX;
1457     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag, action);
1458     if (ret != TELEPHONY_SUCCESS) {
1459         return;
1460     }
1461     CellularCallSupplement supplement;
1462     if (result->result != TELEPHONY_SUCCESS) {
1463         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1464     }
1465     supplement.EventSetCallWaiting(result->result, result->message, flag, action);
1466 }
1467 
GetClirResponse(const AppExecFwk::InnerEvent::Pointer & event)1468 void CellularCallHandler::GetClirResponse(const AppExecFwk::InnerEvent::Pointer &event)
1469 {
1470     auto getClirResult = event->GetSharedObject<GetClirResult>();
1471     if (getClirResult == nullptr) {
1472         TELEPHONY_LOGE("[slot%{public}d] getClirResult is null", slotId_);
1473         return;
1474     }
1475     int32_t flag = SS_FROM_MMI_CODE;
1476     int32_t ret = ConfirmAndRemoveSsRequestCommand(getClirResult->result.index, flag);
1477     if (ret != TELEPHONY_SUCCESS) {
1478         return;
1479     }
1480     CellularCallSupplement supplement;
1481     supplement.EventGetClir(*getClirResult, getClirResult->result.message, flag);
1482 }
1483 
SetClirResponse(const AppExecFwk::InnerEvent::Pointer & event)1484 void CellularCallHandler::SetClirResponse(const AppExecFwk::InnerEvent::Pointer &event)
1485 {
1486     auto result = event->GetSharedObject<SsBaseResult>();
1487     if (result == nullptr) {
1488         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1489         return;
1490     }
1491     int32_t flag = SS_FROM_MMI_CODE;
1492     int32_t action = INVALID_INDEX;
1493     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag, action);
1494     if (ret != TELEPHONY_SUCCESS) {
1495         return;
1496     }
1497     CellularCallSupplement supplement;
1498     supplement.EventSetClir(result->result, result->message, flag, action);
1499 }
1500 
GetClipResponse(const AppExecFwk::InnerEvent::Pointer & event)1501 void CellularCallHandler::GetClipResponse(const AppExecFwk::InnerEvent::Pointer &event)
1502 {
1503     auto getClipResult = event->GetSharedObject<GetClipResult>();
1504     if (getClipResult == nullptr) {
1505         TELEPHONY_LOGE("[slot%{public}d] getClipResult is null", slotId_);
1506         return;
1507     }
1508     int32_t flag = SS_FROM_MMI_CODE;
1509     int32_t ret = ConfirmAndRemoveSsRequestCommand(getClipResult->result.index, flag);
1510     if (ret != TELEPHONY_SUCCESS) {
1511         return;
1512     }
1513     CellularCallSupplement supplement;
1514     supplement.EventGetClip(*getClipResult, getClipResult->result.message, flag);
1515 }
1516 
SetClipResponse(const AppExecFwk::InnerEvent::Pointer & event)1517 void CellularCallHandler::SetClipResponse(const AppExecFwk::InnerEvent::Pointer &event)
1518 {
1519     auto result = event->GetSharedObject<SsBaseResult>();
1520     if (result == nullptr) {
1521         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1522         return;
1523     }
1524     int32_t flag = SS_FROM_MMI_CODE;
1525     int32_t action = INVALID_INDEX;
1526     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag, action);
1527     if (ret != TELEPHONY_SUCCESS) {
1528         return;
1529     }
1530     CellularCallSupplement supplement;
1531     supplement.EventSetClip(result->result, result->message, flag, action);
1532 }
1533 
GetColrResponse(const AppExecFwk::InnerEvent::Pointer & event)1534 void CellularCallHandler::GetColrResponse(const AppExecFwk::InnerEvent::Pointer &event)
1535 {
1536     auto colrResult = event->GetSharedObject<GetColrResult>();
1537     if (colrResult == nullptr) {
1538         TELEPHONY_LOGE("[slot%{public}d] colrResult is null", slotId_);
1539         return;
1540     }
1541     int32_t flag = SS_FROM_MMI_CODE;
1542     int32_t ret = ConfirmAndRemoveSsRequestCommand(colrResult->result.index, flag);
1543     if (ret != TELEPHONY_SUCCESS) {
1544         return;
1545     }
1546     CellularCallSupplement supplement;
1547     supplement.EventGetColr(*colrResult, colrResult->result.message, flag);
1548 }
1549 
SetColrResponse(const AppExecFwk::InnerEvent::Pointer & event)1550 void CellularCallHandler::SetColrResponse(const AppExecFwk::InnerEvent::Pointer &event)
1551 {
1552     auto result = event->GetSharedObject<SsBaseResult>();
1553     if (result == nullptr) {
1554         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1555         return;
1556     }
1557     int32_t flag = SS_FROM_MMI_CODE;
1558     int32_t action = INVALID_INDEX;
1559     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag, action);
1560     if (ret != TELEPHONY_SUCCESS) {
1561         return;
1562     }
1563     CellularCallSupplement supplement;
1564     supplement.EventSetColr(result->result, result->message, flag, action);
1565 }
1566 
GetColpResponse(const AppExecFwk::InnerEvent::Pointer & event)1567 void CellularCallHandler::GetColpResponse(const AppExecFwk::InnerEvent::Pointer &event)
1568 {
1569     auto colpResult = event->GetSharedObject<GetColpResult>();
1570     if (colpResult == nullptr) {
1571         TELEPHONY_LOGE("[slot%{public}d] colpResult is null", slotId_);
1572         return;
1573     }
1574     int32_t flag = SS_FROM_MMI_CODE;
1575     int32_t ret = ConfirmAndRemoveSsRequestCommand(colpResult->result.index, flag);
1576     if (ret != TELEPHONY_SUCCESS) {
1577         return;
1578     }
1579     CellularCallSupplement supplement;
1580     supplement.EventGetColp(*colpResult, colpResult->result.message, flag);
1581 }
1582 
SetColpResponse(const AppExecFwk::InnerEvent::Pointer & event)1583 void CellularCallHandler::SetColpResponse(const AppExecFwk::InnerEvent::Pointer &event)
1584 {
1585     auto result = event->GetSharedObject<SsBaseResult>();
1586     if (result == nullptr) {
1587         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1588         return;
1589     }
1590     int32_t flag = SS_FROM_MMI_CODE;
1591     int32_t action = INVALID_INDEX;
1592     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag, action);
1593     if (ret != TELEPHONY_SUCCESS) {
1594         return;
1595     }
1596     CellularCallSupplement supplement;
1597     supplement.EventSetColp(result->result, result->message, flag, action);
1598 }
1599 
GetCallTransferResponse(const AppExecFwk::InnerEvent::Pointer & event)1600 void CellularCallHandler::GetCallTransferResponse(const AppExecFwk::InnerEvent::Pointer &event)
1601 {
1602     auto cFQueryList = event->GetSharedObject<CallForwardQueryInfoList>();
1603     if (cFQueryList == nullptr) {
1604         TELEPHONY_LOGE("[slot%{public}d] cFQueryList is null", slotId_);
1605         return;
1606     }
1607     SsRequestCommand ss;
1608     int32_t ret = GetSsRequestCommand(cFQueryList->result.index, ss);
1609     if (ret == TELEPHONY_SUCCESS) {
1610         cFQueryList->result.reason = ss.cfReason;
1611     }
1612     int32_t flag = SS_FROM_MMI_CODE;
1613     ret = ConfirmAndRemoveSsRequestCommand(cFQueryList->result.index, flag);
1614     if (ret != TELEPHONY_SUCCESS) {
1615         return;
1616     }
1617     CellularCallSupplement supplement;
1618     supplement.EventGetCallTransferInfo(*cFQueryList, cFQueryList->result.message, flag);
1619 }
1620 
SetCallTransferInfoResponse(const AppExecFwk::InnerEvent::Pointer & event)1621 void CellularCallHandler::SetCallTransferInfoResponse(const AppExecFwk::InnerEvent::Pointer &event)
1622 {
1623     auto result = event->GetSharedObject<SsBaseResult>();
1624     if (result == nullptr) {
1625         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1626         return;
1627     }
1628     int32_t flag = SS_FROM_MMI_CODE;
1629     int32_t action = INVALID_INDEX;
1630     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag, action);
1631     if (ret != TELEPHONY_SUCCESS) {
1632         return;
1633     }
1634     CellularCallSupplement supplement;
1635     CallForwardingInfo info;
1636     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
1637     if (callHiSysEvent == nullptr) {
1638         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
1639         return;
1640     }
1641     callHiSysEvent->GetCallForwardingInfo(info);
1642     if (result->result == TELEPHONY_SUCCESS) {
1643         CoreManagerInner::GetInstance().SetVoiceCallForwarding(info.slotId, info.enable, info.number);
1644     } else {
1645         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1646     }
1647     supplement.EventSetCallTransferInfo(result->result, result->message, flag, action, info.number);
1648 }
1649 
GetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer & event)1650 void CellularCallHandler::GetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer &event)
1651 {
1652     auto result = event->GetSharedObject<CallRestrictionResult>();
1653     if (result == nullptr) {
1654         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1655         return;
1656     }
1657     int32_t flag = SS_FROM_MMI_CODE;
1658     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->result.index, flag);
1659     if (ret != TELEPHONY_SUCCESS) {
1660         return;
1661     }
1662     CellularCallSupplement supplement;
1663     supplement.EventGetCallRestriction(*result, result->result.message, flag);
1664 }
1665 
SetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer & event)1666 void CellularCallHandler::SetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer &event)
1667 {
1668     auto result = event->GetSharedObject<SsBaseResult>();
1669     if (result == nullptr) {
1670         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1671         return;
1672     }
1673     int32_t flag = SS_FROM_MMI_CODE;
1674     int32_t action = INVALID_INDEX;
1675     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag, action);
1676     if (ret != TELEPHONY_SUCCESS) {
1677         return;
1678     }
1679     CellularCallSupplement supplement;
1680     if (result->result != TELEPHONY_SUCCESS) {
1681         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1682     }
1683     supplement.EventSetCallRestriction(result->result, result->message, flag, action);
1684 }
1685 
SetBarringPasswordResponse(const AppExecFwk::InnerEvent::Pointer & event)1686 void CellularCallHandler::SetBarringPasswordResponse(const AppExecFwk::InnerEvent::Pointer &event)
1687 {
1688     auto result = event->GetSharedObject<SsBaseResult>();
1689     if (result == nullptr) {
1690         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1691         return;
1692     }
1693     int32_t flag = SS_FROM_MMI_CODE;
1694     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1695     if (ret != TELEPHONY_SUCCESS) {
1696         return;
1697     }
1698     CellularCallSupplement supplement;
1699     if (result->result != TELEPHONY_SUCCESS) {
1700         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1701     }
1702     supplement.EventSetBarringPassword(result->result, result->message, flag);
1703 }
1704 
SendUssdResponse(const AppExecFwk::InnerEvent::Pointer & event)1705 void CellularCallHandler::SendUssdResponse(const AppExecFwk::InnerEvent::Pointer &event)
1706 {
1707     auto result = event->GetSharedObject<RadioResponseInfo>();
1708     if (result == nullptr) {
1709         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1710         return;
1711     }
1712     CellularCallSupplement supplement;
1713     supplement.EventSendUssd(*result);
1714 }
1715 
SsNotifyResponse(const AppExecFwk::InnerEvent::Pointer & event)1716 void CellularCallHandler::SsNotifyResponse(const AppExecFwk::InnerEvent::Pointer &event)
1717 {
1718     auto result = event->GetSharedObject<SsNoticeInfo>();
1719     if (result == nullptr) {
1720         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1721         return;
1722     }
1723     CellularCallSupplement supplement;
1724     supplement.EventSsNotify(*result);
1725 }
1726 
SendUnlockPinPukResponse(const AppExecFwk::InnerEvent::Pointer & event)1727 void CellularCallHandler::SendUnlockPinPukResponse(const AppExecFwk::InnerEvent::Pointer &event)
1728 {
1729     auto result = event->GetSharedObject<PinPukResponse>();
1730     if (result == nullptr) {
1731         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1732         return;
1733     }
1734     CellularCallSupplement supplement;
1735     supplement.EventSetPinPuk(*result);
1736 }
1737 
HandleOperatorConfigChanged(const AppExecFwk::InnerEvent::Pointer & event)1738 void CellularCallHandler::HandleOperatorConfigChanged(const AppExecFwk::InnerEvent::Pointer &event)
1739 {
1740     auto state = event->GetSharedObject<int32_t>();
1741     if (state == nullptr) {
1742         TELEPHONY_LOGE("[slot%{public}d] state is null", slotId_);
1743         return;
1744     }
1745     CellularCallConfig config;
1746     config.HandleOperatorConfigChanged(slotId_, *state);
1747 }
1748 
UpdateRsrvccStateReport(const AppExecFwk::InnerEvent::Pointer & event)1749 void CellularCallHandler::UpdateRsrvccStateReport(const AppExecFwk::InnerEvent::Pointer &event)
1750 {
1751     isInCsRedial_ = true;
1752     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
1753     if (serviceInstance == nullptr) {
1754         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
1755         return;
1756     }
1757     serviceInstance->SetCsControl(slotId_, nullptr);
1758 }
1759 
RequestSsRequestCommandIndex(int32_t & index)1760 void CellularCallHandler::RequestSsRequestCommandIndex(int32_t &index)
1761 {
1762     if (indexCommand_ >= MAX_REQUEST_COUNT) {
1763         indexCommand_ = 0;
1764     } else {
1765         indexCommand_++;
1766     }
1767     index = indexCommand_;
1768 }
1769 
SaveSsRequestCommand(const std::shared_ptr<SsRequestCommand> & utCommand,int32_t index)1770 void CellularCallHandler::SaveSsRequestCommand(const std::shared_ptr<SsRequestCommand> &utCommand, int32_t index)
1771 {
1772     if (utCommand == nullptr) {
1773         TELEPHONY_LOGE("[slot%{public}d] utCommand is null", slotId_);
1774         return;
1775     }
1776     int32_t indexCommand = indexCommand_;
1777     std::lock_guard<std::mutex> lock(mutex_);
1778     utCommandMap_.insert(std::make_pair(indexCommand, utCommand));
1779 }
1780 
ConfirmAndRemoveSsRequestCommand(int32_t index,int32_t & flag)1781 int32_t CellularCallHandler::ConfirmAndRemoveSsRequestCommand(int32_t index, int32_t &flag)
1782 {
1783     if (index == INVALID_INDEX) {
1784         // -1 mean this command index wasn't come from app, so don't need report result
1785         TELEPHONY_LOGI("[slot%{public}d] index is invalid, nothing need to do", slotId_);
1786         return TELEPHONY_ERROR;
1787     }
1788     std::lock_guard<std::mutex> lock(mutex_);
1789     auto itor = utCommandMap_.find(index);
1790     if (itor == utCommandMap_.end()) {
1791         TELEPHONY_LOGE("[slot%{public}d] the index(%{public}d) in utCommandMap_ haven't been found", slotId_, index);
1792         return TELEPHONY_ERROR;
1793     }
1794     flag = itor->second->flag;
1795     utCommandMap_.erase(index);
1796     return TELEPHONY_SUCCESS;
1797 }
1798 
ConfirmAndRemoveSsRequestCommand(int32_t index,int32_t & flag,int32_t & action)1799 int32_t CellularCallHandler::ConfirmAndRemoveSsRequestCommand(int32_t index, int32_t &flag, int32_t &action)
1800 {
1801     if (index == INVALID_INDEX) {
1802         // -1 mean this command index wasn't come from app, so don't need report result
1803         TELEPHONY_LOGI("[slot%{public}d] index is invalid, nothing need to do", slotId_);
1804         return TELEPHONY_ERROR;
1805     }
1806     std::lock_guard<std::mutex> lock(mutex_);
1807     auto itor = utCommandMap_.find(index);
1808     if (itor == utCommandMap_.end()) {
1809         TELEPHONY_LOGE("[slot%{public}d] the index(%{public}d) in utCommandMap_ haven't been found", slotId_, index);
1810         return TELEPHONY_ERROR;
1811     }
1812     flag = itor->second->flag;
1813     action = itor->second->action;
1814     utCommandMap_.erase(index);
1815     return TELEPHONY_SUCCESS;
1816 }
1817 
GetSsRequestCommand(int32_t index,SsRequestCommand & ss)1818 int32_t CellularCallHandler::GetSsRequestCommand(int32_t index, SsRequestCommand &ss)
1819 {
1820     std::lock_guard<std::mutex> lock(mutex_);
1821     auto itor = utCommandMap_.find(index);
1822     if (itor == utCommandMap_.end()) {
1823         TELEPHONY_LOGE("[slot%{public}d] the index in utCommandMap_ haven't been found", slotId_);
1824         return TELEPHONY_ERROR;
1825     }
1826 
1827     ss.cfAction = itor->second->cfAction;
1828     ss.cfReason = itor->second->cfReason;
1829     ss.number = itor->second->number;
1830     ss.enable = itor->second->enable;
1831     ss.clirAction = itor->second->clirAction;
1832     ss.facility = itor->second->facility;
1833     if (strcpy_s(ss.password, sizeof(ss.password), itor->second->password) != EOK) {
1834         TELEPHONY_LOGE("password strcpy_s fail.");
1835         return TELEPHONY_ERR_STRCPY_FAIL;
1836     }
1837     ss.classType = itor->second->classType;
1838     ss.action = itor->second->action;
1839     ss.flag = itor->second->flag;
1840     return TELEPHONY_SUCCESS;
1841 }
1842 
CloseUnFinishedUssdResponse(const AppExecFwk::InnerEvent::Pointer & event)1843 void CellularCallHandler::CloseUnFinishedUssdResponse(const AppExecFwk::InnerEvent::Pointer &event)
1844 {
1845     auto result = event->GetSharedObject<RadioResponseInfo>();
1846     if (result == nullptr) {
1847         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1848         return;
1849     }
1850     CellularCallSupplement supplement;
1851     supplement.EventCloseUnFinishedUssd(*result);
1852 }
1853 
OnRilAdapterHostDied(const AppExecFwk::InnerEvent::Pointer & event)1854 void CellularCallHandler::OnRilAdapterHostDied(const AppExecFwk::InnerEvent::Pointer &event)
1855 {
1856     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
1857     if (serviceInstance == nullptr) {
1858         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
1859         return;
1860     }
1861     auto csControl = serviceInstance->GetCsControl(slotId_);
1862     if (csControl == nullptr) {
1863         TELEPHONY_LOGE("[slot%{public}d] cs_control is null", slotId_);
1864     } else if (csControl->ReportHangUpInfo(slotId_) != TELEPHONY_SUCCESS) {
1865         TELEPHONY_LOGE("[slot%{public}d] fail to disconnect cs calls", slotId_);
1866     } else {
1867         serviceInstance->SetCsControl(slotId_, nullptr);
1868     }
1869     auto imsControl = serviceInstance->GetImsControl(slotId_);
1870     if (imsControl == nullptr) {
1871         TELEPHONY_LOGE("[slot%{public}d] ims_control is null", slotId_);
1872     } else if (imsControl->ReportHangUpInfo(slotId_) != TELEPHONY_SUCCESS) {
1873         TELEPHONY_LOGE("[slot%{public}d] fail to disconnect ims calls", slotId_);
1874     } else {
1875         serviceInstance->SetImsControl(slotId_, nullptr);
1876     }
1877     auto satelliteControl = serviceInstance->GetSatelliteControl(slotId_);
1878     if (satelliteControl == nullptr) {
1879         TELEPHONY_LOGE("[slot%{public}d] satelliteControl is null", slotId_);
1880     } else if (satelliteControl->ReportHangUpInfo(slotId_) != TELEPHONY_SUCCESS) {
1881         TELEPHONY_LOGE("[slot%{public}d] fail to disconnect satellite calls", slotId_);
1882     } else {
1883         serviceInstance->SetSatelliteControl(slotId_, nullptr);
1884     }
1885 }
1886 
1887 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
StartCallManagerService()1888 void CellularCallHandler::StartCallManagerService()
1889 {
1890     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
1891     if (serviceInstance == nullptr) {
1892         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
1893         return;
1894     }
1895     serviceInstance->StartCallManagerService();
1896 }
1897 #endif
1898 
RadioStateChangeProcess(const AppExecFwk::InnerEvent::Pointer & event)1899 void CellularCallHandler::RadioStateChangeProcess(const AppExecFwk::InnerEvent::Pointer &event)
1900 {
1901     std::shared_ptr<Int32Parcel> object = event->GetSharedObject<Int32Parcel>();
1902     if (object == nullptr) {
1903         TELEPHONY_LOGE("[slot%{public}d] object is null", slotId_);
1904         return;
1905     }
1906     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
1907     if (serviceInstance == nullptr) {
1908         TELEPHONY_LOGE("serviceInstance get failed!");
1909         return;
1910     }
1911 
1912     TELEPHONY_LOGI("[slot%{public}d] Radio changed with state: %{public}d", slotId_, object->data);
1913     if (object->data == CORE_SERVICE_POWER_ON) {
1914 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
1915         StartCallManagerService();
1916 #endif
1917         serviceInstance->setRadioOnFlag(true, slotId_);
1918         GetImsSwitchStatusRequest();
1919 #ifdef BASE_POWER_IMPROVEMENT_FEATURE
1920         auto imsControl = serviceInstance->GetImsControl(slotId_);
1921         if (imsControl == nullptr) {
1922             TELEPHONY_LOGE("imsControl get failed!");
1923             return;
1924         }
1925 
1926         if (imsControl->isPendingEmcFlag()) {
1927             CellularCallInfo callInfo = imsControl->GetPendingEmcCallInfo();
1928             int32_t ret = imsControl->Dial(callInfo, true);
1929             if (ret != TELEPHONY_ERR_SUCCESS) {
1930                 imsControl->ReportHangUpInfo(slotId_);
1931                 TELEPHONY_LOGE("imsControl dial failed!");
1932                 imsControl->setPendingEmcFlag(false);
1933                 return;
1934             }
1935             imsControl->setPendingEmcFlag(false);
1936         }
1937 #endif
1938     } else {
1939         serviceInstance->setRadioOnFlag(false, slotId_);
1940     }
1941 }
1942 
GetRadioStateProcess(const AppExecFwk::InnerEvent::Pointer & event)1943 void CellularCallHandler::GetRadioStateProcess(const AppExecFwk::InnerEvent::Pointer &event)
1944 {
1945     auto object = event->GetUniqueObject<RadioStateInfo>();
1946     if (object == nullptr) {
1947         TELEPHONY_LOGE("object is null");
1948         return;
1949     }
1950     TELEPHONY_LOGI("GetRadioStateProcess [slot%{public}d], state=%{public}d", slotId_, object->state);
1951     if (object->state == CORE_SERVICE_POWER_ON) {
1952 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
1953         StartCallManagerService();
1954 #endif
1955     }
1956 }
1957 
NvCfgFinishedIndication(const AppExecFwk::InnerEvent::Pointer & event)1958 void CellularCallHandler::NvCfgFinishedIndication(const AppExecFwk::InnerEvent::Pointer &event)
1959 {
1960     std::shared_ptr<Int32Parcel> object = event->GetSharedObject<Int32Parcel>();
1961     if (object == nullptr) {
1962         TELEPHONY_LOGE("[slot%{public}d] object is null", slotId_);
1963         return;
1964     }
1965     TELEPHONY_LOGI("[slot%{public}d] NvCfgFinishedIndication state is %{public}d", slotId_, object->data);
1966     if (!(object->data == STATE_NV_REFRESH_FINISHED || object->data >= STATE_NV_REFRESH_ALREADY_FINISHED)) {
1967         return;
1968     }
1969     bool hasSimCard = false;
1970     CoreManagerInner::GetInstance().HasSimCard(slotId_, hasSimCard);
1971     if (!hasSimCard) {
1972         TELEPHONY_LOGE("[slot%{public}d] NvCfgFinishedIndication no simcard", slotId_);
1973         return;
1974     }
1975     bool isUseCloudImsNV = system::GetBoolParameter(KEY_CONST_TELEPHONY_IS_USE_CLOUD_IMS_NV, true);
1976     TELEPHONY_LOGI("[slot%{public}d] entry, isUseCloudImsNV = %{public}d", slotId_, isUseCloudImsNV);
1977     if (isUseCloudImsNV && GetImsCapabilities(slotId_) == TELEPHONY_ERR_SUCCESS) {
1978         TELEPHONY_LOGI("[slot%{public}d] GetImsCapabilities success", slotId_);
1979         return;
1980     }
1981     CellularCallConfig config;
1982     ModuleServiceUtils obtain;
1983     std::vector<int32_t> slotVector = obtain.GetSlotInfo();
1984     for (const auto &it : slotVector) {
1985         config.UpdateImsCapabilities(it, true, false, INVALID_OPERATOR_CONFIG_STATE);
1986     }
1987 }
1988 
GetImsCapabilities(int32_t slotId)1989 int32_t CellularCallHandler::GetImsCapabilities(int32_t slotId)
1990 {
1991     std::shared_ptr<ImsCallClient> imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
1992     if (imsCallClient == nullptr) {
1993         TELEPHONY_LOGE("[slot%{public}d] imsCallClient is null", slotId);
1994         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1995     }
1996     return imsCallClient->GetImsCapabilities(slotId);
1997 }
1998 
GetImsCapResponse(const AppExecFwk::InnerEvent::Pointer & event)1999 void CellularCallHandler::GetImsCapResponse(const AppExecFwk::InnerEvent::Pointer &event)
2000 {
2001     auto imsCap = event->GetSharedObject<ImsCapFromChip>();
2002     if (imsCap == nullptr) {
2003         TELEPHONY_LOGE("[slot%{public}d] imsCap is null", slotId_);
2004         return;
2005     }
2006 
2007     std::string volteCapKey = KEY_PERSIST_TELEPHONY_VOLTE_CAP_IN_CHIP + std::string("_slot") + std::to_string(slotId_);
2008     int32_t volteCapInProp = GetIntParameter(volteCapKey.c_str(), -1);
2009     TELEPHONY_LOGI("[slot%{public}d] volteCapInProp = %{public}d, volteCap = %{public}d",
2010         slotId_, volteCapInProp, imsCap->volteCap);
2011     std::string strVolteCap = std::to_string(imsCap->volteCap);
2012     SetParameter(volteCapKey.c_str(), strVolteCap.c_str());
2013     CoreManagerInner::GetInstance().UpdateImsCapFromChip(slotId_, *imsCap);
2014     UpdateImsConfiguration();
2015     GetImsSwitchStatusRequest();
2016 }
2017 
UpdateImsConfiguration()2018 void CellularCallHandler::UpdateImsConfiguration()
2019 {
2020     bool hasSimCard = false;
2021     CoreManagerInner::GetInstance().HasSimCard(slotId_, hasSimCard);
2022     if (!hasSimCard) {
2023         TELEPHONY_LOGE("[slot%{public}d] UpdateImsConfiguration no simcard", slotId_);
2024         return;
2025     }
2026     CellularCallConfig config;
2027     TELEPHONY_LOGI("[slot%{public}d] UpdateImsConfiguration", slotId_);
2028     config.UpdateImsConfiguration(slotId_, INVALID_OPERATOR_CONFIG_STATE, false);
2029 }
2030 
GetImsSwitchStatusRequest()2031 void CellularCallHandler::GetImsSwitchStatusRequest()
2032 {
2033     bool hasSimCard = false;
2034     CoreManagerInner::GetInstance().HasSimCard(slotId_, hasSimCard);
2035     if (!hasSimCard) {
2036         TELEPHONY_LOGE("[slot%{public}d] GetImsSwitchStatusRequest no simcard", slotId_);
2037         return;
2038     }
2039     CellularCallConfig config;
2040     ModuleServiceUtils moduleUtils;
2041     if (config.IsVolteSupport(slotId_) ||
2042         (moduleUtils.GetImsRegistrationState(slotId_) && !config.IsVolteSupport(slotId_))) {
2043         TELEPHONY_LOGI("[slot%{public}d] GetImsSwitchStatusRequest", slotId_);
2044         config.GetImsSwitchStatusRequest(slotId_);
2045     }
2046 }
2047 
HandleCallDisconnectReason(RilDisconnectedReason reason,const std::string & message)2048 void CellularCallHandler::HandleCallDisconnectReason(RilDisconnectedReason reason, const std::string &message)
2049 {
2050     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
2051     if (serviceInstance == nullptr) {
2052         TELEPHONY_LOGE("serviceInstance get failed!");
2053         return;
2054     }
2055     auto imsControl = serviceInstance->GetImsControl(slotId_);
2056     auto csControl = serviceInstance->GetCsControl(slotId_);
2057     if (imsControl != nullptr) {
2058         imsControl->UpdateDisconnectedReason(currentCallList_, reason, message);
2059         imsControl->ReportImsCallsData(slotId_, currentCallList_, false);
2060     } else if (csControl != nullptr) {
2061         csControl->UpdateDisconnectedReason(currentCsCallInfoList_, reason);
2062         csControl->ReportCsCallsData(slotId_, currentCsCallInfoList_, false);
2063     } else {
2064         TELEPHONY_LOGE("imsControl and csControl get failed!");
2065         return;
2066     }
2067     if (currentCallList_.callSize == 0) {
2068         TELEPHONY_LOGW("all ims calls disconnected, set ims control to nullptr.");
2069         serviceInstance->SetImsControl(slotId_, nullptr);
2070     }
2071     if (currentCsCallInfoList_.callSize == 0) {
2072         TELEPHONY_LOGW("all cs calls disconnected, set cs control to nullptr.");
2073         serviceInstance->SetCsControl(slotId_, nullptr);
2074     }
2075 }
2076 } // namespace Telephony
2077 } // namespace OHOS
2078