1# @ohos.net.policy (Network Policy Management) (System API)
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 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> The APIs provided by this module are system APIs.
9
10## Modules to Import
11
12```ts
13import { policy } from '@kit.NetworkKit';
14```
15
16## policy.setBackgroundAllowed<sup>10+</sup>
17
18setBackgroundAllowed(isAllowed: boolean, callback: AsyncCallback\<void>): void
19
20Specifies whether background applications are allowed to access the network. This API uses an asynchronous callback to return the result.
21
22**System API**: This is a system API.
23
24**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
25
26**System capability**: SystemCapability.Communication.NetManager.Core
27
28**Parameters**
29
30| Name   | Type                | Mandatory| Description                                                        |
31| --------- | -------------------- | ---- | ------------------------------------------------------------ |
32| isAllowed | boolean              | Yes  | Whether background applications are allowed to use mobile data.                                    |
33| callback  | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
34
35**Error codes**
36
37| ID| Error Message                                    |
38| --------- | -------------------------------------------- |
39| 201       | Permission denied.                           |
40| 202       | Non-system applications use system APIs.     |
41| 401       | Parameter error.                             |
42| 2100001   | Invalid parameter value.                     |
43| 2100002   | Failed to connect to the service.            |
44| 2100003   | System internal error.                       |
45
46**Example**
47
48```ts
49import { BusinessError } from '@kit.BasicServicesKit';
50
51policy.setBackgroundAllowed(true, (error: BusinessError) => {
52  console.log(JSON.stringify(error));
53});
54```
55
56## policy.setBackgroundAllowed<sup>10+</sup>
57
58setBackgroundAllowed(isAllowed: boolean): Promise\<void>
59
60Specifies whether background applications are allowed to access the network. This API uses a promise to return the result.
61
62**System API**: This is a system API.
63
64**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
65
66**System capability**: SystemCapability.Communication.NetManager.Core
67
68**Parameters**
69
70| Name   | Type   | Mandatory| Description                    |
71| --------- | ------- | ---- | ------------------------ |
72| isAllowed | boolean | Yes  | Whether background applications are allowed to use mobile data.|
73
74**Error codes**
75
76| ID| Error Message                                    |
77| --------- | -------------------------------------------- |
78| 201       | Permission denied.                           |
79| 202       | Non-system applications use system APIs.     |
80| 401       | Parameter error.                             |
81| 2100001   | Invalid parameter value.                     |
82| 2100002   | Failed to connect to the service.            |
83| 2100003   | System internal error.                       |
84
85**Return value**
86
87| Type          | Description                                                             |
88| -------------- | ----------------------------------------------------------------- |
89| Promise\<void> | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
90
91**Example**
92
93```ts
94import { BusinessError } from '@kit.BasicServicesKit';
95
96policy.setBackgroundAllowed(true).then(() => {
97  console.log("setBackgroundAllowed success");
98}).catch((error: BusinessError) => {
99  console.log(JSON.stringify(error));
100});
101```
102
103## policy.isBackgroundAllowed<sup>10+</sup>
104
105isBackgroundAllowed(callback: AsyncCallback\<boolean>): void
106
107Checks whether the current application is allowed to access the network when running at the background. This API uses an asynchronous callback to return the result.
108
109**System API**: This is a system API.
110
111**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
112
113**System capability**: SystemCapability.Communication.NetManager.Core
114
115**Parameters**
116
117| Name  | Type                   | Mandatory| Description                                                            |
118| -------- | ----------------------- | ---- | ---------------------------------------------------------------- |
119| callback | AsyncCallback\<boolean> | Yes  | Callback used to return the result. If the operation is successful, the value **true** is returned, which means that background applications are allowed to use mobile data. If the operation fails, an error message is returned.|
120
121**Error codes**
122
123| ID| Error Message                                    |
124| --------- | -------------------------------------------- |
125| 201       | Permission denied.                           |
126| 202       | Non-system applications use system APIs.     |
127| 401       | Parameter error.                             |
128| 2100001   | Invalid parameter value.                     |
129| 2100002   | Failed to connect to the service.            |
130| 2100003   | System internal error.                       |
131
132**Example**
133
134```ts
135import { BusinessError } from '@kit.BasicServicesKit';
136
137policy.isBackgroundAllowed((error: BusinessError, data: boolean) => {
138  console.log(JSON.stringify(error));
139  console.log(JSON.stringify(data));
140});
141```
142
143## policy.isBackgroundAllowed<sup>10+</sup>
144
145isBackgroundAllowed(): Promise\<boolean>;
146
147Checks whether the current application is allowed to access the network when running at the background. This API uses a promise to return the result.
148
149**System API**: This is a system API.
150
151**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
152
153**System capability**: SystemCapability.Communication.NetManager.Core
154
155**Return value**
156
157| Type             | Description                                                                                |
158| ----------------- | ------------------------------------------------------------------------------------ |
159| Promise\<boolean> | Promise used to return the result. If the operation is successful, the value **true** is returned, which means that background applications are allowed to use mobile data. If the operation fails, an error message is returned.|
160
161**Error codes**
162
163| ID| Error Message                                    |
164| --------- | -------------------------------------------- |
165| 201       | Permission denied.                           |
166| 202       | Non-system applications use system APIs.     |
167| 401       | Parameter error.                             |
168| 2100001   | Invalid parameter value.                     |
169| 2100002   | Failed to connect to the service.            |
170| 2100003   | System internal error.                       |
171
172**Example**
173
174```ts
175import { BusinessError } from '@kit.BasicServicesKit';
176
177policy
178  .isBackgroundAllowed()
179  .then((data: boolean) => {
180    console.log(JSON.stringify(data));
181  })
182  .catch((error: BusinessError) => {
183    console.log(JSON.stringify(error));
184  });
185```
186
187## policy.setPolicyByUid<sup>10+</sup>
188
189setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback\<void>): void
190
191Sets the metered network access policy for the application specified by a given UID. This API uses an asynchronous callback to return the result.
192
193**System API**: This is a system API.
194
195**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
196
197**System capability**: SystemCapability.Communication.NetManager.Core
198
199**Parameters**
200
201| Name  | Type                           | Mandatory| Description                                          |
202| -------- | ------------------------------- | ---- | ---------------------------------------------- |
203| uid      | number                          | Yes  | Unique ID of the application.                                |
204| policy   | [NetUidPolicy](#netuidpolicy10) | Yes  | Network access policy for the application.                                |
205| callback | AsyncCallback\<void>            | Yes  | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
206
207**Error codes**
208
209| ID| Error Message                                    |
210| --------- | -------------------------------------------- |
211| 201       | Permission denied.                           |
212| 202       | Non-system applications use system APIs.     |
213| 401       | Parameter error.                             |
214| 2100001   | Invalid parameter value.                     |
215| 2100002   | Failed to connect to the service.            |
216| 2100003   | System internal error.                       |
217
218**Example**
219
220```ts
221import { BusinessError } from '@kit.BasicServicesKit';
222
223policy.setPolicyByUid(11111, policy.NetUidPolicy.NET_POLICY_NONE, (error: BusinessError) => {
224  console.log(JSON.stringify(error));
225});
226```
227
228## policy.setPolicyByUid<sup>10+</sup>
229
230setPolicyByUid(uid: number, policy: NetUidPolicy): Promise\<void>;
231
232Sets the metered network access policy for the application specified by a given UID. This API uses a promise to return the result.
233
234**System API**: This is a system API.
235
236**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
237
238**System capability**: SystemCapability.Communication.NetManager.Core
239
240**Parameters**
241
242| Name| Type                           | Mandatory| Description          |
243| ------ | ------------------------------- | ---- | -------------- |
244| uid    | number                          | Yes  | Unique ID of the application.|
245| policy | [NetUidPolicy](#netuidpolicy10) | Yes  | Network access policy for the application.|
246
247**Return value**
248
249| Type          | Description                                                             |
250| -------------- | ----------------------------------------------------------------- |
251| Promise\<void> | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
252
253**Error codes**
254
255| ID| Error Message                                    |
256| --------- | -------------------------------------------- |
257| 201       | Permission denied.                           |
258| 202       | Non-system applications use system APIs.     |
259| 401       | Parameter error.                             |
260| 2100001   | Invalid parameter value.                     |
261| 2100002   | Failed to connect to the service.            |
262| 2100003   | System internal error.                       |
263
264**Example**
265
266```ts
267import { BusinessError } from '@kit.BasicServicesKit';
268
269policy
270  .setPolicyByUid(11111, policy.NetUidPolicy.NET_POLICY_NONE)
271  .then(() => {
272    console.log('setPolicyByUid success');
273  })
274  .catch((error: BusinessError) => {
275    console.log(JSON.stringify(error));
276  });
277```
278
279## policy.getPolicyByUid<sup>10+</sup>
280
281getPolicyByUid(uid: number, callback: AsyncCallback\<NetUidPolicy>): void
282
283Obtains the network access policy for the application specified by a given UID. This API uses an asynchronous callback to return the result.
284
285**System API**: This is a system API.
286
287**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
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| callback | AsyncCallback\<[NetUidPolicy](#netuidpolicy10)> | 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.|
297
298**Error codes**
299
300| ID| Error Message                                    |
301| --------- | -------------------------------------------- |
302| 201       | Permission denied.                           |
303| 202       | Non-system applications use system APIs.     |
304| 401       | Parameter error.                             |
305| 2100001   | Invalid parameter value.                     |
306| 2100002   | Failed to connect to the service.            |
307| 2100003   | System internal error.                       |
308
309**Example**
310
311```ts
312import { BusinessError } from '@kit.BasicServicesKit';
313
314policy.getPolicyByUid(11111, (error: BusinessError, data: policy.NetUidPolicy) => {
315  console.log(JSON.stringify(error));
316  console.log(JSON.stringify(data));
317});
318```
319
320## policy.getPolicyByUid<sup>10+</sup>
321
322getPolicyByUid(uid: number): Promise\<NetUidPolicy>;
323
324Obtains the network access policy for the application specified by a given UID. This API uses a promise to return the result.
325
326**System API**: This is a system API.
327
328**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
329
330**System capability**: SystemCapability.Communication.NetManager.Core
331
332**Parameters**
333
334| Name| Type  | Mandatory| Description          |
335| ------ | ------ | ---- | -------------- |
336| uid    | number | Yes  | Unique ID of the application.|
337
338**Return value**
339
340| Type                                     | Description                                                     |
341| ----------------------------------------- | --------------------------------------------------------- |
342| Promise\<[NetUidPolicy](#netuidpolicy10)> | Promise used to return the result. If the operation fails, an error message is returned.|
343
344**Error codes**
345
346| ID| Error Message                                    |
347| --------- | -------------------------------------------- |
348| 201       | Permission denied.                           |
349| 202       | Non-system applications use system APIs.     |
350| 401       | Parameter error.                             |
351| 2100001   | Invalid parameter value.                     |
352| 2100002   | Failed to connect to the service.            |
353| 2100003   | System internal error.                       |
354
355**Example**
356
357```ts
358import { BusinessError } from '@kit.BasicServicesKit';
359
360policy
361  .getPolicyByUid(11111)
362  .then((data: policy.NetUidPolicy) => {
363    console.log(JSON.stringify(data));
364  })
365  .catch((error: BusinessError) => {
366    console.log(JSON.stringify(error));
367  });
368```
369
370## policy.getUidsByPolicy<sup>10+</sup>
371
372getUidsByPolicy(policy: NetUidPolicy, callback: AsyncCallback\<Array\<number>>): void
373
374Obtains all UIDs that match the specified network policy. This API uses an asynchronous callback to return the result.
375
376**System API**: This is a system API.
377
378**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
379
380**System capability**: SystemCapability.Communication.NetManager.Core
381
382**Parameters**
383
384| Name  | Type                           | Mandatory| Description                                                       |
385| -------- | ------------------------------- | ---- | ----------------------------------------------------------- |
386| policy   | [NetUidPolicy](#netuidpolicy10) | Yes  | Network policy for the application.                                 |
387| 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.|
388
389**Error codes**
390
391| ID| Error Message                                    |
392| --------- | -------------------------------------------- |
393| 201       | Permission denied.                           |
394| 202       | Non-system applications use system APIs.     |
395| 401       | Parameter error.                             |
396| 2100001   | Invalid parameter value.                     |
397| 2100002   | Failed to connect to the service.            |
398| 2100003   | System internal error.                       |
399
400**Example**
401
402```ts
403import { BusinessError } from '@kit.BasicServicesKit';
404
405policy.getUidsByPolicy(11111, (error: BusinessError, data: number[]) => {
406  console.log(JSON.stringify(error));
407  console.log(JSON.stringify(data));
408});
409```
410
411## policy.getUidsByPolicy<sup>10+</sup>
412
413getUidsByPolicy(policy: NetUidPolicy): Promise\<Array\<number>>;
414
415Obtains all UIDs that match the specified network policy. This API uses a promise to return the result.
416
417**System API**: This is a system API.
418
419**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
420
421**System capability**: SystemCapability.Communication.NetManager.Core
422
423**Parameters**
424
425| Name| Type                           | Mandatory| Description                      |
426| ------ | ------------------------------- | ---- | -------------------------- |
427| policy | [NetUidPolicy](#netuidpolicy10) | Yes  | Network policy for the application.|
428
429**Return value**
430
431| Type                    | Description                                                        |
432| ------------------------ | ------------------------------------------------------------ |
433| 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.|
434
435**Error codes**
436
437| ID| Error Message                                    |
438| --------- | -------------------------------------------- |
439| 201       | Permission denied.                           |
440| 202       | Non-system applications use system APIs.     |
441| 401       | Parameter error.                             |
442| 2100001   | Invalid parameter value.                     |
443| 2100002   | Failed to connect to the service.            |
444| 2100003   | System internal error.                       |
445
446**Example**
447
448```ts
449import { BusinessError } from '@kit.BasicServicesKit';
450
451policy
452  .getUidsByPolicy(11111)
453  .then((data: object) => {
454    console.log(JSON.stringify(data));
455  })
456  .catch((error: BusinessError) => {
457    console.log(JSON.stringify(error));
458  });
459```
460
461## policy.getNetQuotaPolicies<sup>10+</sup>
462
463getNetQuotaPolicies(callback: AsyncCallback\<Array\<NetQuotaPolicy>>): void
464
465Obtains the network quota policies. This API uses an asynchronous callback to return the result.
466
467**System API**: This is a system API.
468
469**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
470
471**System capability**: SystemCapability.Communication.NetManager.Core
472
473**Parameters**
474
475| Name  | Type                                                       | Mandatory| Description                    |
476| -------- | ----------------------------------------------------------- | ---- | ------------------------ |
477| callback | AsyncCallback\<Array\<[NetQuotaPolicy](#netquotapolicy10)>> | Yes  | Callback used to return the result.|
478
479**Error codes**
480
481| ID| Error Message                                    |
482| --------- | -------------------------------------------- |
483| 201       | Permission denied.                           |
484| 202       | Non-system applications use system APIs.     |
485| 401       | Parameter error.                             |
486| 2100001   | Invalid parameter value.                     |
487| 2100002   | Failed to connect to the service.            |
488| 2100003   | System internal error.                       |
489
490**Example**
491
492```ts
493import { BusinessError } from '@kit.BasicServicesKit';
494
495policy.getNetQuotaPolicies((error: BusinessError, data: policy.NetQuotaPolicy[]) => {
496  console.log(JSON.stringify(error));
497  console.log(JSON.stringify(data));
498});
499```
500
501## policy.getNetQuotaPolicies<sup>10+</sup>
502
503getNetQuotaPolicies(): Promise\<Array\<NetQuotaPolicy>>;
504
505Obtains the network quota policies. This API uses a promise to return the result.
506
507**System API**: This is a system API.
508
509**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
510
511**System capability**: SystemCapability.Communication.NetManager.Core
512
513**Return value**
514
515| Type                                                 | Description                         |
516| ----------------------------------------------------- | ----------------------------- |
517| Promise\<Array\<[NetQuotaPolicy](#netquotapolicy10)>> | Promise used to return the result.|
518
519**Error codes**
520
521| ID| Error Message                                    |
522| --------- | -------------------------------------------- |
523| 201       | Permission denied.                           |
524| 202       | Non-system applications use system APIs.     |
525| 401       | Parameter error.                             |
526| 2100002   | Failed to connect to the service.            |
527| 2100003   | System internal error.                       |
528
529**Example**
530
531```ts
532import { BusinessError } from '@kit.BasicServicesKit';
533
534policy
535  .getNetQuotaPolicies()
536  .then((data: policy.NetQuotaPolicy[]) => {
537    console.log(JSON.stringify(data));
538  })
539  .catch((error: BusinessError) => {
540    console.log(JSON.stringify(error));
541  });
542```
543
544## policy.setNetQuotaPolicies<sup>10+</sup>
545
546setNetQuotaPolicies(quotaPolicies: Array\<NetQuotaPolicy>, callback: AsyncCallback\<void>): void
547
548Sets network quota policies. This API uses an asynchronous callback to return the result.
549
550**System API**: This is a system API.
551
552**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
553
554**System capability**: SystemCapability.Communication.NetManager.Core
555
556**Parameters**
557
558| Name       | Type                                       | Mandatory| Description                                          |
559| ------------- | ------------------------------------------- | ---- | ---------------------------------------------- |
560| quotaPolicies | Array\<[NetQuotaPolicy](#netquotapolicy10)> | Yes  | Network quota policies.                                  |
561| callback      | AsyncCallback\<void>                        | Yes  | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
562
563**Error codes**
564
565| ID| Error Message                                    |
566| --------- | -------------------------------------------- |
567| 201       | Permission denied.                           |
568| 202       | Non-system applications use system APIs.     |
569| 401       | Parameter error.                             |
570| 2100001   | Invalid parameter value.                     |
571| 2100002   | Failed to connect to the service.            |
572| 2100003   | System internal error.                       |
573
574**Example**
575
576```ts
577import { connection } from '@kit.NetworkKit';
578import { BusinessError } from '@kit.BasicServicesKit';
579
580let netQuotaPolicyList: Array<policy.NetQuotaPolicy> = [];
581let netquotapolicy: policy.NetQuotaPolicy = {
582  networkMatchRule: {
583    netType: connection.NetBearType.BEARER_CELLULAR,
584    identity: '',
585    simId: '1'
586  },
587  quotaPolicy: {
588    periodDuration: 'M1',
589    warningBytes: 40000,
590    limitBytes: 50000,
591    metered: true,
592    limitAction: policy.LimitAction.LIMIT_ACTION_NONE
593  }
594}
595netQuotaPolicyList.push(netquotapolicy);
596
597policy.setNetQuotaPolicies(netQuotaPolicyList, (error: BusinessError) => {
598  console.log(JSON.stringify(error));
599});
600```
601
602## policy.setNetQuotaPolicies<sup>10+</sup>
603
604setNetQuotaPolicies(quotaPolicies: Array\<NetQuotaPolicy>): Promise\<void>;
605
606Sets network quota policies. This API uses a promise to return the result.
607
608**System API**: This is a system API.
609
610**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
611
612**System capability**: SystemCapability.Communication.NetManager.Core
613
614**Parameters**
615
616| Name       | Type                                       | Mandatory| Description        |
617| ------------- | ------------------------------------------- | ---- | ------------ |
618| quotaPolicies | Array\<[NetQuotaPolicy](#netquotapolicy10)> | Yes  | Network quota policies.|
619
620**Error codes**
621
622| ID| Error Message                                    |
623| --------- | -------------------------------------------- |
624| 201       | Permission denied.                           |
625| 202       | Non-system applications use system APIs.     |
626| 401       | Parameter error.                             |
627| 2100001   | Invalid parameter value.                     |
628| 2100002   | Failed to connect to the service.            |
629| 2100003   | System internal error.                       |
630
631**Return value**
632
633| Type          | Description                                                             |
634| -------------- | ----------------------------------------------------------------- |
635| Promise\<void> | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
636
637**Example**
638
639```ts
640import { connection } from '@kit.NetworkKit';
641import { BusinessError } from '@kit.BasicServicesKit';
642
643let netQuotaPolicyList: Array<policy.NetQuotaPolicy> = [];
644let netquotapolicy: policy.NetQuotaPolicy = {
645  networkMatchRule: {
646    netType: connection.NetBearType.BEARER_CELLULAR,
647    identity: '',
648    simId: '1'
649  },
650  quotaPolicy: {
651    periodDuration: 'M1',
652    warningBytes: 40000,
653    limitBytes: 50000,
654    metered: true,
655    limitAction: policy.LimitAction.LIMIT_ACTION_NONE
656  }
657}
658netQuotaPolicyList.push(netquotapolicy);
659
660policy
661  .setNetQuotaPolicies(netQuotaPolicyList)
662  .then(() => {
663    console.log('setNetQuotaPolicies success');
664  })
665  .catch((error: BusinessError) => {
666    console.log(JSON.stringify(error));
667  });
668```
669
670## policy.isUidNetAllowed<sup>10+</sup>
671
672isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback\<boolean>): void
673
674Checks whether the application specified by a given UID is allowed to access a metered network. This API uses an asynchronous callback to return the result.
675
676**System API**: This is a system API.
677
678**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
679
680**System capability**: SystemCapability.Communication.NetManager.Core
681
682**Parameters**
683
684| Name   | Type                   | Mandatory| Description                                                     |
685| --------- | ----------------------- | ---- | --------------------------------------------------------- |
686| uid       | number                  | Yes  | Unique ID of the application.                                           |
687| isMetered | boolean                 | Yes  | Whether the network is a metered network.                                           |
688| callback  | AsyncCallback\<boolean> | Yes  | Callback used to return the result. The value **true** means that the application is allowed to access metered networks, and the value **false** means the opposite.|
689
690**Error codes**
691
692| ID| Error Message                                    |
693| --------- | -------------------------------------------- |
694| 201       | Permission denied.                           |
695| 202       | Non-system applications use system APIs.     |
696| 401       | Parameter error.                             |
697| 2100001   | Invalid parameter value.                     |
698| 2100002   | Failed to connect to the service.            |
699| 2100003   | System internal error.                       |
700
701**Example**
702
703```ts
704import { BusinessError } from '@kit.BasicServicesKit';
705
706policy.isUidNetAllowed(11111, true, (error: BusinessError, data: boolean) => {
707  console.log(JSON.stringify(error));
708  console.log(JSON.stringify(data));
709});
710```
711
712## policy.isUidNetAllowed<sup>10+</sup>
713
714isUidNetAllowed(uid: number, isMetered: boolean): Promise\<boolean>;
715
716Checks whether the application specified by a given UID is allowed to access a metered network. This API uses a promise to return the result.
717
718**System API**: This is a system API.
719
720**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
721
722**System capability**: SystemCapability.Communication.NetManager.Core
723
724**Parameters**
725
726| Name   | Type   | Mandatory| Description          |
727| --------- | ------- | ---- | -------------- |
728| uid       | number  | Yes  | Unique ID of the application.|
729| isMetered | boolean | Yes  | Whether the network is a metered network.|
730
731**Return value**
732
733| Type             | Description                         |
734| ----------------- | ----------------------------- |
735| Promise\<boolean> | Promise used to return the result.|
736
737**Error codes**
738
739| ID| Error Message                                    |
740| --------- | -------------------------------------------- |
741| 201       | Permission denied.                           |
742| 202       | Non-system applications use system APIs.     |
743| 401       | Parameter error.                             |
744| 2100001   | Invalid parameter value.                     |
745| 2100002   | Failed to connect to the service.            |
746| 2100003   | System internal error.                       |
747
748**Example**
749
750```ts
751import { BusinessError } from '@kit.BasicServicesKit';
752
753policy
754  .isUidNetAllowed(11111, true)
755  .then((data: boolean) => {
756    console.log(JSON.stringify(data));
757  })
758  .catch((error: BusinessError) => {
759    console.log(JSON.stringify(error));
760  });
761```
762
763## policy.isUidNetAllowed<sup>10+</sup>
764
765isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback\<boolean>): void
766
767Checks whether an application is allowed to access the specified network. This API uses an asynchronous callback to return the result.
768
769**System API**: This is a system API.
770
771**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
772
773**System capability**: SystemCapability.Communication.NetManager.Core
774
775**Parameters**
776
777| Name  | Type                   | Mandatory| Description                                                        |
778| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
779| uid      | number                  | Yes  | Unique ID of the application.                                              |
780| iface    | string                  | Yes  | Name of the target network.                                              |
781| callback | AsyncCallback\<boolean> | Yes  | Callback used to return the result. The value **true** means that the application is allowed to access the specified network, and the value **false** means the opposite.|
782
783**Error codes**
784
785| ID| Error Message                                    |
786| --------- | -------------------------------------------- |
787| 201       | Permission denied.                           |
788| 202       | Non-system applications use system APIs.     |
789| 401       | Parameter error.                             |
790| 2100001   | Invalid parameter value.                     |
791| 2100002   | Failed to connect to the service.            |
792| 2100003   | System internal error.                       |
793
794**Example**
795
796```ts
797import { BusinessError } from '@kit.BasicServicesKit';
798
799policy.isUidNetAllowed(11111, 'wlan0', (error: BusinessError, data: boolean) => {
800  console.log(JSON.stringify(error));
801  console.log(JSON.stringify(data));
802});
803```
804
805## policy.isUidNetAllowed<sup>10+</sup>
806
807isUidNetAllowed(uid: number, iface: string): Promise\<boolean>;
808
809Checks whether an application is allowed to access the specified network. This API uses a promise to return the result.
810
811**System API**: This is a system API.
812
813**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
814
815**System capability**: SystemCapability.Communication.NetManager.Core
816
817**Parameters**
818
819| Name| Type  | Mandatory| Description          |
820| ------ | ------ | ---- | -------------- |
821| uid    | number | Yes  | Unique ID of the application.|
822| iface  | string | Yes  | Name of the target network.|
823
824**Return value**
825
826| Type             | Description                                                   |
827| ----------------- | ------------------------------------------------------- |
828| Promise\<boolean> | Promise used to return the result. |
829
830**Error codes**
831
832| ID| Error Message                                    |
833| --------- | -------------------------------------------- |
834| 201       | Permission denied.                           |
835| 202       | Non-system applications use system APIs.     |
836| 401       | Parameter error.                             |
837| 2100001   | Invalid parameter value.                     |
838| 2100002   | Failed to connect to the service.            |
839| 2100003   | System internal error.                       |
840
841**Example**
842
843```ts
844import { BusinessError } from '@kit.BasicServicesKit';
845
846policy
847  .isUidNetAllowed(11111, 'wlan0')
848  .then((data: boolean) => {
849    console.log(JSON.stringify(data));
850  })
851  .catch((error: BusinessError) => {
852    console.log(JSON.stringify(error));
853  });
854```
855
856## policy.setDeviceIdleTrustlist<sup>10+</sup>
857
858setDeviceIdleTrustlist(uids: Array\<number>, isAllowed: boolean, callback: AsyncCallback\<void>): void
859
860Adds applications specified by given UIDs to the device idle allowlist. This API uses an asynchronous callback to return the result.
861
862**System API**: This is a system API.
863
864**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
865
866**System capability**: SystemCapability.Communication.NetManager.Core
867
868**Parameters**
869
870| Name   | Type                          | Mandatory| Description                                          |
871| --------- | ------------------------------ | ---- | ---------------------------------------------- |
872| uids      | Array\<number>                 | Yes  | Unique ID of the application.                                |
873| isAllowed | boolean                        | Yes  | Whether to add the application to the allowlist.                                |
874| callback  | callback: AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
875
876**Error codes**
877
878| ID| Error Message                                    |
879| --------- | -------------------------------------------- |
880| 201       | Permission denied.                           |
881| 202       | Non-system applications use system APIs.     |
882| 401       | Parameter error.                             |
883| 2100001   | Invalid parameter value.                     |
884| 2100002   | Failed to connect to the service.            |
885| 2100003   | System internal error.                       |
886
887**Example**
888
889```ts
890import { BusinessError } from '@kit.BasicServicesKit';
891
892policy.setDeviceIdleTrustlist([11111, 22222], true, (error: BusinessError) => {
893  console.log(JSON.stringify(error));
894});
895```
896
897## policy.setDeviceIdleTrustlist<sup>10+</sup>
898
899setDeviceIdleTrustlist(uids: Array\<number>, isAllowed: boolean): Promise\<void>;
900
901Adds applications specified by given UIDs to the device idle allowlist. This API uses a promise to return the result.
902
903**System API**: This is a system API.
904
905**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
906
907**System capability**: SystemCapability.Communication.NetManager.Core
908
909**Parameters**
910
911| Name   | Type          | Mandatory| Description          |
912| --------- | -------------- | ---- | -------------- |
913| uids      | Array\<number> | Yes  | Unique ID of the application.|
914| isAllowed | boolean        | Yes  | Whether to add the application to the allowlist.|
915
916**Return value**
917
918| Type          | Description                                                             |
919| -------------- | ----------------------------------------------------------------- |
920| Promise\<void> | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
921
922**Error codes**
923
924| ID| Error Message                                    |
925| --------- | -------------------------------------------- |
926| 201       | Permission denied.                           |
927| 202       | Non-system applications use system APIs.     |
928| 401       | Parameter error.                             |
929| 2100001   | Invalid parameter value.                     |
930| 2100002   | Failed to connect to the service.            |
931| 2100003   | System internal error.                       |
932
933**Example**
934
935```ts
936import { BusinessError } from '@kit.BasicServicesKit';
937
938policy
939  .setDeviceIdleTrustlist([11111, 22222], true)
940  .then(() => {
941    console.log('setDeviceIdleTrustlist success');
942  })
943  .catch((error: BusinessError) => {
944    console.log(JSON.stringify(error));
945  });
946```
947
948## policy.getDeviceIdleTrustlist<sup>10+</sup>
949
950getDeviceIdleTrustlist(callback: AsyncCallback\<Array\<number>>): void
951
952Obtains the UIDs of applications that are on the device idle allowlist. This API uses an asynchronous callback to return the result.
953
954**System API**: This is a system API.
955
956**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
957
958**System capability**: SystemCapability.Communication.NetManager.Core
959
960**Parameters**
961
962| Name  | Type                          | Mandatory| Description                    |
963| -------- | ------------------------------ | ---- | ------------------------ |
964| callback | AsyncCallback\<Array\<number>> | Yes  | Callback used to return the result.|
965
966**Error codes**
967
968| ID| Error Message                                    |
969| --------- | -------------------------------------------- |
970| 201       | Permission denied.                           |
971| 202       | Non-system applications use system APIs.     |
972| 401       | Parameter error.                             |
973| 2100001   | Invalid parameter value.                     |
974| 2100002   | Failed to connect to the service.            |
975| 2100003   | System internal error.                       |
976
977**Example**
978
979```ts
980import { BusinessError } from '@kit.BasicServicesKit';
981
982policy.getDeviceIdleTrustlist((error: BusinessError, data: number[]) => {
983  console.log(JSON.stringify(error));
984  console.log(JSON.stringify(data));
985});
986```
987
988## policy.getDeviceIdleTrustlist<sup>10+</sup>
989
990getDeviceIdleTrustlist(): Promise\<Array\<number>>;
991
992Obtains the UIDs of applications that are on the device idle allowlist. This API uses a promise to return the result.
993
994**System API**: This is a system API.
995
996**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
997
998**System capability**: SystemCapability.Communication.NetManager.Core
999
1000**Return value**
1001
1002| Type                    | Description                         |
1003| ------------------------ | ----------------------------- |
1004| Promise\<Array\<number>> | Promise used to return the result.|
1005
1006**Error codes**
1007
1008| ID| Error Message                                    |
1009| --------- | -------------------------------------------- |
1010| 201       | Permission denied.                           |
1011| 202       | Non-system applications use system APIs.     |
1012| 401       | Parameter error.                             |
1013| 2100002   | Failed to connect to the service.            |
1014| 2100003   | System internal error.                       |
1015
1016**Example**
1017
1018```ts
1019import { BusinessError } from '@kit.BasicServicesKit';
1020
1021policy
1022  .getDeviceIdleTrustlist()
1023  .then((data: number[]) => {
1024    console.log(JSON.stringify(data));
1025  })
1026  .catch((error: BusinessError) => {
1027    console.log(JSON.stringify(error));
1028  });
1029```
1030
1031## policy.getBackgroundPolicyByUid<sup>10+</sup>
1032
1033getBackgroundPolicyByUid(uid: number, callback: AsyncCallback\<NetBackgroundPolicy>): void
1034
1035Obtains the background network policy for the application specified by a given UID. This API uses an asynchronous callback to return the result.
1036
1037**System API**: This is a system API.
1038
1039**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1040
1041**System capability**: SystemCapability.Communication.NetManager.Core
1042
1043**Parameters**
1044
1045| Name  | Type                                                         | Mandatory| Description                    |
1046| -------- | ------------------------------------------------------------- | ---- | ------------------------ |
1047| uid      | number                                                        | Yes  | Unique ID of the application.          |
1048| callback | AsyncCallback\<[NetBackgroundPolicy](#netbackgroundpolicy10)> | Yes  | Callback used to return the result.|
1049
1050**Error codes**
1051
1052| ID| Error Message                                    |
1053| --------- | -------------------------------------------- |
1054| 201       | Permission denied.                           |
1055| 202       | Non-system applications use system APIs.     |
1056| 401       | Parameter error.                             |
1057| 2100001   | Invalid parameter value.                     |
1058| 2100002   | Failed to connect to the service.            |
1059| 2100003   | System internal error.                       |
1060
1061**Example**
1062
1063```ts
1064import { BusinessError } from '@kit.BasicServicesKit';
1065
1066policy.getBackgroundPolicyByUid(11111, (error: BusinessError, data: policy.NetBackgroundPolicy) => {
1067  console.log(JSON.stringify(error));
1068  console.log(JSON.stringify(data));
1069});
1070```
1071
1072## policy.getBackgroundPolicyByUid<sup>10+</sup>
1073
1074getBackgroundPolicyByUid(uid: number): Promise\<NetBackgroundPolicy>;
1075
1076Obtains the background network policies configured for the specified application. This API uses a promise to return the result.
1077
1078**System API**: This is a system API.
1079
1080**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1081
1082**System capability**: SystemCapability.Communication.NetManager.Core
1083
1084**Parameters**
1085
1086| Name| Type  | Mandatory| Description          |
1087| ------ | ------ | ---- | -------------- |
1088| uid    | number | Yes  | Unique ID of the application.|
1089
1090**Return value**
1091
1092| Type                                                   | Description                         |
1093| ------------------------------------------------------- | ----------------------------- |
1094| Promise\<[NetBackgroundPolicy](#netbackgroundpolicy10)> | Promise used to return the result.|
1095
1096**Error codes**
1097
1098| ID| Error Message                                    |
1099| --------- | -------------------------------------------- |
1100| 201       | Permission denied.                           |
1101| 202       | Non-system applications use system APIs.     |
1102| 401       | Parameter error.                             |
1103| 2100001   | Invalid parameter value.                     |
1104| 2100002   | Failed to connect to the service.            |
1105| 2100003   | System internal error.                       |
1106
1107**Example**
1108
1109```ts
1110import { BusinessError } from '@kit.BasicServicesKit';
1111
1112policy
1113  .getBackgroundPolicyByUid(11111)
1114  .then((data: policy.NetBackgroundPolicy) => {
1115    console.log(JSON.stringify(data));
1116  })
1117  .catch((error: BusinessError) => {
1118    console.log(JSON.stringify(error));
1119  });
1120```
1121
1122## policy.resetPolicies<sup>10+</sup>
1123
1124resetPolicies(simId: string, callback: AsyncCallback\<void>): void
1125
1126Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the specified SIM card. This API uses an asynchronous callback to return the result.
1127
1128**System API**: This is a system API.
1129
1130**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1131
1132**System capability**: SystemCapability.Communication.NetManager.Core
1133
1134**Parameters**
1135
1136| Name  | Type                | Mandatory| Description                                          |
1137| -------- | -------------------- | ---- | ---------------------------------------------- |
1138| simId    | string               | Yes  | SIM card ID.                                     |
1139| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
1140
1141**Error codes**
1142
1143| ID| Error Message                                    |
1144| --------- | -------------------------------------------- |
1145| 201       | Permission denied.                           |
1146| 202       | Non-system applications use system APIs.     |
1147| 401       | Parameter error.                             |
1148| 2100001   | Invalid parameter value.                     |
1149| 2100002   | Failed to connect to the service.            |
1150| 2100003   | System internal error.                       |
1151
1152**Example**
1153
1154```ts
1155import { BusinessError } from '@kit.BasicServicesKit';
1156
1157policy.resetPolicies('1', (error: BusinessError) => {
1158  console.log(JSON.stringify(error));
1159});
1160```
1161
1162## policy.resetPolicies<sup>10+</sup>
1163
1164resetPolicies(simId: string): Promise\<void>;
1165
1166Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the specified SIM card. This API uses a promise to return the result.
1167
1168**System API**: This is a system API.
1169
1170**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1171
1172**System capability**: SystemCapability.Communication.NetManager.Core
1173
1174**Parameters**
1175
1176| Name| Type  | Mandatory| Description     |
1177| ------ | ------ | ---- | --------- |
1178| simId  | string | Yes  | SIM card ID.|
1179
1180**Return value**
1181
1182| Type          | Description                                                             |
1183| -------------- | ----------------------------------------------------------------- |
1184| Promise\<void> | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
1185
1186**Error codes**
1187
1188| ID| Error Message                                    |
1189| --------- | -------------------------------------------- |
1190| 201       | Permission denied.                           |
1191| 202       | Non-system applications use system APIs.     |
1192| 401       | Parameter error.                             |
1193| 2100001   | Invalid parameter value.                     |
1194| 2100002   | Failed to connect to the service.            |
1195| 2100003   | System internal error.                       |
1196
1197**Example**
1198
1199```ts
1200import { BusinessError } from '@kit.BasicServicesKit';
1201
1202policy
1203  .resetPolicies('1')
1204  .then(() => {
1205    console.log('resetPolicies success');
1206  })
1207  .catch((error: BusinessError) => {
1208    console.log(JSON.stringify(error));
1209  });
1210```
1211
1212## policy.updateRemindPolicy<sup>10+</sup>
1213
1214updateRemindPolicy(netType: NetBearType, simId: string, remindType: RemindType, callback: AsyncCallback\<void>): void
1215
1216Updates a reminder policy. This API uses an asynchronous callback to return the result.
1217
1218**System API**: This is a system API.
1219
1220**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1221
1222**System capability**: SystemCapability.Communication.NetManager.Core
1223
1224**Parameters**
1225
1226| Name    | Type                                                | Mandatory| Description                                          |
1227| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
1228| netType    | [NetBearType](js-apis-net-connection.md#netbeartype) | Yes  | Network type.                                      |
1229| simId      | string                                               | Yes  | SIM card ID.                                     |
1230| remindType | [RemindType](#remindtype10)                          | Yes  | Reminder type.                                      |
1231| callback   | AsyncCallback\<void>                                 | Yes  | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
1232
1233**Error codes**
1234
1235| ID| Error Message                                    |
1236| --------- | -------------------------------------------- |
1237| 201       | Permission denied.                           |
1238| 202       | Non-system applications use system APIs.     |
1239| 401       | Parameter error.                             |
1240| 2100001   | Invalid parameter value.                     |
1241| 2100002   | Failed to connect to the service.            |
1242| 2100003   | System internal error.                       |
1243
1244**Example**
1245
1246```ts
1247import { connection } from '@kit.NetworkKit';
1248import { BusinessError } from '@kit.BasicServicesKit';
1249
1250policy.updateRemindPolicy(
1251  connection.NetBearType.BEARER_CELLULAR,
1252  '1',
1253  policy.RemindType.REMIND_TYPE_WARNING,
1254  (error: BusinessError) => {
1255    console.log(JSON.stringify(error));
1256  }
1257);
1258```
1259
1260## policy.updateRemindPolicy<sup>10+</sup>
1261
1262updateRemindPolicy(netType: NetBearType, simId: string, remindType: RemindType): Promise\<void>;
1263
1264Updates a reminder policy. This API uses a promise to return the result.
1265
1266**System API**: This is a system API.
1267
1268**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1269
1270**System capability**: SystemCapability.Communication.NetManager.Core
1271
1272**Parameters**
1273
1274| Name    | Type                                                | Mandatory| Description     |
1275| ---------- | ---------------------------------------------------- | ---- | --------- |
1276| netType    | [NetBearType](js-apis-net-connection.md#netbeartype) | Yes  | Network type. |
1277| simId      | string                                               | Yes  | SIM card ID.|
1278| remindType | [RemindType](#remindtype10)                          | Yes  | Reminder type. |
1279
1280**Return value**
1281
1282| Type          | Description                                                             |
1283| -------------- | ----------------------------------------------------------------- |
1284| Promise\<void> | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
1285
1286**Error codes**
1287
1288| ID| Error Message                                    |
1289| --------- | -------------------------------------------- |
1290| 201       | Permission denied.                           |
1291| 202       | Non-system applications use system APIs.     |
1292| 401       | Parameter error.                             |
1293| 2100001   | Invalid parameter value.                     |
1294| 2100002   | Failed to connect to the service.            |
1295| 2100003   | System internal error.                       |
1296
1297**Example**
1298
1299```ts
1300import { connection } from '@kit.NetworkKit';
1301import { BusinessError } from '@kit.BasicServicesKit';
1302
1303policy
1304  .updateRemindPolicy(
1305    connection.NetBearType.BEARER_CELLULAR,
1306    '1',
1307    policy.RemindType.REMIND_TYPE_WARNING
1308  )
1309  .then(() => {
1310    console.log('updateRemindPolicy success');
1311  })
1312  .catch((error: BusinessError) => {
1313    console.log(JSON.stringify(error));
1314  });
1315```
1316
1317## policy.setPowerSaveTrustlist<sup>10+</sup>
1318
1319setPowerSaveTrustlist(uids: Array\<number>, isAllowed: boolean, callback: AsyncCallback\<void>): void
1320
1321Sets whether to add the application specified by a given UID to the power-saving allowlist. This API uses an asynchronous callback to return the result.
1322
1323**System API**: This is a system API.
1324
1325**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1326
1327**System capability**: SystemCapability.Communication.NetManager.Core
1328
1329**Parameters**
1330
1331| Name   | Type                          | Mandatory| Description                                          |
1332| --------- | ------------------------------ | ---- | ---------------------------------------------- |
1333| uids      | Array\<number>                 | Yes  | Unique ID of the application.                                |
1334| isAllowed | boolean                        | Yes  | Whether to add the application to the allowlist.                                |
1335| callback  | callback: AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
1336
1337**Error codes**
1338
1339| ID| Error Message                                    |
1340| --------- | -------------------------------------------- |
1341| 201       | Permission denied.                           |
1342| 202       | Non-system applications use system APIs.     |
1343| 401       | Parameter error.                             |
1344| 2100001   | Invalid parameter value.                     |
1345| 2100002   | Failed to connect to the service.            |
1346| 2100003   | System internal error.                       |
1347
1348**Example**
1349
1350```ts
1351import { BusinessError } from '@kit.BasicServicesKit';
1352
1353policy.setPowerSaveTrustlist([11111, 22222], true, (error: BusinessError) => {
1354  console.log(JSON.stringify(error));
1355});
1356```
1357
1358## policy.setPowerSaveTrustlist<sup>10+</sup>
1359
1360setPowerSaveTrustlist(uids: Array\<number>, isAllowed: boolean): Promise\<void>;
1361
1362Sets whether to add the application specified by a given UID to the power-saving allowlist. This API uses a promise to return the result.
1363
1364**System API**: This is a system API.
1365
1366**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1367
1368**System capability**: SystemCapability.Communication.NetManager.Core
1369
1370**Parameters**
1371
1372| Name   | Type          | Mandatory| Description          |
1373| --------- | -------------- | ---- | -------------- |
1374| uids      | Array\<number> | Yes  | Unique ID of the application.|
1375| isAllowed | boolean        | Yes  | Whether to add the application to the allowlist.|
1376
1377**Return value**
1378
1379| Type          | Description                                                             |
1380| -------------- | ----------------------------------------------------------------- |
1381| Promise\<void> | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
1382
1383**Error codes**
1384
1385| ID| Error Message                                    |
1386| --------- | -------------------------------------------- |
1387| 201       | Permission denied.                           |
1388| 202       | Non-system applications use system APIs.     |
1389| 401       | Parameter error.                             |
1390| 2100001   | Invalid parameter value.                     |
1391| 2100002   | Failed to connect to the service.            |
1392| 2100003   | System internal error.                       |
1393
1394**Example**
1395
1396```ts
1397import { BusinessError } from '@kit.BasicServicesKit';
1398
1399policy
1400  .setPowerSaveTrustlist([11111, 22222], true)
1401  .then(() => {
1402    console.log('setPowerSaveTrustlist success');
1403  })
1404  .catch((error: BusinessError) => {
1405    console.log(JSON.stringify(error));
1406  });
1407```
1408
1409## policy.getPowerSaveTrustlist<sup>10+</sup>
1410
1411getPowerSaveTrustlist(callback: AsyncCallback\<Array\<number>>): void
1412
1413Obtains the UID array of applications that are on the power-saving allowlist. This API uses an asynchronous callback to return the result.
1414
1415**System API**: This is a system API.
1416
1417**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1418
1419**System capability**: SystemCapability.Communication.NetManager.Core
1420
1421**Parameters**
1422
1423| Name  | Type                          | Mandatory| Description                    |
1424| -------- | ------------------------------ | ---- | ------------------------ |
1425| callback | AsyncCallback\<Array\<number>> | Yes  | Callback used to return the result.|
1426
1427**Error codes**
1428
1429| ID| Error Message                                    |
1430| --------- | -------------------------------------------- |
1431| 201       | Permission denied.                           |
1432| 202       | Non-system applications use system APIs.     |
1433| 401       | Parameter error.                             |
1434| 2100001   | Invalid parameter value.                     |
1435| 2100002   | Failed to connect to the service.            |
1436| 2100003   | System internal error.                       |
1437
1438**Example**
1439
1440```ts
1441import { BusinessError } from '@kit.BasicServicesKit';
1442
1443policy.getPowerSaveTrustlist((error: BusinessError, data: number[]) => {
1444  console.log(JSON.stringify(error));
1445  console.log(JSON.stringify(data));
1446});
1447```
1448
1449## policy.getPowerSaveTrustlist<sup>10+</sup>
1450
1451getPowerSaveTrustlist(): Promise\<Array\<number>>;
1452
1453Obtains the UID array of applications that are on the device idle allowlist. This API uses a promise to return the result.
1454
1455**System API**: This is a system API.
1456
1457**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1458
1459**System capability**: SystemCapability.Communication.NetManager.Core
1460
1461**Return value**
1462
1463| Type                    | Description                         |
1464| ------------------------ | ----------------------------- |
1465| Promise\<Array\<number>> | Promise used to return the result.|
1466
1467**Error codes**
1468
1469| ID| Error Message                                    |
1470| --------- | -------------------------------------------- |
1471| 201       | Permission denied.                           |
1472| 202       | Non-system applications use system APIs.     |
1473| 401       | Parameter error.                             |
1474| 2100002   | Failed to connect to the service.            |
1475| 2100003   | System internal error.                       |
1476
1477**Example**
1478
1479```ts
1480import { BusinessError } from '@kit.BasicServicesKit';
1481
1482policy
1483  .getPowerSaveTrustlist()
1484  .then((data: number[]) => {
1485    console.log(JSON.stringify(data));
1486  })
1487  .catch((error: BusinessError) => {
1488    console.log(JSON.stringify(error));
1489  });
1490```
1491
1492## policy.setNetworkAccessPolicy<sup>12+</sup>
1493
1494setNetworkAccessPolicy(uid: number, policy: NetworkAccessPolicy, isReconfirmed?: boolean): Promise<void>
1495
1496Specifies whether an application with the specified UID can access the network. This API uses a promise to return the result.
1497
1498**System API**: This is a system API.
1499
1500**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1501
1502**System capability**: SystemCapability.Communication.NetManager.Core
1503
1504**Parameters**
1505
1506| Name        | Type                                          | Mandatory| Description                                                                         |
1507| ------------- | ---------------------------------------------- | ---- | ---------------------------------------------------------------------------- |
1508| uid           | number                                         | Yes  | Unique ID of the application.                                                               |
1509| policy        | [NetworkAccessPolicy](#networkaccesspolicy12)  | Yes  | Network policy.                                                                     |
1510| isReconfirmed | boolean                                        | No  | Whether reconfirmation is required. The value **true** indicates that reconfirmation is not required and no dialog box is displayed. The value **false** indicates that reconfirmation is required and a dialog box is displayed when the application accesses the network. The default value is **false**. |
1511
1512**Return value**
1513
1514| Type          | Description                                                         |
1515| -------------- | ------------------------------------------------------------ |
1516| Promise\<void> | Promise used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
1517
1518**Error codes**
1519
1520| ID| Error Message                                    |
1521| --------- | -------------------------------------------- |
1522| 201       | Permission denied.                           |
1523| 202       | Non-system applications use system APIs.     |
1524| 401       | Parameter error.                             |
1525| 2100001   | Invalid parameter value.                     |
1526| 2100002   | Failed to connect to the service.            |
1527| 2100003   | System internal error.                       |
1528
1529**Example**
1530
1531```ts
1532import { BusinessError } from '@kit.BasicServicesKit';
1533
1534let accessPolicy: policy.NetworkAccessPolicy = {
1535  allowWiFi: false,
1536  allowCellular: true,
1537}
1538policy
1539  .setNetworkAccessPolicy(11111, accessPolicy)
1540  .then(() => {
1541    console.log('setNetworkAccessPolicy success');
1542  })
1543  .catch((error: BusinessError) => {
1544    console.error(JSON.stringify(error));
1545  });
1546```
1547
1548## policy.getNetworkAccessPolicy<sup>12+</sup>
1549
1550getNetworkAccessPolicy(uid: number): Promise<NetworkAccessPolicy>
1551
1552Checks whether an application with the specified UID can access the network. This API uses a promise to return the result.
1553
1554**System API**: This is a system API.
1555
1556**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1557
1558**System capability**: SystemCapability.Communication.NetManager.Core
1559
1560**Parameters**
1561
1562| Name| Type  | Mandatory| Description          |
1563| ------ | ------ | ---- | -------------- |
1564| uid    | number | Yes  | Unique ID of the application.|
1565
1566**Return value**
1567
1568| Type                                                   | Description                         |
1569| ------------------------------------------------------- | ----------------------------- |
1570| Promise\<[NetworkAccessPolicy](#networkaccesspolicy12)> | Promise used to return the result.|
1571
1572**Error codes**
1573
1574| ID| Error Message                                    |
1575| --------- | -------------------------------------------- |
1576| 201       | Permission denied.                           |
1577| 202       | Non-system applications use system APIs.     |
1578| 401       | Parameter error.                             |
1579| 2100001   | Invalid parameter value.                     |
1580| 2100002   | Failed to connect to the service.            |
1581| 2100003   | System internal error.                       |
1582
1583**Example**
1584
1585```ts
1586import { BusinessError } from '@kit.BasicServicesKit';
1587
1588policy
1589  .getNetworkAccessPolicy(11111)
1590  .then((data: policy.NetworkAccessPolicy) => {
1591    console.log(JSON.stringify(data));
1592  })
1593  .catch((error: BusinessError) => {
1594    console.error(JSON.stringify(error));
1595  });
1596```
1597
1598## policy.getNetworkAccessPolicy<sup>12+</sup>
1599
1600getNetworkAccessPolicy(): Promise<UidNetworkAccessPolicy>
1601
1602Checks whether all applications of the current user can access the network. This API uses a promise to return the result.
1603
1604**System API**: This is a system API.
1605
1606**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1607
1608**System capability**: SystemCapability.Communication.NetManager.Core
1609
1610**Return value**
1611
1612| Type                                                         | Description                       |
1613| ------------------------------------------------------------- | --------------------------- |
1614| Promise\<[UidNetworkAccessPolicy](#uidnetworkaccesspolicy12)> | Promise used to return the result.|
1615
1616**Error codes**
1617
1618| ID| Error Message                                    |
1619| --------- | -------------------------------------------- |
1620| 201       | Permission denied.                           |
1621| 202       | Non-system applications use system APIs.     |
1622| 2100002   | Failed to connect to the service.            |
1623| 2100003   | System internal error.                       |
1624
1625**Example**
1626
1627```ts
1628import { BusinessError } from '@kit.BasicServicesKit';
1629
1630policy
1631  .getNetworkAccessPolicy()
1632  .then((data: policy.UidNetworkAccessPolicy) => {
1633    let keyMap: Map<string, object> = new Map<string, object>(Object.entries(data));
1634    let uid:number = 0;
1635    let allowWiFi: string = "";
1636    let allowCellular: string = "";
1637
1638    keyMap.forEach((value:object, key:string) => {
1639      let valueMap: Map<string, string> = new Map<string, string>(Object.entries(value));
1640      uid = Number.parseInt(key);
1641      valueMap.forEach((value:string, key:string)=>{
1642        if (key == "allowWiFi") {
1643          allowWiFi = value;
1644        }
1645        if (key == "allowCellular") {
1646          allowCellular = value;
1647        }
1648      })
1649    })
1650    console.log(JSON.stringify(data));
1651  })
1652  .catch((error: BusinessError) => {
1653    console.error(JSON.stringify(error));
1654  });
1655```
1656
1657## policy.on
1658
1659Represents the handle to a network policy.
1660
1661### on('netUidPolicyChange')<sup>10+</sup>
1662
1663on(type: "netUidPolicyChange", callback: Callback\<NetUidPolicyInfo\>): void
1664
1665Subscribes to policy changes. This API uses an asynchronous callback to return the result.
1666
1667**System API**: This is a system API.
1668
1669**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1670
1671**System capability**: SystemCapability.Communication.NetManager.Core
1672
1673**Parameters**
1674
1675| Name  | Type                                                               | Mandatory| Description                                  |
1676| -------- | ------------------------------------------------------------------- | ---- | -------------------------------------- |
1677| type     | string                                                              | Yes  | Event type. The value **netUidPolicyChange** indicates a policy change event.                 |
1678| callback | Callback\<[NetUidPolicyInfo](#netuidpolicyinfo11)> | Yes  | Callback used to return the result. It is called when the network policy changes.|
1679
1680**Error codes**
1681
1682| ID| Error Message                                    |
1683| --------- | -------------------------------------------- |
1684| 201       | Permission denied.                           |
1685| 202       | Non-system applications use system APIs.     |
1686| 401       | Parameter error.                             |
1687| 2100001   | Invalid parameter value.                     |
1688| 2100002   | Failed to connect to the service.            |
1689| 2100003   | System internal error.                       |
1690
1691**Example**
1692
1693```ts
1694import { policy } from '@kit.NetworkKit';
1695
1696interface Data {
1697  uid: number,
1698  policy: policy.NetUidPolicy
1699}
1700
1701try {
1702  policy.on('netUidPolicyChange', (data: Data) => {
1703    console.log('on netUidPolicyChange data: ' + JSON.stringify(data));
1704  });
1705} catch(err) {
1706  console.error('on netUidPolicyChange error: ' + JSON.stringify(err));
1707}
1708```
1709
1710### off('netUidPolicyChange')<sup>10+</sup>
1711
1712off(type: "netUidPolicyChange", callback?: Callback\<NetUidPolicyInfo\>): void
1713
1714Unsubscribes from policy changes. This API uses an asynchronous callback to return the result.
1715
1716**System API**: This is a system API.
1717
1718**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1719
1720**System capability**: SystemCapability.Communication.NetManager.Core
1721
1722**Parameters**
1723
1724| Name  | Type                                                               | Mandatory| Description                                  |
1725| -------- | ------------------------------------------------------------------- | ---- | -------------------------------------- |
1726| type     | string                                                              | Yes  | Event type. The value **netUidPolicyChange** indicates a policy change event.                 |
1727| callback | Callback\<[NetUidPolicyInfo](#netuidpolicyinfo11)> | No  | Callback used to return the result. It is called when the network policy changes.|
1728
1729**Error codes**
1730
1731| ID| Error Message                                    |
1732| --------- | -------------------------------------------- |
1733| 201       | Permission denied.                           |
1734| 202       | Non-system applications use system APIs.     |
1735| 401       | Parameter error.                             |
1736| 2100001   | Invalid parameter value.                     |
1737| 2100002   | Failed to connect to the service.            |
1738| 2100003   | System internal error.                       |
1739
1740**Example**
1741
1742```ts
1743import { policy } from '@kit.NetworkKit';
1744
1745interface Data {
1746  uid: number,
1747  policy: policy.NetUidPolicy
1748}
1749
1750try {
1751  policy.on('netUidPolicyChange', (data: Data) => {
1752    console.log('on netUidPolicyChange data: ' + JSON.stringify(data));
1753  });
1754} catch(err) {
1755  console.error('on netUidPolicyChange error: ' + JSON.stringify(err));
1756}
1757
1758try {
1759  policy.off('netUidPolicyChange', (data: Data) => {
1760    console.log('off netUidPolicyChange data: ' + JSON.stringify(data));
1761  });
1762} catch(err) {
1763  console.error('off netUidPolicyChange error: ' + JSON.stringify(err));
1764}
1765```
1766
1767### on('netUidRuleChange')<sup>10+</sup>
1768
1769on(type: "netUidRuleChange", callback: Callback\<NetUidRuleInfo\>): void
1770
1771Subscribes to rule changes. This API uses an asynchronous callback to return the result.
1772
1773**System API**: This is a system API.
1774
1775**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1776
1777**System capability**: SystemCapability.Communication.NetManager.Core
1778
1779**Parameters**
1780
1781| Name  | Type                                                         | Mandatory| Description                                  |
1782| -------- | ------------------------------------------------------------- | ---- | -------------------------------------- |
1783| type     | string                                                        | Yes  | Event type. The value **netUidRuleChange** indicates a rule change event.                   |
1784| callback | Callback\<[NetUidRuleInfo](#netuidruleinfo11)> | Yes  | Callback used to return the result. It is called when the rule changes.|
1785
1786**Error codes**
1787
1788| ID| Error Message                                    |
1789| --------- | -------------------------------------------- |
1790| 201       | Permission denied.                           |
1791| 202       | Non-system applications use system APIs.     |
1792| 401       | Parameter error.                             |
1793| 2100001   | Invalid parameter value.                     |
1794| 2100002   | Failed to connect to the service.            |
1795| 2100003   | System internal error.                       |
1796
1797**Example**
1798
1799```ts
1800import { policy } from '@kit.NetworkKit';
1801
1802interface Data {
1803  uid: number,
1804  rule: policy.NetUidRule
1805}
1806
1807try {
1808  policy.on('netUidRuleChange', (data: Data) => {
1809    console.log('on netUidRuleChange data: ' + JSON.stringify(data));
1810  });
1811} catch(err) {
1812  console.error('on netUidRuleChange error: ' + JSON.stringify(err));
1813}
1814```
1815
1816### off('netUidRuleChange')<sup>10+</sup>
1817
1818off(type: "netUidRuleChange", callback?: Callback\<NetUidRuleInfo\>): void
1819
1820Unsubscribes from rule changes. This API uses an asynchronous callback to return the result.
1821
1822**System API**: This is a system API.
1823
1824**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1825
1826**System capability**: SystemCapability.Communication.NetManager.Core
1827
1828**Parameters**
1829
1830| Name  | Type                                                         | Mandatory| Description                                  |
1831| -------- | ------------------------------------------------------------- | ---- | -------------------------------------- |
1832| type     | string                                                        | Yes  | Event type. The value **netUidRuleChange** indicates a rule change event.                   |
1833| callback | Callback\<[NetUidRuleInfo](#netuidruleinfo11)> | No  | Callback used to return the result. It is called when the rule changes.|
1834
1835**Error codes**
1836
1837| ID| Error Message                                    |
1838| --------- | -------------------------------------------- |
1839| 201       | Permission denied.                           |
1840| 202       | Non-system applications use system APIs.     |
1841| 401       | Parameter error.                             |
1842| 2100001   | Invalid parameter value.                     |
1843| 2100002   | Failed to connect to the service.            |
1844| 2100003   | System internal error.                       |
1845
1846**Example**
1847
1848```ts
1849import { policy } from '@kit.NetworkKit';
1850
1851interface Data {
1852  uid: number,
1853  rule: policy.NetUidRule
1854}
1855
1856try {
1857  policy.on('netUidRuleChange', (data: Data) => {
1858    console.log('on netUidRuleChange data: ' + JSON.stringify(data));
1859  });
1860} catch(err) {
1861  console.error('on netUidRuleChange error: ' + JSON.stringify(err));
1862}
1863
1864try {
1865  policy.off('netUidRuleChange', (data: Data) => {
1866    console.log('off netUidRuleChange data: ' + JSON.stringify(data));
1867  });
1868} catch(err) {
1869  console.error('off netUidRuleChange error: ' + JSON.stringify(err));
1870}
1871```
1872
1873### on('netMeteredIfacesChange')<sup>10+</sup>
1874
1875on(type: "netMeteredIfacesChange", callback: Callback\<Array\<string>>): void
1876
1877Subscribes to metered **iface** changes. This API uses an asynchronous callback to return the result.
1878
1879**System API**: This is a system API.
1880
1881**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1882
1883**System capability**: SystemCapability.Communication.NetManager.Core
1884
1885**Parameters**
1886
1887| Name  | Type                     | Mandatory| Description                                     |
1888| -------- | ------------------------- | ---- | ----------------------------------------- |
1889| type     | string                    | Yes  | Event type. The value **netMeteredIfacesChange** indicates a metered **iface** change event.                |
1890| callback | Callback\<Array\<string>> | Yes  | Callback used to return the result. It is called when the registered metered **iface** changes.|
1891
1892**Error codes**
1893
1894| ID| Error Message                                    |
1895| --------- | -------------------------------------------- |
1896| 201       | Permission denied.                           |
1897| 202       | Non-system applications use system APIs.     |
1898| 401       | Parameter error.                             |
1899| 2100001   | Invalid parameter value.                     |
1900| 2100002   | Failed to connect to the service.            |
1901| 2100003   | System internal error.                       |
1902
1903**Example**
1904
1905```ts
1906import { policy } from '@kit.NetworkKit';
1907
1908try {
1909  policy.on('netMeteredIfacesChange', (data: string[]) => {
1910    console.log('on netMeteredIfacesChange data: ' + JSON.stringify(data));
1911  });
1912} catch(err) {
1913  console.error('on netMeteredIfacesChange error: ' + JSON.stringify(err));
1914}
1915```
1916
1917### off('netMeteredIfacesChange')<sup>10+</sup>
1918
1919off(type: "netMeteredIfacesChange", callback?: Callback\<Array\<string>>): void
1920
1921Unsubscribes from metered **iface** changes. This API uses an asynchronous callback to return the result.
1922
1923**System API**: This is a system API.
1924
1925**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1926
1927**System capability**: SystemCapability.Communication.NetManager.Core
1928
1929**Parameters**
1930
1931| Name  | Type                     | Mandatory| Description                                     |
1932| -------- | ------------------------- | ---- | ----------------------------------------- |
1933| type     | string                    | Yes  | Event type. The value **netMeteredIfacesChange** indicates a metered **iface** change event.                |
1934| callback | Callback\<Array\<string>> | No  | Callback used to return the result. It is called when the registered metered **iface** changes.|
1935
1936**Error codes**
1937
1938| ID| Error Message                                    |
1939| --------- | -------------------------------------------- |
1940| 201       | Permission denied.                           |
1941| 202       | Non-system applications use system APIs.     |
1942| 401       | Parameter error.                             |
1943| 2100001   | Invalid parameter value.                     |
1944| 2100002   | Failed to connect to the service.            |
1945| 2100003   | System internal error.                       |
1946
1947**Example**
1948
1949```ts
1950import { policy } from '@kit.NetworkKit';
1951
1952try {
1953  policy.on('netMeteredIfacesChange', (data: string[]) => {
1954    console.log('on netMeteredIfacesChange data: ' + JSON.stringify(data));
1955  });
1956} catch(err) {
1957  console.error('on netMeteredIfacesChange error: ' + JSON.stringify(err));
1958}
1959
1960try {
1961  policy.off('netMeteredIfacesChange', (data: string[]) => {
1962    console.log('off netMeteredIfacesChange data: ' + JSON.stringify(data));
1963  });
1964} catch(err) {
1965  console.error('off netMeteredIfacesChange error: ' + JSON.stringify(err));
1966}
1967```
1968
1969### on('netQuotaPolicyChange')<sup>10+</sup>
1970
1971on(type: "netQuotaPolicyChange", callback: Callback\<Array\<NetQuotaPolicy>>): void
1972
1973Subscribes to network quota policy changes. This API uses an asynchronous callback to return the result.
1974
1975**System API**: This is a system API.
1976
1977**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
1978
1979**System capability**: SystemCapability.Communication.NetManager.Core
1980
1981**Parameters**
1982
1983| Name  | Type                                                  | Mandatory| Description                                      |
1984| -------- | ------------------------------------------------------ | ---- | ------------------------------------------ |
1985| type     | string                                                 | Yes  | Event type. The value **netQuotaPolicyChange** indicates a network quota policy change event.                |
1986| callback | Callback\<Array\<[NetQuotaPolicy](#netquotapolicy10)>> | Yes  | Callback used to return the result. It is called when the registered network quota policy changes.|
1987
1988**Error codes**
1989
1990| ID| Error Message                                    |
1991| --------- | -------------------------------------------- |
1992| 201       | Permission denied.                           |
1993| 202       | Non-system applications use system APIs.     |
1994| 401       | Parameter error.                             |
1995| 2100001   | Invalid parameter value.                     |
1996| 2100002   | Failed to connect to the service.            |
1997| 2100003   | System internal error.                       |
1998
1999**Example**
2000
2001```ts
2002import { policy } from '@kit.NetworkKit';
2003
2004interface Data {
2005  uid: number,
2006  policy: policy.NetUidPolicy
2007}
2008
2009try {
2010  policy.on('netQuotaPolicyChange', (data: policy.NetQuotaPolicy[]) => {
2011    console.log('on netQuotaPolicyChange data: ' + JSON.stringify(data));
2012  });
2013} catch(err) {
2014  console.error('on netQuotaPolicyChange error: ' + JSON.stringify(err));
2015}
2016```
2017
2018### off('netQuotaPolicyChange')<sup>10+</sup>
2019
2020off(type: "netQuotaPolicyChange", callback?: Callback\<Array\<NetQuotaPolicy>>): void
2021
2022Unsubscribes from network quota policy changes. This API uses an asynchronous callback to return the result.
2023
2024**System API**: This is a system API.
2025
2026**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
2027
2028**System capability**: SystemCapability.Communication.NetManager.Core
2029
2030**Parameters**
2031
2032| Name  | Type                                                  | Mandatory| Description                                      |
2033| -------- | ------------------------------------------------------ | ---- | ------------------------------------------ |
2034| type     | string                                                 | Yes  | Event type. The value **netQuotaPolicyChange** indicates a network quota policy change event.                |
2035| callback | Callback\<Array\<[NetQuotaPolicy](#netquotapolicy10)>> | No  | Callback used to return the result. It is called when the registered network quota policy changes.|
2036
2037**Error codes**
2038
2039| ID| Error Message                                    |
2040| --------- | -------------------------------------------- |
2041| 201       | Permission denied.                           |
2042| 202       | Non-system applications use system APIs.     |
2043| 401       | Parameter error.                             |
2044| 2100001   | Invalid parameter value.                     |
2045| 2100002   | Failed to connect to the service.            |
2046| 2100003   | System internal error.                       |
2047
2048**Example**
2049
2050```ts
2051import { policy } from '@kit.NetworkKit';
2052
2053try {
2054  policy.on('netQuotaPolicyChange', (data: Array<policy.NetQuotaPolicy>) => {
2055    console.log('on netQuotaPolicyChange data: ' + JSON.stringify(data));
2056  });
2057} catch(err) {
2058  console.error('on netQuotaPolicyChange error: ' + JSON.stringify(err));
2059}
2060
2061try {
2062  policy.off('netQuotaPolicyChange', (data: Array<policy.NetQuotaPolicy>) => {
2063    console.log('off netQuotaPolicyChange data: ' + JSON.stringify(data));
2064  });
2065} catch(err) {
2066  console.error('off netQuotaPolicyChange error: ' + JSON.stringify(err));
2067}
2068```
2069
2070### on('netBackgroundPolicyChange')<sup>10+</sup>
2071
2072on(type: "netBackgroundPolicyChange", callback: Callback\<boolean>): void
2073
2074Subscribes to background network policy changes. This API uses an asynchronous callback to return the result.
2075
2076**System API**: This is a system API.
2077
2078**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
2079
2080**System capability**: SystemCapability.Communication.NetManager.Core
2081
2082**Parameters**
2083
2084| Name  | Type              | Mandatory| Description                                      |
2085| -------- | ------------------ | ---- | ------------------------------------------ |
2086| type     | string             | Yes  | Event type. The value **netBackgroundPolicyChange** indicates a background network policy change event.                |
2087| callback | Callback\<boolean> | Yes  | Callback used to return the result. It is called when the registered background network policy changes.|
2088
2089**Error codes**
2090
2091| ID| Error Message                                    |
2092| --------- | -------------------------------------------- |
2093| 201       | Permission denied.                           |
2094| 202       | Non-system applications use system APIs.     |
2095| 401       | Parameter error.                             |
2096| 2100001   | Invalid parameter value.                     |
2097| 2100002   | Failed to connect to the service.            |
2098| 2100003   | System internal error.                       |
2099
2100**Example**
2101
2102```ts
2103import { policy } from '@kit.NetworkKit';
2104
2105try {
2106  policy.on('netBackgroundPolicyChange', (data: boolean) => {
2107    console.log('on netBackgroundPolicyChange data: ' + JSON.stringify(data));
2108  });
2109} catch(err) {
2110  console.error('on netBackgroundPolicyChange error: ' + JSON.stringify(err));
2111}
2112```
2113
2114### off('netBackgroundPolicyChange')<sup>10+</sup>
2115
2116off(type: "netBackgroundPolicyChange", callback?: Callback\<boolean>): void
2117
2118Unsubscribes from background network policy changes. This API uses an asynchronous callback to return the result.
2119
2120**System API**: This is a system API.
2121
2122**Required permission**: ohos.permission.MANAGE_NET_STRATEGY
2123
2124**System capability**: SystemCapability.Communication.NetManager.Core
2125
2126**Parameters**
2127
2128| Name  | Type              | Mandatory| Description                                      |
2129| -------- | ------------------ | ---- | ------------------------------------------ |
2130| type     | string             | Yes  | Event type. The value **netBackgroundPolicyChange** indicates a background network policy change event.                |
2131| callback | Callback\<boolean> | No  | Callback used to return the result. It is called when the registered background network policy changes.|
2132
2133**Error codes**
2134
2135| ID| Error Message                                    |
2136| --------- | -------------------------------------------- |
2137| 201       | Permission denied.                           |
2138| 202       | Non-system applications use system APIs.     |
2139| 401       | Parameter error.                             |
2140| 2100001   | Invalid parameter value.                     |
2141| 2100002   | Failed to connect to the service.            |
2142| 2100003   | System internal error.                       |
2143
2144**Example**
2145
2146```ts
2147import { policy } from '@kit.NetworkKit';
2148
2149try {
2150  policy.on('netBackgroundPolicyChange', (data: boolean) => {
2151    console.log('on netBackgroundPolicyChange data: ' + JSON.stringify(data));
2152  });
2153} catch(err) {
2154  console.error('on netBackgroundPolicyChange error: ' + JSON.stringify(err));
2155}
2156
2157try {
2158  policy.off('netBackgroundPolicyChange', (data: boolean) => {
2159    console.log('off netBackgroundPolicyChange data: ' + JSON.stringify(data));
2160  });
2161} catch(err) {
2162  console.error('off netBackgroundPolicyChange error: ' + JSON.stringify(err));
2163}
2164```
2165
2166## NetBackgroundPolicy<sup>10+</sup>
2167
2168Enumerates the background network policies.
2169
2170**System API**: This is a system API.
2171
2172**System capability**: SystemCapability.Communication.NetManager.Core
2173
2174| Name                           | Value | Description                                      |
2175| ------------------------------- | --- | ------------------------------------------ |
2176| NET_BACKGROUND_POLICY_NONE      | 0   | No background network policy is specified. This is the default value.                                  |
2177| NET_BACKGROUND_POLICY_ENABLE    | 1   | Background applications are allowed to access a metered network.              |
2178| NET_BACKGROUND_POLICY_DISABLE   | 2   | Applications running in the background are not allowed to access a metered network.            |
2179| NET_BACKGROUND_POLICY_TRUSTLIST | 3   | Only applications on the allowlist are allowed to access metered networks when they are running in the background.|
2180
2181## NetQuotaPolicy<sup>10+</sup>
2182
2183Defines the quota policy for the specified network.
2184
2185**System API**: This is a system API.
2186
2187**System capability**: SystemCapability.Communication.NetManager.Core
2188
2189| Name            | Type                                   | Mandatory| Description                            |
2190| ---------------- | --------------------------------------- | ---- | -------------------------------- |
2191| networkMatchRule | [NetworkMatchRule](#networkmatchrule10) | Yes  | Network for which the quota policy is set.|
2192| quotaPolicy      | [QuotaPolicy](#quotapolicy10)           | Yes  | Network quota policy.              |
2193
2194## NetworkMatchRule<sup>10+</sup>
2195
2196Defines the network for which the quota policy is set.
2197
2198**System API**: This is a system API.
2199
2200**System capability**: SystemCapability.Communication.NetManager.Core
2201
2202| Name    | Type                                                | Mandatory| Description                                                                        |
2203| -------- | ---------------------------------------------------- | ---- | ---------------------------------------------------------------------------- |
2204| netType  | [NetBearType](js-apis-net-connection.md#netbeartype) | Yes  | Network type.                                                                  |
2205| simId    | string                                               | Yes  | Identifier of the SIM card on the metered cellular network. It is not used for Wi-Fi networks.                    |
2206| identity | string                                               | Yes  | ID of the SIM card on the metered cellular network. It is used for Wi-Fi networks. It is used together with **iccid**.|
2207
2208## QuotaPolicy<sup>10+</sup>
2209
2210Defines the network quota policy.
2211
2212**System API**: This is a system API.
2213
2214**System capability**: SystemCapability.Communication.NetManager.Core
2215
2216| Name             | Type                           | Mandatory| Description                                                 |
2217| ----------------- |-------------------------------| ---- |-----------------------------------------------------|
2218| periodDuration    | string                        | Yes  | Metering period for the quota limit. **D1**, **M1**, and **Y1** indicate one day, one month, and one year, respectively. If the specified metering period is exceeded, the quota is not limited.|
2219| warningBytes      | number                        | Yes  | Data volume threshold for generating an alarm.                                         |
2220| limitBytes        | number                        | Yes  | Data volume quota.                                           |
2221| metered           | boolean                       | Yes  | Whether the network is a metered network.                                           |
2222| limitAction       | [LimitAction](#limitaction10) | Yes  | Action to take when the data volume quota is reached.                                        |
2223| lastWarningRemind | number                        | No  | Last time when an alarm was generated. Default value: **-1**                                 |
2224| lastLimitRemind   | number                        | No  | Last time when the quota was exhausted. Default value: **-1**                                       |
2225
2226## LimitAction<sup>10+</sup>
2227
2228Enumerates the actions that can be taken when the data volume quota is reached.
2229
2230**System API**: This is a system API.
2231
2232**System capability**: SystemCapability.Communication.NetManager.Core
2233
2234| Name                        | Value | Description                              |
2235| ---------------------------- | --- | ---------------------------------- |
2236| LIMIT_ACTION_NONE            | -1  | No action is taken. This is the default value.                          |
2237| LIMIT_ACTION_ACCESS_DISABLED | 0   | Internet access is disabled.|
2238| LIMIT_ACTION_ALERT_ONLY      | 1   | An alarm is generated when the quota limit is reached.|
2239
2240## NetUidRule<sup>10+</sup>
2241
2242Enumerates the metered network rules.
2243
2244**System API**: This is a system API.
2245
2246**System capability**: SystemCapability.Communication.NetManager.Core
2247
2248| Name                             | Value    | Description                |
2249| --------------------------------- | ------ | -------------------- |
2250| NET_RULE_NONE                     | 0      | Default rule.            |
2251| NET_RULE_ALLOW_METERED_FOREGROUND | 1 << 0 | Applications running in the foreground are allowed to access a metered network.|
2252| NET_RULE_ALLOW_METERED            | 1 << 1 | Applications are allowed to access a metered network.    |
2253| NET_RULE_REJECT_METERED           | 1 << 2 | Applications are not allowed to access a metered network.    |
2254| NET_RULE_ALLOW_ALL                | 1 << 5 | Applications are allowed to access all networks (metered or non-metered).    |
2255| NET_RULE_REJECT_ALL               | 1 << 6 | Applications are not allowed to access any networks (metered or non-metered).    |
2256
2257## NetUidRuleInfo<sup>11+</sup>
2258
2259Defines a unique network ID.
2260
2261**System API**: This is a system API.
2262
2263**System capability**: SystemCapability.Communication.NetManager.Core
2264
2265| Name             | Type                          | Mandatory| Description                                     |
2266| ----------------- | ----------------------------- | ---- | ----------------------------------------- |
2267| uid               | number                        | Yes  | Traffic alarm threshold. The default value is **DATA_USAGE_UNKNOWN**.|
2268| rule              | [NetUidRule](#netuidrule10)   | Yes  | Rule that specifies whether the application specified by a given UID is allowed to access a metered or non-metered network.    |
2269
2270## NetUidPolicyInfo<sup>11+</sup>
2271
2272Defines the network policy information for an application.
2273
2274**System API**: This is a system API.
2275
2276**System capability**: SystemCapability.Communication.NetManager.Core
2277
2278| Name             | Type                           | Mandatory| Description                                   |
2279| ----------------- | ------------------------------- | ---- | -------------------------------------- |
2280| uid               | number                          | Yes  | Traffic alarm threshold. The default value is **DATA_USAGE_UNKNOWN**.|
2281| policy            | [NetUidPolicy](#netuidpolicy10) | Yes  | Policy that specifies whether the application specified by a given UID is allowed to access the network when running in the background.   |
2282
2283## RemindType<sup>10+</sup>
2284
2285Enumerates the reminder types.
2286
2287**System API**: This is a system API.
2288
2289**System capability**: SystemCapability.Communication.NetManager.Core
2290
2291| Name               | Value | Description    |
2292| ------------------- | --- | -------- |
2293| REMIND_TYPE_WARNING | 1   | Warning.|
2294| REMIND_TYPE_LIMIT   | 2   | Limit.|
2295
2296## NetUidPolicy<sup>10+</sup>
2297
2298Enumerates network access policies for the application.
2299
2300**System API**: This is a system API.
2301
2302**System capability**: SystemCapability.Communication.NetManager.Core
2303
2304| Name                                | Value    | Description                      |
2305| ------------------------------------ | ------ | -------------------------- |
2306| NET_POLICY_NONE                      | 0      | Default network policy.              |
2307| NET_POLICY_ALLOW_METERED_BACKGROUND  | 1 << 0 | Background applications are allowed to access a metered network.|
2308| NET_POLICY_REJECT_METERED_BACKGROUND | 1 << 1 | Applications running in the background are not allowed to access a metered network.|
2309
2310## NetworkAccessPolicy<sup>12+</sup>
2311
2312Network access policy.
2313
2314**System API**: This is a system API.
2315
2316**System capability**: SystemCapability.Communication.NetManager.Core
2317
2318| Name             | Type      | Mandatory| Description                         |
2319| ----------------- | --------- | ---- | ----------------------------- |
2320| allowWiFi         | boolean   | Yes  | Wi-Fi access policy.|
2321| allowCellular     | boolean   | Yes  | Cellular network access policy.|
2322
2323## UidNetworkAccessPolicy<sup>12+</sup>
2324
2325Defines the network policy for an application with the specified UID.
2326
2327**System API**: This is a system API.
2328
2329**System capability**: SystemCapability.Communication.NetManager.Core
2330
2331| Name      | Type                                                        | Mandatory| Description                |
2332| --------- | -----------------------------------------------------------  | ---- | ------------------- |
2333| undefined | [uid: string]: [NetworkAccessPolicy](#networkaccesspolicy12) | No  | Network policy. The data type is key-value pair.     |
2334