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