• 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_traffic.h"
17 
18 #include "broadcast_manager.h"
19 #include "common_event_data.h"
20 #include "common_event_manager.h"
21 #include "common_event_publish_info.h"
22 #include "common_event_support.h"
23 #include "system_ability_definition.h"
24 
25 #include "net_manager_center.h"
26 #include "net_mgr_log_wrapper.h"
27 #include "net_policy_constants.h"
28 #include "net_policy_file.h"
29 #include "net_policy_inner_define.h"
30 #include "net_quota_policy.h"
31 #include "net_specifier.h"
32 #include "net_stats_info.h"
33 #include "netmanager_base_common_utils.h"
34 #include "netmanager_base_permission.h"
35 
36 namespace OHOS {
37 namespace NetManagerStandard {
38 namespace {
39 constexpr const char *BROADCAST_QUOTA_WARNING = "Net Policy Quota Warning";
40 constexpr const char *BROADCAST_QUOTA_LIMIT_REMIND = "Net Policy Quota Limit Remind";
41 constexpr const char *BROADCAST_QUOTA_LIMIT = "Net Policy Quota Limit";
42 } // namespace
43 
Init()44 void NetPolicyTraffic::Init()
45 {
46     netsysCallback_ = new (std::nothrow)
47         NetsysControllerCallbackImpl((std::static_pointer_cast<NetPolicyTraffic>(shared_from_this())));
48     if (netsysCallback_ != nullptr) {
49         GetNetsysInst()->RegisterNetsysCallback(netsysCallback_);
50     }
51 
52     netConnCallback_ =
53         new (std::nothrow) ConnCallBack((std::static_pointer_cast<NetPolicyTraffic>(shared_from_this())));
54     if (netConnCallback_ != nullptr) {
55         GetNetCenterInst().RegisterNetConnCallback(netConnCallback_);
56     }
57     ReadQuotaPolicies();
58 }
59 
IsValidQuotaPolicy(const NetQuotaPolicy & quotaPolicy)60 bool NetPolicyTraffic::IsValidQuotaPolicy(const NetQuotaPolicy &quotaPolicy)
61 {
62     int32_t netType = quotaPolicy.networkmatchrule.netType;
63     if (!IsValidNetType(netType)) {
64         NETMGR_LOG_E("NetPolicyType is invalid policy[%{public}d]", netType);
65         return false;
66     }
67 
68     if (!IsValidPeriodDuration(quotaPolicy.quotapolicy.periodDuration)) {
69         NETMGR_LOG_E("periodDuration [%{public}s] must Mx", quotaPolicy.quotapolicy.periodDuration.c_str());
70         return false;
71     }
72     return true;
73 }
74 
IsValidNetType(int32_t netType)75 bool NetPolicyTraffic::IsValidNetType(int32_t netType)
76 {
77     switch (netType) {
78         case NetBearType::BEARER_CELLULAR:
79         case NetBearType::BEARER_WIFI:
80         case NetBearType::BEARER_BLUETOOTH:
81         case NetBearType::BEARER_ETHERNET:
82         case NetBearType::BEARER_VPN:
83         case NetBearType::BEARER_WIFI_AWARE: {
84             return true;
85         }
86         default: {
87             NETMGR_LOG_E("Invalid netType [%{public}d]", netType);
88             return false;
89         }
90     }
91 }
92 
IsValidNetRemindType(uint32_t remindType)93 bool NetPolicyTraffic::IsValidNetRemindType(uint32_t remindType)
94 {
95     switch (remindType) {
96         case RemindType::REMIND_TYPE_WARNING:
97         case RemindType::REMIND_TYPE_LIMIT: {
98             return true;
99         }
100         default: {
101             NETMGR_LOG_E("Invalid remindType [%{public}d]", remindType);
102             return false;
103         }
104     }
105 }
106 
UpdateQuotaPolicies(const std::vector<NetQuotaPolicy> & quotaPolicies)107 int32_t NetPolicyTraffic::UpdateQuotaPolicies(const std::vector<NetQuotaPolicy> &quotaPolicies)
108 {
109     if (quotaPolicies.empty()) {
110         NETMGR_LOG_E("SetNetQuotaPolicies size is empty");
111         return POLICY_ERR_INVALID_QUOTA_POLICY;
112     }
113     // formalize the quota policy
114     NetmanagerHiTrace::NetmanagerStartSyncTrace("FormalizeQuotaPolicies quotaPolicies start");
115     FormalizeQuotaPolicies(quotaPolicies);
116     NetmanagerHiTrace::NetmanagerFinishSyncTrace("FormalizeQuotaPolicies quotaPolicies end");
117     return UpdateQuotaPoliciesInner();
118 }
119 
UpdateQuotaPoliciesInner()120 int32_t NetPolicyTraffic::UpdateQuotaPoliciesInner()
121 {
122     // calculate the quota remain and get the metered ifaces
123     NetmanagerHiTrace::NetmanagerStartSyncTrace("UpdateMeteredIfacesQuota start");
124     auto meteredIfaces = UpdateMeteredIfacesQuota();
125     NetmanagerHiTrace::NetmanagerFinishSyncTrace("UpdateMeteredIfacesQuota end");
126 
127     // update the metered ifaces and notify the changes.
128     NetmanagerHiTrace::NetmanagerStartSyncTrace("UpdateMeteredIfaces meteredIfaces start");
129     UpdateMeteredIfaces(meteredIfaces);
130     NetmanagerHiTrace::NetmanagerFinishSyncTrace("UpdateMeteredIfaces meteredIfaces end");
131 
132     // notify quota limit or warning.
133     NetmanagerHiTrace::NetmanagerStartSyncTrace("UpdateQuotaNotify start");
134     UpdateQuotaNotify();
135     NetmanagerHiTrace::NetmanagerFinishSyncTrace("UpdateQuotaNotify end");
136     // write quota policies to file.
137     if (!WriteQuotaPolicies()) {
138         NETMGR_LOG_E("UpdateQuotaPolicies WriteFile failed");
139         return NETMANAGER_ERR_WRITE_DATA_FAIL;
140     }
141     // notify the the quota policy change.
142     GetCbInst()->NotifyNetQuotaPolicyChangeAsync(quotaPolicies_);
143     return NETMANAGER_SUCCESS;
144 }
145 
FormalizeQuotaPolicies(const std::vector<NetQuotaPolicy> & quotaPolicies)146 void NetPolicyTraffic::FormalizeQuotaPolicies(const std::vector<NetQuotaPolicy> &quotaPolicies)
147 {
148     quotaPolicies_.clear();
149     for (auto quotaPolicy : quotaPolicies) {
150         if (!IsValidQuotaPolicy(quotaPolicy)) {
151             NETMGR_LOG_E("UpdateQuotaPolicies invalid quota policy netType[%{public}d], periodDuration[%{public}s]",
152                          quotaPolicy.networkmatchrule.netType, quotaPolicy.quotapolicy.periodDuration.c_str());
153             continue;
154         }
155         if (quotaPolicy.quotapolicy.limitBytes == DATA_USAGE_UNKNOWN) {
156             quotaPolicy.quotapolicy.limitAction = LIMIT_ACTION_ALERT_ONLY;
157         } else if (quotaPolicy.quotapolicy.warningBytes == DATA_USAGE_UNKNOWN) {
158             quotaPolicy.quotapolicy.warningBytes =
159                 quotaPolicy.quotapolicy.limitBytes * NINETY_PERCENTAGE / HUNDRED_PERCENTAGE;
160         }
161         if (quotaPolicy.quotapolicy.limitAction == LIMIT_ACTION_ALERT_ONLY) {
162             quotaPolicy.quotapolicy.limitBytes = DATA_USAGE_UNLIMITED;
163         }
164         if (quotaPolicy.quotapolicy.warningBytes > quotaPolicy.quotapolicy.limitBytes) {
165             quotaPolicy.quotapolicy.warningBytes = DATA_USAGE_UNLIMITED;
166         }
167         if (quotaPolicy.quotapolicy.limitBytes == DATA_USAGE_UNLIMITED) {
168             quotaPolicy.quotapolicy.limitAction = LIMIT_ACTION_ALERT_ONLY;
169         }
170         quotaPolicies_.push_back(quotaPolicy);
171     }
172 }
173 
UpdateMeteredIfacesQuota()174 const std::vector<std::string> NetPolicyTraffic::UpdateMeteredIfacesQuota()
175 {
176     std::vector<std::string> newMeteredIfaces;
177     for (auto &quotaPolicy : quotaPolicies_) {
178         std::string iface = GetMatchIfaces(quotaPolicy);
179         // set quota for metered iface.
180         if (iface == UNKNOW_IFACE || !quotaPolicy.quotapolicy.metered) {
181             continue;
182         }
183         newMeteredIfaces.push_back(iface);
184         int64_t quotaRemain = GetQuotaRemain(quotaPolicy);
185         if (quotaRemain >= 0) {
186             GetNetsysInst()->BandwidthSetIfaceQuota(iface, quotaRemain);
187         }
188     }
189     // remove the iface quota that not metered.
190     for (uint32_t i = 0; i < meteredIfaces_.size(); ++i) {
191         if (!std::count(newMeteredIfaces.begin(), newMeteredIfaces.end(), meteredIfaces_[i])) {
192             GetNetsysInst()->BandwidthRemoveIfaceQuota(meteredIfaces_[i]);
193         }
194     }
195     return newMeteredIfaces;
196 }
197 
UpdateMeteredIfaces(std::vector<std::string> & newMeteredIfaces)198 void NetPolicyTraffic::UpdateMeteredIfaces(std::vector<std::string> &newMeteredIfaces)
199 {
200     NETMGR_LOG_D("UpdateMeteredIfaces size[%{public}zu]", newMeteredIfaces.size());
201     meteredIfaces_.clear();
202     meteredIfaces_.reserve(newMeteredIfaces.size());
203     for (auto &iface : newMeteredIfaces) {
204         meteredIfaces_.push_back(iface);
205     }
206     // notify the callback of metered ifaces changed.
207     GetCbInst()->NotifyNetMeteredIfacesChangeAsync(meteredIfaces_);
208 }
209 
UpdateQuotaNotify()210 void NetPolicyTraffic::UpdateQuotaNotify()
211 {
212     NetmanagerHiTrace::NetmanagerStartSyncTrace("Traverse cellular network start");
213     for (auto &quotaPolicy : quotaPolicies_) {
214         NetmanagerHiTrace::NetmanagerStartSyncTrace("Get the start time of the metering cycle start");
215         int64_t start = quotaPolicy.GetPeriodStart();
216         NetmanagerHiTrace::NetmanagerFinishSyncTrace("Get the start time of the metering cycle end");
217 
218         NetmanagerHiTrace::NetmanagerStartSyncTrace("Get the usage of traffic start");
219         int64_t totalQuota = GetTotalQuota(quotaPolicy);
220         NetmanagerHiTrace::NetmanagerFinishSyncTrace("Get the usage of traffic end");
221         // check if the quota is over the limit
222         if (quotaPolicy.IsOverLimit(totalQuota)) {
223             if (quotaPolicy.quotapolicy.lastLimitRemind > start) {
224                 // notify the quota reach limit and has reminded before.
225                 NetmanagerHiTrace::NetmanagerStartSyncTrace("Notify quota limit reminded start");
226                 NotifyQuotaLimitReminded(totalQuota);
227                 NetmanagerHiTrace::NetmanagerFinishSyncTrace("Notify quota limit reminded end");
228                 continue;
229             }
230             NetmanagerHiTrace::NetmanagerStartSyncTrace("Update net enable status start");
231             UpdateNetEnableStatus(quotaPolicy);
232             NetmanagerHiTrace::NetmanagerFinishSyncTrace("Update net enable status end");
233             // notify the quota reach limit
234             NotifyQuotaLimit(totalQuota);
235             continue;
236         }
237         // check if the quota is over the warning
238         if (quotaPolicy.IsOverWarning(totalQuota) && quotaPolicy.quotapolicy.lastWarningRemind < start) {
239             NetmanagerHiTrace::NetmanagerStartSyncTrace("Notify quota warning remind start");
240             NotifyQuotaWarning(totalQuota);
241             NetmanagerHiTrace::NetmanagerFinishSyncTrace("Notify quota warning remind end");
242         }
243     }
244     NetmanagerHiTrace::NetmanagerFinishSyncTrace("Traverse cellular network end");
245 }
246 
GetQuotaRemain(NetQuotaPolicy & quotaPolicy)247 int64_t NetPolicyTraffic::GetQuotaRemain(NetQuotaPolicy &quotaPolicy)
248 {
249     int64_t start = quotaPolicy.GetPeriodStart();
250     int64_t totalQuota = GetTotalQuota(quotaPolicy);
251     NETMGR_LOG_D("GetQuotaRemain totalQuota[%{public}s] limit[%{public}s] start[%{public}s]",
252                  std::to_string(totalQuota).c_str(), std::to_string(quotaPolicy.quotapolicy.limitBytes).c_str(),
253                  ctime(&start));
254     // calculate the quota for each policy.
255     bool hasLimit = quotaPolicy.quotapolicy.limitBytes != DATA_USAGE_UNKNOWN;
256     int64_t quota = LONG_MAX;
257     if (hasLimit || quotaPolicy.quotapolicy.metered) {
258         if (hasLimit && quotaPolicy.quotapolicy.periodDuration != QUOTA_POLICY_NO_PERIOD) {
259             if (quotaPolicy.quotapolicy.lastLimitRemind >= start) {
260                 return LONG_MAX;
261             }
262             quota = quotaPolicy.quotapolicy.limitBytes - totalQuota;
263         }
264     }
265     return quota < 0 ? 0 : quota;
266 }
267 
UpdateNetEnableStatus(const NetQuotaPolicy & quotaPolicy)268 void NetPolicyTraffic::UpdateNetEnableStatus(const NetQuotaPolicy &quotaPolicy)
269 {
270     NETMGR_LOG_D("UpdateNetEnableStatus metered[%{public}d] quotapolicy.limitAction[%{public}d]",
271                  quotaPolicy.quotapolicy.metered, quotaPolicy.quotapolicy.limitAction);
272     if (quotaPolicy.quotapolicy.metered || quotaPolicy.quotapolicy.limitAction == LIMIT_ACTION_ACCESS_DISABLED) {
273         SetNetworkEnableStatus(quotaPolicy, false);
274     }
275 }
276 
GetNetQuotaPolicies(std::vector<NetQuotaPolicy> & quotaPolicies)277 int32_t NetPolicyTraffic::GetNetQuotaPolicies(std::vector<NetQuotaPolicy> &quotaPolicies)
278 {
279     quotaPolicies.clear();
280     quotaPolicies = quotaPolicies_;
281     NETMGR_LOG_D("GetNetQuotaPolicies quotaPolicies end size[%{public}zu]", quotaPolicies.size());
282     return NETMANAGER_SUCCESS;
283 }
284 
UpdateRemindPolicy(int32_t netType,const std::string & simId,uint32_t remindType)285 int32_t NetPolicyTraffic::UpdateRemindPolicy(int32_t netType, const std::string &simId, uint32_t remindType)
286 {
287     if (!IsValidNetType(netType)) {
288         NETMGR_LOG_E("NetPolicyType is invalid policy[%{public}d]", netType);
289         return NETMANAGER_ERR_PARAMETER_ERROR;
290     }
291 
292     if (!IsValidNetRemindType(remindType)) {
293         return NETMANAGER_ERR_PARAMETER_ERROR;
294     }
295 
296     for (uint32_t i = 0; i < quotaPolicies_.size(); ++i) {
297         NetQuotaPolicy &quotaPolicy = quotaPolicies_[i];
298         int32_t netTypeTemp = quotaPolicy.networkmatchrule.netType;
299         std::string iccidTemp = quotaPolicy.networkmatchrule.simId;
300         if (netTypeTemp == netType && iccidTemp == simId) {
301             switch (remindType) {
302                 case REMIND_TYPE_WARNING:
303                     quotaPolicy.quotapolicy.lastWarningRemind = time(nullptr);
304                     break;
305                 case REMIND_TYPE_LIMIT:
306                     quotaPolicy.quotapolicy.lastLimitRemind = time(nullptr);
307                     break;
308                 default:
309                     return NETMANAGER_ERR_PARAMETER_ERROR;
310             }
311         }
312     }
313     UpdateQuotaPoliciesInner();
314 
315     return NETMANAGER_SUCCESS;
316 }
317 
GetMeteredIfaces()318 const std::vector<std::string> &NetPolicyTraffic::GetMeteredIfaces()
319 {
320     return meteredIfaces_;
321 }
322 
ResetPolicies(const std::string & simId)323 int32_t NetPolicyTraffic::ResetPolicies(const std::string &simId)
324 {
325     for (auto &quotaPolicy : quotaPolicies_) {
326         if (quotaPolicy.networkmatchrule.simId == simId) {
327             quotaPolicy.Reset();
328         }
329     }
330     return UpdateQuotaPoliciesInner();
331 }
332 
ReachedLimit(const std::string & iface)333 void NetPolicyTraffic::ReachedLimit(const std::string &iface)
334 {
335     NETMGR_LOG_D("ReachedLimit iface:%{public}s.", iface.c_str());
336     auto &ifaces = GetMeteredIfaces();
337     if (std::find(ifaces.begin(), ifaces.end(), iface) != ifaces.end()) {
338         UpdateQuotaPoliciesInner();
339     }
340 }
341 
UpdateNetPolicy()342 void NetPolicyTraffic::UpdateNetPolicy()
343 {
344     UpdateQuotaPoliciesInner();
345 }
346 
GetTotalQuota(NetQuotaPolicy & quotaPolicy)347 int64_t NetPolicyTraffic::GetTotalQuota(NetQuotaPolicy &quotaPolicy)
348 {
349     std::string iface = GetMatchIfaces(quotaPolicy);
350     NetStatsInfo info;
351     int64_t start = quotaPolicy.GetPeriodStart();
352     int64_t end = static_cast<int64_t>(time(nullptr));
353     GetNetCenterInst().GetIfaceStatsDetail(iface, start, end, info);
354     int64_t quota = static_cast<int64_t>(info.rxBytes_ + info.txBytes_);
355 
356     return quota < 0 ? 0 : quota;
357 }
358 
ReadQuotaPolicies()359 void NetPolicyTraffic::ReadQuotaPolicies()
360 {
361     GetFileInst()->ReadQuotaPolicies(quotaPolicies_);
362     UpdateQuotaPoliciesInner();
363 }
364 
WriteQuotaPolicies()365 bool NetPolicyTraffic::WriteQuotaPolicies()
366 {
367     return GetFileInst()->WriteQuotaPolicies(quotaPolicies_);
368 }
369 
GetMatchIfaces(const NetQuotaPolicy & quotaPolicy)370 const std::string NetPolicyTraffic::GetMatchIfaces(const NetQuotaPolicy &quotaPolicy)
371 {
372     std::string ident = "";
373     if (quotaPolicy.networkmatchrule.netType == BEARER_CELLULAR) {
374         ident = IDENT_PREFIX_CELLULAR + quotaPolicy.networkmatchrule.simId;
375     } else if (quotaPolicy.networkmatchrule.netType == BEARER_WIFI) {
376         ident = quotaPolicy.networkmatchrule.ident;
377     } else if (quotaPolicy.networkmatchrule.netType == BEARER_ETHERNET) {
378         ident = quotaPolicy.networkmatchrule.ident;
379     }
380     std::string iface;
381     GetNetCenterInst().GetIfaceNameByType(static_cast<NetBearType>(quotaPolicy.networkmatchrule.netType), ident, iface);
382     NETMGR_LOG_D("GetMatchIfaces netType: %{public}d ident: %{public}s iface: %{public}s.",
383                  quotaPolicy.networkmatchrule.netType, ident.c_str(), iface.c_str());
384     return iface;
385 }
386 
SetNetworkEnableStatus(const NetQuotaPolicy & quotaPolicy,bool enable)387 void NetPolicyTraffic::SetNetworkEnableStatus(const NetQuotaPolicy &quotaPolicy, bool enable)
388 {
389     NETMGR_LOG_D("SetNetworkEnableStatus enable: %{public}d ", enable);
390 }
391 
NotifyQuotaWarning(int64_t totalQuota)392 void NetPolicyTraffic::NotifyQuotaWarning(int64_t totalQuota)
393 {
394     PublishQuotaEvent(COMMON_EVENT_NET_QUOTA_WARNING, BROADCAST_QUOTA_WARNING, totalQuota);
395 }
396 
NotifyQuotaLimitReminded(int64_t totalQuota)397 void NetPolicyTraffic::NotifyQuotaLimitReminded(int64_t totalQuota)
398 {
399     PublishQuotaEvent(COMMON_EVENT_NET_QUOTA_LIMIT_REMINDED, BROADCAST_QUOTA_LIMIT_REMIND, totalQuota);
400 }
401 
NotifyQuotaLimit(int64_t totalQuota)402 void NetPolicyTraffic::NotifyQuotaLimit(int64_t totalQuota)
403 {
404     PublishQuotaEvent(COMMON_EVENT_NET_QUOTA_LIMIT, BROADCAST_QUOTA_LIMIT, totalQuota);
405 }
406 
PublishQuotaEvent(const std::string & action,const std::string & describe,int64_t quota)407 void NetPolicyTraffic::PublishQuotaEvent(const std::string &action, const std::string &describe, int64_t quota)
408 {
409     BroadcastInfo info;
410     info.action = action;
411     info.data = describe;
412     info.permission = Permission::CONNECTIVITY_INTERNAL;
413     std::map<std::string, int64_t> param = {{"totalQuota", quota}};
414     BroadcastManager::GetInstance().SendBroadcast(info, param);
415 }
416 
IsValidPeriodDuration(const std::string & periodDuration)417 bool NetPolicyTraffic::IsValidPeriodDuration(const std::string &periodDuration)
418 {
419     if (periodDuration.empty() || periodDuration.size() < PERIOD_DURATION_SIZE) {
420         NETMGR_LOG_E("periodDuration is illegal");
421         return false;
422     }
423 
424     std::string cycle = periodDuration.substr(0, 1);
425     NETMGR_LOG_D("PeriodDuration [%{public}s].", periodDuration.c_str());
426     int32_t start = CommonUtils::StrToInt(periodDuration.substr(1, periodDuration.size()));
427 
428     if (cycle == PERIOD_DAY) {
429         if (start >= PERIOD_START && start <= DAY_MAX) {
430             return true;
431         }
432     }
433 
434     if (cycle == PERIOD_MONTH) {
435         if (start >= PERIOD_START && start <= MONTH_MAX) {
436             return true;
437         }
438     }
439 
440     if (cycle == PERIOD_YEAR) {
441         if (start >= PERIOD_START && start <= YEAR_MAX) {
442             return true;
443         }
444     }
445     NETMGR_LOG_E("Invalid periodDuration start [%{public}d],Invalid periodDuration cycle [%{public}s]", start,
446                  cycle.c_str());
447     return false;
448 }
449 
IsQuotaPolicyExist(int32_t netType,const std::string & simId)450 bool NetPolicyTraffic::IsQuotaPolicyExist(int32_t netType, const std::string &simId)
451 {
452     std::vector<NetQuotaPolicy> quotaPolicies;
453     GetFileInst()->ReadQuotaPolicies(quotaPolicies);
454 
455     if (quotaPolicies.empty()) {
456         NETMGR_LOG_E("quotaPolicies is empty");
457         return false;
458     }
459 
460     for (uint32_t i = 0; i < quotaPolicies.size(); i++) {
461         if (netType == quotaPolicies[i].networkmatchrule.netType && simId == quotaPolicies[i].networkmatchrule.simId) {
462             return true;
463         }
464     }
465 
466     return false;
467 }
468 
HandleEvent(int32_t eventId,const std::shared_ptr<PolicyEvent> & policyEvent)469 void NetPolicyTraffic::HandleEvent(int32_t eventId, const std::shared_ptr<PolicyEvent> &policyEvent)
470 {
471     NETMGR_LOG_D("NetPolicyTraffic HandleEvent");
472 }
473 
GetDumpMessage(std::string & message)474 void NetPolicyTraffic::GetDumpMessage(std::string &message)
475 {
476     static const std::string TAB = "    ";
477     message.append(TAB + "MeteredIfaces: {");
478     std::for_each(meteredIfaces_.begin(), meteredIfaces_.end(),
479                   [&message](const std::string &item) { message.append(item + ", "); });
480     message.append("}\n");
481     message.append(TAB + "QuotaPolicies:\n");
482     std::for_each(quotaPolicies_.begin(), quotaPolicies_.end(), [&message](const auto &item) {
483         message.append(TAB + TAB + "NetType: " + std::to_string(item.networkmatchrule.netType) + "\n" + TAB + TAB +
484                        "simId: " + item.networkmatchrule.simId + "\n" + TAB + TAB +
485                        "Ident: " + item.networkmatchrule.ident + "\n");
486         message.append(TAB + TAB + "PeriodStartTime: " + std::to_string(item.quotapolicy.periodStartTime) + "\n");
487         message.append(TAB + TAB + "PeriodDuration: " + item.quotapolicy.periodDuration + "\n");
488         message.append(TAB + TAB + "Title: " + item.quotapolicy.title + "\n" + TAB + TAB +
489                        "Summary: " + item.quotapolicy.summary + "\n");
490         message.append(TAB + TAB + "quotapolicy.warningBytes: " + std::to_string(item.quotapolicy.warningBytes) + "\n");
491         message.append(TAB + TAB + "quotapolicy.limitBytes: " + std::to_string(item.quotapolicy.limitBytes) + "\n");
492         message.append(TAB + TAB +
493                        "quotapolicy.lastWarningRemind: " + std::to_string(item.quotapolicy.lastWarningRemind) + "\n");
494         message.append(TAB + TAB + "quotapolicy.lastLimitRemind: " + std::to_string(item.quotapolicy.lastLimitRemind) +
495                        "\n");
496         message.append(TAB + TAB + "Metered: " + std::to_string(item.quotapolicy.metered) + "\n" + TAB + TAB +
497                        "Ident: " + item.networkmatchrule.ident + "\n");
498         message.append(TAB + TAB + "quotapolicy.limitAction: " + std::to_string(item.quotapolicy.limitAction) + "\n" +
499                        TAB + TAB + "UsedBytes: " + std::to_string(item.quotapolicy.usedBytes) + "\n");
500         message.append(TAB + TAB + "UsedTimeDuration: " + std::to_string(item.quotapolicy.usedTimeDuration) + "\n");
501         message.append(TAB + TAB + "Possessor: " + item.quotapolicy.possessor + "\n\n");
502     });
503 }
504 } // namespace NetManagerStandard
505 } // namespace OHOS
506