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