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 NET_CONN_SERVICE_H
17 #define NET_CONN_SERVICE_H
18 
19 #include <cstdint>
20 #include <functional>
21 #include <list>
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 #include <vector>
26 #include <thread>
27 #include <condition_variable>
28 
29 #include "singleton.h"
30 #include "system_ability.h"
31 
32 #include "http_proxy.h"
33 #include "net_activate.h"
34 #include "net_conn_event_handler.h"
35 #include "net_conn_service_iface.h"
36 #include "net_conn_service_stub.h"
37 #include "net_supplier.h"
38 #include "netsys_controller_callback.h"
39 #include "network.h"
40 #include "dns_result_call_back.h"
41 #include "net_factoryreset_callback.h"
42 #include "common_event_data.h"
43 #include "common_event_manager.h"
44 #include "common_event_subscriber.h"
45 #include "common_event_support.h"
46 #include "os_account_manager.h"
47 
48 namespace OHOS {
49 namespace NetManagerStandard {
50 using EventReceiver = std::function<void(const EventFwk::CommonEventData&)>;
51 namespace {
52 const int32_t PRIMARY_USER_ID = 100;
53 }
54 class NetConnService : public SystemAbility,
55                        public INetActivateCallback,
56                        public NetConnServiceStub,
57                        public std::enable_shared_from_this<NetConnService> {
58     DECLARE_SYSTEM_ABILITY(NetConnService)
59 
60     NetConnService();
61     virtual ~NetConnService();
62     using NET_SUPPLIER_MAP = std::map<uint32_t, sptr<NetSupplier>>;
63     using NET_NETWORK_MAP = std::map<int32_t, std::shared_ptr<Network>>;
64     using NET_ACTIVATE_MAP = std::map<uint32_t, std::shared_ptr<NetActivate>>;
65     using NET_UIDREQUEST_MAP = std::map<uint32_t, uint32_t>;
66 
67 public:
68     class NetConnListener : public EventFwk::CommonEventSubscriber {
69     public:
70         NetConnListener(const EventFwk::CommonEventSubscribeInfo &subscribeInfo, EventReceiver receiver);
71         void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
72 
73     private:
74         EventReceiver eventReceiver_;
75     };
GetInstance()76     static std::shared_ptr<NetConnService> &GetInstance()
77     {
78         static std::shared_ptr<NetConnService> instance = std::make_shared<NetConnService>();
79         return instance;
80     }
81     void OnStart() override;
82     void OnStop() override;
83     /**
84      * The interface in NetConnService can be called when the system is ready
85      *
86      * @return Returns 0, the system is ready, otherwise the system is not ready
87      */
88     int32_t SystemReady() override;
89 
90     /**
91      * Disallow or allow a app to create AF_INET or AF_INET6 socket
92      *
93      * @param uid App's uid which need to be disallowed ot allowed to create AF_INET or AF_INET6 socket
94      * @param allow 0 means disallow, 1 means allow
95      * @return return 0 if OK, return error number if not OK
96      */
97     int32_t SetInternetPermission(uint32_t uid, uint8_t allow) override;
98 
99     /**
100      * The interface is register the network
101      *
102      * @param bearerType Bearer Network Type
103      * @param ident Unique identification of mobile phone card
104      * @param netCaps Network capabilities registered by the network supplier
105      * @param supplierId out param, return supplier id
106      *
107      * @return function result
108      */
109     int32_t RegisterNetSupplier(NetBearType bearerType, const std::string &ident, const std::set<NetCap> &netCaps,
110                                 uint32_t &supplierId) override;
111 
112     /**
113      * The interface is unregister the network
114      *
115      * @param supplierId The id of the network supplier
116      *
117      * @return Returns 0, unregister the network successfully, otherwise it will fail
118      */
119     int32_t UnregisterNetSupplier(uint32_t supplierId) override;
120 
121     /**
122      * Register supplier callback
123      *
124      * @param supplierId The id of the network supplier
125      * @param callback INetSupplierCallback callback interface
126      *
127      * @return Returns 0, unregister the network successfully, otherwise it will fail
128      */
129     int32_t RegisterNetSupplierCallback(uint32_t supplierId, const sptr<INetSupplierCallback> &callback) override;
130 
131     /**
132      * Register net connection callback
133      *
134      * @param netSpecifier specifier information
135      * @param callback The callback of INetConnCallback interface
136      *
137      * @return Returns 0, successfully register net connection callback, otherwise it will failed
138      */
139     int32_t RegisterNetConnCallback(const sptr<INetConnCallback> callback) override;
140 
141     /**
142      * Register net connection callback by NetSpecifier
143      *
144      * @param netSpecifier specifier information
145      * @param callback The callback of INetConnCallback interface
146      * @param timeoutMS net connection time out
147      *
148      * @return Returns 0, successfully register net connection callback, otherwise it will failed
149      */
150     int32_t RegisterNetConnCallback(const sptr<NetSpecifier> &netSpecifier, const sptr<INetConnCallback> callback,
151                                     const uint32_t &timeoutMS) override;
152 
153     /**
154      * Request net connection callback by NetSpecifier
155      *
156      * @param netSpecifier specifier information
157      * @param callback The callback of INetConnCallback interface
158      * @param timeoutMS net connection time out
159      *
160      * @return Returns 0, successfully register net connection callback, otherwise it will failed
161      */
162     int32_t RequestNetConnection(const sptr<NetSpecifier> netSpecifier, const sptr<INetConnCallback> callback,
163                                     const uint32_t timeoutMS) override;
164     /**
165      * Unregister net connection callback
166      *
167      * @return Returns 0, successfully unregister net connection callback, otherwise it will fail
168      */
169     int32_t UnregisterNetConnCallback(const sptr<INetConnCallback> &callback) override;
170 
171     int32_t UpdateNetStateForTest(const sptr<NetSpecifier> &netSpecifier, int32_t netState) override;
172     /**
173      * The interface is update network connection status information
174      *
175      * @param supplierId The id of the network supplier
176      * @param netSupplierInfo network connection status information
177      *
178      * @return Returns 0, successfully update the network connection status information, otherwise it will fail
179      */
180     int32_t UpdateNetSupplierInfo(uint32_t supplierId, const sptr<NetSupplierInfo> &netSupplierInfo) override;
181 
182     /**
183      * The interface is update network link attribute information
184      *
185      * @param supplierId The id of the network supplier
186      * @param netLinkInfo network link attribute information
187      *
188      * @return Returns 0, successfully update the network link attribute information, otherwise it will fail
189      */
190     int32_t UpdateNetLinkInfo(uint32_t supplierId, const sptr<NetLinkInfo> &netLinkInfo) override;
191 
192     /**
193      * The interface names which NetBearType is equal than bearerType
194      *
195      * @param bearerType Network bearer type
196      * @param ifaceNames save the obtained ifaceNames
197      * @return Returns 0, successfully get the network link attribute iface name, otherwise it will fail
198      */
199     int32_t GetIfaceNames(NetBearType bearerType, std::list<std::string> &ifaceNames) override;
200 
201     /**
202      * The interface is get the iface name for network
203      *
204      * @param bearerType Network bearer type
205      * @param ident Unique identification of mobile phone card
206      * @param ifaceName save the obtained ifaceName
207      * @return Returns 0, successfully get the network link attribute iface name, otherwise it will fail
208      */
209     int32_t GetIfaceNameByType(NetBearType bearerType, const std::string &ident, std::string &ifaceName) override;
210 
211     /**
212      * The interface is to get all iface and ident maps
213      *
214      * @param bearerType the type of network
215      * @param ifaceNameIdentMaps the map of ifaceName and ident
216      * @return Returns 0 success. Otherwise fail.
217      * @permission ohos.permission.CONNECTIVITY_INTERNAL
218      * @systemapi Hide this for inner system use.
219      */
220     int32_t GetIfaceNameIdentMaps(NetBearType bearerType,
221                                   SafeMap<std::string, std::string> &ifaceNameIdentMaps) override;
222 
223     /**
224      * register network detection return result method
225      *
226      * @param netId  Network ID
227      * @param callback The callback of INetDetectionCallback interface
228      * @return int32_t  Returns 0, unregister the network successfully, otherwise it will fail
229      */
230     int32_t RegisterNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback) override;
231 
232     /**
233      * unregister network detection return result method
234      *
235      * @param netId Network ID
236      * @param callback  The callback of INetDetectionCallback interface
237      * @return int32_t  Returns 0, unregister the network successfully, otherwise it will fail
238      */
239     int32_t UnRegisterNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback) override;
240 
241     /**
242      * The interface of network detection called by the application
243      *
244      * @param netId network ID
245      * @return int32_t Whether the network probe is successful
246      */
247     int32_t NetDetection(int32_t netId) override;
248     int32_t GetDefaultNet(int32_t &netId) override;
249     int32_t HasDefaultNet(bool &flag) override;
250     int32_t GetAddressesByName(const std::string &host, int32_t netId, std::vector<INetAddr> &addrList) override;
251     int32_t GetAddressByName(const std::string &host, int32_t netId, INetAddr &addr) override;
252     int32_t GetSpecificNet(NetBearType bearerType, std::list<int32_t> &netIdList) override;
253     int32_t GetAllNets(std::list<int32_t> &netIdList) override;
254     int32_t GetSpecificUidNet(int32_t uid, int32_t &netId) override;
255     int32_t GetConnectionProperties(int32_t netId, NetLinkInfo &info) override;
256     int32_t GetNetCapabilities(int32_t netId, NetAllCapabilities &netAllCap) override;
257     int32_t BindSocket(int32_t socketFd, int32_t netId) override;
258     void HandleDetectionResult(uint32_t supplierId, NetDetectionStatus netState);
259     int32_t RestrictBackgroundChanged(bool isRestrictBackground);
260     /**
261      * Set airplane mode
262      *
263      * @param state airplane state
264      * @return Returns 0, successfully set airplane mode, otherwise it will fail
265      */
266     int32_t SetAirplaneMode(bool state) override;
267     /**
268      * Dump
269      *
270      * @param fd file description
271      * @param args unused
272      * @return Returns 0, successfully get dump info, otherwise it will fail
273      */
274     int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
275     /**
276      * Is default network metered
277      *
278      * @param save the metered state
279      * @return Returns 0, Successfully get whether the default network is metered, otherwise it will fail
280      */
281     int32_t IsDefaultNetMetered(bool &isMetered) override;
282 
283     /**
284      * Set http proxy server
285      *
286      * @param httpProxy the http proxy server
287      * @return NETMANAGER_SUCCESS if OK, NET_CONN_ERR_HTTP_PROXY_INVALID if httpProxy is null string
288      */
289     int32_t SetGlobalHttpProxy(const HttpProxy &httpProxy) override;
290 
291     /**
292      * Get http proxy server
293      *
294      * @param httpProxy output param, the http proxy server
295      * @return NETMANAGER_SUCCESS if OK, NET_CONN_ERR_NO_HTTP_PROXY if httpProxy is null string
296      */
297     int32_t GetGlobalHttpProxy(HttpProxy &httpProxy) override;
298 
299     /**
300      * Obtains the default proxy settings.
301      *
302      * <p>If a global proxy is set, the global proxy parameters are returned.
303      * If the process is bound to a network using {@link setAppNet},
304      * the {@link Network} proxy settings are returned.
305      * In other cases, the default proxy settings of network are returned.
306      *
307      * @param bindNetId App bound network ID
308      * @param httpProxy output param, the http proxy server
309      * @return Returns NETMANAGER_SUCCESS even if HttpProxy is empty
310      */
311     int32_t GetDefaultHttpProxy(int32_t bindNetId, HttpProxy &httpProxy) override;
312 
313     /**
314      * Get net id by identifier
315      *
316      * @param ident Net identifier
317      * @param netIdList output param, the net id list
318      * @return NETMANAGER_SUCCESS if OK, ERR_NO_NET_IDENT if ident is null string
319      */
320     int32_t GetNetIdByIdentifier(const std::string &ident, std::list<int32_t> &netIdList) override;
321 
322     /**
323      * Activate network timeout
324      *
325      * @param reqId Net request id
326      */
327     void OnNetActivateTimeOut(uint32_t reqId) override;
328 
329     /**
330      * The interface of network detection called when DNS health check failed
331      *
332      * @param netId network ID
333      * @return int32_t Whether the network probe is successful
334      */
335     int32_t NetDetectionForDnsHealth(int32_t netId, bool dnsHealthSuccess);
336 
337     int32_t SetAppNet(int32_t netId) override;
338     int32_t RegisterNetInterfaceCallback(const sptr<INetInterfaceStateCallback> &callback) override;
339     int32_t GetNetInterfaceConfiguration(const std::string &iface, NetInterfaceConfiguration &config) override;
340     int32_t AddNetworkRoute(int32_t netId, const std::string &ifName,
341                             const std::string &destination, const std::string &nextHop) override;
342     int32_t RemoveNetworkRoute(int32_t netId, const std::string &ifName,
343                                const std::string &destination, const std::string &nextHop) override;
344     int32_t AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
345                                 int32_t prefixLength) override;
346     int32_t DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
347                                 int32_t prefixLength) override;
348     int32_t AddStaticArp(const std::string &ipAddr, const std::string &macAddr,
349                          const std::string &ifName) override;
350     int32_t DelStaticArp(const std::string &ipAddr, const std::string &macAddr,
351                          const std::string &ifName) override;
352     int32_t RegisterSlotType(uint32_t supplierId, int32_t type) override;
353     int32_t GetSlotType(std::string &type) override;
354     int32_t FactoryResetNetwork() override;
355     int32_t RegisterNetFactoryResetCallback(const sptr<INetFactoryResetCallback> &callback) override;
356     int32_t IsPreferCellularUrl(const std::string& url, bool& preferCellular) override;
357     int32_t RegisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback) override;
358     int32_t UnregisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback) override;
359     bool IsAddrInOtherNetwork(const std::string &ifaceName, int32_t netId, const INetAddr &netAddr);
360     bool IsIfaceNameInUse(const std::string &ifaceName, int32_t netId);
361     int32_t UpdateSupplierScore(NetBearType bearerType, uint32_t detectionStatus, uint32_t& supplierId) override;
362     std::string GetNetCapabilitiesAsString(const uint32_t supplierId);
363     int32_t EnableVnicNetwork(const sptr<NetLinkInfo> &netLinkInfo, const std::set<int32_t> &uids) override;
364     int32_t DisableVnicNetwork() override;
365 
366 private:
367     class NetInterfaceStateCallback : public NetsysControllerCallback {
368     public:
369         NetInterfaceStateCallback() = default;
370         ~NetInterfaceStateCallback() = default;
371         int32_t OnInterfaceAddressUpdated(const std::string &addr, const std::string &ifName, int flags,
372                                           int scope) override;
373         int32_t OnInterfaceAddressRemoved(const std::string &addr, const std::string &ifName, int flags,
374                                           int scope) override;
375         int32_t OnInterfaceAdded(const std::string &iface) override;
376         int32_t OnInterfaceRemoved(const std::string &iface) override;
377         int32_t OnInterfaceChanged(const std::string &iface, bool up) override;
378         int32_t OnInterfaceLinkStateChanged(const std::string &iface, bool up) override;
379         int32_t OnRouteChanged(bool updated, const std::string &route, const std::string &gateway,
380                                const std::string &ifName) override;
381         int32_t OnDhcpSuccess(NetsysControllerCallback::DhcpResult &dhcpResult) override;
382         int32_t OnBandwidthReachedLimit(const std::string &limitName, const std::string &iface) override;
383 
384         int32_t RegisterInterfaceCallback(const sptr<INetInterfaceStateCallback> &callback);
385 
386     private:
387         std::mutex mutex_;
388         std::vector<sptr<INetInterfaceStateCallback>> ifaceStateCallbacks_;
389     };
390 
391 protected:
392     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
393     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
394 
395 private:
396     enum RegisterType {
397         INVALIDTYPE,
398         REGISTER,
399         REQUEST,
400     };
401     bool Init();
402     void GetHttpUrlFromConfig(std::string &httpUrl);
403     std::list<sptr<NetSupplier>> GetNetSupplierFromList(NetBearType bearerType, const std::string &ident = "");
404     sptr<NetSupplier> GetNetSupplierFromList(NetBearType bearerType, const std::string &ident,
405                                              const std::set<NetCap> &netCaps);
406     int32_t ActivateNetwork(const sptr<NetSpecifier> &netSpecifier, const sptr<INetConnCallback> &callback,
407                             const uint32_t &timeoutMS, const int32_t registerType = REGISTER,
408                             const uint32_t callingUid = 0);
409     void CallbackForSupplier(sptr<NetSupplier> &supplier, CallbackType type);
410     void CallbackForAvailable(sptr<NetSupplier> &supplier, const sptr<INetConnCallback> &callback);
411     uint32_t FindBestNetworkForRequest(sptr<NetSupplier> &supplier, std::shared_ptr<NetActivate> &netActivateNetwork);
412     uint32_t FindInternalNetworkForRequest(std::shared_ptr<NetActivate> &netActivateNetwork,
413                                            sptr<NetSupplier> &supplier);
414     void SendRequestToAllNetwork(std::shared_ptr<NetActivate> request, const uint32_t callingUid = 0);
415     void SendBestScoreAllNetwork(uint32_t reqId, int32_t bestScore, uint32_t supplierId);
416     void SendAllRequestToNetwork(sptr<NetSupplier> supplier);
417     void FindBestNetworkForAllRequest();
418     void MakeDefaultNetWork(sptr<NetSupplier> &oldService, sptr<NetSupplier> &newService);
419     void NotFindBestSupplier(uint32_t reqId, const std::shared_ptr<NetActivate> &active,
420                              const sptr<NetSupplier> &supplier, const sptr<INetConnCallback> &callback);
421     void CreateDefaultRequest();
422     int32_t RegUnRegNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback, bool isReg);
423     int32_t GenerateNetId();
424     int32_t GenerateInternalNetId();
425     bool FindSameCallback(const sptr<INetConnCallback> &callback, uint32_t &reqId);
426     bool FindSameCallback(const sptr<INetConnCallback> &callback, uint32_t &reqId, RegisterType &registerType);
427     void GetDumpMessage(std::string &message);
428     sptr<NetSupplier> FindNetSupplier(uint32_t supplierId);
429     int32_t RegisterNetSupplierAsync(NetBearType bearerType, const std::string &ident, const std::set<NetCap> &netCaps,
430                                      uint32_t &supplierId);
431     int32_t UnregisterNetSupplierAsync(uint32_t supplierId);
432     int32_t RegisterNetSupplierCallbackAsync(uint32_t supplierId, const sptr<INetSupplierCallback> &callback);
433     int32_t RegisterNetConnCallbackAsync(const sptr<NetSpecifier> &netSpecifier, const sptr<INetConnCallback> &callback,
434                                          const uint32_t &timeoutMS, const uint32_t callingUid);
435     int32_t RequestNetConnectionAsync(const sptr<NetSpecifier> &netSpecifier, const sptr<INetConnCallback> &callback,
436                                          const uint32_t &timeoutMS, const uint32_t callingUid);
437     int32_t UnregisterNetConnCallbackAsync(const sptr<INetConnCallback> &callback, const uint32_t callingUid);
438     int32_t RegUnRegNetDetectionCallbackAsync(int32_t netId, const sptr<INetDetectionCallback> &callback, bool isReg);
439     int32_t UpdateNetStateForTestAsync(const sptr<NetSpecifier> &netSpecifier, int32_t netState);
440     int32_t UpdateNetSupplierInfoAsync(uint32_t supplierId, const sptr<NetSupplierInfo> &netSupplierInfo);
441     int32_t UpdateNetLinkInfoAsync(uint32_t supplierId, const sptr<NetLinkInfo> &netLinkInfo);
442     int32_t NetDetectionAsync(int32_t netId);
443     int32_t RestrictBackgroundChangedAsync(bool restrictBackground);
444     int32_t UpdateSupplierScoreAsync(NetBearType bearerType, uint32_t detectionStatus, uint32_t& supplierId);
445     void SendHttpProxyChangeBroadcast(const HttpProxy &httpProxy);
446     void RequestAllNetworkExceptDefault();
447     void LoadGlobalHttpProxy(HttpProxy &httpProxy);
448     void UpdateGlobalHttpProxy(const HttpProxy &httpProxy);
449     void ActiveHttpProxy();
450     void DecreaseNetConnCallbackCntForUid(const uint32_t callingUid,
451         const RegisterType registerType = REGISTER);
452     int32_t IncreaseNetConnCallbackCntForUid(const uint32_t callingUid,
453         const RegisterType registerType = REGISTER);
454 
455     void OnNetSysRestart();
456 
457     bool IsSupplierMatchRequestAndNetwork(sptr<NetSupplier> ns);
458     std::vector<std::string> GetPreferredUrl();
459     bool IsValidDecValue(const std::string &inputValue);
460     int32_t GetDelayNotifyTime();
461     int32_t NetDetectionForDnsHealthSync(int32_t netId, bool dnsHealthSuccess);
462     std::vector<sptr<NetSupplier>> FindSupplierWithInternetByBearerType(NetBearType bearerType);
463     int32_t GetCallingUserId(int32_t &userId);
IsPrimaryUserId(const int32_t userId)464     inline bool IsPrimaryUserId(const int32_t userId)
465     {
466         return userId == PRIMARY_USER_ID;
467     }
468     uint32_t FindSupplierToReduceScore(std::vector<sptr<NetSupplier>>& suppliers, uint32_t& supplierId);
469     int32_t EnableVnicNetworkAsync(const sptr<NetLinkInfo> &netLinkInfo, const std::set<int32_t> &uids);
470     int32_t DisableVnicNetworkAsync();
471 
472     // for NET_CAPABILITY_INTERNAL_DEFAULT
473     bool IsInRequestNetUids(int32_t uid);
474 private:
475     enum ServiceRunningState {
476         STATE_STOPPED = 0,
477         STATE_RUNNING,
478     };
479 
480     bool registerToService_;
481     ServiceRunningState state_;
482     sptr<NetSpecifier> defaultNetSpecifier_ = nullptr;
483     std::shared_ptr<NetActivate> defaultNetActivate_ = nullptr;
484     sptr<NetSupplier> defaultNetSupplier_ = nullptr;
485     NET_SUPPLIER_MAP netSuppliers_;
486     NET_ACTIVATE_MAP netActivates_;
487     NET_UIDREQUEST_MAP netUidRequest_;
488     NET_UIDREQUEST_MAP internalDefaultUidRequest_;
489     NET_NETWORK_MAP networks_;
490     std::atomic<bool> vnicCreated = false;
491     sptr<NetConnServiceIface> serviceIface_ = nullptr;
492     std::atomic<int32_t> netIdLastValue_ = MIN_NET_ID - 1;
493     std::atomic<int32_t> internalNetIdLastValue_ = MIN_INTERNAL_NET_ID;
494     std::atomic<bool> isDataShareReady_ = false;
495     std::mutex globalHttpProxyMutex_;
496     SafeMap<int32_t, HttpProxy> globalHttpProxyCache_;
497     std::recursive_mutex netManagerMutex_;
498     std::shared_ptr<AppExecFwk::EventRunner> netConnEventRunner_ = nullptr;
499     std::shared_ptr<NetConnEventHandler> netConnEventHandler_ = nullptr;
500     sptr<NetInterfaceStateCallback> interfaceStateCallback_ = nullptr;
501     sptr<NetDnsResultCallback> dnsResultCallback_ = nullptr;
502     sptr<NetFactoryResetCallback> netFactoryResetCallback_ = nullptr;
503     std::atomic_bool httpProxyThreadNeedRun_ = false;
504     std::condition_variable httpProxyThreadCv_;
505     std::mutex httpProxyThreadMutex_;
506     static constexpr const uint32_t HTTP_PROXY_ACTIVE_PERIOD_S = 120;
507     std::map<int32_t, sptr<IPreAirplaneCallback>> preAirplaneCallbacks_;
508     std::mutex preAirplaneCbsMutex_;
509     std::shared_ptr<NetConnListener> subscriber_ = nullptr;
510 
511     bool hasSARemoved_ = false;
512 
513 private:
514     class ConnCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
515     public:
ConnCallbackDeathRecipient(NetConnService & client)516         explicit ConnCallbackDeathRecipient(NetConnService &client) : client_(client) {}
517         ~ConnCallbackDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)518         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
519         {
520             client_.OnRemoteDied(remote);
521         }
522 
523     private:
524         NetConnService &client_;
525     };
526     class NetSupplierCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
527     public:
NetSupplierCallbackDeathRecipient(NetConnService & client)528         explicit NetSupplierCallbackDeathRecipient(NetConnService &client) : client_(client) {}
529         ~NetSupplierCallbackDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)530         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
531         {
532             client_.OnNetSupplierRemoteDied(remote);
533         }
534 
535     private:
536         NetConnService &client_;
537     };
538 
539     void OnRemoteDied(const wptr<IRemoteObject> &remoteObject);
540     void OnNetSupplierRemoteDied(const wptr<IRemoteObject> &remoteObject);
541     void AddClientDeathRecipient(const sptr<INetConnCallback> &callback);
542     void AddNetSupplierDeathRecipient(const sptr<INetSupplierCallback> &callback);
543     void RemoveNetSupplierDeathRecipient(const sptr<INetSupplierCallback> &callback);
544     void RemoveClientDeathRecipient(const sptr<INetConnCallback> &callback);
545     void RemoveALLClientDeathRecipient();
546     void OnReceiveEvent(const EventFwk::CommonEventData &data);
547     void SubscribeCommonEvent(const std::string &eventName, EventReceiver receiver);
548     std::mutex remoteMutex_;
549     sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr;
550     sptr<IRemoteObject::DeathRecipient> netSuplierDeathRecipient_ = nullptr;
551     std::vector<sptr<INetConnCallback>> remoteCallback_;
552     bool CheckIfSettingsDataReady();
553     std::mutex dataShareMutexWait;
554     std::condition_variable dataShareWait;
555 };
556 } // namespace NetManagerStandard
557 } // namespace OHOS
558 #endif // NET_CONN_SERVICE_H
559