• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MANAGER_H
17 #define NETWORK_SEARCH_INCLUDE_NETWORK_SEARCH_MANAGER_H
18 
19 #include <any>
20 #include <cinttypes>
21 #include <list>
22 #include <map>
23 #include <mutex>
24 #include <string>
25 #include <tuple>
26 
27 #include "device_state_handler.h"
28 #include "device_state_observer.h"
29 #include "event_handler.h"
30 #include "i_network_search.h"
31 #include "i_sim_manager.h"
32 #include "i_tel_ril_manager.h"
33 #include "iremote_stub.h"
34 #include "network_search_handler.h"
35 #include "network_search_notify.h"
36 #include "network_search_result.h"
37 #include "network_search_state.h"
38 #include "network_utils.h"
39 #include "observer_handler.h"
40 #include "radio_event.h"
41 #include "setting_utils.h"
42 
43 namespace OHOS {
44 namespace Telephony {
45 enum class HandleRunningState { STATE_NOT_START, STATE_RUNNING };
46 /**
47  * @brief inner objects for network search manager
48  *
49  */
50 struct NetworkSearchManagerInner {
51     static const int32_t MSG_NUM = 3;
52     int32_t msgNum_ = MSG_NUM;
53     static const int32_t DEFAULT_RAF = 0xffff;
54     std::shared_ptr<NetworkSearchState> networkSearchState_ = nullptr;
55     std::shared_ptr<NetworkSearchHandler> networkSearchHandler_ = nullptr;
56     std::shared_ptr<AppExecFwk::EventRunner> eventLoop_ = nullptr;
57     std::unique_ptr<ObserverHandler> observerHandler_ = nullptr;
58     std::shared_ptr<DeviceStateHandler> deviceStateHandler_ = nullptr;
59     std::shared_ptr<DeviceStateObserver> deviceStateObserver_ = nullptr;
60     sptr<AutoTimeObserver> settingAutoTimeObserver_ = nullptr;
61     sptr<AutoTimezoneObserver> settingAutoTimezoneObserver_ = nullptr;
62     sptr<AirplaneModeObserver> airplaneModeObserver_ = nullptr;
63     HandleRunningState state_ = HandleRunningState::STATE_NOT_START;
64     std::unique_ptr<NetworkSearchResult> networkSearchResult_ = nullptr;
65     SelectionMode selection_ = SelectionMode::MODE_TYPE_UNKNOWN;
66     ModemPowerState radioState_ = ModemPowerState::CORE_SERVICE_POWER_OFF;
67     std::u16string imei_ = u"";
68     std::u16string meid_ = u"";
69     std::string basebandVersion_ = "";
70     NrMode nrMode_ = NrMode::NR_MODE_UNKNOWN;
71     int32_t rrcConnectionStatus_ = 0;
72     FrequencyType freqType_ = FrequencyType::FREQ_TYPE_UNKNOWN;
73     std::mutex mutex_;
74     bool isRadioFirstPowerOn_ = true;
75     bool airplaneMode_ = false;
76     int32_t preferredNetworkValue_ = 0;
77     bool hasCall_ = false;
78 
79     bool RegisterSetting();
80     bool UnRegisterSetting();
81     bool RegisterDeviceStateObserver();
82     bool UnRegisterDeviceStateObserver();
InitNetworkSearchManagerInner83     bool Init()
84     {
85         if (networkSearchState_ != nullptr) {
86             if (!networkSearchState_->Init()) {
87                 return false;
88             }
89         }
90         if (networkSearchHandler_ != nullptr) {
91             if (!networkSearchHandler_->Init()) {
92                 return false;
93             }
94             if (!RegisterSetting()) {
95                 return false;
96             }
97         }
98         if (deviceStateHandler_ != nullptr) {
99             if (!RegisterDeviceStateObserver()) {
100                 return false;
101             }
102         }
103         if (eventLoop_ != nullptr) {
104             eventLoop_->Run();
105         }
106         state_ = HandleRunningState::STATE_RUNNING;
107         return true;
108     }
InitMsgNumNetworkSearchManagerInner109     inline void InitMsgNum()
110     {
111         msgNum_ = MSG_NUM;
112     }
CheckIsNeedNotifyNetworkSearchManagerInner113     inline bool CheckIsNeedNotify()
114     {
115         return msgNum_ == 0 ? true : false;
116     }
decMsgNumNetworkSearchManagerInner117     inline void decMsgNum()
118     {
119         msgNum_--;
120     }
121 };
122 
123 /**
124  * @brief manager class of network search module .The main entrance to the module.
125  *
126  */
127 class NetworkSearchManager : public INetworkSearch, public std::enable_shared_from_this<NetworkSearchManager> {
128 public:
129     NetworkSearchManager(std::shared_ptr<ITelRilManager> telRilManager, std::shared_ptr<ISimManager> simManager);
130     virtual ~NetworkSearchManager();
131 
132     bool OnInit() override;
133     void SetRadioState(int32_t slotId, bool isOn, int32_t rst) override;
134     int32_t SetRadioState(int32_t slotId, bool isOn, int32_t rst, NSCALLBACK &callback) override;
135     int32_t GetRadioState(int32_t slotId) override;
136     int32_t GetRadioState(int32_t slotId, NSCALLBACK &callback) override;
137     int32_t GetPsRadioTech(int32_t slotId, int32_t &psRadioTech) override;
138     int32_t GetCsRadioTech(int32_t slotId, int32_t &csRadioTech) override;
139     std::u16string GetOperatorNumeric(int32_t slotId) override;
140     int32_t GetOperatorName(int32_t slotId, std::u16string &operatorName) override;
141     int32_t GetNetworkStatus(int32_t slotId, sptr<NetworkState> &networkState) override;
142     int32_t GetSignalInfoList(int32_t slotId, std::vector<sptr<SignalInformation>> &signals) override;
143     void RegisterCoreNotify(int32_t slotId, HANDLE &handler, int32_t what) override;
144     void UnRegisterCoreNotify(int32_t slotId, HANDLE &handler, int32_t what) override;
145     void RegisterCellularDataObject(const sptr<NetworkSearchCallBackBase> &callback) override;
146     void UnRegisterCellularDataObject(const sptr<NetworkSearchCallBackBase> &callback) override;
147     void RegisterCellularCallObject(const sptr<NetworkSearchCallBackBase> &callback) override;
148     void UnRegisterCellularCallObject(const sptr<NetworkSearchCallBackBase> &callback) override;
149     int32_t GetNetworkSearchInformation(int32_t slotId, NSCALLBACK &callback) override;
150     int32_t GetNetworkSelectionMode(int32_t slotId, NSCALLBACK &callback) override;
151     int32_t SetNetworkSelectionMode(int32_t slotId, int32_t selectMode,
152         const sptr<NetworkInformation> &networkInformation, bool resumeSelection, NSCALLBACK &callback) override;
153     int32_t GetPreferredNetwork(int32_t slotId, NSCALLBACK &callback) override;
154     int32_t SetPreferredNetwork(int32_t slotId, int32_t networkMode, NSCALLBACK &callback) override;
155     int32_t GetIsoCountryCodeForNetwork(int32_t slotId, std::u16string &countryCode) override;
156     int32_t GetImei(int32_t slotId, std::u16string &imei) override;
157     int32_t GetPsRegState(int32_t slotId) override;
158     int32_t GetCsRegState(int32_t slotId) override;
159     int32_t GetPsRoamingState(int32_t slotId) override;
160     int32_t GetCellInfoList(int32_t slotId, std::vector<sptr<CellInformation>> &cellInfo) override;
161     int32_t SendUpdateCellLocationRequest(int32_t slotId) override;
162     sptr<CellLocation> GetCellLocation(int32_t slotId) override;
163     int32_t GetImsRegStatus(int32_t slotId, ImsServiceType imsSrvType, ImsRegInfo &info) override;
164     PhoneType GetPhoneType(int32_t slotId) override;
165     int32_t GetMeid(int32_t slotId, std::u16string &meid) override;
166     int32_t GetUniqueDeviceId(int32_t slotId, std::u16string &deviceId) override;
167     bool IsNrSupported(int32_t slotId) override;
168     FrequencyType GetFrequencyType(int32_t slotId) override;
169     NrState GetNrState(int32_t slotId) override;
170     void DcPhysicalLinkActiveUpdate(int32_t slotId, bool isActive) override;
171     int32_t NotifyCallStatusToNetworkSearch(int32_t slotId, int32_t callStatus) override;
172     int32_t HandleNotifyStateChangeWithDelay(int32_t slotId, bool isNeedDelay) override;
173     bool IsNeedDelayNotify(int32_t slotId);
174     int32_t SetNrOptionMode(int32_t slotId, int32_t mode);
175     int32_t SetNrOptionMode(int32_t slotId, int32_t mode, NSCALLBACK &callback) override;
176     int32_t GetNrOptionMode(int32_t slotId, NrMode &mode) override;
177     int32_t GetNrOptionMode(int32_t slotId, NSCALLBACK &callback) override;
178     int32_t RegisterImsRegInfoCallback(int32_t slotId, ImsServiceType imsSrvType, const std::string &bundleName,
179         const sptr<ImsRegInfoCallback> &callback) override;
180     int32_t UnregisterImsRegInfoCallback(
181         int32_t slotId, ImsServiceType imsSrvType, const std::string &bundleName) override;
182     int32_t GetNetworkCapability(
183         int32_t slotId, int32_t networkCapabilityType, int32_t &networkCapabilityState) override;
184     int32_t SetNetworkCapability(
185         int32_t slotId, int32_t networkCapabilityType, int32_t networkCapabilityState) override;
186 
187     void NotifyPsRoamingOpenChanged(int32_t slotId);
188     void NotifyPsRoamingCloseChanged(int32_t slotId);
189     void NotifyPsConnectionAttachedChanged(int32_t slotId);
190     void NotifyPsConnectionDetachedChanged(int32_t slotId);
191     void NotifyPsRatChanged(int32_t slotId);
192     void NotifyEmergencyOpenChanged(int32_t slotId);
193     void NotifyEmergencyCloseChanged(int32_t slotId);
194     void NotifyNrStateChanged(int32_t slotId);
195     void NotifyNrFrequencyChanged(int32_t slotId);
196     std::shared_ptr<NetworkSearchState> GetNetworkSearchState(int32_t slotId);
197     void TriggerSimRefresh(int32_t slotId);
198     void TriggerTimezoneRefresh(int32_t slotId);
199     void SetNetworkSearchResultValue(
200         int32_t slotId, int32_t listSize, const std::vector<NetworkInformation> &operatorInfo);
201     sptr<NetworkSearchResult> GetNetworkSearchInformationValue(int32_t slotId);
202     int32_t GetNetworkSelectionMode(int32_t slotId);
203     bool SetNetworkSelectionMode(
204         int32_t slotId, int32_t selectMode, const sptr<NetworkInformation> &networkInformation, bool resumeSelection);
205     void SetRadioStateValue(int32_t slotId, ModemPowerState radioState);
206     void SetNetworkSelectionValue(int32_t slotId, SelectionMode selection);
207     int32_t GetPreferredNetwork(int32_t slotId);
208     int32_t SetCachePreferredNetworkValue(int32_t slotId, int32_t networkMode);
209     int32_t GetCachePreferredNetworkValue(int32_t slotId, int32_t &networkMode);
210     bool SetPreferredNetwork(int32_t slotId, int32_t networkMode);
211     void SavePreferredNetworkValue(int32_t slotId, int32_t networkMode);
212     int32_t GetPreferredNetworkValue(int32_t slotId) const;
213     void UpdatePhone(int32_t slotId, RadioTech csRadioTech, const RadioTech &psRadioTech);
214     void SetImei(int32_t slotId, std::u16string imei);
215     void UpdateCellLocation(int32_t slotId, int32_t techType, int32_t cellId, int32_t lac);
216     void SetMeid(int32_t slotId, std::u16string meid);
217     void SetFrequencyType(int32_t slotId, FrequencyType type);
218     void GetVoiceTech(int32_t slotId);
219     std::shared_ptr<NetworkSearchManagerInner> FindManagerInner(int32_t slotId);
220     void SetLocateUpdate(int32_t slotId);
221     int32_t GetAirplaneMode(bool &airplaneMode) override;
222     int32_t ProcessNotifyStateChangeEvent(int32_t slotId);
223     bool IsRadioFirstPowerOn(int32_t slotId);
224     void SetRadioFirstPowerOn(int32_t slotId, bool isFirstPowerOn);
225     void NotifyImsRegInfoChanged(int32_t slotId, ImsServiceType imsSrvType, const ImsRegInfo &info);
226     void InitSimRadioProtocol(int32_t slotId);
227     int32_t SetLocalAirplaneMode(int32_t slotId, bool state);
228     int32_t GetLocalAirplaneMode(int32_t slotId, bool &state);
229     void SetBasebandVersion(int32_t slotId, std::string version);
230     int32_t GetBasebandVersion(int32_t slotId, std::string &version) override;
231     int32_t UpdateNrOptionMode(int32_t slotId, NrMode mode);
232     int32_t UpdateRadioOn(int32_t slotId) override;
233     int32_t HandleRrcStateChanged(int32_t slotId, int32_t status);
234     int32_t GetRrcConnectionState(int32_t slotId, int32_t &status) override;
235     int32_t UpdateRrcConnectionState(int32_t slotId, int32_t &status);
236 
InitMsgNum(int32_t slotId)237     inline void InitMsgNum(int32_t slotId)
238     {
239         auto inner = FindManagerInner(slotId);
240         if (inner != nullptr) {
241             inner->InitMsgNum();
242         }
243     }
CheckIsNeedNotify(int32_t slotId)244     inline bool CheckIsNeedNotify(int32_t slotId)
245     {
246         auto inner = FindManagerInner(slotId);
247         if (inner != nullptr) {
248             return inner->CheckIsNeedNotify();
249         }
250         return false;
251     }
decMsgNum(int32_t slotId)252     inline void decMsgNum(int32_t slotId)
253     {
254         auto inner = FindManagerInner(slotId);
255         if (inner != nullptr) {
256             inner->decMsgNum();
257         }
258     }
GetCellularDataCallBack()259     inline sptr<NetworkSearchCallBackBase> GetCellularDataCallBack()
260     {
261         return cellularDataCallBack_;
262     }
GetCellularCallCallBack()263     inline sptr<NetworkSearchCallBackBase> GetCellularCallCallBack()
264     {
265         return cellularCallCallBack_;
266     }
GetSimManager()267     inline std::shared_ptr<ISimManager> GetSimManager() const
268     {
269         return simManager_;
270     }
271 
272 private:
273     bool InitPointer(std::shared_ptr<NetworkSearchManagerInner> &inner, int32_t slotId);
274     void ClearManagerInner();
275     void AddManagerInner(int32_t slotId, const std::shared_ptr<NetworkSearchManagerInner> &inner);
276     bool RemoveManagerInner(int32_t slotId);
277     int32_t GetDelayNotifyTime();
278     int32_t RevertLastTechnology(int32_t slotId);
279     int32_t ConvertNetworkModeToCapabilityType(int32_t preferredNetwork);
280 
281 private:
282     struct ImsRegInfoCallbackRecord {
283         int32_t slotId;
284         ImsServiceType imsSrvType;
285         std::string bundleName;
286         sptr<ImsRegInfoCallback> imsCallback;
287     };
288 
289     sptr<NetworkSearchCallBackBase> cellularDataCallBack_ = nullptr;
290     sptr<NetworkSearchCallBackBase> cellularCallCallBack_ = nullptr;
291     std::shared_ptr<ITelRilManager> telRilManager_ = nullptr;
292     std::shared_ptr<ISimManager> simManager_ = nullptr;
293     std::unique_ptr<EventSender> eventSender_ = nullptr;
294     std::map<int32_t, std::shared_ptr<NetworkSearchManagerInner>> mapManagerInner_;
295     std::list<ImsRegInfoCallbackRecord> listImsRegInfoCallbackRecord_;
296     std::mutex mutexInner_;
297     int32_t delayTime_ = 0;
298 };
299 } // namespace Telephony
300 } // namespace OHOS
301 #endif // NETWORK_SEARCH_INCLUDE_NETWORK_SEARCH_MANAGER_H
302