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