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 UpdateImsServiceStatus(const AppExecFwk::InnerEvent::Pointer &event); 55 void UpdateImsRegisterState(const AppExecFwk::InnerEvent::Pointer &event); 56 int32_t SendUpdateCellLocationRequest(); 57 PhoneType GetPhoneType(); 58 59 /** 60 * Get signal quality 61 * 27007-410_2001 8.5 Signal quality +CSQ 62 * 3GPP TS 27.007 V4.1.0 (2001-03) 63 */ 64 void GetRilSignalIntensity(bool checkTime = true); 65 66 /** 67 * querying the status of all GSM/UMTS operators detected in the area. 68 * 27007-410_2001 7.3 PLMN selection +COPS 69 * 3GPP TS 27.007 V4.1.0 (2001-03) 70 */ 71 void GetRilOperatorInfo(bool checkTime = true); 72 73 /** 74 * Get PS network registration status 75 * 27007-410_2001 10.1.19 GPRS network registration status +CGREG 76 * 3GPP TS 27.007 V4.1.0 (2001-03) 77 */ 78 void GetRilPsRegistration(bool checkTime = true); 79 80 /** 81 * Get CS network registration status 82 * 27007-410_2001 7.2 Network registration +CREG 83 * 3GPP TS 27.007 V4.1.0 (2001-03) 84 */ 85 void GetRilCsRegistration(bool checkTime = true); 86 87 void UpdateCellLocation(int32_t techType, int32_t cellId, int32_t lac); 88 sptr<CellLocation> GetCellLocation(); 89 void TimezoneRefresh(); 90 void SetCellRequestMinInterval(uint32_t minInterval); 91 92 private: 93 void RadioOnState(); 94 void RadioOffOrUnavailableState(int32_t radioState) const; 95 void GetRadioStateResponse(const AppExecFwk::InnerEvent::Pointer &event); 96 void SetRadioStateResponse(const AppExecFwk::InnerEvent::Pointer &event); 97 void SimStateChange(const AppExecFwk::InnerEvent::Pointer &); 98 void ImsiLoadedReady(const AppExecFwk::InnerEvent::Pointer &event); 99 void SimRecordsLoaded(const AppExecFwk::InnerEvent::Pointer &); 100 void RadioStateChange(const AppExecFwk::InnerEvent::Pointer &event); 101 void GetNetworkStateInfo(const AppExecFwk::InnerEvent::Pointer &); 102 void RadioRestrictedState(const AppExecFwk::InnerEvent::Pointer &event); 103 void RadioRilDataRegState(const AppExecFwk::InnerEvent::Pointer &event); 104 void RadioRilVoiceRegState(const AppExecFwk::InnerEvent::Pointer &event); 105 void RadioSignalStrength(const AppExecFwk::InnerEvent::Pointer &event); 106 void RadioRilOperator(const AppExecFwk::InnerEvent::Pointer &event); 107 bool TimeOutCheck(int64_t &lastTime, bool checkTime = true); 108 void NetworkSearchResult(const AppExecFwk::InnerEvent::Pointer &event); 109 void GetNetworkSelectionModeResponse(const AppExecFwk::InnerEvent::Pointer &event); 110 void SetNetworkSelectionModeResponse(const AppExecFwk::InnerEvent::Pointer &event); 111 void InitGetNetworkSelectionMode(); 112 void InitNetworkSearchResult(); 113 void GetPreferredNetworkResponse(const AppExecFwk::InnerEvent::Pointer &event); 114 void SetPreferredNetworkResponse(const AppExecFwk::InnerEvent::Pointer &event); 115 void RadioNitzUpdate(const AppExecFwk::InnerEvent::Pointer &event); 116 void RadioGetImei(const AppExecFwk::InnerEvent::Pointer &event); 117 void RadioGetMeid(const AppExecFwk::InnerEvent::Pointer &event); 118 void RadioGetNeighboringCellInfo(const AppExecFwk::InnerEvent::Pointer &event); 119 void RadioGetCurrentCellInfo(const AppExecFwk::InnerEvent::Pointer &event); 120 void RadioCurrentCellInfoUpdate(const AppExecFwk::InnerEvent::Pointer &event); 121 void RadioChannelConfigInfo(const AppExecFwk::InnerEvent::Pointer &event); 122 void RadioVoiceTechChange(const AppExecFwk::InnerEvent::Pointer &event); 123 void AutoTimeChange(const AppExecFwk::InnerEvent::Pointer &); 124 void AutoTimeZoneChange(const AppExecFwk::InnerEvent::Pointer &); 125 void AirplaneModeChange(const AppExecFwk::InnerEvent::Pointer &); 126 bool InitOperatorName(); 127 128 private: 129 std::weak_ptr<NetworkSearchManager> networkSearchManager_; 130 std::unique_ptr<NetworkRegister> networkRegister_ = nullptr; 131 std::shared_ptr<OperatorName> operatorName_ = nullptr; 132 std::unique_ptr<RadioInfo> radioInfo_ = nullptr; 133 std::unique_ptr<SignalInfo> signalInfo_ = nullptr; 134 std::unique_ptr<NetworkSelection> networkSelection_ = nullptr; 135 std::weak_ptr<ITelRilManager> telRilManager_; 136 std::weak_ptr<ISimManager> simManager_; 137 std::unique_ptr<NetworkType> networkType_ = nullptr; 138 std::unique_ptr<NitzUpdate> nitzUpdate_ = nullptr; 139 std::unique_ptr<CellInfo> cellInfo_ = nullptr; 140 static const std::map<uint32_t, NsHandlerFunc> memberFuncMap_; 141 int64_t lastTimeSignalReq_ = 0; 142 int64_t lastTimeOperatorReq_ = 0; 143 int64_t lastTimePsRegistrationReq_ = 0; 144 int64_t lastTimeCsRegistrationReq_ = 0; 145 bool firstInit_ = true; 146 int32_t slotId_ = 0; 147 uint32_t cellRequestMinInterval_ = 2; // This is the minimum interval in seconds for cell requests 148 uint32_t lastCellRequestTime_ = 0; 149 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 150 151 private: 152 class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { 153 public: 154 explicit SystemAbilityStatusChangeListener(std::shared_ptr<OperatorName> &operatorName); 155 ~SystemAbilityStatusChangeListener() = default; 156 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 157 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 158 159 private: 160 std::shared_ptr<OperatorName> opName_ = nullptr; 161 }; 162 }; 163 } // namespace Telephony 164 } // namespace OHOS 165 #endif // NETWORK_SEARCH_INCLUDE_NETWORK_SEARCH_HANDLER_H 166