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