• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "cellular_call_handler.h"
17 
18 #include "cellular_call_config.h"
19 #include "cellular_call_hisysevent.h"
20 #include "cellular_call_service.h"
21 #include "hitrace_meter.h"
22 #include "hril_call_parcel.h"
23 #include "hril_types.h"
24 #include "ims_call_client.h"
25 #include "operator_config_types.h"
26 #include "radio_event.h"
27 #include "resource_utils.h"
28 #include "satellite_call_client.h"
29 #include "satellite_radio_event.h"
30 #include "securec.h"
31 
32 namespace OHOS {
33 namespace Telephony {
34 const uint32_t GET_CS_CALL_DATA_ID = 10001;
35 const uint32_t GET_IMS_CALL_DATA_ID = 10002;
36 const uint32_t OPERATOR_CONFIG_CHANGED_ID = 10004;
37 const uint32_t GET_SATELLITE_CALL_DATA_ID = 10005;
38 const int64_t DELAY_TIME = 100;
39 const int32_t MAX_REQUEST_COUNT = 50;
40 // message was null, mean report the default message to user which have been define at CellularCallSupplement
41 const std::string DEFAULT_NULL_MESSAGE = "";
42 
CellularCallHandler(const EventFwk::CommonEventSubscribeInfo & subscriberInfo)43 CellularCallHandler::CellularCallHandler(const EventFwk::CommonEventSubscribeInfo &subscriberInfo)
44     : TelEventHandler("CellularCallHandler"), CommonEventSubscriber(subscriberInfo)
45 {
46     InitBasicFuncMap();
47     InitConfigFuncMap();
48     InitSupplementFuncMap();
49     InitActiveReportFuncMap();
50     InitSatelliteCallFuncMap();
51 }
52 
InitBasicFuncMap()53 void CellularCallHandler::InitBasicFuncMap()
54 {
55     requestFuncMap_[RadioEvent::RADIO_DIAL] = &CellularCallHandler::DialResponse;
56     requestFuncMap_[RadioEvent::RADIO_HANGUP_CONNECT] = &CellularCallHandler::CommonResultResponse;
57     requestFuncMap_[RadioEvent::RADIO_REJECT_CALL] = &CellularCallHandler::CommonResultResponse;
58     requestFuncMap_[RadioEvent::RADIO_ACCEPT_CALL] = &CellularCallHandler::CommonResultResponse;
59     requestFuncMap_[RadioEvent::RADIO_HOLD_CALL] = &CellularCallHandler::CommonResultResponse;
60     requestFuncMap_[RadioEvent::RADIO_ACTIVE_CALL] = &CellularCallHandler::CommonResultResponse;
61     requestFuncMap_[RadioEvent::RADIO_SWAP_CALL] = &CellularCallHandler::SwapCallResponse;
62     requestFuncMap_[RadioEvent::RADIO_COMBINE_CALL] = &CellularCallHandler::CommonResultResponse;
63     requestFuncMap_[RadioEvent::RADIO_JOIN_CALL] = &CellularCallHandler::CommonResultResponse;
64     requestFuncMap_[RadioEvent::RADIO_SPLIT_CALL] = &CellularCallHandler::CommonResultResponse;
65     requestFuncMap_[RadioEvent::RADIO_CALL_SUPPLEMENT] = &CellularCallHandler::CommonResultResponse;
66     requestFuncMap_[RadioEvent::RADIO_SEND_DTMF] = &CellularCallHandler::SendDtmfResponse;
67     requestFuncMap_[RadioEvent::RADIO_START_DTMF] = &CellularCallHandler::StartDtmfResponse;
68     requestFuncMap_[RadioEvent::RADIO_STOP_DTMF] = &CellularCallHandler::StopDtmfResponse;
69     requestFuncMap_[RadioEvent::RADIO_CURRENT_CALLS] = &CellularCallHandler::GetCsCallsDataResponse;
70     requestFuncMap_[RadioEvent::RADIO_GET_CALL_FAIL_REASON] = &CellularCallHandler::GetCallFailReasonResponse;
71     requestFuncMap_[RadioEvent::RADIO_RECV_CALL_MEDIA_MODE_REQUEST] =
72         &CellularCallHandler::ReceiveUpdateCallMediaModeRequest;
73     requestFuncMap_[RadioEvent::RADIO_RECV_CALL_MEDIA_MODE_RESPONSE] =
74         &CellularCallHandler::ReceiveUpdateCallMediaModeResponse;
75     requestFuncMap_[RadioEvent::RADIO_CALL_SESSION_EVENT_CHANGED] = &CellularCallHandler::HandleCallSessionEventChanged;
76     requestFuncMap_[RadioEvent::RADIO_CALL_PEER_DIMENSIONS_CHANGED] =
77         &CellularCallHandler::HandlePeerDimensionsChanged;
78     requestFuncMap_[RadioEvent::RADIO_CALL_DATA_USAGE_CHANGED] = &CellularCallHandler::HandleCallDataUsageChanged;
79     requestFuncMap_[RadioEvent::RADIO_CAMERA_CAPABILITIES_CHANGED] =
80         &CellularCallHandler::HandleCameraCapabilitiesChanged;
81 
82     requestFuncMap_[GET_CS_CALL_DATA_ID] = &CellularCallHandler::GetCsCallsDataRequest;
83     requestFuncMap_[GET_IMS_CALL_DATA_ID] = &CellularCallHandler::GetImsCallsDataRequest;
84     requestFuncMap_[REGISTER_HANDLER_ID] = &CellularCallHandler::RegisterHandler;
85     requestFuncMap_[MMIHandlerId::EVENT_MMI_Id] = &CellularCallHandler::GetMMIResponse;
86     requestFuncMap_[DtmfHandlerId::EVENT_EXECUTE_POST_DIAL] = &CellularCallHandler::ExecutePostDial;
87 
88     requestFuncMap_[RadioEvent::RADIO_IMS_GET_CALL_DATA] = &CellularCallHandler::GetImsCallsDataResponse;
89 }
90 
InitConfigFuncMap()91 void CellularCallHandler::InitConfigFuncMap()
92 {
93     requestFuncMap_[RadioEvent::RADIO_SET_CMUT] = &CellularCallHandler::SetMuteResponse;
94     requestFuncMap_[RadioEvent::RADIO_GET_CMUT] = &CellularCallHandler::GetMuteResponse;
95     requestFuncMap_[RadioEvent::RADIO_SET_CALL_PREFERENCE_MODE] = &CellularCallHandler::SetDomainPreferenceModeResponse;
96     requestFuncMap_[RadioEvent::RADIO_GET_CALL_PREFERENCE_MODE] = &CellularCallHandler::GetDomainPreferenceModeResponse;
97     requestFuncMap_[RadioEvent::RADIO_SET_IMS_SWITCH_STATUS] = &CellularCallHandler::SetImsSwitchStatusResponse;
98     requestFuncMap_[RadioEvent::RADIO_GET_IMS_SWITCH_STATUS] = &CellularCallHandler::GetImsSwitchStatusResponse;
99     requestFuncMap_[RadioEvent::RADIO_SET_VONR_SWITCH_STATUS] = &CellularCallHandler::SetVoNRSwitchStatusResponse;
100     requestFuncMap_[RadioEvent::RADIO_SET_EMERGENCY_CALL_LIST] = &CellularCallHandler::SetEmergencyCallListResponse;
101     requestFuncMap_[RadioEvent::RADIO_GET_EMERGENCY_CALL_LIST] = &CellularCallHandler::GetEmergencyCallListResponse;
102     requestFuncMap_[OPERATOR_CONFIG_CHANGED_ID] = &CellularCallHandler::HandleOperatorConfigChanged;
103 }
104 
InitSupplementFuncMap()105 void CellularCallHandler::InitSupplementFuncMap()
106 {
107     requestFuncMap_[RadioEvent::RADIO_GET_CALL_WAIT] = &CellularCallHandler::GetCallWaitingResponse;
108     requestFuncMap_[RadioEvent::RADIO_SET_CALL_WAIT] = &CellularCallHandler::SetCallWaitingResponse;
109     requestFuncMap_[RadioEvent::RADIO_GET_CALL_FORWARD] = &CellularCallHandler::GetCallTransferResponse;
110     requestFuncMap_[RadioEvent::RADIO_SET_CALL_FORWARD] = &CellularCallHandler::SetCallTransferInfoResponse;
111     requestFuncMap_[RadioEvent::RADIO_GET_CALL_CLIP] = &CellularCallHandler::GetClipResponse;
112     requestFuncMap_[RadioEvent::RADIO_SET_CALL_CLIP] = &CellularCallHandler::SetClipResponse;
113     requestFuncMap_[RadioEvent::RADIO_GET_CALL_CLIR] = &CellularCallHandler::GetClirResponse;
114     requestFuncMap_[RadioEvent::RADIO_SET_CALL_CLIR] = &CellularCallHandler::SetClirResponse;
115     requestFuncMap_[RadioEvent::RADIO_IMS_GET_COLR] = &CellularCallHandler::GetColrResponse;
116     requestFuncMap_[RadioEvent::RADIO_IMS_SET_COLR] = &CellularCallHandler::SetColrResponse;
117     requestFuncMap_[RadioEvent::RADIO_IMS_GET_COLP] = &CellularCallHandler::GetColpResponse;
118     requestFuncMap_[RadioEvent::RADIO_IMS_SET_COLP] = &CellularCallHandler::SetColpResponse;
119     requestFuncMap_[RadioEvent::RADIO_GET_CALL_RESTRICTION] = &CellularCallHandler::GetCallRestrictionResponse;
120     requestFuncMap_[RadioEvent::RADIO_SET_CALL_RESTRICTION] = &CellularCallHandler::SetCallRestrictionResponse;
121     requestFuncMap_[RadioEvent::RADIO_SET_CALL_RESTRICTION_PWD] = &CellularCallHandler::SetBarringPasswordResponse;
122     requestFuncMap_[RadioEvent::RADIO_SET_USSD] = &CellularCallHandler::SendUssdResponse;
123     requestFuncMap_[MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID] = &CellularCallHandler::SendUnlockPinPukResponse;
124     requestFuncMap_[RadioEvent::RADIO_CLOSE_UNFINISHED_USSD] = &CellularCallHandler::CloseUnFinishedUssdResponse;
125 }
126 
InitActiveReportFuncMap()127 void CellularCallHandler::InitActiveReportFuncMap()
128 {
129     requestFuncMap_[RadioEvent::RADIO_CALL_STATUS_INFO] = &CellularCallHandler::CsCallStatusInfoReport;
130     requestFuncMap_[RadioEvent::RADIO_IMS_CALL_STATUS_INFO] = &CellularCallHandler::ImsCallStatusInfoReport;
131     requestFuncMap_[RadioEvent::RADIO_AVAIL] = &CellularCallHandler::GetCsCallData;
132     requestFuncMap_[RadioEvent::RADIO_NOT_AVAIL] = &CellularCallHandler::GetCsCallData;
133     requestFuncMap_[RadioEvent::RADIO_CALL_USSD_NOTICE] = &CellularCallHandler::UssdNotifyResponse;
134     requestFuncMap_[RadioEvent::RADIO_CALL_RINGBACK_VOICE] = &CellularCallHandler::CallRingBackVoiceResponse;
135     requestFuncMap_[RadioEvent::RADIO_CALL_SRVCC_STATUS] = &CellularCallHandler::UpdateSrvccStateReport;
136     requestFuncMap_[RadioEvent::RADIO_CALL_SS_NOTICE] = &CellularCallHandler::SsNotifyResponse;
137     requestFuncMap_[RadioEvent::RADIO_CALL_EMERGENCY_NUMBER_REPORT] = &CellularCallHandler::ReportEccChanged;
138     requestFuncMap_[RadioEvent::RADIO_SIM_STATE_CHANGE] = &CellularCallHandler::SimStateChangeReport;
139     requestFuncMap_[RadioEvent::RADIO_SIM_RECORDS_LOADED] = &CellularCallHandler::SimRecordsLoadedReport;
140     requestFuncMap_[RadioEvent::RADIO_SIM_ACCOUNT_LOADED] = &CellularCallHandler::SimAccountLoadedReport;
141     requestFuncMap_[RadioEvent::RADIO_CALL_RSRVCC_STATUS] = &CellularCallHandler::UpdateRsrvccStateReport;
142     requestFuncMap_[RadioEvent::RADIO_RESIDENT_NETWORK_CHANGE] = &CellularCallHandler::ResidentNetworkChangeReport;
143     requestFuncMap_[RadioEvent::RADIO_PS_CONNECTION_ATTACHED] = &CellularCallHandler::NetworkStateChangeReport;
144     requestFuncMap_[RadioEvent::RADIO_PS_CONNECTION_DETACHED] = &CellularCallHandler::NetworkStateChangeReport;
145     requestFuncMap_[RadioEvent::RADIO_RIL_ADAPTER_HOST_DIED] = &CellularCallHandler::OnRilAdapterHostDied;
146     requestFuncMap_[RadioEvent::RADIO_FACTORY_RESET] = &CellularCallHandler::FactoryReset;
147 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
148     requestFuncMap_[RadioEvent::RADIO_GET_STATUS] = &CellularCallHandler::GetRadioStateProcess;
149     requestFuncMap_[RadioEvent::RADIO_STATE_CHANGED] = &CellularCallHandler::RadioStateChangeProcess;
150 #endif
151 }
152 
InitSatelliteCallFuncMap()153 void CellularCallHandler::InitSatelliteCallFuncMap()
154 {
155     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_CALL_STATE_CHANGED] =
156         &CellularCallHandler::SatelliteCallStatusInfoReport;
157     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_DIAL] = &CellularCallHandler::DialSatelliteResponse;
158     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_HANGUP] = &CellularCallHandler::CommonResultResponse;
159     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_ANSWER] = &CellularCallHandler::CommonResultResponse;
160     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_REJECT] = &CellularCallHandler::CommonResultResponse;
161     requestFuncMap_[SatelliteRadioEvent::SATELLITE_RADIO_GET_CALL_DATA] =
162         &CellularCallHandler::GetSatelliteCallsDataResponse;
163     requestFuncMap_[GET_SATELLITE_CALL_DATA_ID] = &CellularCallHandler::GetSatelliteCallsDataRequest;
164 }
165 
RegisterImsCallCallbackHandler()166 void CellularCallHandler::RegisterImsCallCallbackHandler()
167 {
168     // Register IMS
169     std::shared_ptr<ImsCallClient> imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
170     if (imsCallClient != nullptr) {
171         imsCallClient->RegisterImsCallCallbackHandler(slotId_, shared_from_this());
172     }
173 }
174 
RegisterSatelliteCallCallbackHandler()175 void CellularCallHandler::RegisterSatelliteCallCallbackHandler()
176 {
177     // Register Satellite
178     std::shared_ptr<SatelliteCallClient> satelliteCallClient = DelayedSingleton<SatelliteCallClient>::GetInstance();
179     if (satelliteCallClient != nullptr) {
180         satelliteCallClient->RegisterSatelliteCallCallbackHandler(slotId_, shared_from_this());
181     }
182 }
183 
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)184 void CellularCallHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
185 {
186     if (event == nullptr) {
187         TELEPHONY_LOGE("[slot%{public}d] event is null", slotId_);
188         return;
189     }
190 
191     uint32_t eventId = event->GetInnerEventId();
192     TELEPHONY_LOGD("[slot%{public}d] eventId = %{public}d", slotId_, eventId);
193 
194     auto itFunc = requestFuncMap_.find(event->GetInnerEventId());
195     if (itFunc != requestFuncMap_.end()) {
196         auto requestFunc = itFunc->second;
197         if (requestFunc != nullptr) {
198             return (this->*requestFunc)(event);
199         }
200     }
201     TELEPHONY_LOGI("[slot%{public}d] Function not found, need check.", slotId_);
202 }
203 
OnReceiveEvent(const EventFwk::CommonEventData & data)204 void CellularCallHandler::OnReceiveEvent(const EventFwk::CommonEventData &data)
205 {
206     EventFwk::Want want = data.GetWant();
207     std::string action = want.GetAction();
208     TELEPHONY_LOGI("[slot%{public}d] action=%{public}s code=%{public}d", slotId_, action.c_str(), data.GetCode());
209     if (action == EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED) {
210         int32_t slotId = want.GetIntParam(BROADCAST_ARG_SLOT_ID, DEFAULT_SIM_SLOT_ID);
211         if (slotId_ != slotId) {
212             return;
213         }
214         this->SendEvent(OPERATOR_CONFIG_CHANGED_ID, DELAY_TIME, Priority::HIGH);
215     }
216 }
217 
GetCsCallData(const AppExecFwk::InnerEvent::Pointer & event)218 void CellularCallHandler::GetCsCallData(const AppExecFwk::InnerEvent::Pointer &event)
219 {
220     this->SendEvent(GET_CS_CALL_DATA_ID, 0, Priority::HIGH);
221 }
222 
GetImsCallData(const AppExecFwk::InnerEvent::Pointer & event)223 void CellularCallHandler::GetImsCallData(const AppExecFwk::InnerEvent::Pointer &event)
224 {
225     this->SendEvent(GET_IMS_CALL_DATA_ID, 0, Priority::HIGH);
226 }
227 
GetSatelliteCallData(const AppExecFwk::InnerEvent::Pointer & event)228 void CellularCallHandler::GetSatelliteCallData(const AppExecFwk::InnerEvent::Pointer &event)
229 {
230     this->SendEvent(GET_SATELLITE_CALL_DATA_ID, 0, Priority::HIGH);
231 }
232 
CellularCallIncomingStartTrace(const int32_t state)233 void CellularCallHandler::CellularCallIncomingStartTrace(const int32_t state)
234 {
235     if (state == static_cast<int32_t>(TelCallState::CALL_STATUS_INCOMING)) {
236         StartAsyncTrace(HITRACE_TAG_OHOS, "CellularCallIncoming", getpid());
237     }
238 }
239 
CellularCallIncomingFinishTrace(const int32_t state)240 void CellularCallHandler::CellularCallIncomingFinishTrace(const int32_t state)
241 {
242     if (state == static_cast<int32_t>(TelCallState::CALL_STATUS_INCOMING)) {
243         FinishAsyncTrace(HITRACE_TAG_OHOS, "CellularCallIncoming", getpid());
244     }
245 }
246 
ReportCsCallsData(const CallInfoList & callInfoList)247 void CellularCallHandler::ReportCsCallsData(const CallInfoList &callInfoList)
248 {
249     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
250     if (serviceInstance == nullptr) {
251         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
252         return;
253     }
254     auto csControl = serviceInstance->GetCsControl(slotId_);
255     CallInfo callInfo;
256     std::vector<CallInfo>::const_iterator it = callInfoList.calls.begin();
257     for (; it != callInfoList.calls.end(); ++it) {
258         callInfo.state = (*it).state;
259     }
260     TELEPHONY_LOGI("[slot%{public}d] callInfoList.callSize:%{public}d", slotId_, callInfoList.callSize);
261     CellularCallIncomingStartTrace(callInfo.state);
262     if (callInfoList.callSize == 0) {
263         if (isInCsRedial_) {
264             TELEPHONY_LOGI("[slot%{public}d] Ignore hangup during cs redial", slotId_);
265             isInCsRedial_ = false;
266             return;
267         }
268         if (csControl == nullptr) {
269             TELEPHONY_LOGE("[slot%{public}d] cs_control is null", slotId_);
270             CellularCallIncomingFinishTrace(callInfo.state);
271             return;
272         }
273         if (csControl->ReportCallsData(slotId_, callInfoList) != TELEPHONY_SUCCESS) {
274             CellularCallIncomingFinishTrace(callInfo.state);
275         }
276         serviceInstance->SetCsControl(slotId_, nullptr);
277         return;
278     }
279     if (isInCsRedial_) {
280         TELEPHONY_LOGI("[slot%{public}d] Ignore cs call state change during cs redial", slotId_);
281         return;
282     }
283     if (callInfoList.callSize == 1) {
284         if (csControl == nullptr) {
285             csControl = std::make_shared<CSControl>();
286             serviceInstance->SetCsControl(slotId_, csControl);
287         }
288     }
289     if (csControl == nullptr) {
290         TELEPHONY_LOGE("[slot%{public}d] cs_control is null", slotId_);
291         CellularCallIncomingFinishTrace(callInfo.state);
292         return;
293     }
294     if (csControl->ReportCallsData(slotId_, callInfoList) != TELEPHONY_SUCCESS) {
295         CellularCallIncomingFinishTrace(callInfo.state);
296     }
297 }
298 
ReportImsCallsData(const ImsCurrentCallList & imsCallInfoList)299 void CellularCallHandler::ReportImsCallsData(const ImsCurrentCallList &imsCallInfoList)
300 {
301     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
302     if (serviceInstance == nullptr) {
303         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
304         return;
305     }
306     ImsCurrentCall imsCallInfo;
307     std::vector<ImsCurrentCall>::const_iterator it = imsCallInfoList.calls.begin();
308     for (; it != imsCallInfoList.calls.end(); ++it) {
309         imsCallInfo.state = (*it).state;
310     }
311     TELEPHONY_LOGI("[slot%{public}d] imsCallInfoList.callSize:%{public}d", slotId_, imsCallInfoList.callSize);
312     CellularCallIncomingStartTrace(imsCallInfo.state);
313     auto imsControl = serviceInstance->GetImsControl(slotId_);
314     if (imsCallInfoList.callSize == 0) {
315         if (imsControl == nullptr) {
316             TELEPHONY_LOGE("[slot%{public}d] ims_control is null", slotId_);
317             return;
318         }
319         if (imsControl->ReportImsCallsData(slotId_, imsCallInfoList) != TELEPHONY_SUCCESS) {
320             CellularCallIncomingFinishTrace(imsCallInfo.state);
321         }
322         serviceInstance->SetImsControl(slotId_, nullptr);
323         return;
324     }
325     if (srvccState_ == SrvccState::STARTED) {
326         TELEPHONY_LOGI("[slot%{public}d] Ignore to report ims call state change during srvcc", slotId_);
327         return;
328     }
329     if (imsCallInfoList.callSize == 1) {
330         if (imsControl == nullptr) {
331             imsControl = std::make_shared<IMSControl>();
332             serviceInstance->SetImsControl(slotId_, imsControl);
333         }
334     }
335     if (imsControl == nullptr) {
336         TELEPHONY_LOGE("[slot%{public}d] ims_control is null", slotId_);
337         CellularCallIncomingFinishTrace(imsCallInfo.state);
338         return;
339     }
340     if (imsControl->ReportImsCallsData(slotId_, imsCallInfoList) != TELEPHONY_SUCCESS) {
341         CellularCallIncomingFinishTrace(imsCallInfo.state);
342     }
343 }
344 
GetCsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer & event)345 void CellularCallHandler::GetCsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event)
346 {
347     // Returns list of current calls of ME. If command succeeds but no calls are available,
348     // no information response is sent to TE. Refer subclause 9.2 for possible <err> values.
349     auto callInfoList = event->GetSharedObject<CallInfoList>();
350     if (callInfoList == nullptr) {
351         TELEPHONY_LOGE("[slot%{public}d] Cannot get the callInfoList, need to get rilResponseInfo", slotId_);
352         auto rilResponseInfo = event->GetSharedObject<HRilRadioResponseInfo>();
353         if (rilResponseInfo == nullptr) {
354             TELEPHONY_LOGE("[slot%{public}d] callInfoList and rilResponseInfo are null", slotId_);
355             return;
356         }
357         if (rilResponseInfo->error == HRilErrType::NONE) {
358             TELEPHONY_LOGE("[slot%{public}d] Failed to query the call list but no reason!", slotId_);
359             return;
360         }
361         CellularCallEventInfo eventInfo;
362         eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
363         eventInfo.eventId = RequestResultEventId::RESULT_GET_CURRENT_CALLS_FAILED;
364         if (registerInstance_ == nullptr) {
365             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
366             return;
367         }
368         registerInstance_->ReportEventResultInfo(eventInfo);
369         return;
370     }
371     ReportCsCallsData(*callInfoList);
372 }
373 
GetImsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer & event)374 void CellularCallHandler::GetImsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event)
375 {
376     // Returns list of current calls of ME. If command succeeds but no calls are available,
377     // no information response is sent to TE. Refer subclause 9.2 for possible <err> values.
378     auto imsCallInfoList = event->GetSharedObject<ImsCurrentCallList>();
379     if (imsCallInfoList == nullptr) {
380         TELEPHONY_LOGE("[slot%{public}d] Cannot get the imsCallInfoList, need to get rilResponseInfo", slotId_);
381         auto rilResponseInfo = event->GetSharedObject<HRilRadioResponseInfo>();
382         if (rilResponseInfo == nullptr) {
383             TELEPHONY_LOGE("[slot%{public}d] callInfoList and rilResponseInfo are null", slotId_);
384             return;
385         }
386         if (rilResponseInfo->error == HRilErrType::NONE) {
387             TELEPHONY_LOGE("[slot%{public}d] Failed to query the call list but no reason!", slotId_);
388             return;
389         }
390         if (registerInstance_ == nullptr) {
391             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
392             return;
393         }
394         registerInstance_->ReportGetCallDataResult(static_cast<int32_t>(rilResponseInfo->error));
395         return;
396     }
397     ReportImsCallsData(*imsCallInfoList);
398 }
399 
DialResponse(const AppExecFwk::InnerEvent::Pointer & event)400 void CellularCallHandler::DialResponse(const AppExecFwk::InnerEvent::Pointer &event)
401 {
402     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
403     if (result == nullptr) {
404         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
405         return;
406     }
407     struct CallBehaviorParameterInfo info = { 0 };
408     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
409     if (callHiSysEvent == nullptr) {
410         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
411         return;
412     }
413     callHiSysEvent->GetCallParameterInfo(info);
414     if (result->error != HRilErrType::NONE) {
415         TELEPHONY_LOGE("[slot%{public}d] dial error:%{public}d", slotId_, result->error);
416         CellularCallEventInfo eventInfo;
417         eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
418 
419         /*
420          * 3GPP TS 27.007 V3.9.0 (2001-06)
421          * If ME has succeeded in establishing a logical link between application protocols and external interface,
422          * it will send CONNECT message to the TE. Otherwise, the NO CARRIER response will be returned.
423          */
424         if (result->error == HRilErrType::HRIL_ERR_CMD_NO_CARRIER) {
425             eventInfo.eventId = RequestResultEventId::RESULT_DIAL_NO_CARRIER;
426         } else {
427             eventInfo.eventId = RequestResultEventId::RESULT_DIAL_SEND_FAILED;
428         }
429         if (registerInstance_ == nullptr) {
430             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
431             return;
432         }
433         registerInstance_->ReportEventResultInfo(eventInfo);
434         CellularCallHiSysEvent::WriteDialCallBehaviorEvent(info, CallResponseResult::COMMAND_FAILURE);
435     } else {
436         CellularCallHiSysEvent::WriteDialCallBehaviorEvent(info, CallResponseResult::COMMAND_SUCCESS);
437     }
438 }
439 
DialSatelliteResponse(const AppExecFwk::InnerEvent::Pointer & event)440 void CellularCallHandler::DialSatelliteResponse(const AppExecFwk::InnerEvent::Pointer &event)
441 {
442     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
443     if (result == nullptr) {
444         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
445         return;
446     }
447     struct CallBehaviorParameterInfo satelliteCallInfo = { 0 };
448     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
449     if (callHiSysEvent == nullptr) {
450         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
451         return;
452     }
453     callHiSysEvent->GetCallParameterInfo(satelliteCallInfo);
454     if (result->error != HRilErrType::NONE) {
455         TELEPHONY_LOGE("[slot%{public}d] dial error:%{public}d", slotId_, result->error);
456         CellularCallEventInfo eventInfo;
457         eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
458 
459         if (result->error == HRilErrType::HRIL_ERR_CMD_NO_CARRIER) {
460             eventInfo.eventId = RequestResultEventId::RESULT_DIAL_NO_CARRIER;
461         } else {
462             eventInfo.eventId = RequestResultEventId::RESULT_DIAL_SEND_FAILED;
463         }
464         if (registerInstance_ == nullptr) {
465             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
466             return;
467         }
468         registerInstance_->ReportEventResultInfo(eventInfo);
469         CellularCallHiSysEvent::WriteDialCallBehaviorEvent(satelliteCallInfo, CallResponseResult::COMMAND_FAILURE);
470     } else {
471         CellularCallHiSysEvent::WriteDialCallBehaviorEvent(satelliteCallInfo, CallResponseResult::COMMAND_SUCCESS);
472     }
473 }
474 
GetSatelliteCallsDataResponse(const AppExecFwk::InnerEvent::Pointer & event)475 void CellularCallHandler::GetSatelliteCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event)
476 {
477     auto satelliteCallInfoList = event->GetSharedObject<SatelliteCurrentCallList>();
478     if (satelliteCallInfoList == nullptr) {
479         TELEPHONY_LOGE(
480             "[slot%{public}d] Cannot get the SatelliteCurrentCallList, need to get rilResponseInfo", slotId_);
481         auto rilResponseInfo = event->GetSharedObject<HRilRadioResponseInfo>();
482         if (rilResponseInfo == nullptr) {
483             TELEPHONY_LOGE("[slot%{public}d] SatelliteCurrentCallList and rilResponseInfo are null", slotId_);
484             return;
485         }
486         if (rilResponseInfo->error == HRilErrType::NONE) {
487             TELEPHONY_LOGE("[slot%{public}d] Failed to query the call list but no reason!", slotId_);
488             return;
489         }
490         CellularCallEventInfo eventInfo;
491         eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
492         eventInfo.eventId = RequestResultEventId::RESULT_GET_CURRENT_CALLS_FAILED;
493         if (registerInstance_ == nullptr) {
494             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
495             return;
496         }
497         registerInstance_->ReportEventResultInfo(eventInfo);
498         return;
499     }
500     ReportSatelliteCallsData(*satelliteCallInfoList);
501 }
502 
ReportSatelliteCallsData(const SatelliteCurrentCallList & callInfoList)503 void CellularCallHandler::ReportSatelliteCallsData(const SatelliteCurrentCallList &callInfoList)
504 {
505     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
506     if (serviceInstance == nullptr) {
507         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
508         return;
509     }
510     auto satelliteControl = serviceInstance->GetSatelliteControl(slotId_);
511     SatelliteCurrentCall callInfo;
512     std::vector<SatelliteCurrentCall>::const_iterator it = callInfoList.calls.begin();
513     for (; it != callInfoList.calls.end(); ++it) {
514         callInfo.state = (*it).state;
515     }
516     TELEPHONY_LOGI("[slot%{public}d] callInfoList.callSize:%{public}d", slotId_, callInfoList.callSize);
517     CellularCallIncomingStartTrace(callInfo.state);
518     if (callInfoList.callSize == 0) {
519         if (satelliteControl == nullptr) {
520             TELEPHONY_LOGE("[slot%{public}d] satelliteControl is null", slotId_);
521             CellularCallIncomingFinishTrace(callInfo.state);
522             return;
523         }
524         if (satelliteControl->ReportSatelliteCallsData(slotId_, callInfoList) != TELEPHONY_SUCCESS) {
525             CellularCallIncomingFinishTrace(callInfo.state);
526         }
527         serviceInstance->SetSatelliteControl(slotId_, nullptr);
528         return;
529     }
530     if (callInfoList.callSize == 1) {
531         if (satelliteControl == nullptr) {
532             satelliteControl = std::make_shared<SatelliteControl>();
533             serviceInstance->SetSatelliteControl(slotId_, satelliteControl);
534         }
535     }
536     if (satelliteControl == nullptr) {
537         TELEPHONY_LOGE("[slot%{public}d] satelliteControl is null", slotId_);
538         CellularCallIncomingFinishTrace(callInfo.state);
539         return;
540     }
541     if (satelliteControl->ReportSatelliteCallsData(slotId_, callInfoList) != TELEPHONY_SUCCESS) {
542         CellularCallIncomingFinishTrace(callInfo.state);
543     }
544 }
545 
CommonResultEventHandling(const AppExecFwk::InnerEvent::Pointer & event,CellularCallEventInfo & eventInfo)546 void CellularCallHandler::CommonResultEventHandling(
547     const AppExecFwk::InnerEvent::Pointer &event, CellularCallEventInfo &eventInfo)
548 {
549     eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
550     switch (event->GetInnerEventId()) {
551         case RadioEvent::RADIO_HANGUP_CONNECT:
552             eventInfo.eventId = RequestResultEventId::RESULT_END_SEND_FAILED;
553             break;
554         case RadioEvent::RADIO_REJECT_CALL:
555             eventInfo.eventId = RequestResultEventId::RESULT_REJECT_SEND_FAILED;
556             break;
557         case RadioEvent::RADIO_ACCEPT_CALL:
558             eventInfo.eventId = RequestResultEventId::RESULT_ACCEPT_SEND_FAILED;
559             break;
560         case RadioEvent::RADIO_HOLD_CALL:
561             eventInfo.eventId = RequestResultEventId::RESULT_HOLD_SEND_FAILED;
562             break;
563         case RadioEvent::RADIO_ACTIVE_CALL:
564             eventInfo.eventId = RequestResultEventId::RESULT_ACTIVE_SEND_FAILED;
565             break;
566         case RadioEvent::RADIO_SWAP_CALL:
567             eventInfo.eventId = RequestResultEventId::RESULT_SWAP_SEND_FAILED;
568             break;
569         case RadioEvent::RADIO_COMBINE_CALL:
570         case RadioEvent::RADIO_JOIN_CALL:
571             eventInfo.eventId = RequestResultEventId::RESULT_COMBINE_SEND_FAILED;
572             break;
573         case RadioEvent::RADIO_SPLIT_CALL:
574             eventInfo.eventId = RequestResultEventId::RESULT_SPLIT_SEND_FAILED;
575             break;
576         case RadioEvent::RADIO_CALL_SUPPLEMENT:
577             eventInfo.eventId = RequestResultEventId::RESULT_SUPPLEMENT_SEND_FAILED;
578             break;
579         default:
580             break;
581     }
582 }
583 
CommonResultResponse(const AppExecFwk::InnerEvent::Pointer & event)584 void CellularCallHandler::CommonResultResponse(const AppExecFwk::InnerEvent::Pointer &event)
585 {
586     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
587     if (result == nullptr) {
588         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
589         return;
590     }
591     struct CallBehaviorParameterInfo info = { 0 };
592     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
593     if (callHiSysEvent == nullptr) {
594         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
595         return;
596     }
597     callHiSysEvent->GetCallParameterInfo(info);
598     if (result->error != HRilErrType::NONE) {
599         CellularCallEventInfo eventInfo;
600         eventInfo.eventId = RequestResultEventId::INVALID_REQUEST_RESULT_EVENT_ID;
601         CommonResultEventHandling(event, eventInfo);
602         if (eventInfo.eventId == RequestResultEventId::RESULT_END_SEND_FAILED ||
603             eventInfo.eventId == RequestResultEventId::RESULT_REJECT_SEND_FAILED) {
604             CellularCallHiSysEvent::WriteHangUpCallBehaviorEvent(info, CallResponseResult::COMMAND_FAILURE);
605         } else if (eventInfo.eventId == RequestResultEventId::RESULT_ACCEPT_SEND_FAILED) {
606             CellularCallHiSysEvent::WriteAnswerCallBehaviorEvent(info, CallResponseResult::COMMAND_FAILURE);
607         } else {
608             TELEPHONY_LOGW("[slot%{public}d] eventId is:%{public}d, not within the scope of processing", slotId_,
609                 eventInfo.eventId);
610         }
611         if (registerInstance_ == nullptr) {
612             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
613             return;
614         }
615         registerInstance_->ReportEventResultInfo(eventInfo);
616         return;
617     }
618     uint32_t id = event->GetInnerEventId();
619     if (id == RadioEvent::RADIO_HANGUP_CONNECT || id == RadioEvent::RADIO_REJECT_CALL) {
620         CellularCallHiSysEvent::WriteHangUpCallBehaviorEvent(info, CallResponseResult::COMMAND_SUCCESS);
621     } else if (id == RadioEvent::RADIO_ACCEPT_CALL) {
622         CellularCallHiSysEvent::WriteAnswerCallBehaviorEvent(info, CallResponseResult::COMMAND_SUCCESS);
623     } else {
624         TELEPHONY_LOGW("[slot%{public}d] id is:%{public}d, not within the scope of processing", slotId_, id);
625     }
626 }
627 
ExecutePostDial(const AppExecFwk::InnerEvent::Pointer & event)628 void CellularCallHandler::ExecutePostDial(const AppExecFwk::InnerEvent::Pointer &event)
629 {
630     auto postDialData = event->GetSharedObject<PostDialData>();
631     if (postDialData == nullptr) {
632         TELEPHONY_LOGE("[slot%{public}d] postDialData is null", slotId_);
633         return;
634     }
635     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
636     if (serviceInstance == nullptr) {
637         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
638         return;
639     }
640     int64_t callId = postDialData->callId;
641     if (postDialData->isIms) {
642         auto imsControl = serviceInstance->GetImsControl(slotId_);
643         if (imsControl == nullptr) {
644             TELEPHONY_LOGE("[slot%{public}d] imsControl is null", slotId_);
645             return;
646         }
647         imsControl->ExecutePostDial(slotId_, callId);
648     } else {
649         auto csControl = serviceInstance->GetCsControl(slotId_);
650         if (csControl == nullptr) {
651             TELEPHONY_LOGE("[slot%{public}d] csControl is null", slotId_);
652             return;
653         }
654         csControl->ExecutePostDial(slotId_, callId);
655     }
656 }
657 
SwapCallResponse(const AppExecFwk::InnerEvent::Pointer & event)658 void CellularCallHandler::SwapCallResponse(const AppExecFwk::InnerEvent::Pointer &event)
659 {
660     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
661     if (result == nullptr) {
662         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
663         return;
664     }
665     if (result->error != HRilErrType::NONE) {
666         CellularCallEventInfo eventInfo;
667         eventInfo.eventId = RequestResultEventId::INVALID_REQUEST_RESULT_EVENT_ID;
668         CommonResultEventHandling(event, eventInfo);
669         if (registerInstance_ == nullptr) {
670             TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
671             return;
672         }
673         registerInstance_->ReportEventResultInfo(eventInfo);
674         return;
675     }
676     auto serviceInstence = DelayedSingleton<CellularCallService>::GetInstance();
677     if (serviceInstence == nullptr) {
678         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
679         return;
680     }
681     auto callType = event->GetParam();
682     if (callType == static_cast<int32_t>(CallType::TYPE_IMS)) {
683         std::shared_ptr<IMSControl> imsControl = serviceInstence->GetImsControl(slotId_);
684         if (imsControl == nullptr) {
685             TELEPHONY_LOGE("[slot%{public}d] imsControl is null", slotId_);
686             return;
687         }
688         imsControl->DialAfterHold(slotId_);
689     }
690 }
691 
SendDtmfResponse(const AppExecFwk::InnerEvent::Pointer & event)692 void CellularCallHandler::SendDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event)
693 {
694     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
695     if (result == nullptr) {
696         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
697         return;
698     }
699 
700     std::shared_ptr<PostDialData> postDial = std::make_shared<PostDialData>();
701     postDial->callId = result->flag;
702     postDial->isIms = event->GetParam() == static_cast<int32_t>(CallType::TYPE_IMS);
703     this->SendEvent(EVENT_EXECUTE_POST_DIAL, postDial, DELAY_TIME);
704 
705     CellularCallEventInfo eventInfo;
706     eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
707     if (result->error != HRilErrType::NONE) {
708         eventInfo.eventId = RequestResultEventId::RESULT_SEND_DTMF_FAILED;
709     } else {
710         eventInfo.eventId = RequestResultEventId::RESULT_SEND_DTMF_SUCCESS;
711     }
712     if (registerInstance_ == nullptr) {
713         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
714         return;
715     }
716     registerInstance_->ReportEventResultInfo(eventInfo);
717 }
718 
StartDtmfResponse(const AppExecFwk::InnerEvent::Pointer & event)719 void CellularCallHandler::StartDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event)
720 {
721     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
722     if (result == nullptr) {
723         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
724         return;
725     }
726     if (registerInstance_ == nullptr) {
727         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
728         return;
729     }
730     registerInstance_->ReportStartDtmfResult(static_cast<int32_t>(result->error));
731 }
732 
SimStateChangeReport(const AppExecFwk::InnerEvent::Pointer & event)733 void CellularCallHandler::SimStateChangeReport(const AppExecFwk::InnerEvent::Pointer &event)
734 {
735     CellularCallConfig config;
736     config.HandleSimStateChanged(slotId_);
737 }
738 
FactoryReset(const AppExecFwk::InnerEvent::Pointer & event)739 void CellularCallHandler::FactoryReset(const AppExecFwk::InnerEvent::Pointer &event)
740 {
741     CellularCallConfig config;
742     config.HandleFactoryReset(slotId_);
743 }
744 
SimRecordsLoadedReport(const AppExecFwk::InnerEvent::Pointer & event)745 void CellularCallHandler::SimRecordsLoadedReport(const AppExecFwk::InnerEvent::Pointer &event)
746 {
747     CellularCallConfig config;
748     config.HandleSimRecordsLoaded(slotId_);
749 }
750 
SimAccountLoadedReport(const AppExecFwk::InnerEvent::Pointer & event)751 void CellularCallHandler::SimAccountLoadedReport(const AppExecFwk::InnerEvent::Pointer &event)
752 {
753     CellularCallConfig config;
754     config.HandleSimAccountLoaded(slotId_);
755 }
756 
ResidentNetworkChangeReport(const AppExecFwk::InnerEvent::Pointer & event)757 void CellularCallHandler::ResidentNetworkChangeReport(const AppExecFwk::InnerEvent::Pointer &event)
758 {
759     if (event == nullptr) {
760         TELEPHONY_LOGE("ResidentNetworkChangeReport event is nullptr slotId:%{public}d!", slotId_);
761         return;
762     }
763     auto result = event->GetSharedObject<std::string>();
764     if (result == nullptr) {
765         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
766         return;
767     }
768     CellularCallConfig config;
769     config.HandleResidentNetworkChange(slotId_, *result);
770 }
771 
NetworkStateChangeReport(const AppExecFwk::InnerEvent::Pointer & event)772 void CellularCallHandler::NetworkStateChangeReport(const AppExecFwk::InnerEvent::Pointer &event)
773 {
774     if (event == nullptr) {
775         TELEPHONY_LOGE("NetworkStateChangeReport event is nullptr slotId:%{public}d!", slotId_);
776         return;
777     }
778     CellularCallConfig config;
779     config.HandleNetworkStateChange(slotId_);
780 }
781 
StopDtmfResponse(const AppExecFwk::InnerEvent::Pointer & event)782 void CellularCallHandler::StopDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event)
783 {
784     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
785     if (result == nullptr) {
786         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
787         return;
788     }
789     if (registerInstance_ == nullptr) {
790         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
791         return;
792     }
793     registerInstance_->ReportStopDtmfResult(static_cast<int32_t>(result->error));
794 }
795 
ReceiveUpdateCallMediaModeRequest(const AppExecFwk::InnerEvent::Pointer & event)796 void CellularCallHandler::ReceiveUpdateCallMediaModeRequest(const AppExecFwk::InnerEvent::Pointer &event)
797 {
798     struct CallBehaviorParameterInfo info = { 0 };
799     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
800     if (callHiSysEvent == nullptr) {
801         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
802         return;
803     }
804     callHiSysEvent->GetCallParameterInfo(info);
805     auto result = event->GetSharedObject<ImsCallModeReceiveInfo>();
806     if (result == nullptr) {
807         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
808         return;
809     }
810     if (registerInstance_ == nullptr) {
811         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
812         return;
813     }
814     registerInstance_->ReceiveUpdateCallMediaModeRequest(*result);
815     int32_t requestResult = static_cast<ImsCallModeRequestResult>(result->result);
816     CellularCallHiSysEvent::WriteImsCallModeBehaviorEvent(
817         CallModeBehaviorType::RECEIVE_REQUEST_EVENT, info, requestResult);
818 }
819 
ReceiveUpdateCallMediaModeResponse(const AppExecFwk::InnerEvent::Pointer & event)820 void CellularCallHandler::ReceiveUpdateCallMediaModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
821 {
822     struct CallBehaviorParameterInfo info = { 0 };
823     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
824     if (callHiSysEvent == nullptr) {
825         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
826         return;
827     }
828     callHiSysEvent->GetCallParameterInfo(info);
829     auto result = event->GetSharedObject<ImsCallModeReceiveInfo>();
830     if (result == nullptr) {
831         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
832         return;
833     }
834     if (registerInstance_ == nullptr) {
835         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
836         return;
837     }
838     registerInstance_->ReceiveUpdateCallMediaModeResponse(*result);
839     info.videoState = static_cast<ImsCallType>(result->callType);
840     int32_t requestResult = static_cast<ImsCallModeRequestResult>(result->result);
841     CellularCallHiSysEvent::WriteImsCallModeBehaviorEvent(
842         CallModeBehaviorType::RECEIVE_RESPONSE_EVENT, info, requestResult);
843 }
844 
HandleCallSessionEventChanged(const AppExecFwk::InnerEvent::Pointer & event)845 void CellularCallHandler::HandleCallSessionEventChanged(const AppExecFwk::InnerEvent::Pointer &event)
846 {
847     auto result = event->GetSharedObject<ImsCallSessionEventInfo>();
848     if (result == nullptr) {
849         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
850         return;
851     }
852     if (registerInstance_ == nullptr) {
853         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
854         return;
855     }
856     registerInstance_->HandleCallSessionEventChanged(*result);
857 }
858 
HandlePeerDimensionsChanged(const AppExecFwk::InnerEvent::Pointer & event)859 void CellularCallHandler::HandlePeerDimensionsChanged(const AppExecFwk::InnerEvent::Pointer &event)
860 {
861     auto result = event->GetSharedObject<ImsCallPeerDimensionsInfo>();
862     if (result == nullptr) {
863         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
864         return;
865     }
866     if (registerInstance_ == nullptr) {
867         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
868         return;
869     }
870     registerInstance_->HandlePeerDimensionsChanged(*result);
871 }
872 
HandleCallDataUsageChanged(const AppExecFwk::InnerEvent::Pointer & event)873 void CellularCallHandler::HandleCallDataUsageChanged(const AppExecFwk::InnerEvent::Pointer &event)
874 {
875     auto result = event->GetSharedObject<ImsCallDataUsageInfo>();
876     if (result == nullptr) {
877         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
878         return;
879     }
880     if (registerInstance_ == nullptr) {
881         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
882         return;
883     }
884     registerInstance_->HandleCallDataUsageChanged(*result);
885 }
886 
HandleCameraCapabilitiesChanged(const AppExecFwk::InnerEvent::Pointer & event)887 void CellularCallHandler::HandleCameraCapabilitiesChanged(const AppExecFwk::InnerEvent::Pointer &event)
888 {
889     auto result = event->GetSharedObject<CameraCapabilitiesInfo>();
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_->HandleCameraCapabilitiesChanged(*result);
899 }
900 
SetSlotId(int32_t id)901 void CellularCallHandler::SetSlotId(int32_t id)
902 {
903     slotId_ = id;
904 }
905 
GetSlotId()906 int32_t CellularCallHandler::GetSlotId()
907 {
908     return slotId_;
909 }
910 
CurrentTimeMillis()911 int64_t CellularCallHandler::CurrentTimeMillis()
912 {
913     int64_t timems =
914         std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
915             .count();
916     return timems;
917 }
918 
GetCsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer & event)919 void CellularCallHandler::GetCsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event)
920 {
921     lastCallsDataFlag_ = CurrentTimeMillis();
922     CellularCallConnectionCS connectionCs;
923     connectionCs.GetCsCallsDataRequest(slotId_, lastCallsDataFlag_);
924 }
925 
GetImsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer & event)926 void CellularCallHandler::GetImsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event)
927 {
928     lastCallsDataFlag_ = CurrentTimeMillis();
929     CellularCallConnectionIMS connectionIms;
930     connectionIms.GetImsCallsDataRequest(slotId_, lastCallsDataFlag_);
931 }
932 
GetSatelliteCallsDataRequest(const AppExecFwk::InnerEvent::Pointer & event)933 void CellularCallHandler::GetSatelliteCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event)
934 {
935     lastCallsDataFlag_ = CurrentTimeMillis();
936     CellularCallConnectionSatellite connectionSatellite;
937     connectionSatellite.GetSatelliteCallsDataRequest(slotId_, lastCallsDataFlag_);
938 }
939 
RegisterHandler(const AppExecFwk::InnerEvent::Pointer & event)940 void CellularCallHandler::RegisterHandler(const AppExecFwk::InnerEvent::Pointer &event)
941 {
942     CellularCallConnectionCS connectionCs;
943     connectionCs.RegisterHandler();
944 }
945 
SetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer & event)946 void CellularCallHandler::SetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
947 {
948     auto info = event->GetSharedObject<HRilRadioResponseInfo>();
949     if (info == nullptr) {
950         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
951         return;
952     }
953     CellularCallEventInfo eventInfo;
954     eventInfo.eventType = CellularCallEventType::EVENT_REQUEST_RESULT_TYPE;
955     if (info->error != HRilErrType::NONE) {
956         eventInfo.eventId = RequestResultEventId::RESULT_SET_CALL_PREFERENCE_MODE_FAILED;
957     } else {
958         eventInfo.eventId = RequestResultEventId::RESULT_SET_CALL_PREFERENCE_MODE_SUCCESS;
959 
960         CellularCallConfig config;
961         config.SetTempMode(slotId_);
962     }
963     if (registerInstance_ == nullptr) {
964         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
965         return;
966     }
967     registerInstance_->ReportEventResultInfo(eventInfo);
968 }
969 
GetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer & event)970 void CellularCallHandler::GetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
971 {
972     auto mode = event->GetSharedObject<int32_t>();
973     if (mode == nullptr) {
974         TELEPHONY_LOGI("[slot%{public}d] mode is null", slotId_);
975         return;
976     }
977     CellularCallConfig config;
978     config.GetDomainPreferenceModeResponse(slotId_, *mode);
979 }
980 
SetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer & event)981 void CellularCallHandler::SetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event)
982 {
983     auto info = event->GetSharedObject<HRilRadioResponseInfo>();
984     if (info == nullptr) {
985         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
986         return;
987     }
988     if (registerInstance_ == nullptr) {
989         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
990         return;
991     }
992     CellularCallConfig config;
993     config.HandleSetLteImsSwitchResult(slotId_, info->error);
994 }
995 
GetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer & event)996 void CellularCallHandler::GetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event) {}
997 
SetVoNRSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer & event)998 void CellularCallHandler::SetVoNRSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event)
999 {
1000     auto info = event->GetSharedObject<HRilRadioResponseInfo>();
1001     if (info == nullptr) {
1002         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1003         return;
1004     }
1005     CellularCallConfig config;
1006     config.HandleSetVoNRSwitchResult(slotId_, info->error);
1007 }
1008 
CsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer & event)1009 void CellularCallHandler::CsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event)
1010 {
1011     if (srvccState_ == SrvccState::STARTED) {
1012         TELEPHONY_LOGI("[slot%{public}d] Ignore to report cs call state change cause by srvcc started", slotId_);
1013         return;
1014     }
1015     GetCsCallData(event);
1016 }
1017 
ImsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer & event)1018 void CellularCallHandler::ImsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event)
1019 {
1020     GetImsCallData(event);
1021 }
1022 
SatelliteCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer & event)1023 void CellularCallHandler::SatelliteCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event)
1024 {
1025     if (srvccState_ == SrvccState::STARTED) {
1026         TELEPHONY_LOGI("[slot%{public}d] Ignore to report satellite call state change cause by srvcc started", slotId_);
1027         return;
1028     }
1029     GetSatelliteCallData(event);
1030 }
1031 
UssdNotifyResponse(const AppExecFwk::InnerEvent::Pointer & event)1032 void CellularCallHandler::UssdNotifyResponse(const AppExecFwk::InnerEvent::Pointer &event)
1033 {
1034     auto result = event->GetSharedObject<UssdNoticeInfo>();
1035     if (result == nullptr) {
1036         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1037         return;
1038     }
1039     CellularCallSupplement supplement;
1040     supplement.EventUssdNotify(*result);
1041 }
1042 
SetMuteResponse(const AppExecFwk::InnerEvent::Pointer & event)1043 void CellularCallHandler::SetMuteResponse(const AppExecFwk::InnerEvent::Pointer &event)
1044 {
1045     auto info = event->GetSharedObject<HRilRadioResponseInfo>();
1046     if (info == nullptr) {
1047         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1048         return;
1049     }
1050     MuteControlResponse response;
1051     if (registerInstance_ == nullptr) {
1052         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1053         return;
1054     }
1055     response.result = static_cast<int32_t>(info->error);
1056     registerInstance_->ReportSetMuteResult(response);
1057 }
1058 
GetMuteResponse(const AppExecFwk::InnerEvent::Pointer & event)1059 void CellularCallHandler::GetMuteResponse(const AppExecFwk::InnerEvent::Pointer &event)
1060 {
1061     MuteControlResponse response;
1062     auto mute = event->GetSharedObject<int32_t>();
1063     if (mute == nullptr) {
1064         TELEPHONY_LOGI("[slot%{public}d] mute is null", slotId_);
1065         auto info = event->GetSharedObject<HRilRadioResponseInfo>();
1066         if (info == nullptr) {
1067             TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1068             return;
1069         }
1070         response.result = static_cast<int32_t>(info->error);
1071     } else {
1072         response.result = static_cast<int32_t>(HRilErrType::NONE);
1073         response.value = *mute;
1074     }
1075     if (registerInstance_ == nullptr) {
1076         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1077         return;
1078     }
1079     registerInstance_->ReportGetMuteResult(response);
1080 }
1081 
GetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer & event)1082 void CellularCallHandler::GetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer &event)
1083 {
1084     auto eccList = event->GetSharedObject<EmergencyInfoList>();
1085     if (eccList == nullptr) {
1086         TELEPHONY_LOGE("[slot%{public}d] eccList is null", slotId_);
1087         return;
1088     }
1089     CellularCallConfig config;
1090     config.UpdateEmergencyCallFromRadio(slotId_, *eccList);
1091 }
1092 
SetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer & event)1093 void CellularCallHandler::SetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer &event)
1094 {
1095     auto info = event->GetSharedObject<HRilRadioResponseInfo>();
1096     if (info == nullptr) {
1097         TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1098         return;
1099     }
1100     if (registerInstance_ == nullptr) {
1101         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1102         return;
1103     }
1104     SetEccListResponse response;
1105     response.result = static_cast<int32_t>(info->error);
1106     registerInstance_->ReportSetEmergencyCallListResponse(response);
1107 }
1108 
CallRingBackVoiceResponse(const AppExecFwk::InnerEvent::Pointer & event)1109 void CellularCallHandler::CallRingBackVoiceResponse(const AppExecFwk::InnerEvent::Pointer &event)
1110 {
1111     auto ringBackVoice = event->GetSharedObject<RingbackVoice>();
1112     if (ringBackVoice == nullptr) {
1113         TELEPHONY_LOGE("[slot%{public}d] ringBackVoice is null", slotId_);
1114         return;
1115     }
1116     if (registerInstance_ == nullptr) {
1117         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1118         return;
1119     }
1120     registerInstance_->ReportCallRingBackResult(ringBackVoice->status);
1121 }
1122 
GetCallFailReasonResponse(const AppExecFwk::InnerEvent::Pointer & event)1123 void CellularCallHandler::GetCallFailReasonResponse(const AppExecFwk::InnerEvent::Pointer &event)
1124 {
1125     if (registerInstance_ == nullptr) {
1126         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1127         return;
1128     }
1129     auto reason = event->GetSharedObject<int32_t>();
1130     DisconnectedDetails details;
1131     if (reason == nullptr) {
1132         auto info = event->GetSharedObject<DisconnectedDetails>();
1133         if (info == nullptr) {
1134             TELEPHONY_LOGE("[slot%{public}d] info is null", slotId_);
1135             return;
1136         }
1137         details.reason = static_cast<DisconnectedReason>(info->reason);
1138         details.message = (info->message.c_str() == nullptr) ? "" : info->message;
1139     } else {
1140         details.reason = static_cast<DisconnectedReason>(*reason);
1141         details.message = "";
1142     }
1143 
1144     if (details.message.empty()) {
1145         std::string callFailedMessageName = "";
1146         bool ret =
1147             ResourceUtils::Get().GetCallFailedMessageName(static_cast<int32_t>(details.reason), callFailedMessageName);
1148         if (!ret) {
1149             TELEPHONY_LOGE("[slot%{public}d] Get call failed message failed!", slotId_);
1150             return;
1151         }
1152         ResourceUtils::Get().GetStringValueByName(callFailedMessageName, details.message);
1153     }
1154     CellularCallHiSysEvent::WriteCallEndBehaviorEvent(slotId_, static_cast<int32_t>(details.reason));
1155     registerInstance_->ReportCallFailReason(details);
1156 }
1157 
UpdateSrvccStateReport(const AppExecFwk::InnerEvent::Pointer & event)1158 void CellularCallHandler::UpdateSrvccStateReport(const AppExecFwk::InnerEvent::Pointer &event)
1159 {
1160     auto srvccStatus = event->GetSharedObject<SrvccStatus>();
1161     if (srvccStatus == nullptr) {
1162         TELEPHONY_LOGE("[slot%{public}d] srvccStatus is null", slotId_);
1163         return;
1164     }
1165     TELEPHONY_LOGI("[slot%{public}d] srvccStatus is %{public}d", slotId_, srvccStatus->status);
1166     srvccState_ = srvccStatus->status;
1167     auto serviceInstance_ = DelayedSingleton<CellularCallService>::GetInstance();
1168     if (registerInstance_ == nullptr) {
1169         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1170         return;
1171     }
1172     serviceInstance_->SetSrvccState(srvccState_);
1173     if (srvccState_ != SrvccState::COMPLETED) {
1174         TELEPHONY_LOGE("[slot%{public}d] srvccState_ != SrvccState::COMPLETED", slotId_);
1175         return;
1176     }
1177     SrvccStateCompleted();
1178 }
1179 
ReportEccChanged(const AppExecFwk::InnerEvent::Pointer & event)1180 void CellularCallHandler::ReportEccChanged(const AppExecFwk::InnerEvent::Pointer &event)
1181 {
1182     auto emergencyInfoList = event->GetSharedObject<EmergencyInfoList>();
1183     if (emergencyInfoList == nullptr) {
1184         TELEPHONY_LOGE("[slot%{public}d] emergencyInfoList is null", slotId_);
1185         return;
1186     }
1187     CellularCallConfig config;
1188     auto calls = emergencyInfoList->calls;
1189     if (calls.size() > 0 && static_cast<uint32_t>(calls.back().total) != calls.size()) {
1190         TELEPHONY_LOGE("[slot%{public}d] data error", slotId_);
1191         auto endCall = calls.back();
1192         if (endCall.index < endCall.total) {
1193             return;
1194         }
1195         TELEPHONY_LOGI("[slot%{public}d] try query", slotId_);
1196         config.GetEmergencyCallList(slotId_);
1197         return;
1198     }
1199     config.UpdateEmergencyCallFromRadio(slotId_, *emergencyInfoList);
1200 }
1201 
SrvccStateCompleted()1202 void CellularCallHandler::SrvccStateCompleted()
1203 {
1204     if (srvccState_ != SrvccState::COMPLETED) {
1205         TELEPHONY_LOGE("[slot%{public}d] srvccState_ != SrvccState::COMPLETED", slotId_);
1206         return;
1207     }
1208     auto serviceInstance_ = DelayedSingleton<CellularCallService>::GetInstance();
1209     if (serviceInstance_ == nullptr) {
1210         TELEPHONY_LOGE("[slot%{public}d] registerInstance_ is null", slotId_);
1211         return;
1212     }
1213     auto csControl = serviceInstance_->GetCsControl(slotId_);
1214     if (csControl != nullptr) {
1215         TELEPHONY_LOGI("[slot%{public}d] CsControl ReleaseAllConnection", slotId_);
1216         csControl->ReleaseAllConnection();
1217         serviceInstance_->SetCsControl(slotId_, nullptr);
1218     } else {
1219         TELEPHONY_LOGI("[slot%{public}d] CsControl is null", slotId_);
1220         csControl = std::make_shared<CSControl>();
1221         serviceInstance_->SetCsControl(slotId_, csControl);
1222     }
1223     auto imsControl = serviceInstance_->GetImsControl(slotId_);
1224     if (imsControl != nullptr) {
1225         TELEPHONY_LOGI("[slot%{public}d] ImsControl ReleaseAllConnection", slotId_);
1226         imsControl->ReleaseAllConnection();
1227         serviceInstance_->SetImsControl(slotId_, nullptr);
1228     } else {
1229         TELEPHONY_LOGI("[slot%{public}d] imsControl is null", slotId_);
1230     }
1231     srvccState_ = SrvccState::SRVCC_NONE;
1232 }
1233 
GetMMIResponse(const AppExecFwk::InnerEvent::Pointer & event)1234 void CellularCallHandler::GetMMIResponse(const AppExecFwk::InnerEvent::Pointer &event)
1235 {
1236     std::unique_ptr<MMICodeUtils> mmiCodeUtils = event->GetUniqueObject<MMICodeUtils>();
1237     if (mmiCodeUtils == nullptr) {
1238         TELEPHONY_LOGE("[slot%{public}d] mmiCodeUtils is null", slotId_);
1239         return;
1240     }
1241     mmiCodeUtils->ExecuteMmiCode(slotId_);
1242 }
1243 
GetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer & event)1244 void CellularCallHandler::GetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer &event)
1245 {
1246     auto result = event->GetSharedObject<CallWaitResult>();
1247     if (result == nullptr) {
1248         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1249         return;
1250     }
1251     int32_t flag = SS_FROM_MMI_CODE;
1252     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->result.index, flag);
1253     if (ret != TELEPHONY_SUCCESS) {
1254         return;
1255     }
1256     CellularCallSupplement supplement;
1257     supplement.EventGetCallWaiting(*result, result->result.message, flag);
1258 }
1259 
SetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer & event)1260 void CellularCallHandler::SetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer &event)
1261 {
1262     auto result = event->GetSharedObject<SsBaseResult>();
1263     if (result == nullptr) {
1264         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1265         return;
1266     }
1267     int32_t flag = SS_FROM_MMI_CODE;
1268     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1269     if (ret != TELEPHONY_SUCCESS) {
1270         return;
1271     }
1272     CellularCallSupplement supplement;
1273     if (result->result != TELEPHONY_SUCCESS) {
1274         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1275     }
1276     supplement.EventSetCallWaiting(result->result, result->message, flag);
1277 }
1278 
GetClirResponse(const AppExecFwk::InnerEvent::Pointer & event)1279 void CellularCallHandler::GetClirResponse(const AppExecFwk::InnerEvent::Pointer &event)
1280 {
1281     auto getClirResult = event->GetSharedObject<GetClirResult>();
1282     if (getClirResult == nullptr) {
1283         TELEPHONY_LOGE("[slot%{public}d] getClirResult is null", slotId_);
1284         return;
1285     }
1286     int32_t flag = SS_FROM_MMI_CODE;
1287     int32_t ret = ConfirmAndRemoveSsRequestCommand(getClirResult->result.index, flag);
1288     if (ret != TELEPHONY_SUCCESS) {
1289         return;
1290     }
1291     CellularCallSupplement supplement;
1292     supplement.EventGetClir(*getClirResult, getClirResult->result.message, flag);
1293 }
1294 
SetClirResponse(const AppExecFwk::InnerEvent::Pointer & event)1295 void CellularCallHandler::SetClirResponse(const AppExecFwk::InnerEvent::Pointer &event)
1296 {
1297     auto result = event->GetSharedObject<SsBaseResult>();
1298     if (result == nullptr) {
1299         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1300         return;
1301     }
1302     int32_t flag = SS_FROM_MMI_CODE;
1303     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1304     if (ret != TELEPHONY_SUCCESS) {
1305         return;
1306     }
1307     CellularCallSupplement supplement;
1308     supplement.EventSetClir(result->result, result->message, flag);
1309 }
1310 
GetClipResponse(const AppExecFwk::InnerEvent::Pointer & event)1311 void CellularCallHandler::GetClipResponse(const AppExecFwk::InnerEvent::Pointer &event)
1312 {
1313     auto getClipResult = event->GetSharedObject<GetClipResult>();
1314     if (getClipResult == nullptr) {
1315         TELEPHONY_LOGE("[slot%{public}d] getClipResult is null", slotId_);
1316         return;
1317     }
1318     int32_t flag = SS_FROM_MMI_CODE;
1319     int32_t ret = ConfirmAndRemoveSsRequestCommand(getClipResult->result.index, flag);
1320     if (ret != TELEPHONY_SUCCESS) {
1321         return;
1322     }
1323     CellularCallSupplement supplement;
1324     supplement.EventGetClip(*getClipResult, getClipResult->result.message, flag);
1325 }
1326 
SetClipResponse(const AppExecFwk::InnerEvent::Pointer & event)1327 void CellularCallHandler::SetClipResponse(const AppExecFwk::InnerEvent::Pointer &event)
1328 {
1329     auto result = event->GetSharedObject<SsBaseResult>();
1330     if (result == nullptr) {
1331         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1332         return;
1333     }
1334     int32_t flag = SS_FROM_MMI_CODE;
1335     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1336     if (ret != TELEPHONY_SUCCESS) {
1337         return;
1338     }
1339     CellularCallSupplement supplement;
1340     supplement.EventSetClip(result->result, result->message, flag);
1341 }
1342 
GetColrResponse(const AppExecFwk::InnerEvent::Pointer & event)1343 void CellularCallHandler::GetColrResponse(const AppExecFwk::InnerEvent::Pointer &event)
1344 {
1345     auto colrResult = event->GetSharedObject<GetColrResult>();
1346     if (colrResult == nullptr) {
1347         TELEPHONY_LOGE("[slot%{public}d] colrResult is null", slotId_);
1348         return;
1349     }
1350     int32_t flag = SS_FROM_MMI_CODE;
1351     int32_t ret = ConfirmAndRemoveSsRequestCommand(colrResult->result.index, flag);
1352     if (ret != TELEPHONY_SUCCESS) {
1353         return;
1354     }
1355     CellularCallSupplement supplement;
1356     supplement.EventGetColr(*colrResult, colrResult->result.message, flag);
1357 }
1358 
SetColrResponse(const AppExecFwk::InnerEvent::Pointer & event)1359 void CellularCallHandler::SetColrResponse(const AppExecFwk::InnerEvent::Pointer &event)
1360 {
1361     auto result = event->GetSharedObject<SsBaseResult>();
1362     if (result == nullptr) {
1363         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1364         return;
1365     }
1366     int32_t flag = SS_FROM_MMI_CODE;
1367     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1368     if (ret != TELEPHONY_SUCCESS) {
1369         return;
1370     }
1371     CellularCallSupplement supplement;
1372     supplement.EventSetColr(result->result, result->message, flag);
1373 }
1374 
GetColpResponse(const AppExecFwk::InnerEvent::Pointer & event)1375 void CellularCallHandler::GetColpResponse(const AppExecFwk::InnerEvent::Pointer &event)
1376 {
1377     auto colpResult = event->GetSharedObject<GetColpResult>();
1378     if (colpResult == nullptr) {
1379         TELEPHONY_LOGE("[slot%{public}d] colpResult is null", slotId_);
1380         return;
1381     }
1382     int32_t flag = SS_FROM_MMI_CODE;
1383     int32_t ret = ConfirmAndRemoveSsRequestCommand(colpResult->result.index, flag);
1384     if (ret != TELEPHONY_SUCCESS) {
1385         return;
1386     }
1387     CellularCallSupplement supplement;
1388     supplement.EventGetColp(*colpResult, colpResult->result.message, flag);
1389 }
1390 
SetColpResponse(const AppExecFwk::InnerEvent::Pointer & event)1391 void CellularCallHandler::SetColpResponse(const AppExecFwk::InnerEvent::Pointer &event)
1392 {
1393     auto result = event->GetSharedObject<SsBaseResult>();
1394     if (result == nullptr) {
1395         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1396         return;
1397     }
1398     int32_t flag = SS_FROM_MMI_CODE;
1399     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1400     if (ret != TELEPHONY_SUCCESS) {
1401         return;
1402     }
1403     CellularCallSupplement supplement;
1404     supplement.EventSetColp(result->result, result->message, flag);
1405 }
1406 
GetCallTransferResponse(const AppExecFwk::InnerEvent::Pointer & event)1407 void CellularCallHandler::GetCallTransferResponse(const AppExecFwk::InnerEvent::Pointer &event)
1408 {
1409     auto cFQueryList = event->GetSharedObject<CallForwardQueryInfoList>();
1410     if (cFQueryList == nullptr) {
1411         TELEPHONY_LOGE("[slot%{public}d] cFQueryList is null", slotId_);
1412         return;
1413     }
1414     SsRequestCommand ss;
1415     int32_t ret = GetSsRequestCommand(cFQueryList->result.index, ss);
1416     if (ret == TELEPHONY_SUCCESS) {
1417         cFQueryList->result.reason = ss.cfReason;
1418     }
1419     int32_t flag = SS_FROM_MMI_CODE;
1420     ret = ConfirmAndRemoveSsRequestCommand(cFQueryList->result.index, flag);
1421     if (ret != TELEPHONY_SUCCESS) {
1422         return;
1423     }
1424     CellularCallSupplement supplement;
1425     supplement.EventGetCallTransferInfo(*cFQueryList, cFQueryList->result.message, flag);
1426 }
1427 
SetCallTransferInfoResponse(const AppExecFwk::InnerEvent::Pointer & event)1428 void CellularCallHandler::SetCallTransferInfoResponse(const AppExecFwk::InnerEvent::Pointer &event)
1429 {
1430     auto result = event->GetSharedObject<SsBaseResult>();
1431     if (result == nullptr) {
1432         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1433         return;
1434     }
1435     int32_t flag = SS_FROM_MMI_CODE;
1436     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1437     if (ret != TELEPHONY_SUCCESS) {
1438         return;
1439     }
1440     CellularCallSupplement supplement;
1441     CallForwardingInfo info;
1442     auto callHiSysEvent = DelayedSingleton<CellularCallHiSysEvent>::GetInstance();
1443     if (callHiSysEvent == nullptr) {
1444         TELEPHONY_LOGE("CellularCallHiSysEvent is null.");
1445         return;
1446     }
1447     callHiSysEvent->GetCallForwardingInfo(info);
1448     if (result->result == TELEPHONY_SUCCESS) {
1449         CoreManagerInner::GetInstance().SetVoiceCallForwarding(info.slotId, info.enable, info.number);
1450     } else {
1451         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1452     }
1453     supplement.EventSetCallTransferInfo(result->result, result->message, flag);
1454 }
1455 
GetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer & event)1456 void CellularCallHandler::GetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer &event)
1457 {
1458     auto result = event->GetSharedObject<CallRestrictionResult>();
1459     if (result == nullptr) {
1460         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1461         return;
1462     }
1463     int32_t flag = SS_FROM_MMI_CODE;
1464     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->result.index, flag);
1465     if (ret != TELEPHONY_SUCCESS) {
1466         return;
1467     }
1468     CellularCallSupplement supplement;
1469     supplement.EventGetCallRestriction(*result, result->result.message, flag);
1470 }
1471 
SetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer & event)1472 void CellularCallHandler::SetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer &event)
1473 {
1474     auto result = event->GetSharedObject<SsBaseResult>();
1475     if (result == nullptr) {
1476         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1477         return;
1478     }
1479     int32_t flag = SS_FROM_MMI_CODE;
1480     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1481     if (ret != TELEPHONY_SUCCESS) {
1482         return;
1483     }
1484     CellularCallSupplement supplement;
1485     if (result->result != TELEPHONY_SUCCESS) {
1486         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1487     }
1488     supplement.EventSetCallRestriction(result->result, result->message, flag);
1489 }
1490 
SetBarringPasswordResponse(const AppExecFwk::InnerEvent::Pointer & event)1491 void CellularCallHandler::SetBarringPasswordResponse(const AppExecFwk::InnerEvent::Pointer &event)
1492 {
1493     auto result = event->GetSharedObject<SsBaseResult>();
1494     if (result == nullptr) {
1495         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1496         return;
1497     }
1498     int32_t flag = SS_FROM_MMI_CODE;
1499     int32_t ret = ConfirmAndRemoveSsRequestCommand(result->index, flag);
1500     if (ret != TELEPHONY_SUCCESS) {
1501         return;
1502     }
1503     CellularCallSupplement supplement;
1504     if (result->result != TELEPHONY_SUCCESS) {
1505         result->result = TELEPHONY_ERR_RIL_CMD_FAIL;
1506     }
1507     supplement.EventSetBarringPassword(result->result, result->message, flag);
1508 }
1509 
SendUssdResponse(const AppExecFwk::InnerEvent::Pointer & event)1510 void CellularCallHandler::SendUssdResponse(const AppExecFwk::InnerEvent::Pointer &event)
1511 {
1512     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
1513     if (result == nullptr) {
1514         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1515         return;
1516     }
1517     CellularCallSupplement supplement;
1518     supplement.EventSendUssd(*result);
1519 }
1520 
SsNotifyResponse(const AppExecFwk::InnerEvent::Pointer & event)1521 void CellularCallHandler::SsNotifyResponse(const AppExecFwk::InnerEvent::Pointer &event)
1522 {
1523     auto result = event->GetSharedObject<SsNoticeInfo>();
1524     if (result == nullptr) {
1525         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1526         return;
1527     }
1528     CellularCallSupplement supplement;
1529     supplement.EventSsNotify(*result);
1530 }
1531 
SendUnlockPinPukResponse(const AppExecFwk::InnerEvent::Pointer & event)1532 void CellularCallHandler::SendUnlockPinPukResponse(const AppExecFwk::InnerEvent::Pointer &event)
1533 {
1534     auto result = event->GetSharedObject<PinPukResponse>();
1535     if (result == nullptr) {
1536         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1537         return;
1538     }
1539     CellularCallSupplement supplement;
1540     supplement.EventSetPinPuk(*result);
1541 }
1542 
HandleOperatorConfigChanged(const AppExecFwk::InnerEvent::Pointer & event)1543 void CellularCallHandler::HandleOperatorConfigChanged(const AppExecFwk::InnerEvent::Pointer &event)
1544 {
1545     CellularCallConfig config;
1546     config.HandleOperatorConfigChanged(slotId_);
1547 }
1548 
UpdateRsrvccStateReport(const AppExecFwk::InnerEvent::Pointer & event)1549 void CellularCallHandler::UpdateRsrvccStateReport(const AppExecFwk::InnerEvent::Pointer &event)
1550 {
1551     isInCsRedial_ = true;
1552     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
1553     if (serviceInstance == nullptr) {
1554         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
1555         return;
1556     }
1557     serviceInstance->SetCsControl(slotId_, nullptr);
1558 }
1559 
RequestSsRequestCommandIndex(int32_t & index)1560 void CellularCallHandler::RequestSsRequestCommandIndex(int32_t &index)
1561 {
1562     if (indexCommand_ >= MAX_REQUEST_COUNT) {
1563         indexCommand_ = 0;
1564     } else {
1565         indexCommand_++;
1566     }
1567     index = indexCommand_;
1568 }
1569 
SaveSsRequestCommand(const std::shared_ptr<SsRequestCommand> & utCommand,int32_t index)1570 void CellularCallHandler::SaveSsRequestCommand(const std::shared_ptr<SsRequestCommand> &utCommand, int32_t index)
1571 {
1572     if (utCommand == nullptr) {
1573         TELEPHONY_LOGE("[slot%{public}d] utCommand is null", slotId_);
1574         return;
1575     }
1576     std::lock_guard<std::mutex> lock(mutex_);
1577     utCommandMap_.insert(std::make_pair(indexCommand_, utCommand));
1578 }
1579 
ConfirmAndRemoveSsRequestCommand(int32_t index,int32_t & flag)1580 int32_t CellularCallHandler::ConfirmAndRemoveSsRequestCommand(int32_t index, int32_t &flag)
1581 {
1582     if (index == INVALID_INDEX) {
1583         // -1 mean this command index wasn't come from app, so don't need report result
1584         TELEPHONY_LOGI("[slot%{public}d] index is invalid, nothing need to do", slotId_);
1585         return TELEPHONY_ERROR;
1586     }
1587     std::lock_guard<std::mutex> lock(mutex_);
1588     auto itor = utCommandMap_.find(index);
1589     if (itor == utCommandMap_.end()) {
1590         TELEPHONY_LOGE("[slot%{public}d] the index(%{public}d) in utCommandMap_ haven't been found", slotId_, index);
1591         return TELEPHONY_ERROR;
1592     }
1593     flag = itor->second->flag;
1594     utCommandMap_.erase(index);
1595     return TELEPHONY_SUCCESS;
1596 }
1597 
GetSsRequestCommand(int32_t index,SsRequestCommand & ss)1598 int32_t CellularCallHandler::GetSsRequestCommand(int32_t index, SsRequestCommand &ss)
1599 {
1600     std::lock_guard<std::mutex> lock(mutex_);
1601     auto itor = utCommandMap_.find(index);
1602     if (itor == utCommandMap_.end()) {
1603         TELEPHONY_LOGE("[slot%{public}d] the index in utCommandMap_ haven't been found", slotId_);
1604         return TELEPHONY_ERROR;
1605     }
1606 
1607     ss.cfAction = itor->second->cfAction;
1608     ss.cfReason = itor->second->cfReason;
1609     ss.number = itor->second->number;
1610     ss.enable = itor->second->enable;
1611     ss.clirAction = itor->second->clirAction;
1612     ss.facility = itor->second->facility;
1613     if (strcpy_s(ss.password, sizeof(ss.password), itor->second->password) != EOK) {
1614         TELEPHONY_LOGE("password strcpy_s fail.");
1615         return TELEPHONY_ERR_STRCPY_FAIL;
1616     }
1617     ss.classType = itor->second->classType;
1618     ss.action = itor->second->action;
1619     ss.flag = itor->second->flag;
1620     return TELEPHONY_SUCCESS;
1621 }
1622 
CloseUnFinishedUssdResponse(const AppExecFwk::InnerEvent::Pointer & event)1623 void CellularCallHandler::CloseUnFinishedUssdResponse(const AppExecFwk::InnerEvent::Pointer &event)
1624 {
1625     auto result = event->GetSharedObject<HRilRadioResponseInfo>();
1626     if (result == nullptr) {
1627         TELEPHONY_LOGE("[slot%{public}d] result is null", slotId_);
1628         return;
1629     }
1630     CellularCallSupplement supplement;
1631     supplement.EventCloseUnFinishedUssd(*result);
1632 }
1633 
OnRilAdapterHostDied(const AppExecFwk::InnerEvent::Pointer & event)1634 void CellularCallHandler::OnRilAdapterHostDied(const AppExecFwk::InnerEvent::Pointer &event)
1635 {
1636     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
1637     if (serviceInstance == nullptr) {
1638         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
1639         return;
1640     }
1641     auto csControl = serviceInstance->GetCsControl(slotId_);
1642     if (csControl == nullptr) {
1643         TELEPHONY_LOGE("[slot%{public}d] cs_control is null", slotId_);
1644     } else if (csControl->ReportHangUpInfo(slotId_) != TELEPHONY_SUCCESS) {
1645         TELEPHONY_LOGE("[slot%{public}d] fail to disconnect cs calls", slotId_);
1646     } else {
1647         serviceInstance->SetCsControl(slotId_, nullptr);
1648     }
1649     auto imsControl = serviceInstance->GetImsControl(slotId_);
1650     if (imsControl == nullptr) {
1651         TELEPHONY_LOGE("[slot%{public}d] ims_control is null", slotId_);
1652     } else if (imsControl->ReportHangUpInfo(slotId_) != TELEPHONY_SUCCESS) {
1653         TELEPHONY_LOGE("[slot%{public}d] fail to disconnect ims calls", slotId_);
1654     } else {
1655         serviceInstance->SetImsControl(slotId_, nullptr);
1656     }
1657 }
1658 
1659 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
StartCallManagerService()1660 void CellularCallHandler::StartCallManagerService()
1661 {
1662     auto serviceInstance = DelayedSingleton<CellularCallService>::GetInstance();
1663     if (serviceInstance == nullptr) {
1664         TELEPHONY_LOGE("[slot%{public}d] serviceInstance is null", slotId_);
1665         return;
1666     }
1667     serviceInstance->StartCallManagerService();
1668 }
1669 
RadioStateChangeProcess(const AppExecFwk::InnerEvent::Pointer & event)1670 void CellularCallHandler::RadioStateChangeProcess(const AppExecFwk::InnerEvent::Pointer &event)
1671 {
1672     std::shared_ptr<HRilInt32Parcel> object = event->GetSharedObject<HRilInt32Parcel>();
1673     if (object == nullptr) {
1674         TELEPHONY_LOGE("[slot%{public}d] object is null", slotId_);
1675         return;
1676     }
1677     TELEPHONY_LOGI("[slot%{public}d] Radio changed with state: %{public}d", slotId_, object->data);
1678     if (object->data == CORE_SERVICE_POWER_ON) {
1679         StartCallManagerService();
1680     }
1681 }
1682 
GetRadioStateProcess(const AppExecFwk::InnerEvent::Pointer & event)1683 void CellularCallHandler::GetRadioStateProcess(const AppExecFwk::InnerEvent::Pointer &event)
1684 {
1685     auto object = event->GetUniqueObject<HRilRadioStateInfo>();
1686     if (object == nullptr) {
1687         TELEPHONY_LOGE("object is null");
1688         return;
1689     }
1690     TELEPHONY_LOGI("GetRadioStateProcess [slot%{public}d], state=%{public}d", slotId_, object->state);
1691     if (object->state == CORE_SERVICE_POWER_ON) {
1692         StartCallManagerService();
1693     }
1694 }
1695 #endif
1696 } // namespace Telephony
1697 } // namespace OHOS
1698