1 /* 2 * Copyright (C) 2021-2024 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 NETWORK_SEARCH_INCLUDE_NETWORK_SEARCH_HANDLER_H 17 #define NETWORK_SEARCH_INCLUDE_NETWORK_SEARCH_HANDLER_H 18 19 #include <memory> 20 21 #include "cell_info.h" 22 #include "i_sim_manager.h" 23 #include "i_tel_ril_manager.h" 24 #include "network_register.h" 25 #include "network_selection.h" 26 #include "network_type.h" 27 #include "nitz_update.h" 28 #include "nr_ssb_info.h" 29 #include "operator_name.h" 30 #include "radio_event.h" 31 #include "radio_info.h" 32 #include "satellite_core_callback.h" 33 #include "signal_info.h" 34 #include "system_ability_status_change_stub.h" 35 #include "tel_event_handler.h" 36 #include "tel_ril_types.h" 37 38 namespace OHOS { 39 namespace Telephony { 40 class NetworkSearchManager; 41 class NetworkSearchHandler : public TelEventHandler { 42 public: 43 using NsHandlerFunc = std::function<void(NetworkSearchHandler *, const AppExecFwk::InnerEvent::Pointer &)>; 44 explicit NetworkSearchHandler(const std::weak_ptr<NetworkSearchManager> &networkSearchManager, 45 const std::weak_ptr<ITelRilManager> &telRilManager, const std::weak_ptr<ISimManager> &simManager, 46 int32_t slotId); 47 virtual ~NetworkSearchHandler(); 48 bool Init(); 49 void RegisterEvents(); 50 void UnregisterEvents(); 51 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 52 void GetSignalInfo(std::vector<sptr<SignalInformation>> &signals); 53 void UpdatePhone(RadioTech csRadioTech, const RadioTech &psRadioTech) const; 54 int32_t GetCellInfoList(std::vector<sptr<CellInformation>> &cells); 55 int32_t GetNeighboringCellInfoList(std::vector<sptr<CellInformation>> &cells); 56 void DcPhysicalLinkActiveUpdate(const AppExecFwk::InnerEvent::Pointer &event); 57 void NotifyStateChange(const AppExecFwk::InnerEvent::Pointer &event); 58 void HandleDelayNotifyEvent(const AppExecFwk::InnerEvent::Pointer &event); 59 int32_t HandleRrcStateChanged(int32_t status); 60 int32_t RevertLastTechnology(); 61 void UpdateImsServiceStatus(const AppExecFwk::InnerEvent::Pointer &event); 62 void UpdateImsRegisterState(const AppExecFwk::InnerEvent::Pointer &event); 63 void RegisterSatelliteCallback(); 64 void UnregisterSatelliteCallback(); 65 int32_t SendUpdateCellLocationRequest(); 66 PhoneType GetPhoneType(); 67 int32_t GetNrSsbId(const std::shared_ptr<NrSsbInformation> &nrCellSsbIdsInfo); 68 69 /** 70 * Get signal quality 71 * 27007-410_2001 8.5 Signal quality +CSQ 72 * 3GPP TS 27.007 V4.1.0 (2001-03) 73 */ 74 void GetRilSignalIntensity(bool checkTime = true); 75 76 /** 77 * querying the status of all GSM/UMTS operators detected in the area. 78 * 27007-410_2001 7.3 PLMN selection +COPS 79 * 3GPP TS 27.007 V4.1.0 (2001-03) 80 */ 81 void GetRilOperatorInfo(int64_t serialNum, bool checkTime = true); 82 83 /** 84 * Get PS network registration status 85 * 27007-410_2001 10.1.19 GPRS network registration status +CGREG 86 * 3GPP TS 27.007 V4.1.0 (2001-03) 87 */ 88 void GetRilPsRegistration(int64_t serialNum, bool checkTime = true); 89 90 /** 91 * Get CS network registration status 92 * 27007-410_2001 7.2 Network registration +CREG 93 * 3GPP TS 27.007 V4.1.0 (2001-03) 94 */ 95 void GetRilCsRegistration(int64_t serialNum, bool checkTime = true); 96 97 void UpdateCellLocation(int32_t techType, int32_t cellId, int32_t lac); 98 sptr<CellLocation> GetCellLocation(); 99 void TimezoneRefresh(); 100 void SetCellRequestMinInterval(uint32_t minInterval); 101 bool IsPowerOnPrimaryRadioWhenNoSim() const; 102 void ProcessSignalIntensity(int32_t slotId, const Rssi &signalIntensity); 103 void RadioOnState(bool forceNotify = true); 104 void UpdateOperatorName(); 105 106 private: 107 void RadioOffOrUnavailableState(int32_t radioState) const; 108 void SetRadioOffWhenAirplaneIsOn(); 109 void SetRadioOffWhenSimDeactive(); 110 void GetRadioStateResponse(const AppExecFwk::InnerEvent::Pointer &event); 111 void SetRadioStateResponse(const AppExecFwk::InnerEvent::Pointer &event); 112 void SimStateChange(const AppExecFwk::InnerEvent::Pointer &); 113 void ImsiLoadedReady(const AppExecFwk::InnerEvent::Pointer &event); 114 void SimRecordsLoaded(const AppExecFwk::InnerEvent::Pointer &); 115 void RadioStateChange(const AppExecFwk::InnerEvent::Pointer &event); 116 void GetNetworkStateInfo(const AppExecFwk::InnerEvent::Pointer &); 117 void RadioRestrictedState(const AppExecFwk::InnerEvent::Pointer &event); 118 void RadioRilDataRegState(const AppExecFwk::InnerEvent::Pointer &event); 119 void RadioRilVoiceRegState(const AppExecFwk::InnerEvent::Pointer &event); 120 void RadioSignalStrength(const AppExecFwk::InnerEvent::Pointer &event); 121 void RadioRilOperator(const AppExecFwk::InnerEvent::Pointer &event); 122 bool TimeOutCheck(int64_t &lastTime, bool checkTime = true); 123 void NetworkSearchResult(const AppExecFwk::InnerEvent::Pointer &event); 124 void GetNetworkSelectionModeResponse(const AppExecFwk::InnerEvent::Pointer &event); 125 void SetNetworkSelectionModeResponse(const AppExecFwk::InnerEvent::Pointer &event); 126 void InitGetNetworkSelectionMode(); 127 void InitNetworkSearchResult(); 128 void GetPreferredNetworkResponse(const AppExecFwk::InnerEvent::Pointer &event); 129 void SetPreferredNetworkResponse(const AppExecFwk::InnerEvent::Pointer &event); 130 void RadioNitzUpdate(const AppExecFwk::InnerEvent::Pointer &event); 131 void RadioGetImei(const AppExecFwk::InnerEvent::Pointer &event); 132 void RadioGetImeiSv(const AppExecFwk::InnerEvent::Pointer &event); 133 void RadioGetMeid(const AppExecFwk::InnerEvent::Pointer &event); 134 void RadioGetNeighboringCellInfo(const AppExecFwk::InnerEvent::Pointer &event); 135 void RadioGetCurrentCellInfo(const AppExecFwk::InnerEvent::Pointer &event); 136 void RadioCurrentCellInfoUpdate(const AppExecFwk::InnerEvent::Pointer &event); 137 void RadioChannelConfigInfo(const AppExecFwk::InnerEvent::Pointer &event); 138 void RadioVoiceTechChange(const AppExecFwk::InnerEvent::Pointer &event); 139 void AutoTimeChange(const AppExecFwk::InnerEvent::Pointer &); 140 void AutoTimeZoneChange(const AppExecFwk::InnerEvent::Pointer &); 141 void AirplaneModeChange(const AppExecFwk::InnerEvent::Pointer &); 142 void RadioGetBasebandVersion(const AppExecFwk::InnerEvent::Pointer &event); 143 void SetNrOptionModeResponse(const AppExecFwk::InnerEvent::Pointer &event); 144 void GetNrOptionModeResponse(const AppExecFwk::InnerEvent::Pointer &event); 145 void RadioGetRrcConnectionState(const AppExecFwk::InnerEvent::Pointer &event); 146 void RadioResidentNetworkChange(const AppExecFwk::InnerEvent::Pointer &event); 147 void SatelliteStatusChanged(const AppExecFwk::InnerEvent::Pointer &event); 148 bool InitOperatorName(); 149 bool InitSettingUtils(); 150 void SubscribeSystemAbility(); 151 int32_t IsSatelliteSupported() const; 152 void GetNrSsbIdResponse(const AppExecFwk::InnerEvent::Pointer &event); 153 void SyncGetSsbInfoResponse(); 154 bool SubModuleInit(); 155 void ClearSignalAndCellInfoList() const; 156 bool IsSatelliteOn() const; 157 void RadioOnWhenHasSim(std::shared_ptr<NetworkSearchManager> &networkSearchManager, int32_t radioState) const; 158 void UpdateNetworkState(); 159 void GetDeviceId(); 160 bool CheckRegistrationState(const std::shared_ptr<NetworkSearchManager> &networkSearchManager); 161 162 private: 163 std::weak_ptr<NetworkSearchManager> networkSearchManager_; 164 std::unique_ptr<NetworkRegister> networkRegister_ = nullptr; 165 std::shared_ptr<OperatorName> operatorName_ = nullptr; 166 std::unique_ptr<RadioInfo> radioInfo_ = nullptr; 167 std::unique_ptr<SignalInfo> signalInfo_ = nullptr; 168 std::unique_ptr<NetworkSelection> networkSelection_ = nullptr; 169 std::weak_ptr<ITelRilManager> telRilManager_; 170 std::weak_ptr<ISimManager> simManager_; 171 std::unique_ptr<NetworkType> networkType_ = nullptr; 172 std::unique_ptr<NitzUpdate> nitzUpdate_ = nullptr; 173 std::unique_ptr<CellInfo> cellInfo_ = nullptr; 174 std::unique_ptr<NrSsbInfo> nrSsbInfo_ = nullptr; 175 std::shared_ptr<PsRegStatusResultInfo> psRegStatusResultInfo_ = nullptr; 176 std::shared_ptr<CsRegStatusInfo> csRegStatusInfo_ = nullptr; 177 std::shared_ptr<OperatorInfoResult> operatorInfoResult_ = nullptr; 178 static const std::map<uint32_t, NsHandlerFunc> memberFuncMap_; 179 int64_t lastTimeSignalReq_ = 0; 180 int64_t lastTimeOperatorReq_ = 0; 181 int64_t lastTimePsRegistrationReq_ = 0; 182 int64_t lastTimeCsRegistrationReq_ = 0; 183 bool firstInit_ = true; 184 int32_t slotId_ = 0; 185 uint32_t cellRequestMinInterval_ = 2; // This is the minimum interval in seconds for cell requests 186 uint32_t lastCellRequestTime_ = 0; 187 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 188 sptr<ISatelliteCoreCallback> satelliteCallback_ = nullptr; 189 const int32_t INVALID_SLOT_ID = -1; 190 bool isCsCapable_ = true; 191 std::mutex mutex_; 192 193 private: 194 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 195 public: 196 explicit SystemAbilityStatusChangeListener(std::shared_ptr<OperatorName> &operatorName); 197 ~SystemAbilityStatusChangeListener() = default; 198 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 199 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 200 201 private: 202 std::shared_ptr<OperatorName> opName_ = nullptr; 203 }; 204 }; 205 } // namespace Telephony 206 } // namespace OHOS 207 #endif // NETWORK_SEARCH_INCLUDE_NETWORK_SEARCH_HANDLER_H 208