1b1b8bc3fSopenharmony_ci/*
2b1b8bc3fSopenharmony_ci * Copyright (c) 2021-2023 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_POLICY_SERVICE_H
17b1b8bc3fSopenharmony_ci#define NET_POLICY_SERVICE_H
18b1b8bc3fSopenharmony_ci
19b1b8bc3fSopenharmony_ci#include <atomic>
20b1b8bc3fSopenharmony_ci#include <mutex>
21b1b8bc3fSopenharmony_ci
22b1b8bc3fSopenharmony_ci#include "event_runner.h"
23b1b8bc3fSopenharmony_ci#include "singleton.h"
24b1b8bc3fSopenharmony_ci#include "system_ability.h"
25b1b8bc3fSopenharmony_ci#include "system_ability_definition.h"
26b1b8bc3fSopenharmony_ci
27b1b8bc3fSopenharmony_ci#include "net_policy_callback.h"
28b1b8bc3fSopenharmony_ci#include "net_policy_event_handler.h"
29b1b8bc3fSopenharmony_ci#include "net_policy_firewall.h"
30b1b8bc3fSopenharmony_ci#include "net_policy_rule.h"
31b1b8bc3fSopenharmony_ci#include "net_policy_service_common.h"
32b1b8bc3fSopenharmony_ci#include "net_policy_service_stub.h"
33b1b8bc3fSopenharmony_ci#include "net_policy_traffic.h"
34b1b8bc3fSopenharmony_ci#include "net_access_policy.h"
35b1b8bc3fSopenharmony_ci#include "net_access_policy_rdb.h"
36b1b8bc3fSopenharmony_ci#include "common_event_subscriber.h"
37b1b8bc3fSopenharmony_ci#include "common_event_support.h"
38b1b8bc3fSopenharmony_ci
39b1b8bc3fSopenharmony_cinamespace OHOS {
40b1b8bc3fSopenharmony_cinamespace NetManagerStandard {
41b1b8bc3fSopenharmony_ci#define NET_SYMBOL_VISIBLE __attribute__ ((visibility("default")))
42b1b8bc3fSopenharmony_ciclass NET_SYMBOL_VISIBLE NetPolicyService : public SystemAbility,
43b1b8bc3fSopenharmony_ci                         public NetPolicyServiceStub,
44b1b8bc3fSopenharmony_ci                         public std::enable_shared_from_this<NetPolicyService> {
45b1b8bc3fSopenharmony_ci    DECLARE_DELAYED_SINGLETON(NetPolicyService)
46b1b8bc3fSopenharmony_ci    DECLARE_SYSTEM_ABILITY(NetPolicyService)
47b1b8bc3fSopenharmony_ci
48b1b8bc3fSopenharmony_cipublic:
49b1b8bc3fSopenharmony_ci    void OnStart() override;
50b1b8bc3fSopenharmony_ci    void OnStop() override;
51b1b8bc3fSopenharmony_ci    int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
52b1b8bc3fSopenharmony_ci
53b1b8bc3fSopenharmony_ci    /**
54b1b8bc3fSopenharmony_ci     * Set the network policy for the specified UID.
55b1b8bc3fSopenharmony_ci     * @param uid The specified UID of app.
56b1b8bc3fSopenharmony_ci     * @param policy The network policy for application.
57b1b8bc3fSopenharmony_ci     *      For details, see {@link NetUidPolicy}.
58b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
59b1b8bc3fSopenharmony_ci     */
60b1b8bc3fSopenharmony_ci    int32_t SetPolicyByUid(uint32_t uid, uint32_t policy) override;
61b1b8bc3fSopenharmony_ci
62b1b8bc3fSopenharmony_ci    /**
63b1b8bc3fSopenharmony_ci     * Get the network policy of the specified UID.
64b1b8bc3fSopenharmony_ci     * @param uid The specified UID of app.
65b1b8bc3fSopenharmony_ci     * @param policy Return this uid's policy.
66b1b8bc3fSopenharmony_ci     *      For details, see {@link NetUidPolicy}.
67b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
68b1b8bc3fSopenharmony_ci     */
69b1b8bc3fSopenharmony_ci    int32_t GetPolicyByUid(uint32_t uid, uint32_t &policy) override;
70b1b8bc3fSopenharmony_ci
71b1b8bc3fSopenharmony_ci    /**
72b1b8bc3fSopenharmony_ci     * Get the application UIDs of the specified policy.
73b1b8bc3fSopenharmony_ci     * @param policy the network policy of the current UID of application.
74b1b8bc3fSopenharmony_ci     *      For details, see {@link NetUidPolicy}.
75b1b8bc3fSopenharmony_ci     * @param uids The list of UIDs
76b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
77b1b8bc3fSopenharmony_ci     */
78b1b8bc3fSopenharmony_ci    int32_t GetUidsByPolicy(uint32_t policy, std::vector<uint32_t> &uids) override;
79b1b8bc3fSopenharmony_ci
80b1b8bc3fSopenharmony_ci    /**
81b1b8bc3fSopenharmony_ci     * Get the status whether the specified uid app can access the metered network or non-metered network.
82b1b8bc3fSopenharmony_ci     * @param uid The specified UID of application.
83b1b8bc3fSopenharmony_ci     * @param metered Indicates metered network or non-metered network.
84b1b8bc3fSopenharmony_ci     * @param isAllowed Return true means it's allowed to access the network.
85b1b8bc3fSopenharmony_ci     *      Return false means it's not allowed to access the network.
86b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
87b1b8bc3fSopenharmony_ci     */
88b1b8bc3fSopenharmony_ci    int32_t IsUidNetAllowed(uint32_t uid, bool metered, bool &isAllowed) override;
89b1b8bc3fSopenharmony_ci
90b1b8bc3fSopenharmony_ci    /**
91b1b8bc3fSopenharmony_ci     * Get the status whether the specified uid app can access the specified iface network.
92b1b8bc3fSopenharmony_ci     * @param uid The specified UID of application.
93b1b8bc3fSopenharmony_ci     * @param ifaceName Iface name.
94b1b8bc3fSopenharmony_ci     * @param isAllowed Return true means it's allowed to access the network.
95b1b8bc3fSopenharmony_ci     *      Return false means it's not allowed to access the network.
96b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
97b1b8bc3fSopenharmony_ci     */
98b1b8bc3fSopenharmony_ci    int32_t IsUidNetAllowed(uint32_t uid, const std::string &ifaceName, bool &isAllowed) override;
99b1b8bc3fSopenharmony_ci
100b1b8bc3fSopenharmony_ci    /**
101b1b8bc3fSopenharmony_ci     * Register network policy change callback.
102b1b8bc3fSopenharmony_ci     * @param callback Interface type pointer.
103b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
104b1b8bc3fSopenharmony_ci     */
105b1b8bc3fSopenharmony_ci    int32_t RegisterNetPolicyCallback(const sptr<INetPolicyCallback> &callback) override;
106b1b8bc3fSopenharmony_ci
107b1b8bc3fSopenharmony_ci    /**
108b1b8bc3fSopenharmony_ci     * Unregister network policy change callback.
109b1b8bc3fSopenharmony_ci     * @param callback Interface type pointer.
110b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
111b1b8bc3fSopenharmony_ci     */
112b1b8bc3fSopenharmony_ci    int32_t UnregisterNetPolicyCallback(const sptr<INetPolicyCallback> &callback) override;
113b1b8bc3fSopenharmony_ci
114b1b8bc3fSopenharmony_ci    /**
115b1b8bc3fSopenharmony_ci     * Set policies by NetPolicyQuotaPolicy.
116b1b8bc3fSopenharmony_ci     * @param quotaPolicies The list of network quota policy, {@link NetQuotaPolicy}.
117b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
118b1b8bc3fSopenharmony_ci     */
119b1b8bc3fSopenharmony_ci    int32_t SetNetQuotaPolicies(const std::vector<NetQuotaPolicy> &quotaPolicies) override;
120b1b8bc3fSopenharmony_ci
121b1b8bc3fSopenharmony_ci    /**
122b1b8bc3fSopenharmony_ci     * Get network policies.
123b1b8bc3fSopenharmony_ci     * @param quotaPolicies The list of network quota policy, {@link NetQuotaPolicy}.
124b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
125b1b8bc3fSopenharmony_ci     */
126b1b8bc3fSopenharmony_ci    int32_t GetNetQuotaPolicies(std::vector<NetQuotaPolicy> &quotaPolicies) override;
127b1b8bc3fSopenharmony_ci
128b1b8bc3fSopenharmony_ci    /**
129b1b8bc3fSopenharmony_ci     * Reset network policies\rules\quota policies\firewall rules.
130b1b8bc3fSopenharmony_ci     * @param simId Specify the matched simId of quota policy.
131b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
132b1b8bc3fSopenharmony_ci     */
133b1b8bc3fSopenharmony_ci    int32_t ResetPolicies(const std::string &simId) override;
134b1b8bc3fSopenharmony_ci
135b1b8bc3fSopenharmony_ci    /**
136b1b8bc3fSopenharmony_ci     * Control if apps can use data on background.
137b1b8bc3fSopenharmony_ci     * @param allowBackground Allow apps to use data on background.
138b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
139b1b8bc3fSopenharmony_ci     */
140b1b8bc3fSopenharmony_ci    int32_t SetBackgroundPolicy(bool allowBackground) override;
141b1b8bc3fSopenharmony_ci
142b1b8bc3fSopenharmony_ci    /**
143b1b8bc3fSopenharmony_ci     * Get the status if apps can use data on background.
144b1b8bc3fSopenharmony_ci     * @param backgroundPolicy True is allowed to use data on background.
145b1b8bc3fSopenharmony_ci     *      False is not allowed to use data on background.
146b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
147b1b8bc3fSopenharmony_ci     */
148b1b8bc3fSopenharmony_ci    int32_t GetBackgroundPolicy(bool &backgroundPolicy) override;
149b1b8bc3fSopenharmony_ci
150b1b8bc3fSopenharmony_ci    /**
151b1b8bc3fSopenharmony_ci     * Get the background network restriction policy for the specified uid.
152b1b8bc3fSopenharmony_ci     * @param uid uid The specified UID of application.
153b1b8bc3fSopenharmony_ci     * @param backgroundPolicyOfUid The specified UID of backgroundPolicy.
154b1b8bc3fSopenharmony_ci     *      For details, see {@link NetBackgroundPolicy}.
155b1b8bc3fSopenharmony_ci     * @return uint32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
156b1b8bc3fSopenharmony_ci     */
157b1b8bc3fSopenharmony_ci    int32_t GetBackgroundPolicyByUid(uint32_t uid, uint32_t &backgroundPolicyOfUid) override;
158b1b8bc3fSopenharmony_ci
159b1b8bc3fSopenharmony_ci    /**
160b1b8bc3fSopenharmony_ci     * Update the limit or warning remind time of quota policy.
161b1b8bc3fSopenharmony_ci     * @param netType {@link NetBearType}.
162b1b8bc3fSopenharmony_ci     * @param simId Specify the matched simId of quota policy when netType is cellular.
163b1b8bc3fSopenharmony_ci     * @param remindType {@link RemindType}.
164b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
165b1b8bc3fSopenharmony_ci     */
166b1b8bc3fSopenharmony_ci    int32_t UpdateRemindPolicy(int32_t netType, const std::string &simId, uint32_t remindType) override;
167b1b8bc3fSopenharmony_ci
168b1b8bc3fSopenharmony_ci    /**
169b1b8bc3fSopenharmony_ci     * Set the UID into device idle allow list.
170b1b8bc3fSopenharmony_ci     * @param uid The specified UID of application.
171b1b8bc3fSopenharmony_ci     * @param isAllowed The UID is into allowed list or not.
172b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
173b1b8bc3fSopenharmony_ci     */
174b1b8bc3fSopenharmony_ci    int32_t SetDeviceIdleTrustlist(const std::vector<uint32_t> &uids, bool isAllowed) override;
175b1b8bc3fSopenharmony_ci
176b1b8bc3fSopenharmony_ci    /**
177b1b8bc3fSopenharmony_ci     * Get the allow list of UID in device idle mode.
178b1b8bc3fSopenharmony_ci     * @param uids The list of UIDs
179b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
180b1b8bc3fSopenharmony_ci     */
181b1b8bc3fSopenharmony_ci    int32_t GetDeviceIdleTrustlist(std::vector<uint32_t> &uids) override;
182b1b8bc3fSopenharmony_ci
183b1b8bc3fSopenharmony_ci    /**
184b1b8bc3fSopenharmony_ci     * Process network policy in device idle mode.
185b1b8bc3fSopenharmony_ci     * @param enable Device idle mode is open or not.
186b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
187b1b8bc3fSopenharmony_ci     */
188b1b8bc3fSopenharmony_ci    int32_t SetDeviceIdlePolicy(bool enable) override;
189b1b8bc3fSopenharmony_ci
190b1b8bc3fSopenharmony_ci    /**
191b1b8bc3fSopenharmony_ci     * Get the allow list of UID in power save mode.
192b1b8bc3fSopenharmony_ci     *
193b1b8bc3fSopenharmony_ci     * @param uids The list of UIDs.
194b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
195b1b8bc3fSopenharmony_ci     */
196b1b8bc3fSopenharmony_ci    int32_t GetPowerSaveTrustlist(std::vector<uint32_t> &uids) override;
197b1b8bc3fSopenharmony_ci
198b1b8bc3fSopenharmony_ci    /**
199b1b8bc3fSopenharmony_ci     * Set the UID into power save allow list.
200b1b8bc3fSopenharmony_ci     * @param uid The specified UID of application.
201b1b8bc3fSopenharmony_ci     * @param isAllowed The UID is into allowed list or not.
202b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
203b1b8bc3fSopenharmony_ci     */
204b1b8bc3fSopenharmony_ci    int32_t SetPowerSaveTrustlist(const std::vector<uint32_t> &uids, bool isAllowed) override;
205b1b8bc3fSopenharmony_ci
206b1b8bc3fSopenharmony_ci    /**
207b1b8bc3fSopenharmony_ci     * Process network policy in Power Save mode.
208b1b8bc3fSopenharmony_ci     *
209b1b8bc3fSopenharmony_ci     * @param enable Power save mode is open or not.
210b1b8bc3fSopenharmony_ci     * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
211b1b8bc3fSopenharmony_ci     */
212b1b8bc3fSopenharmony_ci    int32_t SetPowerSavePolicy(bool enable) override;
213b1b8bc3fSopenharmony_ci
214b1b8bc3fSopenharmony_ci    /**
215b1b8bc3fSopenharmony_ci     * Check if you have permission
216b1b8bc3fSopenharmony_ci     *
217b1b8bc3fSopenharmony_ci     * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
218b1b8bc3fSopenharmony_ci     */
219b1b8bc3fSopenharmony_ci    int32_t CheckPermission() override;
220b1b8bc3fSopenharmony_ci
221b1b8bc3fSopenharmony_ci	/**
222b1b8bc3fSopenharmony_ci     * factory reset net policies
223b1b8bc3fSopenharmony_ci     *
224b1b8bc3fSopenharmony_ci     * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
225b1b8bc3fSopenharmony_ci     */
226b1b8bc3fSopenharmony_ci    int32_t FactoryResetPolicies() override;
227b1b8bc3fSopenharmony_ci
228b1b8bc3fSopenharmony_ci    /**
229b1b8bc3fSopenharmony_ci     * Set the policy to access the network of the specified application.
230b1b8bc3fSopenharmony_ci     *
231b1b8bc3fSopenharmony_ci     * @param uid The specified UID of application.
232b1b8bc3fSopenharmony_ci     * @param policy The network access policy of application, {@link NetworkAccessPolicy}.
233b1b8bc3fSopenharmony_ci     * @param reconfirmFlag true means a reconfirm diaglog trigger while policy deny network access.
234b1b8bc3fSopenharmony_ci     * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
235b1b8bc3fSopenharmony_ci     */
236b1b8bc3fSopenharmony_ci    int32_t SetNetworkAccessPolicy(uint32_t uid, NetworkAccessPolicy policy, bool reconfirmFlag) override;
237b1b8bc3fSopenharmony_ci
238b1b8bc3fSopenharmony_ci    /**
239b1b8bc3fSopenharmony_ci     * Query the network access policy of the specified application or all applications.
240b1b8bc3fSopenharmony_ci     *
241b1b8bc3fSopenharmony_ci     * @param parameter Indicate to get all or an application network access policy, {@link AccessPolicyParameter}.
242b1b8bc3fSopenharmony_ci     * @param policy The network access policy of application, {@link AccessPolicySave}.
243b1b8bc3fSopenharmony_ci     * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
244b1b8bc3fSopenharmony_ci     */
245b1b8bc3fSopenharmony_ci    int32_t GetNetworkAccessPolicy(AccessPolicyParameter parameter, AccessPolicySave& policy) override;
246b1b8bc3fSopenharmony_ci
247b1b8bc3fSopenharmony_ci    NetAccessPolicyRDB GetNetAccessPolicyDBHandler()
248b1b8bc3fSopenharmony_ci    {
249b1b8bc3fSopenharmony_ci        static NetAccessPolicyRDB netAccessPolicy;
250b1b8bc3fSopenharmony_ci        return netAccessPolicy;
251b1b8bc3fSopenharmony_ci    }
252b1b8bc3fSopenharmony_ci    int32_t DeleteNetworkAccessPolicy(uint32_t uid);
253b1b8bc3fSopenharmony_ci    int32_t NotifyNetAccessPolicyDiag(uint32_t uid) override;
254b1b8bc3fSopenharmony_ci
255b1b8bc3fSopenharmony_ci    /**
256b1b8bc3fSopenharmony_ci     * Set NIC Traffic allowed or disallowed
257b1b8bc3fSopenharmony_ci     *
258b1b8bc3fSopenharmony_ci     * @param ifaceNames ifaceNames
259b1b8bc3fSopenharmony_ci     * @param status true for allowed, false for disallowed
260b1b8bc3fSopenharmony_ci     * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}.
261b1b8bc3fSopenharmony_ci     */
262b1b8bc3fSopenharmony_ci    int32_t SetNicTrafficAllowed(const std::vector<std::string> &ifaceNames, bool status) override;
263b1b8bc3fSopenharmony_ci
264b1b8bc3fSopenharmony_ciprotected:
265b1b8bc3fSopenharmony_ci    void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
266b1b8bc3fSopenharmony_ci    void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
267b1b8bc3fSopenharmony_ci
268b1b8bc3fSopenharmony_ciprivate:
269b1b8bc3fSopenharmony_ci    void Init();
270b1b8bc3fSopenharmony_ci    int32_t GetDumpMessage(std::string &message);
271b1b8bc3fSopenharmony_ci
272b1b8bc3fSopenharmony_ci    void OnNetSysRestart();
273b1b8bc3fSopenharmony_ci    void UpdateNetAccessPolicyToMapFromDB();
274b1b8bc3fSopenharmony_ci    bool CheckNetworkAccessIsBroker(uint32_t uid);
275b1b8bc3fSopenharmony_ci
276b1b8bc3fSopenharmony_ciprivate:
277b1b8bc3fSopenharmony_ci    enum ServiceRunningState {
278b1b8bc3fSopenharmony_ci        STATE_STOPPED = 0,
279b1b8bc3fSopenharmony_ci        STATE_RUNNING,
280b1b8bc3fSopenharmony_ci    };
281b1b8bc3fSopenharmony_ci
282b1b8bc3fSopenharmony_ci    std::shared_ptr<NetPolicyTraffic> netPolicyTraffic_ = nullptr;
283b1b8bc3fSopenharmony_ci    std::shared_ptr<NetPolicyFirewall> netPolicyFirewall_ = nullptr;
284b1b8bc3fSopenharmony_ci    std::shared_ptr<NetPolicyRule> netPolicyRule_ = nullptr;
285b1b8bc3fSopenharmony_ci    std::shared_ptr<NetPolicyFile> netPolicyFile_ = nullptr;
286b1b8bc3fSopenharmony_ci    ServiceRunningState state_ = ServiceRunningState::STATE_STOPPED;
287b1b8bc3fSopenharmony_ci    std::shared_ptr<NetPolicyCore> netPolicyCore_ = nullptr;
288b1b8bc3fSopenharmony_ci    std::shared_ptr<NetPolicyCallback> netPolicyCallback_ = nullptr;
289b1b8bc3fSopenharmony_ci    sptr<NetPolicyServiceCommon> serviceComm_ = nullptr;
290b1b8bc3fSopenharmony_ci    std::mutex mutex_;
291b1b8bc3fSopenharmony_ci    std::vector<uint16_t> monthDay_;
292b1b8bc3fSopenharmony_ci
293b1b8bc3fSopenharmony_ci    bool hasSARemoved_ = false;
294b1b8bc3fSopenharmony_ci
295b1b8bc3fSopenharmony_ciprivate:
296b1b8bc3fSopenharmony_ci    void RegisterFactoryResetCallback();
297b1b8bc3fSopenharmony_ci
298b1b8bc3fSopenharmony_ci    class FactoryResetCallBack : public IRemoteStub<INetFactoryResetCallback> {
299b1b8bc3fSopenharmony_ci    public:
300b1b8bc3fSopenharmony_ci        FactoryResetCallBack(std::shared_ptr<NetPolicyService> netPolicy)
301b1b8bc3fSopenharmony_ci        {
302b1b8bc3fSopenharmony_ci            netPolicy_ = netPolicy;
303b1b8bc3fSopenharmony_ci        }
304b1b8bc3fSopenharmony_ci
305b1b8bc3fSopenharmony_ci        int32_t OnNetFactoryReset()
306b1b8bc3fSopenharmony_ci        {
307b1b8bc3fSopenharmony_ci            if (netPolicy_ != nullptr) {
308b1b8bc3fSopenharmony_ci                netPolicy_->FactoryResetPolicies();
309b1b8bc3fSopenharmony_ci                return NETMANAGER_SUCCESS;
310b1b8bc3fSopenharmony_ci            } else {
311b1b8bc3fSopenharmony_ci                return NETMANAGER_ERR_LOCAL_PTR_NULL;
312b1b8bc3fSopenharmony_ci            }
313b1b8bc3fSopenharmony_ci        }
314b1b8bc3fSopenharmony_ci    private:
315b1b8bc3fSopenharmony_ci        std::shared_ptr<NetPolicyService> netPolicy_ = nullptr;
316b1b8bc3fSopenharmony_ci    };
317b1b8bc3fSopenharmony_ci    sptr<INetFactoryResetCallback> netFactoryResetCallback_ = nullptr;
318b1b8bc3fSopenharmony_ci};
319b1b8bc3fSopenharmony_ci} // namespace NetManagerStandard
320b1b8bc3fSopenharmony_ci} // namespace OHOS
321b1b8bc3fSopenharmony_ci#endif // NET_POLICY_SERVICE_H
322