• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 #include "net_policy_file.h"
17 
18 #include <fcntl.h>
19 #include <string>
20 
21 #include <json/json.h>
22 
23 #include "net_manager_center.h"
24 #include "net_mgr_log_wrapper.h"
25 #include "net_policy_file_event_handler.h"
26 #include "net_policy_inner_define.h"
27 
28 namespace OHOS {
29 namespace NetManagerStandard {
30 namespace {
CheckFilePath(const std::string & fileName,std::string & realPath)31 bool CheckFilePath(const std::string &fileName, std::string &realPath)
32 {
33     char tmpPath[PATH_MAX] = {0};
34     if (!realpath(fileName.c_str(), tmpPath)) {
35         NETMGR_LOG_E("file name is illegal");
36         return false;
37     }
38     if (strcmp(tmpPath, POLICY_FILE_NAME) != 0) {
39         NETMGR_LOG_E("file path is illegal");
40         return false;
41     }
42     realPath = tmpPath;
43     return true;
44 }
45 } // namespace
46 constexpr const char *NET_POLICY_WORK_THREAD = "NET_POLICY_FILE_WORK_THREAD";
47 
NetPolicyFile()48 NetPolicyFile::NetPolicyFile()
49 {
50     InitPolicy();
51 }
52 
53 NetPolicyFile::~NetPolicyFile() = default;
54 
ReadFile(const std::string & fileName)55 bool NetPolicyFile::ReadFile(const std::string &fileName)
56 {
57     NETMGR_LOG_D("read [%{public}s] from disk.", fileName.c_str());
58     struct stat st;
59     if (stat(fileName.c_str(), &st) != 0) {
60         NETMGR_LOG_E("stat file fail");
61         return false;
62     }
63 
64     std::string realPath;
65     if (!CheckFilePath(fileName, realPath)) {
66         NETMGR_LOG_E("file does not exist");
67         return false;
68     }
69 
70     std::fstream file(realPath.c_str(), std::fstream::in);
71     if (!file.is_open()) {
72         NETMGR_LOG_E("file open fail");
73         return false;
74     }
75 
76     std::stringstream buffer;
77     buffer << file.rdbuf();
78     std::string fileContent = buffer.str();
79     file.close();
80     return Json2Obj(fileContent, netPolicy_);
81 }
82 
ReadFile()83 bool NetPolicyFile::ReadFile()
84 {
85     return ReadFile(POLICY_FILE_NAME) || ReadFile(POLICY_FILE_BAK_NAME);
86 }
87 
WriteFile()88 bool NetPolicyFile::WriteFile()
89 {
90     auto data = std::make_shared<PolicyFileEvent>();
91     Obj2Json(netPolicy_, data->json);
92     auto event = AppExecFwk::InnerEvent::Get(NetPolicyFileEventHandler::MSG_POLICY_FILE_WRITE, data);
93     auto handler = GetHandler();
94     if (!handler) {
95         NETMGR_LOG_E("NetPolicyFileEventHandler not existed");
96         return false;
97     }
98     handler->SendWriteEvent(event);
99     return true;
100 }
101 
ReadUidPolicies()102 const std::vector<UidPolicy> &NetPolicyFile::ReadUidPolicies()
103 {
104     return netPolicy_.uidPolicies;
105 }
106 
ParseUidPolicy(const Json::Value & root,NetPolicy & netPolicy)107 void NetPolicyFile::ParseUidPolicy(const Json::Value &root, NetPolicy &netPolicy)
108 {
109     const Json::Value &arrayUidPolicy = root[CONFIG_UID_POLICY];
110     uint32_t size = arrayUidPolicy.size();
111     UidPolicy uidPolicy;
112     for (uint32_t i = 0; i < size; i++) {
113         uidPolicy.uid = arrayUidPolicy[i][CONFIG_UID].asString();
114         uidPolicy.policy = arrayUidPolicy[i][CONFIG_POLICY].asString();
115         netPolicy.uidPolicies.push_back(uidPolicy);
116     }
117 }
118 
ParseBackgroundPolicy(const Json::Value & root,NetPolicy & netPolicy)119 void NetPolicyFile::ParseBackgroundPolicy(const Json::Value &root, NetPolicy &netPolicy)
120 {
121     const Json::Value &mapBackgroundPolicy = root[CONFIG_BACKGROUND_POLICY];
122     netPolicy.backgroundPolicyStatus = mapBackgroundPolicy[CONFIG_BACKGROUND_POLICY_STATUS].asString();
123 }
124 
ParseQuotaPolicy(const Json::Value & root,NetPolicy & netPolicy)125 void NetPolicyFile::ParseQuotaPolicy(const Json::Value &root, NetPolicy &netPolicy)
126 {
127     const Json::Value &arrayQuotaPolicy = root[CONFIG_QUOTA_POLICY];
128     uint32_t size = arrayQuotaPolicy.size();
129     NetPolicyQuota quotaPolicy;
130     for (uint32_t i = 0; i < size; i++) {
131         quotaPolicy.netType = arrayQuotaPolicy[i][CONFIG_QUOTA_POLICY_NETTYPE].asString();
132         quotaPolicy.simId = arrayQuotaPolicy[i][CONFIG_QUOTA_POLICY_SUBSCRIBERID].asString();
133         quotaPolicy.periodStartTime = arrayQuotaPolicy[i][CONFIG_QUOTA_POLICY_PERIODSTARTTIME].asString();
134         quotaPolicy.periodDuration = arrayQuotaPolicy[i][CONFIG_QUOTA_POLICY_PERIODDURATION].asString();
135         quotaPolicy.warningBytes = arrayQuotaPolicy[i][CONFIG_QUOTA_POLICY_WARNINGBYTES].asString();
136         quotaPolicy.limitBytes = arrayQuotaPolicy[i][CONFIG_QUOTA_POLICY_LIMITBYTES].asString();
137         quotaPolicy.lastLimitSnooze = arrayQuotaPolicy[i][CONFIG_QUOTA_POLICY_LASTLIMITSNOOZE].asString();
138         quotaPolicy.metered = arrayQuotaPolicy[i][CONFIG_QUOTA_POLICY_METERED].asString();
139         quotaPolicy.ident = arrayQuotaPolicy[i][CONFIG_QUOTA_POLICY_IDENT].asString();
140         netPolicy.netQuotaPolicies.push_back(quotaPolicy);
141     }
142 }
143 
ParseFirewallRule(const Json::Value & root,NetPolicy & netPolicy)144 void NetPolicyFile::ParseFirewallRule(const Json::Value &root, NetPolicy &netPolicy)
145 {
146     const Json::Value &mapFirewallList = root[CONFIG_FIREWALL_RULE];
147     for (auto iter = mapFirewallList.begin(); iter != mapFirewallList.end(); iter++) {
148         uint32_t chainType = CommonUtils::StrToUint(iter.key().asString());
149         const Json::Value &deniedList = (*iter)[CONFIG_FIREWALL_RULE_DENIEDLIST];
150         const Json::Value &allowedList = (*iter)[CONFIG_FIREWALL_RULE_ALLOWEDLIST];
151         for (uint32_t i = 0; i < deniedList.size(); i++) {
152             netPolicy_.netFirewallRules[chainType].deniedList.insert(CommonUtils::StrToUint(deniedList[i].asString()));
153         }
154         for (uint32_t i = 0; i < allowedList.size(); i++) {
155             netPolicy_.netFirewallRules[chainType].allowedList.insert(
156                 CommonUtils::StrToUint(allowedList[i].asString()));
157         }
158     }
159 }
160 
Json2Obj(const std::string & content,NetPolicy & netPolicy)161 bool NetPolicyFile::Json2Obj(const std::string &content, NetPolicy &netPolicy)
162 {
163     if (content.empty()) {
164         return false;
165     }
166 
167     Json::Value root;
168     Json::CharReaderBuilder builder;
169     std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
170     JSONCPP_STRING errs;
171 
172     bool isSuccess = reader->parse(content.c_str(), content.c_str() + content.length(), &root, &errs);
173     if (isSuccess && errs.size() == 0) {
174         netPolicy.hosVersion = root[CONFIG_HOS_VERSION].asString();
175         if (netPolicy.hosVersion.empty()) {
176             netPolicy.hosVersion = HOS_VERSION;
177         }
178 
179         // parse uid policy from file
180         ParseUidPolicy(root, netPolicy);
181 
182         // parse background policy from file
183         ParseBackgroundPolicy(root, netPolicy);
184 
185         // parse quota policy from file
186         ParseQuotaPolicy(root, netPolicy);
187 
188         // parse firewall rule from file
189         ParseFirewallRule(root, netPolicy);
190 
191         return true;
192     }
193 
194     return false;
195 }
196 
Obj2Json(const NetPolicy & netPolicy,std::string & content)197 bool NetPolicyFile::Obj2Json(const NetPolicy &netPolicy, std::string &content)
198 {
199     Json::Value root;
200     Json::StreamWriterBuilder builder;
201     auto streamWriter = std::unique_ptr<Json::StreamWriter>(builder.newStreamWriter());
202     if (netPolicy_.hosVersion.empty()) {
203         netPolicy_.hosVersion = HOS_VERSION;
204     }
205     root[CONFIG_HOS_VERSION] = Json::Value(netPolicy_.hosVersion);
206     AddUidPolicy(root);
207     AddBackgroundPolicy(root);
208     AddQuotaPolicy(root);
209     AddFirewallRule(root);
210 
211     std::ostringstream out;
212     streamWriter->write(root, &out);
213     content = out.str();
214     return true;
215 }
216 
AddQuotaPolicy(Json::Value & root)217 void NetPolicyFile::AddQuotaPolicy(Json::Value &root)
218 {
219     uint32_t size = netPolicy_.netQuotaPolicies.size();
220     for (uint32_t i = 0; i < size; i++) {
221         Json::Value quotaPolicy;
222         quotaPolicy[CONFIG_QUOTA_POLICY_NETTYPE] = netPolicy_.netQuotaPolicies[i].netType;
223         quotaPolicy[CONFIG_QUOTA_POLICY_SUBSCRIBERID] = netPolicy_.netQuotaPolicies[i].simId;
224         quotaPolicy[CONFIG_QUOTA_POLICY_PERIODSTARTTIME] = netPolicy_.netQuotaPolicies[i].periodStartTime;
225         quotaPolicy[CONFIG_QUOTA_POLICY_PERIODDURATION] = netPolicy_.netQuotaPolicies[i].periodDuration;
226         quotaPolicy[CONFIG_QUOTA_POLICY_WARNINGBYTES] = netPolicy_.netQuotaPolicies[i].warningBytes;
227         quotaPolicy[CONFIG_QUOTA_POLICY_LIMITBYTES] = netPolicy_.netQuotaPolicies[i].limitBytes;
228         quotaPolicy[CONFIG_QUOTA_POLICY_LASTLIMITSNOOZE] = netPolicy_.netQuotaPolicies[i].lastLimitSnooze;
229         quotaPolicy[CONFIG_QUOTA_POLICY_METERED] = netPolicy_.netQuotaPolicies[i].metered;
230         quotaPolicy[CONFIG_QUOTA_POLICY_IDENT] = netPolicy_.netQuotaPolicies[i].ident;
231         root[CONFIG_QUOTA_POLICY].append(quotaPolicy);
232     }
233 }
234 
AddUidPolicy(Json::Value & root)235 void NetPolicyFile::AddUidPolicy(Json::Value &root)
236 {
237     uint32_t size = netPolicy_.uidPolicies.size();
238     for (uint32_t i = 0; i < size; i++) {
239         Json::Value uidPolicy;
240         uidPolicy[CONFIG_UID] = netPolicy_.uidPolicies[i].uid;
241         uidPolicy[CONFIG_POLICY] = netPolicy_.uidPolicies[i].policy;
242         root[CONFIG_UID_POLICY].append(uidPolicy);
243     }
244 }
245 
AddBackgroundPolicy(Json::Value & root)246 void NetPolicyFile::AddBackgroundPolicy(Json::Value &root)
247 {
248     Json::Value backgroundPolicy;
249     if (netPolicy_.backgroundPolicyStatus.empty()) {
250         netPolicy_.backgroundPolicyStatus = BACKGROUND_POLICY_ALLOW;
251     }
252     backgroundPolicy[CONFIG_BACKGROUND_POLICY_STATUS] = netPolicy_.backgroundPolicyStatus;
253     root[CONFIG_BACKGROUND_POLICY] = backgroundPolicy;
254 }
255 
AddFirewallRule(Json::Value & root)256 void NetPolicyFile::AddFirewallRule(Json::Value &root)
257 {
258     Json::Value mapFirewallList(Json::objectValue);
259     for (auto &&[k, v] : netPolicy_.netFirewallRules) {
260         NETMGR_LOG_D("read k[%{public}d].", k);
261         Json::Value deniedList(Json::arrayValue);
262         Json::Value allowedList(Json::arrayValue);
263         std::for_each(v.deniedList.begin(), v.deniedList.end(),
264                       [&deniedList](const auto &it) { deniedList.append(std::to_string(it)); });
265         std::for_each(v.allowedList.begin(), v.allowedList.end(),
266                       [&allowedList](const auto &it) { allowedList.append(std::to_string(it)); });
267         mapFirewallList[std::to_string(k)][CONFIG_FIREWALL_RULE_DENIEDLIST] = deniedList;
268         mapFirewallList[std::to_string(k)][CONFIG_FIREWALL_RULE_ALLOWEDLIST] = allowedList;
269     }
270     root[CONFIG_FIREWALL_RULE] = mapFirewallList;
271 }
272 
ArbitrationWritePolicyToFile(uint32_t uid,uint32_t policy)273 uint32_t NetPolicyFile::ArbitrationWritePolicyToFile(uint32_t uid, uint32_t policy)
274 {
275     uint32_t size = netPolicy_.uidPolicies.size();
276     bool haveUidAndPolicy = false;
277     uint32_t oldPolicy;
278     for (uint32_t i = 0; i < size; i++) {
279         auto uidTemp = CommonUtils::StrToUint(netPolicy_.uidPolicies[i].uid.c_str());
280         if (uid == uidTemp) {
281             haveUidAndPolicy = true;
282             oldPolicy = uidTemp;
283         }
284     }
285 
286     if (haveUidAndPolicy) {
287         if (oldPolicy != policy && policy == NET_POLICY_NONE) {
288             return NET_POLICY_UID_OP_TYPE_DELETE;
289         }
290 
291         if (oldPolicy != policy && policy != NET_POLICY_NONE) {
292             return NET_POLICY_UID_OP_TYPE_UPDATE;
293         }
294 
295         return NET_POLICY_UID_OP_TYPE_DO_NOTHING;
296     }
297 
298     if (policy == NET_POLICY_NONE) {
299         return NET_POLICY_UID_OP_TYPE_DO_NOTHING;
300     }
301     return NET_POLICY_UID_OP_TYPE_ADD;
302 }
303 
WritePolicyByUid(uint32_t uid,uint32_t policy)304 void NetPolicyFile::WritePolicyByUid(uint32_t uid, uint32_t policy)
305 {
306     uint32_t netUidPolicyOpType = ArbitrationWritePolicyToFile(uid, policy);
307     WritePolicyByUid(netUidPolicyOpType, uid, policy);
308 }
309 
WritePolicyByUid(uint32_t netUidPolicyOpType,uint32_t uid,uint32_t policy)310 void NetPolicyFile::WritePolicyByUid(uint32_t netUidPolicyOpType, uint32_t uid, uint32_t policy)
311 {
312     NETMGR_LOG_D("Write File start, model:[%{public}u]", netUidPolicyOpType);
313     if (netUidPolicyOpType == NetUidPolicyOpType::NET_POLICY_UID_OP_TYPE_UPDATE) {
314         for (auto &uidPolicy : netPolicy_.uidPolicies) {
315             if (uidPolicy.uid == std::to_string(uid)) {
316                 uidPolicy.policy = std::to_string(policy);
317                 break;
318             }
319         }
320     } else if (netUidPolicyOpType == NetUidPolicyOpType::NET_POLICY_UID_OP_TYPE_DELETE) {
321         for (auto iter = netPolicy_.uidPolicies.begin(); iter != netPolicy_.uidPolicies.end(); ++iter) {
322             if (iter->uid == std::to_string(uid)) {
323                 netPolicy_.uidPolicies.erase(iter);
324                 break;
325             }
326         }
327     } else if (netUidPolicyOpType == NetUidPolicyOpType::NET_POLICY_UID_OP_TYPE_ADD) {
328         UidPolicy uidPolicy;
329         uidPolicy.uid = std::to_string(uid);
330         uidPolicy.policy = std::to_string(static_cast<uint32_t>(policy));
331         netPolicy_.uidPolicies.push_back(uidPolicy);
332     } else {
333         NETMGR_LOG_I("Need to do nothing!");
334     }
335 
336     WriteFile();
337 }
338 
UpdateQuotaPolicyExist(const NetQuotaPolicy & quotaPolicy)339 bool NetPolicyFile::UpdateQuotaPolicyExist(const NetQuotaPolicy &quotaPolicy)
340 {
341     if (netPolicy_.netQuotaPolicies.empty()) {
342         NETMGR_LOG_E("UpdateQuotaPolicyExist netQuotaPolicies is empty");
343         return false;
344     }
345 
346     for (uint32_t i = 0; i < netPolicy_.netQuotaPolicies.size(); ++i) {
347         if (quotaPolicy.networkmatchrule.simId == netPolicy_.netQuotaPolicies[i].simId &&
348             netPolicy_.netQuotaPolicies[i].netType == std::to_string(quotaPolicy.networkmatchrule.netType)) {
349             netPolicy_.netQuotaPolicies[i].lastLimitSnooze = std::to_string(quotaPolicy.quotapolicy.lastLimitRemind);
350             netPolicy_.netQuotaPolicies[i].limitBytes = std::to_string(quotaPolicy.quotapolicy.limitBytes);
351             netPolicy_.netQuotaPolicies[i].metered = std::to_string(quotaPolicy.quotapolicy.metered);
352             netPolicy_.netQuotaPolicies[i].netType = std::to_string(quotaPolicy.networkmatchrule.netType);
353             netPolicy_.netQuotaPolicies[i].periodDuration = quotaPolicy.quotapolicy.periodDuration;
354             netPolicy_.netQuotaPolicies[i].periodStartTime = std::to_string(quotaPolicy.quotapolicy.periodStartTime);
355             netPolicy_.netQuotaPolicies[i].ident = quotaPolicy.networkmatchrule.ident;
356             netPolicy_.netQuotaPolicies[i].simId = quotaPolicy.networkmatchrule.simId;
357             netPolicy_.netQuotaPolicies[i].warningBytes = std::to_string(quotaPolicy.quotapolicy.warningBytes);
358             return true;
359         }
360     }
361 
362     return false;
363 }
364 
WriteQuotaPolicies(const std::vector<NetQuotaPolicy> & quotaPolicies)365 bool NetPolicyFile::WriteQuotaPolicies(const std::vector<NetQuotaPolicy> &quotaPolicies)
366 {
367     netPolicy_.netQuotaPolicies.clear();
368     uint32_t vSize = quotaPolicies.size();
369     NetPolicyQuota quotaPolicy;
370     for (uint32_t i = 0; i < vSize; i++) {
371         if (UpdateQuotaPolicyExist(quotaPolicies[i])) {
372             NETMGR_LOG_E("quotaPolicies:periodDuration[%{public}s], don't write this quotaPolicies!",
373                          quotaPolicies[i].quotapolicy.periodDuration.c_str());
374             continue;
375         }
376         quotaPolicy.lastLimitSnooze = std::to_string(quotaPolicies[i].quotapolicy.lastLimitRemind);
377         quotaPolicy.limitBytes = std::to_string(quotaPolicies[i].quotapolicy.limitBytes);
378         quotaPolicy.metered = std::to_string(quotaPolicies[i].quotapolicy.metered);
379         quotaPolicy.ident = quotaPolicies[i].networkmatchrule.ident;
380         quotaPolicy.netType = std::to_string(quotaPolicies[i].networkmatchrule.netType);
381         quotaPolicy.periodDuration = quotaPolicies[i].quotapolicy.periodDuration;
382         quotaPolicy.periodStartTime = std::to_string(quotaPolicies[i].quotapolicy.periodStartTime);
383         quotaPolicy.simId = quotaPolicies[i].networkmatchrule.simId;
384         quotaPolicy.warningBytes = std::to_string(quotaPolicies[i].quotapolicy.warningBytes);
385         netPolicy_.netQuotaPolicies.push_back(quotaPolicy);
386     }
387 
388     return WriteFile();
389 }
390 
ReadQuotaPolicies(std::vector<NetQuotaPolicy> & quotaPolicies)391 void NetPolicyFile::ReadQuotaPolicies(std::vector<NetQuotaPolicy> &quotaPolicies)
392 {
393     NetQuotaPolicy quotaPolicyTmp;
394     for (const auto &quotaPolicy : netPolicy_.netQuotaPolicies) {
395         ToQuotaPolicy(quotaPolicy, quotaPolicyTmp);
396         quotaPolicies.push_back(quotaPolicyTmp);
397     }
398 }
399 
ReadFirewallRules(uint32_t chainType,std::set<uint32_t> & allowedList,std::set<uint32_t> & deniedList)400 int32_t NetPolicyFile::ReadFirewallRules(uint32_t chainType, std::set<uint32_t> &allowedList,
401                                          std::set<uint32_t> &deniedList)
402 {
403     auto &&w = netPolicy_.netFirewallRules[chainType].allowedList;
404     auto &&b = netPolicy_.netFirewallRules[chainType].deniedList;
405     allowedList.insert(w.begin(), w.end());
406     deniedList.insert(b.begin(), b.end());
407     return NETMANAGER_SUCCESS;
408 }
409 
WriteFirewallRules(uint32_t chainType,const std::set<uint32_t> & allowedList,const std::set<uint32_t> & deniedList)410 void NetPolicyFile::WriteFirewallRules(uint32_t chainType, const std::set<uint32_t> &allowedList,
411                                        const std::set<uint32_t> &deniedList)
412 {
413     netPolicy_.netFirewallRules[chainType].allowedList.clear();
414     netPolicy_.netFirewallRules[chainType].deniedList.clear();
415     netPolicy_.netFirewallRules[chainType].allowedList.insert(allowedList.begin(), allowedList.end());
416     netPolicy_.netFirewallRules[chainType].deniedList.insert(deniedList.begin(), deniedList.end());
417     WriteFile();
418 }
419 
ResetPolicies()420 int32_t NetPolicyFile::ResetPolicies()
421 {
422     netPolicy_.uidPolicies.clear();
423     netPolicy_.backgroundPolicyStatus = BACKGROUND_POLICY_ALLOW;
424     netPolicy_.netQuotaPolicies.clear();
425     netPolicy_.netFirewallRules.clear();
426     WriteFile();
427 
428     return NETMANAGER_SUCCESS;
429 }
430 
WriteBackgroundPolicy(bool backgroundPolicy)431 void NetPolicyFile::WriteBackgroundPolicy(bool backgroundPolicy)
432 {
433     if (backgroundPolicy) {
434         netPolicy_.backgroundPolicyStatus = BACKGROUND_POLICY_ALLOW;
435     } else {
436         netPolicy_.backgroundPolicyStatus = BACKGROUND_POLICY_REJECT;
437     }
438 
439     WriteFile();
440 }
441 
ReadBackgroundPolicy()442 bool NetPolicyFile::ReadBackgroundPolicy()
443 {
444     return netPolicy_.backgroundPolicyStatus == BACKGROUND_POLICY_ALLOW;
445 }
446 
GetHandler()447 std::shared_ptr<NetPolicyFileEventHandler> NetPolicyFile::GetHandler()
448 {
449     static auto handler = [this]() -> std::shared_ptr<NetPolicyFileEventHandler> {
450         auto runner = AppExecFwk::EventRunner::Create(NET_POLICY_WORK_THREAD);
451         if (!runner) {
452             NETMGR_LOG_E("Create net policy file work event runner.");
453             return nullptr;
454         }
455         return std::make_shared<NetPolicyFileEventHandler>(runner);
456     }();
457     return handler;
458 }
459 
InitPolicy()460 bool NetPolicyFile::InitPolicy()
461 {
462     ResetPolicies();
463     return ReadFile();
464 }
465 
RemoveInexistentUid(uint32_t uid)466 void NetPolicyFile::RemoveInexistentUid(uint32_t uid)
467 {
468     WritePolicyByUid(NetUidPolicyOpType::NET_POLICY_UID_OP_TYPE_DELETE, uid, 0);
469 }
470 } // namespace NetManagerStandard
471 } // namespace OHOS
472