• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.net.policy (Network Policy Management)
2
3The **policy** module provides APIs for managing network policies, through which you can control and manage the data volume used.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```js
12import policy from '@ohos.net.policy'
13```
14
15## policy.setBackgroundPolicy
16
17setBackgroundPolicy(isAllowed: boolean, callback: AsyncCallback\<void>): void
18
19Sets a background network policy. This API uses an asynchronous callback to return the result.
20
21**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
22
23**System capability**: SystemCapability.Communication.NetManager.Core
24
25**Parameters**
26
27| Name  | Type                                   | Mandatory| Description      |
28| -------- | --------------------------------------- | ---- | ---------- |
29| isAllowed | boolean | Yes  | Whether applications running in the background are allowed to use mobile data.|
30| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
31
32**Error codes**
33
34| ID| Error Message                                     |
35| ------- | -------------------------------------------- |
36| 201     | Permission denied.                           |
37| 401     | Parameter error.                             |
38| 2100001 | Invalid parameter value.                |
39| 2100002 | Operation failed. Cannot connect to service.|
40| 2100003 | System internal error.                  |
41
42**Example**
43
44```js
45policy.setBackgroundPolicy(Boolean(Number.parseInt(this.isBoolean))), (error, data) => {
46    this.callBack(error, data);
47    console.log(JSON.stringify(error))
48    console.log(JSON.stringify(data))
49});
50```
51
52## policy.setBackgroundPolicy
53
54setBackgroundPolicy(isAllowed: boolean): Promise\<void>
55
56Sets a background network policy. This API uses a promise to return the result.
57
58**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
59
60**System capability**: SystemCapability.Communication.NetManager.Core
61
62**Parameters**
63
64| Name  | Type                                   | Mandatory| Description      |
65| -------- | --------------------------------------- | ---- | ---------- |
66| isAllowed | boolean | Yes  | Whether applications running in the background are allowed to use mobile data.|
67
68**Error codes**
69
70| ID| Error Message                                     |
71| ------- | -------------------------------------------- |
72| 201     | Permission denied.                           |
73| 401     | Parameter error.                             |
74| 2100001 | Invalid parameter value.                |
75| 2100002 | Operation failed. Cannot connect to service.|
76| 2100003 | System internal error.                  |
77
78**Return value**
79
80| Type                             | Description                                 |
81| --------------------------------- | ------------------------------------- |
82| Promise\<void> | Promise used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
83
84**Example**
85
86```js
87policy.setBackgroundPolicy(Boolean(Number.parseInt(this.isBoolean))).then(function(error, data) {
88    console.log(JSON.stringify(error))
89    console.log(JSON.stringify(data))
90})
91```
92
93## policy.isBackgroundAllowed
94
95isBackgroundAllowed(callback: AsyncCallback\<boolean>): void
96
97Obtains the background network policy. This API uses an asynchronous callback to return the result.
98
99**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
100
101**System capability**: SystemCapability.Communication.NetManager.Core
102
103**Parameters**
104
105| Name  | Type                                   | Mandatory| Description      |
106| -------- | --------------------------------------- | ---- | ---------- |
107| callback | AsyncCallback\<boolean> | Yes  | Callback used to return the result. If the operation is successful, **true** is returned, which means that applications running in the background are allowed to use mobile data. If the operation fails, an error message is returned.|
108
109**Error codes**
110
111| ID| Error Message                                     |
112| ------- | -------------------------------------------- |
113| 201     | Permission denied.                           |
114| 2100002 | Operation failed. Cannot connect to service.|
115| 2100003 | System internal error.                  |
116
117**Example**
118
119```js
120policy.isBackgroundAllowed((error, data) => {
121    this.callBack(error, data);
122    console.log(JSON.stringify(error))
123    console.log(JSON.stringify(data))
124});
125```
126
127## policy.isBackgroundAllowed
128
129isBackgroundAllowed(): Promise\<boolean>;
130
131Obtains the background network policy. This API uses a promise to return the result.
132
133**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
134
135**System capability**: SystemCapability.Communication.NetManager.Core
136
137**Return value**
138
139| Type                             | Description                                 |
140| --------------------------------- | ------------------------------------- |
141| Promise\<boolean> | Promise used to return the result. If the operation is successful, **true** is returned, which means that applications running in the background are allowed to use mobile data. If the operation fails, an error message is returned.|
142
143**Error codes**
144
145| ID| Error Message                                     |
146| ------- | -------------------------------------------- |
147| 201     | Permission denied.                           |
148| 2100002 | Operation failed. Cannot connect to service.|
149| 2100003 | System internal error.                  |
150
151**Example**
152
153```js
154policy.isBackgroundAllowed().then(function(error, data) {
155    console.log(JSON.stringify(error))
156    console.log(JSON.stringify(data))
157})
158
159```
160
161## policy.setPolicyByUid
162
163setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback\<void>): void
164
165Sets an application-specific network policy. This API uses an asynchronous callback to return the result.
166
167**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
168
169**System capability**: SystemCapability.Communication.NetManager.Core
170
171**Parameters**
172
173| Name  | Type                                   | Mandatory| Description      |
174| -------- | --------------------------------------- | ---- | ---------- |
175| uid | number | Yes  | Unique ID of the application.|
176| policy | [NetUidPolicy](#netuidpolicy) | Yes| Application-specific network policy to set.|
177| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
178
179**Error codes**
180
181| ID| Error Message                                     |
182| ------- | -------------------------------------------- |
183| 201     | Permission denied.                           |
184| 401     | Parameter error.                             |
185| 2100001 | Invalid parameter value.                |
186| 2100002 | Operation failed. Cannot connect to service.|
187| 2100003 | System internal error.                  |
188
189**Example**
190
191```js
192let param = {
193    uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy)
194}
195policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy), (error, data) => {
196    this.callBack(error, data);
197});
198```
199
200## policy.setPolicyByUid
201
202setPolicyByUid(uid: number, policy: NetUidPolicy): Promise\<void>;
203
204Sets an application-specific network policy. This API uses a promise to return the result.
205
206**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
207
208**System capability**: SystemCapability.Communication.NetManager.Core
209
210**Parameters**
211
212| Name  | Type                                   | Mandatory| Description      |
213| -------- | --------------------------------------- | ---- | ---------- |
214| uid | number | Yes  | Unique ID of the application.|
215| policy | [NetUidPolicy](#netuidpolicy) | Yes| Application-specific network policy to set.|
216
217**Return value**
218
219| Type                             | Description                                 |
220| --------------------------------- | ------------------------------------- |
221| Promise\<void> | Promise used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
222
223**Error codes**
224
225| ID| Error Message                                     |
226| ------- | -------------------------------------------- |
227| 201     | Permission denied.                           |
228| 401     | Parameter error.                             |
229| 2100001 | Invalid parameter value.                |
230| 2100002 | Operation failed. Cannot connect to service.|
231| 2100003 | System internal error.                  |
232
233**Example**
234
235```js
236let param = {
237    uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy)
238}
239policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy)).then(function(error, data) {
240    console.log(JSON.stringify(error))
241    console.log(JSON.stringify(data))
242})
243
244```
245
246## policy.getPolicyByUid
247
248getPolicyByUid(uid: number, callback: AsyncCallback\<NetUidPolicy>): void
249
250Obtains an application-specific network policy by **uid**. This API uses an asynchronous callback to return the result.
251
252**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
253
254**System capability**: SystemCapability.Communication.NetManager.Core
255
256**Parameters**
257
258| Name  | Type                                   | Mandatory| Description      |
259| -------- | --------------------------------------- | ---- | ---------- |
260| uid | number | Yes| Unique ID of the application.|
261| callback | AsyncCallback\<[NetUidPolicy](#netuidpolicy)> | Yes  | Callback used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
262
263**Error codes**
264
265| ID| Error Message                                     |
266| ------- | -------------------------------------------- |
267| 201     | Permission denied.                           |
268| 401     | Parameter error.                             |
269| 2100001 | Invalid parameter value.                |
270| 2100002 | Operation failed. Cannot connect to service.|
271| 2100003 | System internal error.                  |
272
273**Example**
274
275```js
276policy.getPolicyByUid(Number.parseInt(this.firstParam), (error, data) => {
277    this.callBack(error, data);
278});
279```
280
281## policy.getPolicyByUid
282
283getPolicyByUid(uid: number): Promise\<NetUidPolicy>;
284
285Obtains an application-specific network policy by **uid**. This API uses a promise to return the result.
286
287**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
288
289**System capability**: SystemCapability.Communication.NetManager.Core
290
291**Parameters**
292
293| Name  | Type                                   | Mandatory| Description      |
294| -------- | --------------------------------------- | ---- | ---------- |
295| uid | number | Yes| Unique ID of the application.|
296
297**Return value**
298
299| Type                             | Description                                 |
300| --------------------------------- | ------------------------------------- |
301| Promise\<[NetUidPolicy](#netuidpolicy)> | Promise used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
302
303**Error codes**
304
305| ID| Error Message                                     |
306| ------- | -------------------------------------------- |
307| 201     | Permission denied.                           |
308| 401     | Parameter error.                             |
309| 2100001 | Invalid parameter value.                |
310| 2100002 | Operation failed. Cannot connect to service.|
311| 2100003 | System internal error.                  |
312
313**Example**
314
315```js
316policy.getPolicyByUid(Number.parseInt(this.firstParam)).then(function(error, data) {
317    console.log(JSON.stringify(error))
318    console.log(JSON.stringify(data))
319})
320
321```
322
323## policy.getUidsByPolicy
324
325getUidsByPolicy(policy: NetUidPolicy, callback: AsyncCallback\<Array\<number>>): void
326
327Obtains the UID array of applications configured with a certain application-specific network policy. This API uses an asynchronous callback to return the result.
328
329**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
330
331**System capability**: SystemCapability.Communication.NetManager.Core
332
333**Parameters**
334
335| Name  | Type                                   | Mandatory| Description      |
336| -------- | --------------------------------------- | ---- | ---------- |
337| policy | [NetUidPolicy](#netuidpolicy) | Yes| Target application-specific network policy.|
338| callback | AsyncCallback\<Array\<number>> | Yes  | Callback used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
339
340**Error codes**
341
342| ID| Error Message                                     |
343| ------- | -------------------------------------------- |
344| 201     | Permission denied.                           |
345| 401     | Parameter error.                             |
346| 2100001 | Invalid parameter value.                |
347| 2100002 | Operation failed. Cannot connect to service.|
348| 2100003 | System internal error.                  |
349
350**Example**
351
352```js
353policy.getUidsByPolicy(Number.parseInt(this.currentNetUidPolicy), (error, data) => {
354    this.callBack(error, data);
355});
356```
357
358## policy.getUidsByPolicy
359
360function getUidsByPolicy(policy: NetUidPolicy): Promise\<Array\<number>>;
361
362Obtains the UID array of applications configured with a certain application-specific network policy. This API uses a promise to return the result.
363
364**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
365
366**System capability**: SystemCapability.Communication.NetManager.Core
367
368**Parameters**
369
370| Name  | Type                                   | Mandatory| Description      |
371| -------- | --------------------------------------- | ---- | ---------- |
372| policy | [NetUidPolicy](#netuidpolicy) | Yes| Target application-specific network policy.|
373
374**Return value**
375
376| Type                             | Description                                 |
377| --------------------------------- | ------------------------------------- |
378| Promise\<Array\<number>> | Promise used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
379
380**Error codes**
381
382| ID| Error Message                                     |
383| ------- | -------------------------------------------- |
384| 201     | Permission denied.                           |
385| 401     | Parameter error.                             |
386| 2100001 | Invalid parameter value.                |
387| 2100002 | Operation failed. Cannot connect to service.|
388| 2100003 | System internal error.                  |
389
390**Example**
391
392```js
393policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then(function(error, data) {
394    console.log(JSON.stringify(error))
395    console.log(JSON.stringify(data))
396})
397
398```
399
400## policy.getNetQuotaPolicies
401
402getNetQuotaPolicies(callback: AsyncCallback\<Array\<NetQuotaPolicy>>): void
403
404Obtains the network quota policies. This API uses an asynchronous callback to return the result.
405
406**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
407
408**System capability**: SystemCapability.Communication.NetManager.Core
409
410**Parameters**
411
412| Name  | Type                                   | Mandatory| Description      |
413| -------- | --------------------------------------- | ---- | ---------- |
414| callback | AsyncCallback\<Array\<[NetQuotaPolicy](#netquotapolicy)>> | Yes  | Callback used to return the result.|
415
416**Error codes**
417
418| ID| Error Message                                     |
419| ------- | -------------------------------------------- |
420| 201     | Permission denied.                           |
421| 2100002 | Operation failed. Cannot connect to service.|
422| 2100003 | System internal error.                  |
423
424**Example**
425
426```js
427policy.getNetQuotaPolicies((error, data) => {
428    this.callBack(error, data);
429});
430```
431
432## policy.getNetQuotaPolicies
433
434getNetQuotaPolicies(): Promise\<Array\<NetQuotaPolicy>>;
435
436Obtains the network quota policies. This API uses a promise to return the result.
437
438**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
439
440**System capability**: SystemCapability.Communication.NetManager.Core
441
442**Return value**
443
444| Type                             | Description                                 |
445| --------------------------------- | ------------------------------------- |
446| Promise\<Array\<[NetQuotaPolicy](#netquotapolicy)>> | Promise used to return the result.|
447
448**Error codes**
449
450| ID| Error Message                                     |
451| ------- | -------------------------------------------- |
452| 201     | Permission denied.                           |
453| 2100002 | Operation failed. Cannot connect to service.|
454| 2100003 | System internal error.                  |
455
456**Example**
457
458```js
459policy.getNetQuotaPolicies().then(function(error, data) {
460    console.log(JSON.stringify(error))
461    console.log(JSON.stringify(data))
462})
463
464```
465
466## policy.setNetQuotaPolicies
467
468setNetQuotaPolicies(quotaPolicies: Array\<NetQuotaPolicy>, callback: AsyncCallback\<void>): void
469
470Sets an array of network quota policies. This API uses an asynchronous callback to return the result.
471
472**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
473
474**System capability**: SystemCapability.Communication.NetManager.Core
475
476**Parameters**
477
478| Name  | Type                                   | Mandatory| Description      |
479| -------- | --------------------------------------- | ---- | ---------- |
480| quotaPolicies | Array\<[NetQuotaPolicy](#netquotapolicy)> | Yes| An array of network quota policies to set.|
481| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
482
483**Error codes**
484
485| ID| Error Message                                     |
486| ------- | -------------------------------------------- |
487| 201     | Permission denied.                           |
488| 401     | Parameter error.                             |
489| 2100001 | Invalid parameter value.                |
490| 2100002 | Operation failed. Cannot connect to service.|
491| 2100003 | System internal error.                  |
492
493**Example**
494
495```js
496let param = {netType:Number.parseInt(this.netType), iccid:this.iccid, ident:this.ident, periodDuration:this.periodDuration, warningBytes:Number.parseInt(this.warningBytes),
497    limitBytes:Number.parseInt(this.limitBytes), lastWarningRemind:this.lastWarningRemind, lastLimitRemind:this.lastLimitRemind, metered:Boolean(Number.parseInt(this.metered)), limitAction:this.limitAction};
498this.netQuotaPolicyList.push(param);
499
500policy.setNetQuotaPolicies(this.netQuotaPolicyList, (error, data) => {
501    this.callBack(error, data);
502});
503```
504
505## policy.setNetQuotaPolicies
506
507setNetQuotaPolicies(quotaPolicies: Array\<NetQuotaPolicy>): Promise\<void>;
508
509Sets an array of network quota policies. This API uses a promise to return the result.
510
511**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
512
513**System capability**: SystemCapability.Communication.NetManager.Core
514
515**Parameters**
516
517| Name  | Type                                   | Mandatory| Description      |
518| -------- | --------------------------------------- | ---- | ---------- |
519| quotaPolicies | Array\<[NetQuotaPolicy](#netquotapolicy)> | Yes| An array of network quota policies to set.|
520
521**Error codes**
522
523| ID| Error Message                                     |
524| ------- | -------------------------------------------- |
525| 201     | Permission denied.                           |
526| 401     | Parameter error.                             |
527| 2100001 | Invalid parameter value.                |
528| 2100002 | Operation failed. Cannot connect to service.|
529| 2100003 | System internal error.                  |
530
531**Return value**
532
533| Type                             | Description                                 |
534| --------------------------------- | ------------------------------------- |
535| Promise\<void> | Promise used to return the result.|
536
537**Example**
538
539```js
540let param = {netType:Number.parseInt(this.netType), iccid:this.iccid, ident:this.ident, periodDuration:this.periodDuration, warningBytes:Number.parseInt(this.warningBytes),
541    limitBytes:Number.parseInt(this.limitBytes), lastWarningRemind:this.lastWarningRemind, lastLimitRemind:this.lastLimitRemind, metered:Boolean(Number.parseInt(this.metered)), limitAction:this.limitAction};
542this.netQuotaPolicyList.push(param);
543
544policy.setNetQuotaPolicies(this.netQuotaPolicyList).then(function(error, data) {
545    console.log(JSON.stringify(error))
546    console.log(JSON.stringify(data))
547})
548```
549
550## policy.restoreAllPolicies
551
552restoreAllPolicies(iccid: string, callback: AsyncCallback\<void>): void
553
554Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses an asynchronous callback to return the result.
555
556**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
557
558**System capability**: SystemCapability.Communication.NetManager.Core
559
560**Parameters**
561
562| Name  | Type                                   | Mandatory| Description      |
563| -------- | --------------------------------------- | ---- | ---------- |
564| iccid | string | Yes| SIM card ID.|
565| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
566
567**Error codes**
568
569| ID| Error Message                                     |
570| ------- | -------------------------------------------- |
571| 201     | Permission denied.                           |
572| 401     | Parameter error.                             |
573| 2100001 | Invalid parameter value.                |
574| 2100002 | Operation failed. Cannot connect to service.|
575| 2100003 | System internal error.                  |
576
577**Example**
578
579```js
580this.firstParam = iccid;
581policy.restoreAllPolicies(this.firstParam, (error, data) => {
582    this.callBack(error, data);
583});
584```
585
586## policy.restoreAllPolicies
587
588restoreAllPolicies(iccid: string): Promise\<void>;
589
590Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses a promise to return the result.
591
592**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
593
594**System capability**: SystemCapability.Communication.NetManager.Core
595
596**Parameters**
597
598| Name  | Type                                   | Mandatory| Description      |
599| -------- | --------------------------------------- | ---- | ---------- |
600| iccid | string | Yes| SIM card ID.|
601
602**Return value**
603
604| Type                             | Description                                 |
605| --------------------------------- | ------------------------------------- |
606| Promise\<void> | Promise used to return the result.|
607
608**Error codes**
609
610| ID| Error Message                                     |
611| ------- | -------------------------------------------- |
612| 201     | Permission denied.                           |
613| 401     | Parameter error.                             |
614| 2100001 | Invalid parameter value.                |
615| 2100002 | Operation failed. Cannot connect to service.|
616| 2100003 | System internal error.                  |
617
618**Example**
619
620```js
621this.firstParam = iccid;
622policy.restoreAllPolicies(this.firstParam).then(function(error, data){
623    console.log(JSON.stringify(error))
624    console.log(JSON.stringify(data))
625})
626
627```
628
629## policy.isUidNetAllowed
630
631isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback\<boolean>): void
632
633Checks whether an application is allowed to access metered networks. This API uses an asynchronous callback to return the result.
634
635**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
636
637**System capability**: SystemCapability.Communication.NetManager.Core
638
639**Parameters**
640
641| Name  | Type                                   | Mandatory| Description      |
642| -------- | --------------------------------------- | ---- | ---------- |
643| uid | number | Yes| Unique ID of the application.|
644| isMetered | boolean | Yes| Whether the network is a metered network.|
645| callback | AsyncCallback\<boolean> | Yes  | Callback used to return the result. The value **true** means that the application is allowed to access metered networks, and **false** means the opposite.|
646
647**Error codes**
648
649| ID| Error Message                                     |
650| ------- | -------------------------------------------- |
651| 201     | Permission denied.                           |
652| 401     | Parameter error.                             |
653| 2100001 | Invalid parameter value.                |
654| 2100002 | Operation failed. Cannot connect to service.|
655| 2100003 | System internal error.                  |
656
657**Example**
658
659```js
660
661let param = {
662    uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean))
663}
664policy.isUidNetAllowed(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (error, data) => {
665    this.callBack(error, data);
666});
667```
668
669## policy.isUidNetAllowed
670
671isUidNetAllowed(uid: number, isMetered: boolean): Promise\<boolean>;
672
673Checks whether an application is allowed to access metered networks. This API uses a promise to return the result.
674
675**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
676
677**System capability**: SystemCapability.Communication.NetManager.Core
678
679**Parameters**
680
681| Name  | Type                                   | Mandatory| Description      |
682| -------- | --------------------------------------- | ---- | ---------- |
683| uid | number | Yes| Unique ID of the application.|
684| isMetered | boolean | Yes| Whether the network is a metered network.|
685
686**Return value**
687
688| Type                             | Description                                 |
689| --------------------------------- | ------------------------------------- |
690| Promise\<boolean> | Promise used to return the result.|
691
692**Error codes**
693
694| ID| Error Message                                     |
695| ------- | -------------------------------------------- |
696| 201     | Permission denied.                           |
697| 401     | Parameter error.                             |
698| 2100001 | Invalid parameter value.                |
699| 2100002 | Operation failed. Cannot connect to service.|
700| 2100003 | System internal error.                  |
701
702**Example**
703
704```js
705
706let param = {
707    uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean))
708}
709policy.isUidNetAllowed(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then(function(error, data) {
710    console.log(JSON.stringify(error))
711    console.log(JSON.stringify(data))
712})
713
714```
715
716## policy.isUidNetAllowed
717
718isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback\<boolean>): void
719
720Checks whether an application is allowed to access the given network. This API uses an asynchronous callback to return the result.
721
722**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
723
724**System capability**: SystemCapability.Communication.NetManager.Core
725
726**Parameters**
727
728| Name  | Type                                   | Mandatory| Description      |
729| -------- | --------------------------------------- | ---- | ---------- |
730| uid | number | Yes| Unique ID of the application.|
731| iface | string | Yes| Name of the target network.|
732| callback | AsyncCallback\<boolean> | Yes  | Callback used to return the result. The value **true** means that the application is allowed to access the given network, and **false** means the opposite.|
733
734**Error codes**
735
736| ID| Error Message                                     |
737| ------- | -------------------------------------------- |
738| 201     | Permission denied.                           |
739| 401     | Parameter error.                             |
740| 2100001 | Invalid parameter value.                |
741| 2100002 | Operation failed. Cannot connect to service.|
742| 2100003 | System internal error.                  |
743
744**Example**
745
746```js
747
748let param = {
749    uid: Number.parseInt(this.firstParam), iface: this.secondParam
750}
751policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam, (error, data) => {
752    this.callBack(error, data);
753});
754```
755
756## policy.isUidNetAllowed
757
758isUidNetAllowed(uid: number, iface: string): Promise\<boolean>;
759
760Checks whether an application is allowed to access the given network. This API uses a promise to return the result.
761
762**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
763
764**System capability**: SystemCapability.Communication.NetManager.Core
765
766**Parameters**
767
768| Name  | Type                                   | Mandatory| Description      |
769| -------- | --------------------------------------- | ---- | ---------- |
770| uid | number | Yes| Unique ID of the application.|
771| iface | string | Yes| Name of the target network.|
772
773**Return value**
774
775| Type                             | Description                                 |
776| --------------------------------- | ------------------------------------- |
777| Promise\<boolean> | Promise used to return the result.|
778
779**Error codes**
780
781| ID| Error Message                                     |
782| ------- | -------------------------------------------- |
783| 201     | Permission denied.                           |
784| 401     | Parameter error.                             |
785| 2100001 | Invalid parameter value.                |
786| 2100002 | Operation failed. Cannot connect to service.|
787| 2100003 | System internal error.                  |
788
789**Example**
790
791```js
792let param = {
793    uid: Number.parseInt(this.firstParam), iface: this.secondParam
794}
795policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam).then(function(error, data) {
796    console.log(JSON.stringify(error))
797    console.log(JSON.stringify(data))
798})
799
800```
801
802## policy.setDeviceIdleAllowList
803
804setDeviceIdleAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\<void>): void
805
806Sets whether to add an application to the device idle allowlist. This API uses an asynchronous callback to return the result.
807
808**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
809
810**System capability**: SystemCapability.Communication.NetManager.Core
811
812**Parameters**
813
814| Name  | Type                                   | Mandatory| Description      |
815| -------- | --------------------------------------- | ---- | ---------- |
816| uid | number | Yes| Unique ID of the application.|
817| isAllowed | boolean | Yes| Whether to add the application to the allowlist.|
818| callback | callback: AsyncCallback\<void> | Yes  | Callback used to return the result.|
819
820**Error codes**
821
822| ID| Error Message                                     |
823| ------- | -------------------------------------------- |
824| 201     | Permission denied.                           |
825| 401     | Parameter error.                             |
826| 2100001 | Invalid parameter value.                |
827| 2100002 | Operation failed. Cannot connect to service.|
828| 2100003 | System internal error.                  |
829
830**Example**
831
832```js
833let param = {
834    uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
835}
836policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (error, data) => {
837    this.callBack(error, data);
838});
839```
840
841## policy.setDeviceIdleAllowList
842
843setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise\<void>;
844
845Sets whether to add an application to the device idle allowlist. This API uses a promise to return the result.
846
847**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
848
849**System capability**: SystemCapability.Communication.NetManager.Core
850
851**Parameters**
852
853| Name  | Type                                   | Mandatory| Description      |
854| -------- | --------------------------------------- | ---- | ---------- |
855| uid | number | Yes| Unique ID of the application.|
856| isAllowed | boolean | Yes| Whether to add the application to the allowlist.|
857
858**Return value**
859
860| Type                             | Description                                 |
861| --------------------------------- | ------------------------------------- |
862| Promise\<void> | Promise used to return the result.|
863
864**Error codes**
865
866| ID| Error Message                                     |
867| ------- | -------------------------------------------- |
868| 201     | Permission denied.                           |
869| 401     | Parameter error.                             |
870| 2100001 | Invalid parameter value.                |
871| 2100002 | Operation failed. Cannot connect to service.|
872| 2100003 | System internal error.                  |
873
874**Example**
875
876```js
877let param = {
878    uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
879}
880policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then(function(error, data) {
881    console.log(JSON.stringify(error))
882    console.log(JSON.stringify(data))
883})
884
885```
886
887## policy.getDeviceIdleAllowList
888
889getDeviceIdleAllowList(callback: AsyncCallback\<Array\<number>>): void
890
891Obtains the UID array of applications that are on the device idle allowlist. This API uses an asynchronous callback to return the result.
892
893**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
894
895**System capability**: SystemCapability.Communication.NetManager.Core
896
897**Parameters**
898
899| Name  | Type                                   | Mandatory| Description      |
900| -------- | --------------------------------------- | ---- | ---------- |
901| callback | AsyncCallback\<Array\<number>> | Yes  | Callback used to return the result.|
902
903**Error codes**
904
905| ID| Error Message                                     |
906| ------- | -------------------------------------------- |
907| 201     | Permission denied.                           |
908| 2100002 | Operation failed. Cannot connect to service.|
909| 2100003 | System internal error.                  |
910
911**Example**
912
913```js
914policy.getDeviceIdleAllowList((error, data) => {
915    this.callBack(error, data);
916});
917```
918
919## policy.getDeviceIdleAllowList
920
921getDeviceIdleAllowList(): Promise\<Array\<number>>;
922
923Obtains the UID array of applications that are on the device idle allowlist. This API uses a promise to return the result.
924
925**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
926
927**System capability**: SystemCapability.Communication.NetManager.Core
928
929**Return value**
930
931| Type                             | Description                                 |
932| --------------------------------- | ------------------------------------- |
933| Promise\<Array\<number>> | Promise used to return the result.|
934
935**Error codes**
936
937| ID| Error Message                                     |
938| ------- | -------------------------------------------- |
939| 201     | Permission denied.                           |
940| 2100002 | Operation failed. Cannot connect to service.|
941| 2100003 | System internal error.                  |
942
943**Example**
944
945```js
946policy.getDeviceIdleAllowList().then(function(error, data) {
947    console.log(JSON.stringify(error))
948    console.log(JSON.stringify(data))
949})
950```
951
952## policy.getBackgroundPolicyByUid
953
954getBackgroundPolicyByUid(uid: number, callback: AsyncCallback\<NetBackgroundPolicy>): void
955
956Obtains the background network policies configured for the given application. This API uses an asynchronous callback to return the result.
957
958**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
959
960**System capability**: SystemCapability.Communication.NetManager.Core
961
962**Parameters**
963
964| Name  | Type                                   | Mandatory| Description      |
965| -------- | --------------------------------------- | ---- | ---------- |
966| uid | number | Yes| Unique ID of the application.|
967| callback | AsyncCallback\<[NetBackgroundPolicy](#netbackgroundpolicy)> | Yes  | Callback used to return the result.|
968
969**Error codes**
970
971| ID| Error Message                                     |
972| ------- | -------------------------------------------- |
973| 201     | Permission denied.                           |
974| 401     | Parameter error.                             |
975| 2100001 | Invalid parameter value.                |
976| 2100002 | Operation failed. Cannot connect to service.|
977| 2100003 | System internal error.                  |
978
979**Example**
980
981```js
982this.firstParam = uid
983policy.getBackgroundPolicyByUid(Number.parseInt(this.firstParam), (error, data) => {
984    this.callBack(error, data);
985});
986```
987
988## policy.getBackgroundPolicyByUid
989
990getBackgroundPolicyByUid(uid: number): Promise\<NetBackgroundPolicy>;
991
992Obtains the background network policies configured for the given application. This API uses a promise to return the result.
993
994**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
995
996**System capability**: SystemCapability.Communication.NetManager.Core
997
998**Parameters**
999
1000| Name  | Type                                   | Mandatory| Description      |
1001| -------- | --------------------------------------- | ---- | ---------- |
1002| uid | number | Yes| Unique ID of the application.|
1003
1004**Return value**
1005
1006| Type                             | Description                                 |
1007| --------------------------------- | ------------------------------------- |
1008| Promise\<[NetBackgroundPolicy](#netbackgroundpolicy)> | Promise used to return the result.|
1009
1010**Error codes**
1011
1012| ID| Error Message                                     |
1013| ------- | -------------------------------------------- |
1014| 201     | Permission denied.                           |
1015| 401     | Parameter error.                             |
1016| 2100001 | Invalid parameter value.                |
1017| 2100002 | Operation failed. Cannot connect to service.|
1018| 2100003 | System internal error.                  |
1019
1020**Example**
1021
1022```js
1023this.firstParam = uid
1024policy.getBackgroundPolicyByUid(Number.parseInt(this.firstParam)).then(function(error, data) {
1025    console.log(JSON.stringify(error))
1026    console.log(JSON.stringify(data))
1027})
1028```
1029
1030## policy.resetPolicies
1031
1032resetPolicies(iccid: string, callback: AsyncCallback\<void>): void
1033
1034Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses an asynchronous callback to return the result.
1035
1036**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1037
1038**System capability**: SystemCapability.Communication.NetManager.Core
1039
1040**Parameters**
1041
1042| Name  | Type                                   | Mandatory| Description      |
1043| -------- | --------------------------------------- | ---- | ---------- |
1044| iccid | string | Yes| SIM card ID.|
1045| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
1046
1047**Error codes**
1048
1049| ID| Error Message                                     |
1050| ------- | -------------------------------------------- |
1051| 201     | Permission denied.                           |
1052| 401     | Parameter error.                             |
1053| 2100001 | Invalid parameter value.                |
1054| 2100002 | Operation failed. Cannot connect to service.|
1055| 2100003 | System internal error.                  |
1056
1057**Example**
1058
1059```js
1060this.firstParam = iccid
1061policy.resetPolicies(this.firstParam, (error, data) => {
1062    this.callBack(error, data);
1063});
1064```
1065
1066## policy.resetPolicies
1067
1068resetPolicies(iccid: string): Promise\<void>;
1069
1070Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses a promise to return the result.
1071
1072**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1073
1074**System capability**: SystemCapability.Communication.NetManager.Core
1075
1076**Parameters**
1077
1078| Name  | Type                                   | Mandatory| Description      |
1079| -------- | --------------------------------------- | ---- | ---------- |
1080| iccid | string | Yes| SIM card ID.|
1081
1082**Return value**
1083
1084| Type                             | Description                                 |
1085| --------------------------------- | ------------------------------------- |
1086| Promise\<void> | Promise used to return the result.|
1087
1088**Error codes**
1089
1090| ID| Error Message                                     |
1091| ------- | -------------------------------------------- |
1092| 201     | Permission denied.                           |
1093| 401     | Parameter error.                             |
1094| 2100001 | Invalid parameter value.                |
1095| 2100002 | Operation failed. Cannot connect to service.|
1096| 2100003 | System internal error.                  |
1097
1098**Example**
1099
1100```js
1101policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then(function(error, data) {
1102
1103})
1104this.firstParam = iccid
1105policy.resetPolicies(this.firstParam).then(function(error, data) {
1106    console.log(JSON.stringify(error))
1107    console.log(JSON.stringify(data))
1108})
1109
1110```
1111
1112## policy.updateRemindPolicy
1113
1114updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType, callback: AsyncCallback\<void>): void
1115
1116Updates a reminder policy. This API uses an asynchronous callback to return the result.
1117
1118**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1119
1120**System capability**: SystemCapability.Communication.NetManager.Core
1121
1122**Parameters**
1123
1124| Name  | Type                                   | Mandatory| Description      |
1125| -------- | --------------------------------------- | ---- | ---------- |
1126| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | Yes| Network type.|
1127| iccid | string | Yes| SIM card ID.|
1128| remindType | [RemindType](#remindtype) | Yes| Reminder type.|
1129| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
1130
1131**Error codes**
1132
1133| ID| Error Message                                     |
1134| ------- | -------------------------------------------- |
1135| 201     | Permission denied.                           |
1136| 401     | Parameter error.                             |
1137| 2100001 | Invalid parameter value.                |
1138| 2100002 | Operation failed. Cannot connect to service.|
1139| 2100003 | System internal error.                  |
1140
1141**Example**
1142
1143```js
1144let param = {
1145    netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType
1146}
1147policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType), (error, data) => {
1148    this.callBack(error, data);
1149});
1150```
1151
1152## policy.updateRemindPolicy
1153
1154updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType): Promise\<void>;
1155
1156Updates a reminder policy. This API uses a promise to return the result.
1157
1158**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1159
1160**System capability**: SystemCapability.Communication.NetManager.Core
1161
1162**Parameters**
1163
1164| Name  | Type                                   | Mandatory| Description      |
1165| -------- | --------------------------------------- | ---- | ---------- |
1166| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | Yes| Network type.|
1167| iccid | string | Yes| SIM card ID.|
1168| remindType | [RemindType](#remindtype) | Yes| Reminder type.|
1169
1170**Return value**
1171
1172| Type                             | Description                                 |
1173| --------------------------------- | ------------------------------------- |
1174| Promise\<void> | Promise used to return the result.|
1175
1176**Error codes**
1177
1178| ID| Error Message                                     |
1179| ------- | -------------------------------------------- |
1180| 201     | Permission denied.                           |
1181| 401     | Parameter error.                             |
1182| 2100001 | Invalid parameter value.                |
1183| 2100002 | Operation failed. Cannot connect to service.|
1184| 2100003 | System internal error.                  |
1185
1186**Example**
1187
1188```js
1189let param = {
1190    netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType
1191}
1192policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType)).then(function(error, data) {
1193    console.log(JSON.stringify(error))
1194    console.log(JSON.stringify(data))
1195})
1196
1197```
1198
1199## policy.setPowerSaveAllowList
1200
1201setPowerSaveAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\<void>): void
1202
1203Sets whether to add an application to the power-saving allowlist. This API uses an asynchronous callback to return the result.
1204
1205**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1206
1207**System capability**: SystemCapability.Communication.NetManager.Core
1208
1209**Parameters**
1210
1211| Name  | Type                                   | Mandatory| Description      |
1212| -------- | --------------------------------------- | ---- | ---------- |
1213| uid | number | Yes| Unique ID of the application.|
1214| isAllowed | boolean | Yes| Whether to add the application to the allowlist.|
1215| callback | callback: AsyncCallback\<void> | Yes  | Callback used to return the result.|
1216
1217**Error codes**
1218
1219| ID| Error Message                                     |
1220| ------- | -------------------------------------------- |
1221| 201     | Permission denied.                           |
1222| 401     | Parameter error.                             |
1223| 2100001 | Invalid parameter value.                |
1224| 2100002 | Operation failed. Cannot connect to service.|
1225| 2100003 | System internal error.                  |
1226
1227**Example**
1228
1229```js
1230let param = {
1231    uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
1232}
1233policy.setPowerSaveAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (error, data) => {
1234    this.callBack(error, data);
1235});
1236```
1237
1238## policy.setPowerSaveAllowList
1239
1240setPowerSaveAllowList(uid: number, isAllowed: boolean): Promise\<void>;
1241
1242Sets whether to add an application to the power-saving allowlist. This API uses a promise to return the result.
1243
1244**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1245
1246**System capability**: SystemCapability.Communication.NetManager.Core
1247
1248**Parameters**
1249
1250| Name  | Type                                   | Mandatory| Description      |
1251| -------- | --------------------------------------- | ---- | ---------- |
1252| uid | number | Yes| Unique ID of the application.|
1253| isAllowed | boolean | Yes| Whether to add the application to the allowlist.|
1254
1255**Return value**
1256
1257| Type                             | Description                                 |
1258| --------------------------------- | ------------------------------------- |
1259| Promise\<void> | Promise used to return the result.|
1260
1261**Error codes**
1262
1263| ID| Error Message                                     |
1264| ------- | -------------------------------------------- |
1265| 201     | Permission denied.                           |
1266| 401     | Parameter error.                             |
1267| 2100001 | Invalid parameter value.                |
1268| 2100002 | Operation failed. Cannot connect to service.|
1269| 2100003 | System internal error.                  |
1270
1271**Example**
1272
1273```js
1274let param = {
1275    uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
1276}
1277policy.setPowerSaveAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then(function(error, data) {
1278    console.log(JSON.stringify(error))
1279    console.log(JSON.stringify(data))
1280})
1281
1282```
1283
1284## policy.getPowerSaveAllowList
1285
1286getPowerSaveAllowList(callback: AsyncCallback\<Array\<number>>): void
1287
1288Obtains the UID array of applications that are on the power-saving allowlist. This API uses an asynchronous callback to return the result.
1289
1290**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1291
1292**System capability**: SystemCapability.Communication.NetManager.Core
1293
1294**Parameters**
1295
1296| Name  | Type                                   | Mandatory| Description      |
1297| -------- | --------------------------------------- | ---- | ---------- |
1298| callback | AsyncCallback\<Array\<number>> | Yes  | Callback used to return the result.|
1299
1300**Error codes**
1301
1302| ID| Error Message                                     |
1303| ------- | -------------------------------------------- |
1304| 201     | Permission denied.                           |
1305| 2100002 | Operation failed. Cannot connect to service.|
1306| 2100003 | System internal error.                  |
1307
1308**Example**
1309
1310```js
1311policy.getPowerSaveAllowList((error, data) => {
1312    this.callBack(error, data);
1313});
1314```
1315
1316## policy.getPowerSaveAllowList
1317
1318getPowerSaveAllowList(): Promise\<Array\<number>>;
1319
1320Obtains the UID array of applications that are on the device idle allowlist. This API uses a promise to return the result.
1321
1322**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1323
1324**System capability**: SystemCapability.Communication.NetManager.Core
1325
1326**Return value**
1327
1328| Type                             | Description                                 |
1329| --------------------------------- | ------------------------------------- |
1330| Promise\<Array\<number>> | Promise used to return the result.|
1331
1332**Error codes**
1333
1334| ID| Error Message                                     |
1335| ------- | -------------------------------------------- |
1336| 201     | Permission denied.                           |
1337| 2100002 | Operation failed. Cannot connect to service.|
1338| 2100003 | System internal error.                  |
1339
1340**Example**
1341
1342```js
1343policy.getPowerSaveAllowList().then(function(error, data) {
1344    console.log(JSON.stringify(error))
1345    console.log(JSON.stringify(data))
1346})
1347```
1348
1349## policy.on
1350
1351Functions as the handle to a network policy.
1352
1353### on('netUidPolicyChange')
1354
1355on(type: "netUidPolicyChange", callback: Callback\<{ uid: number, policy: NetUidPolicy }>): void
1356
1357Subscribes to policy changes. This API uses an asynchronous callback to return the result.
1358
1359**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1360
1361**System capability**: SystemCapability.Communication.NetManager.Core
1362
1363**Parameters**
1364
1365| Name  | Type                              | Mandatory| Description                                                        |
1366| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
1367| type | netUidPolicyChange | Yes| Event type. The value **netUidPolicyChange** indicates a policy change event.|
1368| callback | Callback\<{ uid: number, policy: [NetUidPolicy](#netuidpolicy) }> | Yes  | Callback used to return the result. It is called when the registered network policy changes.|
1369
1370**Example**
1371
1372```js
1373policy.on('netUidPolicyChange', (data) => {
1374    this.log('on netUidPolicyChange: ' + JSON.stringify(data));
1375})
1376```
1377
1378### on('netUidRuleChange')
1379
1380on(type: "netUidRuleChange", callback: Callback\<{ uid: number, rule: NetUidRule }>): void
1381
1382Subscribes to rule changes. This API uses an asynchronous callback to return the result.
1383
1384**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1385
1386**System capability**: SystemCapability.Communication.NetManager.Core
1387
1388**Parameters**
1389
1390| Name  | Type                              | Mandatory| Description                                                        |
1391| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
1392| type | netUidRuleChange | Yes| Event type. The value **netUidRuleChange** indicates a rule change event.|
1393| callback | Callback\<{ uid: number, rule: [NetUidRule](#netuidrule) }> | Yes  | Callback used to return the result. It is called when the registered rule changes.|
1394
1395**Example**
1396
1397```js
1398policy.on('netUidRuleChange', (data) => {
1399    this.log('on netUidRuleChange: ' + JSON.stringify(data));
1400})
1401```
1402
1403### on('netMeteredIfacesChange')
1404
1405on(type: "netMeteredIfacesChange", callback: Callback\<Array\<string>>): void
1406
1407Subscribes to metered **iface** changes. This API uses an asynchronous callback to return the result.
1408
1409**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1410
1411**System capability**: SystemCapability.Communication.NetManager.Core
1412
1413**Parameters**
1414
1415| Name  | Type                              | Mandatory| Description                                                        |
1416| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
1417| type | netMeteredIfacesChange | Yes| Event type. The value **netMeteredIfacesChange** indicates a metered **iface** change event.|
1418| callback | Callback\<Array\<string>> | Yes  | Callback used to return the result. It is called when the registered metered **iface** changes.|
1419
1420**Example**
1421
1422```js
1423policy.on('netMeteredIfacesChange', (data) => {
1424    this.log('on netMeteredIfacesChange: ' + JSON.stringify(data));
1425})
1426```
1427
1428### on('netQuotaPolicyChange')
1429
1430on(type: "netQuotaPolicyChange", callback: Callback\<Array\<NetQuotaPolicy>>): void
1431
1432Subscribes to network quota policy changes. This API uses an asynchronous callback to return the result.
1433
1434**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1435
1436**System capability**: SystemCapability.Communication.NetManager.Core
1437
1438**Parameters**
1439
1440| Name  | Type                              | Mandatory| Description                                                        |
1441| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
1442| type | netQuotaPolicyChange | Yes| Event type. The value **netQuotaPolicyChange** indicates a network quota policy change event.|
1443| callback | Callback\<Array\<[NetQuotaPolicy](#netquotapolicy)>> | Yes  | Callback used to return the result. It is called when the registered network quota policy changes.|
1444
1445**Example**
1446
1447```js
1448policy.on('netQuotaPolicyChange', (data) => {
1449    this.log('on netQuotaPolicyChange: ' + JSON.stringify(data));
1450})
1451```
1452
1453### on('netBackgroundPolicyChange')
1454
1455on(type: "netBackgroundPolicyChange", callback: Callback\<boolean>): void
1456
1457Subscribes to background network policy changes. This API uses an asynchronous callback to return the result.
1458
1459**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1460
1461**System capability**: SystemCapability.Communication.NetManager.Core
1462
1463**Parameters**
1464
1465| Name  | Type                              | Mandatory| Description                                                        |
1466| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
1467| type | netBackgroundPolicyChange | Yes| Event type. The value **netBackgroundPolicyChange** indicates a background network policy change event.|
1468| callback | Callback\<boolean> | Yes  | Callback used to return the result. It is called when the registered background network policy changes.|
1469
1470**Example**
1471
1472```js
1473policy.on('netBackgroundPolicyChange', (data) => {
1474    this.log('on netBackgroundPolicyChange: ' + JSON.stringify(data));
1475})
1476```
1477
1478## NetBackgroundPolicy
1479
1480Enumerates the background network policies.
1481
1482**System capability**: SystemCapability.Communication.NetManager.Core
1483
1484| Name                 | Value  | Description                  |
1485| ------------------------ | ---- | ---------------------- |
1486| NET_BACKGROUND_POLICY_NONE       | 0 | Default policy.|
1487| NET_BACKGROUND_POLICY_ENABLE     | 1 | Applications running in the background are allowed to access metered networks.|
1488| NET_BACKGROUND_POLICY_DISABLE    | 2 | Applications running in the background are not allowed to access metered networks.|
1489| NET_BACKGROUND_POLICY_ALLOW_LIST | 3 | Only applications on the allowlist are allowed to access metered networks when they are running in the background.|
1490
1491## NetQuotaPolicy
1492
1493Defines a network quota policy.
1494
1495**System capability**: SystemCapability.Communication.NetManager.Core
1496
1497| Name                 | Type                               | Description                                                        |
1498| ----------------------- | ----------------------------------- | ------------------------------------------------------------ |
1499| netType           | [NetBearType](js-apis-net-connection.md#netbeartype) | Network type.|
1500| iccid             | string                      | Identifier of the SIM card on the metered cellular network. It is not used for Wi-Fi networks.|
1501| ident             | string                      | Identifier of the SIM card on the metered cellular network. It is used for Wi-Fi networks. It is used together with **iccid**.|
1502| periodDuration    | string                      | Start time of metering.|
1503| warningBytes      | number                      | Data volume threshold for generating an alarm.|
1504| limitBytes        | number                      | Data volume quota.|
1505| lastWarningRemind | string                      | Last time when an alarm was generated.|
1506| lastLimitRemind   | string                      | Last time when the quota was exhausted.|
1507| metered           | string                      | Whether the network is a metered network.|
1508| limitAction       | [LimitAction](#limitaction) | Action to take when the data volume quota is reached.|
1509
1510## LimitAction
1511
1512Enumerates the actions that can be taken when the data volume quota is reached.
1513
1514**System capability**: SystemCapability.Communication.NetManager.Core
1515
1516| Name                 | Value| Description  |
1517| ---------------------- | ----- | ------------ |
1518| LIMIT_ACTION_NONE     | -1 | Default policy.|
1519| LIMIT_ACTION_DISABLE  | 0  | Internet access is disabled.|
1520| LIMIT_ACTION_AUTO_BILL| 1  | Users will be automatically charged for the data volume they use.|
1521
1522## NetUidRule
1523
1524Enumerates the metered network rules.
1525
1526**System capability**: SystemCapability.Communication.NetManager.Core
1527
1528| Name                 | Value| Description  |
1529| ---------------------- | ----- | ------------ |
1530| NET_RULE_NONE                     | 0 | Default rule.|
1531| NET_RULE_ALLOW_METERED_FOREGROUND | 1 | Applications running in the foreground are allowed to access metered networks.|
1532| NET_RULE_ALLOW_METERED            | 2 | Applications are allowed to access metered networks.|
1533| NET_RULE_REJECT_METERED           | 4 | Applications are not allowed to access metered networks.|
1534| NET_RULE_ALLOW_ALL                | 32 | Applications are allowed to access all networks (metered or non-metered).|
1535| NET_RULE_REJECT_ALL               | 64 | Applications are not allowed to access any networks (metered or non-metered).|
1536
1537## RemindType
1538
1539Enumerates the reminder types.
1540
1541**System capability**: SystemCapability.Communication.NetManager.Core
1542
1543| Name                 | Value| Description  |
1544| ---------------------- | - | ------- |
1545| REMIND_TYPE_WARNING    | 1 | Warning.|
1546| REMIND_TYPE_LIMIT      | 2 | Limit.|
1547
1548## NetUidPolicy
1549
1550Enumerates the application-specific network policies.
1551
1552**System capability**: SystemCapability.Communication.NetManager.Core
1553
1554| Name                 | Value| Description  |
1555| ---------------------- | ----- | ------------ |
1556| NET_POLICY_NONE                       | 0 | Default network policy.|
1557| NET_POLICY_ALLOW_METERED_BACKGROUND   | 1 | Applications running in the background are allowed to access metered networks.|
1558| NET_POLICY_REJECT_METERED_BACKGROUND  | 2 | Applications running in the background are not allowed to access metered networks.|
1559