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