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 #ifndef CELLULAR_CALL_HANDLER_H 17 #define CELLULAR_CALL_HANDLER_H 18 19 #include <memory> 20 #include <mutex> 21 #include <regex> 22 23 #include "cellular_call_config.h" 24 #include "cellular_call_data_struct.h" 25 #include "cellular_call_register.h" 26 #include "common_event.h" 27 #include "common_event_manager.h" 28 #include "common_event_support.h" 29 #include "cs_control.h" 30 #include "ims_call_types.h" 31 #include "ims_control.h" 32 #include "satellite_control.h" 33 #include "tel_event_handler.h" 34 #include "telephony_log_wrapper.h" 35 36 namespace OHOS { 37 namespace Telephony { 38 39 constexpr const char *KEY_CONST_TELEPHONY_IS_USE_CLOUD_IMS_NV = "const.telephony.is_use_cloud_ims_nv"; 40 constexpr const char *KEY_PERSIST_TELEPHONY_VOLTE_CAP_IN_CHIP = "persist.telephony.volte_cap_in_chip"; 41 class CellularCallHandler : public TelEventHandler, public EventFwk::CommonEventSubscriber { 42 public: 43 /** 44 * CellularCallHandler constructor 45 * 46 * @param runner 47 * @param subscriberInfo 48 */ 49 explicit CellularCallHandler(const EventFwk::CommonEventSubscribeInfo &subscriberInfo); 50 51 /** 52 * ~CellularCallHandler destructor 53 */ 54 ~CellularCallHandler() = default; 55 56 /** 57 * ProcessEvent. 58 * 59 * @param CellularCallRadioResponseEvent, Process Radio Response Event . 60 */ 61 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 62 63 /** 64 * Receive Operator Config Change event and process. 65 * 66 * @param CommonEventData, Process Operator Config Change . 67 */ 68 void OnReceiveEvent(const EventFwk::CommonEventData &data) override; 69 70 /** 71 * Set Slot Id 72 * 73 * @param id 74 */ 75 void SetSlotId(int32_t id); 76 77 /** 78 * Get Slot Id 79 * @return id 80 */ 81 int32_t GetSlotId(); 82 83 void RegisterImsCallCallbackHandler(); 84 85 void RegisterSatelliteCallCallbackHandler(); 86 87 void SimStateChangeReport(const AppExecFwk::InnerEvent::Pointer &event); 88 89 void FactoryReset(const AppExecFwk::InnerEvent::Pointer &event); 90 91 void SimRecordsLoadedReport(const AppExecFwk::InnerEvent::Pointer &event); 92 93 void SimAccountLoadedReport(const AppExecFwk::InnerEvent::Pointer &event); 94 95 void ResidentNetworkChangeReport(const AppExecFwk::InnerEvent::Pointer &event); 96 97 void NetworkStateChangeReport(const AppExecFwk::InnerEvent::Pointer &event); 98 99 void DialResponse(const AppExecFwk::InnerEvent::Pointer &event); 100 101 void DialSatelliteResponse(const AppExecFwk::InnerEvent::Pointer &event); 102 103 void CommonResultEventHandling(const AppExecFwk::InnerEvent::Pointer &event, CellularCallEventInfo &eventInfo); 104 105 void CommonResultResponse(const AppExecFwk::InnerEvent::Pointer &event); 106 107 void ExecutePostDial(const AppExecFwk::InnerEvent::Pointer &event); 108 109 void SwapCallResponse(const AppExecFwk::InnerEvent::Pointer &event); 110 111 void SendDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event); 112 113 void StartDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event); 114 115 void StopDtmfResponse(const AppExecFwk::InnerEvent::Pointer &event); 116 117 void GetCsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event); 118 119 void GetImsCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event); 120 121 void CsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event); 122 123 void ImsCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event); 124 125 void SatelliteCallStatusInfoReport(const AppExecFwk::InnerEvent::Pointer &event); 126 127 void ReportEccChanged(const AppExecFwk::InnerEvent::Pointer &event); 128 129 void SetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer &event); 130 131 void GetDomainPreferenceModeResponse(const AppExecFwk::InnerEvent::Pointer &event); 132 133 void SetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event); 134 135 void GetImsSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event); 136 137 void SetVoNRSwitchStatusResponse(const AppExecFwk::InnerEvent::Pointer &event); 138 139 void UssdNotifyResponse(const AppExecFwk::InnerEvent::Pointer &event); 140 141 void SsNotifyResponse(const AppExecFwk::InnerEvent::Pointer &event); 142 143 void CallRingBackVoiceResponse(const AppExecFwk::InnerEvent::Pointer &event); 144 145 void SetMuteResponse(const AppExecFwk::InnerEvent::Pointer &event); 146 147 void GetMuteResponse(const AppExecFwk::InnerEvent::Pointer &event); 148 149 void GetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer &event); 150 151 void SetEmergencyCallListResponse(const AppExecFwk::InnerEvent::Pointer &event); 152 153 void GetCallFailReasonResponse(const AppExecFwk::InnerEvent::Pointer &event); 154 155 void UpdateSrvccStateReport(const AppExecFwk::InnerEvent::Pointer &event); 156 157 void SrvccStateCompleted(); 158 159 void ReceiveUpdateCallMediaModeRequest(const AppExecFwk::InnerEvent::Pointer &event); 160 161 void ReceiveUpdateCallMediaModeResponse(const AppExecFwk::InnerEvent::Pointer &event); 162 163 void HandleCallSessionEventChanged(const AppExecFwk::InnerEvent::Pointer &event); 164 165 void HandlePeerDimensionsChanged(const AppExecFwk::InnerEvent::Pointer &event); 166 167 void HandleCallDataUsageChanged(const AppExecFwk::InnerEvent::Pointer &event); 168 169 void HandleCameraCapabilitiesChanged(const AppExecFwk::InnerEvent::Pointer &event); 170 171 void GetSatelliteCallsDataResponse(const AppExecFwk::InnerEvent::Pointer &event); 172 173 /** 174 * request the ut command index which will be used to report the result 175 * 176 * @param index 177 */ 178 void RequestSsRequestCommandIndex(int32_t &index); 179 180 /** 181 * save the ut command which will be used to report the result 182 * 183 * @param SsRequestCommand 184 * @param index 185 */ 186 void SaveSsRequestCommand(const std::shared_ptr<SsRequestCommand> &utCommand, int32_t index); 187 188 int32_t GetSsRequestCommand(int32_t index, SsRequestCommand &ss); 189 190 void NvCfgFinishedIndication(const AppExecFwk::InnerEvent::Pointer &event); 191 192 int32_t GetImsCapabilities(int32_t slotId); 193 194 void GetImsCapResponse(const AppExecFwk::InnerEvent::Pointer &event); 195 196 public: 197 const uint32_t REGISTER_HANDLER_ID = 10003; 198 const int32_t INTERNATION_CODE = 145; 199 int32_t srvccState_ = SrvccState::SRVCC_NONE; 200 201 private: 202 int64_t CurrentTimeMillis(); 203 void GetCsCallData(const AppExecFwk::InnerEvent::Pointer &event); 204 void GetImsCallData(const AppExecFwk::InnerEvent::Pointer &event); 205 void GetSatelliteCallData(const AppExecFwk::InnerEvent::Pointer &event); 206 void GetCsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event); 207 void GetImsCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event); 208 void GetSatelliteCallsDataRequest(const AppExecFwk::InnerEvent::Pointer &event); 209 void RegisterHandler(const AppExecFwk::InnerEvent::Pointer &event); 210 void GetMMIResponse(const AppExecFwk::InnerEvent::Pointer &event); 211 void GetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer &event); 212 void SetCallWaitingResponse(const AppExecFwk::InnerEvent::Pointer &event); 213 void GetClirResponse(const AppExecFwk::InnerEvent::Pointer &event); 214 void SetClirResponse(const AppExecFwk::InnerEvent::Pointer &event); 215 void GetClipResponse(const AppExecFwk::InnerEvent::Pointer &event); 216 void SetClipResponse(const AppExecFwk::InnerEvent::Pointer &event); 217 void GetColrResponse(const AppExecFwk::InnerEvent::Pointer &event); 218 void SetColrResponse(const AppExecFwk::InnerEvent::Pointer &event); 219 void GetColpResponse(const AppExecFwk::InnerEvent::Pointer &event); 220 void SetColpResponse(const AppExecFwk::InnerEvent::Pointer &event); 221 void GetCallTransferResponse(const AppExecFwk::InnerEvent::Pointer &event); 222 void SetCallTransferInfoResponse(const AppExecFwk::InnerEvent::Pointer &event); 223 void GetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer &event); 224 void SetCallRestrictionResponse(const AppExecFwk::InnerEvent::Pointer &event); 225 void SetBarringPasswordResponse(const AppExecFwk::InnerEvent::Pointer &event); 226 int32_t ConfirmAndRemoveSsRequestCommand(int32_t index, int32_t &flag); 227 int32_t ConfirmAndRemoveSsRequestCommand(int32_t index, int32_t &flag, int32_t &action); 228 void SendUssdResponse(const AppExecFwk::InnerEvent::Pointer &event); 229 void SendUnlockPinPukResponse(const AppExecFwk::InnerEvent::Pointer &event); 230 void CloseUnFinishedUssdResponse(const AppExecFwk::InnerEvent::Pointer &event); 231 void OnRilAdapterHostDied(const AppExecFwk::InnerEvent::Pointer &event); 232 233 void InitBasicFuncMap(); 234 void InitConfigFuncMap(); 235 void InitSupplementFuncMap(); 236 void InitActiveReportFuncMap(); 237 void InitSatelliteCallFuncMap(); 238 void InitAdditionalFuncMap(); 239 240 void ReportCsCallsData(const CallInfoList &callInfoList); 241 void ReportNoCsCallsData(const CallInfoList &callInfoList, const int32_t state, 242 const std::shared_ptr<CSControl> &csControl); 243 void ReportImsCallsData(const ImsCurrentCallList &imsCallInfoList); 244 void ReportSatelliteCallsData(const SatelliteCurrentCallList &callInfoList); 245 void HandleOperatorConfigChanged(const AppExecFwk::InnerEvent::Pointer &event); 246 void UpdateRsrvccStateReport(const AppExecFwk::InnerEvent::Pointer &event); 247 void ProcessRedundantCode(CallInfoList &callInfoList); 248 void ProcessCsPhoneNumber(CallInfoList &list); 249 void ProcessImsPhoneNumber(ImsCurrentCallList &list); 250 void replacePrefix(std::string &number); 251 void HandleCallDisconnectReason(RilDisconnectedReason reason, const std::string &message); 252 void UpdateImsConfiguration(); 253 void GetImsSwitchStatusRequest(); 254 255 /** 256 * If radio state change get call manager service 257 * 258 * @param AppExecFwk::InnerEvent::Pointer 259 */ 260 void RadioStateChangeProcess(const AppExecFwk::InnerEvent::Pointer &event); 261 262 /** 263 * If get radio state on, get call manager service 264 * 265 * @param AppExecFwk::InnerEvent::Pointer 266 */ 267 void GetRadioStateProcess(const AppExecFwk::InnerEvent::Pointer &event); 268 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE 269 void StartCallManagerService(); 270 #endif 271 272 private: 273 void CellularCallIncomingStartTrace(const int32_t state); 274 void CellularCallIncomingFinishTrace(const int32_t state); 275 276 private: 277 int32_t slotId_ = DEFAULT_SIM_SLOT_ID; 278 int64_t lastCallsDataFlag_ = 0L; 279 using RequestFuncType = std::function<void(const AppExecFwk::InnerEvent::Pointer &event)>; 280 std::map<uint32_t, RequestFuncType> requestFuncMap_; 281 std::shared_ptr<CellularCallRegister> registerInstance_ = DelayedSingleton<CellularCallRegister>::GetInstance(); 282 bool isInCsRedial_ = false; 283 int32_t indexCommand_ = 0; 284 std::map<int32_t, std::shared_ptr<SsRequestCommand>> utCommandMap_; 285 std::mutex mutex_; 286 ImsCurrentCallList currentCallList_{}; 287 CallInfoList currentCsCallInfoList_{}; 288 }; 289 } // namespace Telephony 290 } // namespace OHOS 291 292 #endif 293