1# @ohos.enterprise.networkManager (Network Management) 2 3The **networkManager** module provides APIs for network management of enterprise devices, including obtaining the device IP address and MAC address. 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> 9> - The APIs of this module can be used only in the stage model. 10> 11> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin). 12 13## Modules to Import 14 15```ts 16import networkManager from '@ohos.enterprise.networkManager'; 17``` 18 19## networkManager.getAllNetworkInterfaces 20 21getAllNetworkInterfaces(admin: Want, callback: AsyncCallback<Array<string>>): void 22 23Obtains all activated network ports through the specified device administrator application. This API uses an asynchronous callback to return the result. 24 25**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 26 27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 28 29**System API**: This is a system API. 30 31**Parameters** 32 33| Name | Type | Mandatory | Description | 34| -------- | ---------------------------------------- | ---- | ------------------------------- | 35| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 36| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is an array of network ports obtained. If the operation fails, **err** is an error object. | 37 38**Error codes** 39 40For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 41 42| ID| Error Message | 43| ------- | ---------------------------------------------------------------------------- | 44| 9200001 | The application is not an administrator application of the device. | 45| 9200002 | The administrator application does not have permission to manage the device.| 46 47**Example** 48 49```ts 50import Want from '@ohos.app.ability.Want'; 51let wantTemp: Want = { 52 bundleName: 'com.example.myapplication', 53 abilityName: 'EntryAbility', 54}; 55 56networkManager.getAllNetworkInterfaces(wantTemp, (err, result) => { 57 if (err) { 58 console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`); 59 return; 60 } 61 console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`); 62}); 63``` 64 65## networkManager.getAllNetworkInterfaces 66 67getAllNetworkInterfaces(admin: Want): Promise<Array<string>> 68 69Obtains all activated network ports through the specified device administrator application. This API uses a promise to return the result. 70 71**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 72 73**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 74 75**System API**: This is a system API. 76 77**Parameters** 78 79| Name | Type | Mandatory | Description | 80| ----- | ----------------------------------- | ---- | ------- | 81| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 82 83**Return value** 84 85| Type | Description | 86| --------------------- | ------------------------- | 87| Promise<Array<string>> | Promise used to return an array of network ports obtained. | 88 89**Error codes** 90 91For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 92 93| ID| Error Message | 94| ------- | ---------------------------------------------------------------------------- | 95| 9200001 | The application is not an administrator application of the device. | 96| 9200002 | The administrator application does not have permission to manage the device.| 97 98**Example** 99 100```ts 101import Want from '@ohos.app.ability.Want'; 102import { BusinessError } from '@ohos.base'; 103let wantTemp: Want = { 104 bundleName: 'com.example.myapplication', 105 abilityName: 'EntryAbility', 106}; 107 108networkManager.getAllNetworkInterfaces(wantTemp).then((result) => { 109 console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`); 110}).catch((err: BusinessError) => { 111 console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`); 112}); 113``` 114 115## networkManager.getIpAddress 116 117getIpAddress(admin: Want, networkInterface: string, callback: AsyncCallback<string>): void 118 119Obtains the device IP address based on the network port through the specified device administrator application. This API uses an asynchronous callback to return the result. 120 121**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 122 123**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 124 125**System API**: This is a system API. 126 127**Parameters** 128 129| Name | Type | Mandatory | Description | 130| -------- | ---------------------------------------- | ---- | ------------------------------- | 131| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 132| networkInterface | string | Yes | Network port. | 133| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the IP address obtained. If the operation fails, **err** is an error object. | 134 135**Error codes** 136 137For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 138 139| ID| Error Message | 140| ------- | ---------------------------------------------------------------------------- | 141| 9200001 | The application is not an administrator application of the device. | 142| 9200002 | The administrator application does not have permission to manage the device.| 143 144**Example** 145 146```ts 147import Want from '@ohos.app.ability.Want'; 148let wantTemp: Want = { 149 bundleName: 'com.example.myapplication', 150 abilityName: 'EntryAbility', 151}; 152 153networkManager.getIpAddress(wantTemp, 'eth0', (err, result) => { 154 if (err) { 155 console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`); 156 return; 157 } 158 console.info(`Succeeded in getting ip address, result : ${result}`); 159}); 160``` 161 162## networkManager.getIpAddress 163 164getIpAddress(admin: Want, networkInterface: string): Promise<string> 165 166Obtains the device IP address based on the network port through the specified device administrator application. This API uses a promise to return the result. 167 168**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 169 170**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 171 172**System API**: This is a system API. 173 174**Parameters** 175 176| Name | Type | Mandatory | Description | 177| ----- | ----------------------------------- | ---- | ------- | 178| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 179| networkInterface | string | Yes | Network port. | 180 181**Return value** 182 183| Type | Description | 184| --------------------- | ------------------------- | 185| Promise<string> | Promise used to return the device IP address obtained. | 186 187**Error codes** 188 189For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 190 191| ID| Error Message | 192| ------- | ---------------------------------------------------------------------------- | 193| 9200001 | The application is not an administrator application of the device. | 194| 9200002 | The administrator application does not have permission to manage the device.| 195 196**Example** 197 198```ts 199import Want from '@ohos.app.ability.Want'; 200import { BusinessError } from '@ohos.base'; 201let wantTemp: Want = { 202 bundleName: 'com.example.myapplication', 203 abilityName: 'EntryAbility', 204}; 205 206networkManager.getIpAddress(wantTemp, 'eth0').then((result) => { 207 console.info(`Succeeded in getting ip address, result : ${result}`); 208}).catch((err: BusinessError) => { 209 console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`); 210}); 211``` 212 213## networkManager.getMac 214 215getMac(admin: Want, networkInterface: string, callback: AsyncCallback<string>): void 216 217Obtains the device MAC address based on the network port through the specified device administrator application. This API uses an asynchronous callback to return the result. 218 219**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 220 221**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 222 223**System API**: This is a system API. 224 225**Parameters** 226 227| Name | Type | Mandatory | Description | 228| -------- | ---------------------------------------- | ---- | ------------------------------- | 229| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 230| networkInterface | string | Yes | Network port. | 231| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the MAC address obtained. If the operation fails, **err** is an error object. | 232 233**Error codes** 234 235For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 236 237| ID| Error Message | 238| ------- | ---------------------------------------------------------------------------- | 239| 9200001 | The application is not an administrator application of the device. | 240| 9200002 | The administrator application does not have permission to manage the device.| 241 242**Example** 243 244```ts 245import Want from '@ohos.app.ability.Want'; 246let wantTemp: Want = { 247 bundleName: 'com.example.myapplication', 248 abilityName: 'EntryAbility', 249}; 250 251networkManager.getMac(wantTemp, 'eth0', (err, result) => { 252 if (err) { 253 console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`); 254 return; 255 } 256 console.info(`Succeeded in getting mac, result : ${result}`); 257}); 258``` 259 260## networkManager.getMac 261 262getMac(admin: Want, networkInterface: string): Promise\<string> 263 264Obtains the device MAC address based on the network port through the specified device administrator application. This API uses a promise to return the result. 265 266**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 267 268**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 269 270**System API**: This is a system API. 271 272**Parameters** 273 274| Name | Type | Mandatory | Description | 275| ----- | ----------------------------------- | ---- | ------- | 276| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 277| networkInterface | string | Yes | Network port. | 278 279**Return value** 280 281| Type | Description | 282| --------------------- | ------------------------- | 283| Promise<string> | Promise used to return the device MAC address obtained. | 284 285**Error codes** 286 287For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 288 289| ID| Error Message | 290| ------- | ---------------------------------------------------------------------------- | 291| 9200001 | The application is not an administrator application of the device. | 292| 9200002 | The administrator application does not have permission to manage the device.| 293 294**Example** 295 296```ts 297import Want from '@ohos.app.ability.Want'; 298import { BusinessError } from '@ohos.base'; 299let wantTemp: Want = { 300 bundleName: 'com.example.myapplication', 301 abilityName: 'EntryAbility', 302}; 303 304networkManager.getMac(wantTemp, 'eth0').then((result) => { 305 console.info(`Succeeded in getting mac, result : ${result}`); 306}).catch((err: BusinessError) => { 307 console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`); 308}); 309``` 310 311## networkManager.isNetworkInterfaceDisabled 312 313isNetworkInterfaceDisabled(admin: Want, networkInterface: string, callback: AsyncCallback<boolean>): void 314 315Checks whether a network port is disabled through the specified device administrator application. This API uses an asynchronous callback to return the result. 316 317**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 318 319**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 320 321**System API**: This is a system API. 322 323**Parameters** 324 325| Name | Type | Mandatory | Description | 326| -------- | ---------------------------------------- | ---- | ------------------------------- | 327| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 328| networkInterface | string | Yes | Network port. | 329| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**, and **data** indicates whether the network port is disabled. The value **true** means the network port is disabled; and **false** means the opposite. If the operation fails, **err** is an error object. | 330 331**Error codes** 332 333For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 334 335| ID| Error Message | 336| ------- | ---------------------------------------------------------------------------- | 337| 9200001 | The application is not an administrator application of the device. | 338| 9200002 | The administrator application does not have permission to manage the device.| 339 340**Example** 341 342```ts 343import Want from '@ohos.app.ability.Want'; 344let wantTemp: Want = { 345 bundleName: 'com.example.myapplication', 346 abilityName: 'EntryAbility', 347}; 348 349networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0', (err, result) => { 350 if (err) { 351 console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`); 352 return; 353 } 354 console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`); 355}); 356``` 357 358## networkManager.isNetworkInterfaceDisabled 359 360isNetworkInterfaceDisabled(admin: Want, networkInterface: string): Promise<boolean> 361 362Checks whether a network port is disabled through the specified device administrator application. This API uses a promise to return the result. 363 364**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 365 366**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 367 368**System API**: This is a system API. 369 370**Parameters** 371 372| Name | Type | Mandatory | Description | 373| ----- | ----------------------------------- | ---- | ------- | 374| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 375| networkInterface | string | Yes | Network port. | 376 377**Return value** 378 379| Type | Description | 380| --------------------- | ------------------------- | 381| Promise<boolean> | Promise used to return the result. The value **true** means the network port is disabled, and the value **false** means the opposite. | 382 383**Error codes** 384 385For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 386 387| ID| Error Message | 388| ------- | ---------------------------------------------------------------------------- | 389| 9200001 | The application is not an administrator application of the device. | 390| 9200002 | The administrator application does not have permission to manage the device.| 391 392**Example** 393 394```ts 395import Want from '@ohos.app.ability.Want'; 396import { BusinessError } from '@ohos.base'; 397let wantTemp: Want = { 398 bundleName: 'com.example.myapplication', 399 abilityName: 'EntryAbility', 400}; 401 402networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0').then((result) => { 403 console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`); 404}).catch((err: BusinessError) => { 405 console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`); 406}); 407``` 408 409## networkManager.setNetworkInterfaceDisabled 410 411setNetworkInterfaceDisabled(admin: Want, networkInterface: string, isDisabled: boolean, callback: AsyncCallback<void>): void 412 413Disables a network port through the specified device administrator application. This API uses an asynchronous callback to return the result. 414 415**Required permissions**: ohos.permission.ENTERPRISE_SET_NETWORK 416 417**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 418 419**System API**: This is a system API. 420 421**Parameters** 422 423| Name | Type | Mandatory | Description | 424| -------- | ---------------------------------------- | ---- | ------------------------------- | 425| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 426| networkInterface | string | Yes | Network port. | 427| isDisabled | boolean | Yes | Network port status to set. The value **true** means to disable the network port, and **false** means to enable the network port. | 428| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 429 430**Error codes** 431 432For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 433 434| ID| Error Message | 435| ------- | ---------------------------------------------------------------------------- | 436| 9200001 | The application is not an administrator application of the device. | 437| 9200002 | The administrator application does not have permission to manage the device.| 438 439**Example** 440 441```ts 442import Want from '@ohos.app.ability.Want'; 443let wantTemp: Want = { 444 bundleName: 'com.example.myapplication', 445 abilityName: 'EntryAbility', 446}; 447 448networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true, (err) => { 449 if (err) { 450 console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`); 451 return; 452 } 453 console.info(`Succeeded in setting network interface disabled`); 454}); 455``` 456 457## networkManager.setNetworkInterfaceDisabled 458 459setNetworkInterfaceDisabled(admin: Want, networkInterface: string, isDisabled: boolean): Promise<void> 460 461Disables a network port through the specified device administrator application. This API uses a promise to return the result. 462 463**Required permissions**: ohos.permission.ENTERPRISE_SET_NETWORK 464 465**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 466 467**System API**: This is a system API. 468 469**Parameters** 470 471| Name | Type | Mandatory | Description | 472| ----- | ----------------------------------- | ---- | ------- | 473| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 474| networkInterface | string | Yes | Network port. | 475| isDisabled | boolean | Yes | Network port status to set. The value **true** means to disable the network port, and **false** means to enable the network port. | 476 477**Return value** 478 479| Type | Description | 480| --------------------- | ------------------------- | 481| Promise<void> | Promise that returns no value. An error object is thrown if the network port fails to be disabled. | 482 483**Error codes** 484 485For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 486 487| ID| Error Message | 488| ------- | ---------------------------------------------------------------------------- | 489| 9200001 | The application is not an administrator application of the device. | 490| 9200002 | The administrator application does not have permission to manage the device.| 491 492**Example** 493 494```ts 495import Want from '@ohos.app.ability.Want'; 496import { BusinessError } from '@ohos.base'; 497let wantTemp: Want = { 498 bundleName: 'com.example.myapplication', 499 abilityName: 'EntryAbility', 500}; 501 502networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true).then(() => { 503 console.info(`Succeeded in setting network interface disabled`); 504}).catch((err: BusinessError) => { 505 console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`); 506}); 507``` 508 509## networkManager.setGlobalProxy 510 511setGlobalProxy(admin: Want, httpProxy: connection.HttpProxy, callback: AsyncCallback\<void>): void 512 513Sets the global network proxy through the specified device administrator application. This API uses an asynchronous callback to return the result. 514 515**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 516 517**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 518 519**System API**: This is a system API. 520 521**Parameters** 522 523| Name | Type | Mandatory | Description | 524| -------- | ---------------------------------------- | ---- | ------------------------------- | 525| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 526| httpProxy | [connection.HttpProxy](js-apis-net-connection.md#httpproxy10) | Yes | Global HTTP proxy to set. | 527| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 528 529**Error codes** 530 531For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 532 533| ID| Error Message | 534| ------- | ---------------------------------------------------------------------------- | 535| 9200001 | The application is not an administrator application of the device. | 536| 9200002 | The administrator application does not have permission to manage the device.| 537 538**Example** 539 540```ts 541import Want from '@ohos.app.ability.Want'; 542import connection from '@ohos.net.connection'; 543let wantTemp: Want = { 544 bundleName: 'com.example.myapplication', 545 abilityName: 'EntryAbility', 546}; 547let exclusionStr: string = "192.168,baidu.com" 548let exclusionArray: Array<string> = exclusionStr.split(','); 549let httpProxy: connection.HttpProxy = { 550 host: "192.168.xx.xxx", 551 port: 8080, 552 exclusionList: exclusionArray 553}; 554 555networkManager.setGlobalProxy(wantTemp, httpProxy, (err) => { 556 if (err) { 557 console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`); 558 return; 559 } 560 console.info(`Succeeded in setting network global proxy`); 561}); 562``` 563 564## networkManager.setGlobalProxy 565 566setGlobalProxy(admin: Want, httpProxy: connection.HttpProxy): Promise\<void> 567 568Sets the global network proxy through the specified device administrator application. This API uses a promise to return the result. 569 570**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 571 572**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 573 574**System API**: This is a system API. 575 576**Parameters** 577 578| Name | Type | Mandatory | Description | 579| ----- | ----------------------------------- | ---- | ------- | 580| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 581| httpProxy | [connection.HttpProxy](js-apis-net-connection.md#httpproxy10) | Yes | Global HTTP proxy to set. | 582 583**Return value** 584 585| Type | Description | 586| --------------------- | ------------------------- | 587| Promise<void> | Promise that returns no value. An error object will be thrown if the operation fails. | 588 589**Error codes** 590 591For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 592 593| ID| Error Message | 594| ------- | ---------------------------------------------------------------------------- | 595| 9200001 | The application is not an administrator application of the device. | 596| 9200002 | The administrator application does not have permission to manage the device.| 597 598**Example** 599 600```ts 601import Want from '@ohos.app.ability.Want'; 602import { BusinessError } from '@ohos.base'; 603import connection from '@ohos.net.connection'; 604let wantTemp: Want = { 605 bundleName: 'com.example.myapplication', 606 abilityName: 'EntryAbility', 607}; 608let exclusionStr: string = "192.168,baidu.com" 609let exclusionArray: Array<string> = exclusionStr.split(','); 610let httpProxy: connection.HttpProxy = { 611 host: "192.168.xx.xxx", 612 port: 8080, 613 exclusionList: exclusionArray 614}; 615 616networkManager.setGlobalProxy(wantTemp, httpProxy).then(() => { 617 console.info(`Succeeded in setting network global proxy`); 618}).catch((err: BusinessError) => { 619 console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`); 620}); 621``` 622 623## networkManager.getGlobalProxy 624 625getGlobalProxy(admin: Want, callback: AsyncCallback\<connection.HttpProxy>): void 626 627Obtains the global network proxy through the specified device administrator application. This API uses an asynchronous callback to return the result. 628 629**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 630 631**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 632 633**System API**: This is a system API. 634 635**Parameters** 636 637| Name | Type | Mandatory | Description | 638| -------- | ---------------------------------------- | ---- | ------------------------------- | 639| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 640| callback | AsyncCallback<[connection.HttpProxy](js-apis-net-connection.md#httpproxy10)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 641 642**Error codes** 643 644For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 645 646| ID| Error Message | 647| ------- | ---------------------------------------------------------------------------- | 648| 9200001 | The application is not an administrator application of the device. | 649| 9200002 | The administrator application does not have permission to manage the device.| 650 651**Example** 652 653```ts 654import Want from '@ohos.app.ability.Want'; 655let wantTemp: Want = { 656 bundleName: 'com.example.myapplication', 657 abilityName: 'EntryAbility', 658}; 659 660networkManager.getGlobalProxy(wantTemp, (err, result) => { 661 if (err) { 662 console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`); 663 return; 664 } 665 console.info(`Succeeded in getting network global proxy, result : ${JSON.stringify(result)}`); 666}); 667``` 668 669## networkManager.getGlobalProxy 670 671getGlobalProxy(admin: Want): Promise\<connection.HttpProxy> 672 673Obtains the global network proxy through the specified device administrator application. This API uses a promise to return the result. 674 675**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 676 677**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 678 679**System API**: This is a system API. 680 681**Parameters** 682 683| Name | Type | Mandatory | Description | 684| ----- | ----------------------------------- | ---- | ------- | 685| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 686 687**Return value** 688 689| Type | Description | 690| --------------------- | ------------------------- | 691| Promise<[connection.HttpProxy](js-apis-net-connection.md#httpproxy10)> | Promise used to return the global HTTP proxy information obtained. | 692 693**Error codes** 694 695For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 696 697| ID| Error Message | 698| ------- | ---------------------------------------------------------------------------- | 699| 9200001 | The application is not an administrator application of the device. | 700| 9200002 | The administrator application does not have permission to manage the device.| 701 702**Example** 703 704```ts 705import Want from '@ohos.app.ability.Want'; 706import { BusinessError } from '@ohos.base'; 707let wantTemp: Want = { 708 bundleName: 'com.example.myapplication', 709 abilityName: 'EntryAbility', 710}; 711 712networkManager.getGlobalProxy(wantTemp).then(() => { 713 console.info(`Succeeded in getting network global proxy`); 714}).catch((err: BusinessError) => { 715 console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`); 716}); 717``` 718 719## networkManager.addIptablesFilterRule 720 721addIptablesFilterRule(admin: Want, filterRule: AddFilterRule, callback: AsyncCallback\<void>): void 722 723Adds a network packet filtering rule through the specified device administrator application. This API uses an asynchronous callback to return the result. 724 725**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 726 727**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 728 729**System API**: This is a system API. 730 731**Parameters** 732 733| Name | Type | Mandatory | Description | 734| -------- | ---------------------------------------- | ---- | ------------------------------- | 735| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 736| filterRule | [AddFilterRule](#addfilterrule) | Yes | Network packet filtering rule to add. | 737| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 738 739**Error codes** 740 741For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 742 743| ID| Error Message | 744| ------- | ---------------------------------------------------------------------------- | 745| 9200001 | The application is not an administrator application of the device. | 746| 9200002 | The administrator application does not have permission to manage the device.| 747 748**Example** 749 750```ts 751import Want from '@ohos.app.ability.Want'; 752let wantTemp: Want = { 753 bundleName: 'com.example.myapplication', 754 abilityName: 'EntryAbility', 755}; 756let filterRule: networkManager.AddFilterRule = { 757 "ruleNo": 1, 758 "srcAddr": "192.168.1.1-192.168.255.255", 759 "destAddr": "10.1.1.1", 760 "srcPort": "8080", 761 "destPort": "8080", 762 "uid": "9696", 763 "method": networkManager.AddMethod.APPEND, 764 "direction": networkManager.Direction.OUTPUT, 765 "action": networkManager.Action.DENY, 766 "protocol": networkManager.Protocol.UDP, 767} 768 769networkManager.addIptablesFilterRule(wantTemp, filterRule, (err) => { 770 if (err) { 771 console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`); 772 return; 773 } 774 console.info(`Succeeded in setting iptables filter rule`); 775}); 776``` 777 778## networkManager.addIptablesFilterRule 779 780addIptablesFilterRule(admin: Want, filterRule: AddFilterRule): Promise\<void> 781 782Adds a network packet filtering rule through the specified device administrator application. This API uses a promise to return the result. 783 784**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 785 786**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 787 788**System API**: This is a system API. 789 790**Parameters** 791 792| Name | Type | Mandatory | Description | 793| ----- | ----------------------------------- | ---- | ------- | 794| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 795| filterRule | [AddFilterRule](#addfilterrule) | Yes | Network packet filtering rule to add. | 796 797**Return value** 798 799| Type | Description | 800| --------------------- | ------------------------- | 801| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown. | 802 803**Error codes** 804 805For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 806 807| ID| Error Message | 808| ------- | ---------------------------------------------------------------------------- | 809| 9200001 | The application is not an administrator application of the device. | 810| 9200002 | The administrator application does not have permission to manage the device.| 811 812**Example** 813 814```ts 815import Want from '@ohos.app.ability.Want'; 816import { BusinessError } from '@ohos.base'; 817let wantTemp: Want = { 818 bundleName: 'com.example.myapplication', 819 abilityName: 'EntryAbility', 820}; 821let filterRule: networkManager.AddFilterRule = { 822 "ruleNo": 1, 823 "srcAddr": "192.168.1.1-192.168.255.255", 824 "destAddr": "10.1.1.1", 825 "srcPort": "8080", 826 "destPort": "8080", 827 "uid": "9696", 828 "method": networkManager.AddMethod.APPEND, 829 "direction": networkManager.Direction.OUTPUT, 830 "action": networkManager.Action.DENY, 831 "protocol": networkManager.Protocol.UDP, 832} 833 834networkManager.addIptablesFilterRule(wantTemp, filterRule).then(() => { 835 console.info(`Succeeded in setting iptables filter rule`); 836}).catch((err: BusinessError) => { 837 console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`); 838}); 839``` 840 841## networkManager.removeIptablesFilterRule 842 843removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule, callback: AsyncCallback\<void>): void 844 845Removes a network packet filtering rule through the specified device administrator application. This API uses an asynchronous callback to return the result. 846 847**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 848 849**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 850 851**System API**: This is a system API. 852 853**Parameters** 854 855| Name | Type | Mandatory | Description | 856| -------- | ---------------------------------------- | ---- | ------------------------------- | 857| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 858| filterRule | [RemoveFilterRule](#removefilterrule) | Yes | Network packet filtering rule to remove. | 859| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 860 861**Error codes** 862 863For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 864 865| ID| Error Message | 866| ------- | ---------------------------------------------------------------------------- | 867| 9200001 | The application is not an administrator application of the device. | 868| 9200002 | The administrator application does not have permission to manage the device.| 869 870**Example** 871 872```ts 873import Want from '@ohos.app.ability.Want'; 874let wantTemp: Want = { 875 bundleName: 'com.example.myapplication', 876 abilityName: 'EntryAbility', 877}; 878let filterRule: networkManager.RemoveFilterRule = { 879 "srcAddr": "192.168.1.1-192.168.255.255", 880 "destAddr": "10.1.1.1", 881 "srcPort": "8080", 882 "destPort": "8080", 883 "uid": "9696", 884 "direction": networkManager.Direction.OUTPUT, 885 "action": networkManager.Action.DENY, 886 "protocol": networkManager.Protocol.UDP, 887} 888 889networkManager.removeIptablesFilterRule(wantTemp, filterRule, (err) => { 890 if (err) { 891 console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 892 return; 893 } 894 console.info(`Succeeded in removing iptables filter rule`); 895}); 896``` 897 898## networkManager.removeIptablesFilterRule 899 900removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule): Promise\<void> 901 902Removes a network packet filtering rule through the specified device administrator application. This API uses a promise to return the result. 903 904**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 905 906**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 907 908**System API**: This is a system API. 909 910**Parameters** 911 912| Name | Type | Mandatory | Description | 913| ----- | ----------------------------------- | ---- | ------- | 914| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 915| filterRule | [RemoveFilterRule](#removefilterrule) | Yes | Network packet filtering rule to remove. | 916 917**Return value** 918 919| Type | Description | 920| --------------------- | ------------------------- | 921| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown. | 922 923**Error codes** 924 925For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 926 927| ID| Error Message | 928| ------- | ---------------------------------------------------------------------------- | 929| 9200001 | The application is not an administrator application of the device. | 930| 9200002 | The administrator application does not have permission to manage the device.| 931 932**Example** 933 934```ts 935import Want from '@ohos.app.ability.Want'; 936import { BusinessError } from '@ohos.base'; 937let wantTemp: Want = { 938 bundleName: 'com.example.myapplication', 939 abilityName: 'EntryAbility', 940}; 941let filterRule: networkManager.RemoveFilterRule = { 942 "srcAddr": "192.168.1.1-192.168.255.255", 943 "destAddr": "10.1.1.1", 944 "srcPort": "8080", 945 "destPort": "8080", 946 "uid": "9696", 947 "direction": networkManager.Direction.OUTPUT, 948 "action": networkManager.Action.DENY, 949 "protocol": networkManager.Protocol.UDP, 950} 951 952networkManager.removeIptablesFilterRule(wantTemp, filterRule).then(() => { 953 console.info(`Succeeded in removing iptables filter rule`); 954}).catch((err: BusinessError) => { 955 console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 956}); 957``` 958 959## networkManager.listIptablesFilterRules 960 961listIptablesFilterRules(admin: Want, callback: AsyncCallback\<string>): void 962 963Obtains network packet filtering rules through the specified device administrator application. This API uses an asynchronous callback to return the result. 964 965**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 966 967**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 968 969**System API**: This is a system API. 970 971**Parameters** 972 973| Name | Type | Mandatory | Description | 974| -------- | ---------------------------------------- | ---- | ------------------------------- | 975| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 976| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 977 978**Error codes** 979 980For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 981 982| ID| Error Message | 983| ------- | ---------------------------------------------------------------------------- | 984| 9200001 | The application is not an administrator application of the device. | 985| 9200002 | The administrator application does not have permission to manage the device.| 986 987**Example** 988 989```ts 990import Want from '@ohos.app.ability.Want'; 991let wantTemp: Want = { 992 bundleName: 'com.example.myapplication', 993 abilityName: 'EntryAbility', 994}; 995 996networkManager.listIptablesFilterRules(wantTemp, (err, result) => { 997 if (err) { 998 console.error(`Failed to get iptables filter rule. Code: ${err.code}, message: ${err.message}`); 999 return; 1000 } 1001 console.info(`Succeeded in getting iptables filter rule, result : ${result}`); 1002}); 1003``` 1004 1005## networkManager.listIptablesFilterRules 1006 1007listIptablesFilterRules(admin: Want): Promise\<string> 1008 1009Obtains network packet filtering rules through the specified device administrator application. This API uses a promise to return the result. 1010 1011**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1012 1013**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1014 1015**System API**: This is a system API. 1016 1017**Parameters** 1018 1019| Name | Type | Mandatory | Description | 1020| ----- | ----------------------------------- | ---- | ------- | 1021| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 1022 1023**Return value** 1024 1025| Type | Description | 1026| --------------------- | ------------------------- | 1027| Promise<string> | Promise used to return the network packet filtering rules obtained. | 1028 1029**Error codes** 1030 1031For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 1032 1033| ID| Error Message | 1034| ------- | ---------------------------------------------------------------------------- | 1035| 9200001 | The application is not an administrator application of the device. | 1036| 9200002 | The administrator application does not have permission to manage the device.| 1037 1038**Example** 1039 1040```ts 1041import Want from '@ohos.app.ability.Want'; 1042import { BusinessError } from '@ohos.base'; 1043let wantTemp: Want = { 1044 bundleName: 'com.example.myapplication', 1045 abilityName: 'EntryAbility', 1046}; 1047 1048networkManager.listIptablesFilterRules(wantTemp).then((result) => { 1049 console.info(`Succeeded in getting iptables filter rule, result: ${result}`); 1050}).catch((err: BusinessError) => { 1051 console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 1052}); 1053``` 1054 1055## networkManager.addFirewallRule<sup>11+</sup> 1056 1057addFirewallRule(admin: Want, firewallRule: FirewallRule): void 1058 1059Adds a firewall rule for devices through the specified device administrator application.<br> 1060After a rule with [Action](#action) set to **ALLOW** is added, a rule with **Action** set to **DENY** is added by default to discard or intercept all network data packets that do not meet the **ALLOW** rule. 1061 1062**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1063 1064**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1065 1066**System API**: This is a system API. 1067 1068**Parameters** 1069 1070| Name | Type | Mandatory | Description | 1071|--------------|-------------------------------------| ---- |------------| 1072| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 1073| firewallRule | [FirewallRule](#firewallrule11) | Yes | Firewall rule to add.| 1074 1075**Error codes** 1076 1077For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 1078 1079| ID| Error Message | 1080| ------- | ---------------------------------------------------------------------------- | 1081| 9200001 | The application is not an administrator application of the device. | 1082| 9200002 | The administrator application does not have permission to manage the device.| 1083 1084**Example** 1085 1086```ts 1087import Want from '@ohos.app.ability.Want'; 1088 1089let wantTemp: Want = { 1090 bundleName: 'com.example.myapplication', 1091 abilityName: 'EntryAbility', 1092}; 1093let firewallRule: networkManager.FirewallRule = { 1094 "srcAddr": "192.168.1.1-192.188.22.66", 1095 "destAddr": "10.1.1.1", 1096 "srcPort": "8080", 1097 "destPort": "8080", 1098 "appUid": "9696", 1099 "direction": networkManager.Direction.OUTPUT, 1100 "action": networkManager.Action.DENY, 1101 "protocol": networkManager.Protocol.UDP, 1102} 1103 1104networkManager.addFirewallRule(wantTemp, firewallRule); 1105``` 1106 1107## networkManager.removeFirewallRule<sup>11+</sup> 1108 1109removeFirewallRule(admin: Want, firewallRule?: FirewallRule): void 1110 1111Removes a firewall rule for devices through the specified device administrator application.<br> 1112If there is no rule with [Action](#action) being **ALLOW** after the rule is removed, the **DENY** rules that are added by default with [addFirewallRule](#networkmanageraddfirewallrule11) will be removed. 1113 1114**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1115 1116**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1117 1118**System API**: This is a system API. 1119 1120**Parameters** 1121 1122| Name | Type | Mandatory| Description | 1123|--------------|-------------------------------------|----|-----------------------------| 1124| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 1125| firewallRule | [FirewallRule](#firewallrule11) | No | Firewall rule to remove. If the value is empty, all firewall rules will be removed.| 1126 1127**Error codes** 1128 1129For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 1130 1131| ID| Error Message | 1132| ------- | ---------------------------------------------------------------------------- | 1133| 9200001 | The application is not an administrator application of the device. | 1134| 9200002 | The administrator application does not have permission to manage the device.| 1135 1136**Example** 1137 1138```ts 1139import Want from '@ohos.app.ability.Want'; 1140 1141let wantTemp: Want = { 1142 bundleName: 'com.example.myapplication', 1143 abilityName: 'EntryAbility', 1144}; 1145// Remove the specified firewall rule. 1146let firewallRule: networkManager.FirewallRule = { 1147 "srcAddr": "192.168.1.1-192.188.22.66", 1148 "destAddr": "10.1.1.1", 1149 "srcPort": "8080", 1150 "destPort": "8080", 1151 "appUid": "9696", 1152 "direction": networkManager.Direction.OUTPUT, 1153 "action": networkManager.Action.DENY, 1154 "protocol": networkManager.Protocol.UDP, 1155} 1156networkManager.removeFirewallRule(wantTemp, firewallRule); 1157 1158// Remove all firewall rules. 1159networkManager.removeFirewallRule(wantTemp); 1160``` 1161 1162## networkManager.getFirewallRules<sup>11+</sup> 1163 1164getFirewallRules(admin: Want): Array\<FirewallRule> 1165 1166Obtains firewall rules through the specified device administrator application. 1167 1168**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1169 1170**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1171 1172**System API**: This is a system API. 1173 1174**Parameters** 1175 1176| Name | Type | Mandatory| Description | 1177|--------------|-------------------------------------|----|-----------------------------| 1178| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 1179 1180**Return value** 1181 1182| Type | Description | 1183|---------------------------------------|-----------------------------------| 1184| Array\<[FirewallRule](#firewallrule11)> | A list of firewall rules configured for the device is returned. If the operation fails, an exception will be thrown.| 1185 1186**Error codes** 1187 1188For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 1189 1190| ID| Error Message | 1191| ------- | ---------------------------------------------------------------------------- | 1192| 9200001 | The application is not an administrator application of the device. | 1193| 9200002 | The administrator application does not have permission to manage the device.| 1194 1195**Example** 1196 1197```ts 1198import Want from '@ohos.app.ability.Want'; 1199 1200let wantTemp: Want = { 1201 bundleName: 'com.example.myapplication', 1202 abilityName: 'EntryAbility', 1203}; 1204let firewallRule: Array<networkManager.FirewallRule>; 1205firewallRule = networkManager.getFirewallRules(wantTemp); 1206``` 1207 1208## networkManager.addDomainFilterRule<sup>11+</sup> 1209 1210addDomainFilterRule(admin: Want, domainFilterRule: DomainFilterRule): void 1211 1212Adds a domain name filtering rule for the device through the specified device administrator application.<br> 1213After a rule with [Action](#action) set to **ALLOW** is added, a rule with **Action** set to **DENY** is added by default to discard or intercept all packets for domain name resolution that do not meet the **ALLOW** rule. 1214 1215**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1216 1217**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1218 1219**System API**: This is a system API. 1220 1221**Parameters** 1222 1223| Name | Type | Mandatory | Description | 1224|--------------|---------------------------------------| ---- |------------| 1225| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 1226| domainFilterRule | [DomainFilterRule](#domainfilterrule11) | Yes | Domain name filtering rule to add.| 1227 1228**Error codes** 1229 1230For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 1231 1232| ID| Error Message | 1233| ------- | ---------------------------------------------------------------------------- | 1234| 9200001 | The application is not an administrator application of the device. | 1235| 9200002 | The administrator application does not have permission to manage the device.| 1236 1237**Example** 1238 1239```ts 1240import Want from '@ohos.app.ability.Want'; 1241 1242let wantTemp: Want = { 1243 bundleName: 'com.example.myapplication', 1244 abilityName: 'EntryAbility', 1245}; 1246let domainFilterRule: networkManager.DomainFilterRule = { 1247 "domainName": "www.example.com", 1248 "appUid": "9696", 1249 "action": networkManager.Action.DENY, 1250} 1251 1252networkManager.addDomainFilterRule(wantTemp, domainFilterRule); 1253``` 1254 1255## networkManager.removeDomainFilterRule<sup>11+</sup> 1256 1257removeDomainFilterRule(admin: Want, domainFilterRule?: DomainFilterRule): void 1258 1259Removes a domain name filtering rule through the specified device administrator application.<br> 1260If there is no rule with [Action](#action) being **ALLOW** after the rule is removed, the **DENY** rules that are added by default with [addDomainFilterRule](#networkmanageradddomainfilterrule11) will be removed. 1261 1262**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1263 1264**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1265 1266**System API**: This is a system API. 1267 1268**Parameters** 1269 1270| Name | Type | Mandatory| Description | 1271|--------------|---------------------------------------|----|--------------------------| 1272| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 1273| domainFilterRule | [DomainFilterRule](#domainfilterrule11) | No | Domain name filtering rule to remove. If the value is empty, all domain name filtering rules will be removed.| 1274 1275**Error codes** 1276 1277For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 1278 1279| ID| Error Message | 1280| ------- | ---------------------------------------------------------------------------- | 1281| 9200001 | The application is not an administrator application of the device. | 1282| 9200002 | The administrator application does not have permission to manage the device.| 1283 1284**Example** 1285 1286```ts 1287import Want from '@ohos.app.ability.Want'; 1288 1289let wantTemp: Want = { 1290 bundleName: 'com.example.myapplication', 1291 abilityName: 'EntryAbility', 1292}; 1293// Remove the specified domain name filtering rule. 1294let domainFilterRule: networkManager.DomainFilterRule = { 1295 "domainName": "www.example.com", 1296 "appUid": "9696", 1297 "action": networkManager.Action.DENY, 1298} 1299networkManager.removeDomainFilterRule(wantTemp, domainFilterRule); 1300 1301// Remove all domain name filtering rules. 1302networkManager.removeDomainFilterRule(wantTemp); 1303``` 1304 1305## networkManager.getDomainFilterRules<sup>11+</sup> 1306 1307getDomainFilterRules(admin: Want): Array\<DomainFilterRule> 1308 1309Obtains domain name filtering rules through the specified device administrator application. 1310 1311**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1312 1313**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1314 1315**System API**: This is a system API. 1316 1317**Parameters** 1318 1319| Name | Type | Mandatory| Description | 1320|--------------|-------------------------------------|----|-----------------------------| 1321| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 1322 1323**Return value** 1324 1325| Type | Description | 1326|-----------------------------------------------|----------------------------------| 1327| Array\<[DomainFilterRule](#domainfilterrule11)> | A list of domain name filtering rules configured for the device is returned. If the operation fails, an exception will be thrown.| 1328 1329**Error codes** 1330 1331For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 1332 1333| ID| Error Message | 1334| ------- | ---------------------------------------------------------------------------- | 1335| 9200001 | The application is not an administrator application of the device. | 1336| 9200002 | The administrator application does not have permission to manage the device.| 1337 1338**Example** 1339 1340```ts 1341import Want from '@ohos.app.ability.Want'; 1342 1343let wantTemp: Want = { 1344 bundleName: 'com.example.myapplication', 1345 abilityName: 'EntryAbility', 1346}; 1347let domainFilterRule: Array<networkManager.DomainFilterRule>; 1348domainFilterRule = networkManager.getDomainFilterRules(wantTemp); 1349``` 1350 1351## AddFilterRule 1352 1353Defines the network packet filtering rule to add. 1354 1355**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1356 1357**System API**: This is a system API. 1358 1359| Name | Type | Mandatory| Description | 1360| ----------- | --------| ---- | ------------------------------- | 1361| ruleNo | number | No | Sequence number of the rule.| 1362| srcAddr | string | No | Source IP address.| 1363| destAddr | string | No | Destination IP address.| 1364| srcPort | string | No | Port of the source IP address.| 1365| destPort | string | No | Port of the destination IP address.| 1366| uid | string | No | UID of the application.| 1367| method | [AddMethod](#addmethod) | Yes | Method used to add the data packets.| 1368| direction | [Direction](#direction) | Yes | Direction chains to which the rule applies.| 1369| action | [Action](#action) | Yes | Action to take, that is, receive or discard the data packets.| 1370| protocol | [Protocol](#protocol) | No | Network protocol.| 1371 1372## RemoveFilterRule 1373 1374Defines the network packet filtering rule to remove. 1375 1376**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1377 1378**System API**: This is a system API. 1379 1380| Name | Type | Mandatory| Description | 1381| ----------- | --------| ---- | ------------------------------- | 1382| srcAddr | string | No | Source IP address.| 1383| destAddr | string | No | Destination IP address.| 1384| srcPort | string | No | Port of the source IP address.| 1385| destPort | string | No | Port of the destination IP address.| 1386| uid | string | No | UID of the application.| 1387| direction | [Direction](#direction) | Yes | Direction chains to which the rule applies.| 1388| action | [Action](#action) | No | Action to take, that is, receive or discard the data packets.| 1389| protocol | [Protocol](#protocol) | No | Network protocol.| 1390 1391## AddMethod 1392 1393Enumerates the methods used to add the network packets. 1394 1395**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1396 1397**System API**: This is a system API. 1398 1399| Name| Value| Description| 1400| -------- | -------- | -------- | 1401| APPEND | 0 | Append the packet.| 1402| INSERT | 1 | Insert the packet.| 1403 1404## Direction 1405 1406Enumerates the direction chains to which the rule applies. 1407 1408**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1409 1410**System API**: This is a system API. 1411 1412| Name| Value| Description| 1413| -------- | -------- | -------- | 1414| INPUT | 0 | Input chain.| 1415| OUTPUT | 1 | Output chain.| 1416 1417## Action 1418 1419Enumerates the actions that can be taken for the data packets. 1420 1421**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1422 1423**System API**: This is a system API. 1424 1425| Name| Value| Description| 1426| -------- | -------- | -------- | 1427| ALLOW | 0 | Receive the data packets.| 1428| DENY | 1 | Discard the data packets.| 1429 1430## Protocol 1431 1432Enumerates the network protocols supported. 1433 1434**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1435 1436**System API**: This is a system API. 1437 1438| Name| Value| Description| 1439| -------- | -------- | -------- | 1440| ALL | 0 | All network protocols.| 1441| TCP | 1 | TCP.| 1442| UDP | 2 | UDP.| 1443| ICMP | 3 | ICMP.| 1444 1445## FirewallRule<sup>11+</sup> 1446 1447Represents a firewall rule. 1448 1449**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1450 1451**System API**: This is a system API. 1452 1453| Name | Type | Mandatory| Description | 1454|-----------|-------------------------|----|-----------------------------------------------------------------------------------------------------------------------| 1455| srcAddr | string | No | Source IP address. Source IP address segment supported, for example, **192.168.0.0/22** or **192.168.1.100-192.168.1.200**. | 1456| destAddr | string | No | Destination IP address. Destination IP address segment supported, for example, **192.168.0.0/22** or **192.168.1.100-192.168.1.200**. | 1457| srcPort | string | No | Source port. | 1458| destPort | string | No | Destination port. | 1459| appUid | string | No | UID of the application. | 1460| direction | [Direction](#direction) | No | Direction chains to which the rule applies.<br>This parameter is mandatory when you add a firewall rule. If it is not specified when you remove a firewall rule, all [direction](#direction) chains will be removed.<br>If this parameter is empty, **srcAddr**, **destAddr**, **srcPort**, **destPort**, and **appUid** must also be empty. | 1461| action | [Action](#action) | No | Action to take, that is, receive or discard the data packets.<br>This parameter is mandatory when you add a firewall rule. If it is not specified when you remove a firewall rule, all chains that match the [Action](#action) rule will be removed.<br>If this parameter is empty, **srcAddr**, **destAddr**, **srcPort**, **destPort**, and **appUid** must also be empty.| 1462| protocol | [Protocol](#protocol) | No | Network protocol. If this parameter is set to **ALL** or **ICMP**, **srcPort** and **destPort** cannot be set. | 1463 1464## DomainFilterRule<sup>11+</sup> 1465 1466Represents a domain name filtering rule. 1467 1468**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1469 1470**System API**: This is a system API. 1471 1472| Name | Type | Mandatory| Description | 1473|------------|-------------------|----|---------------------------------------------------------------------------------------------------| 1474| domainName | string | No | Domain name. This parameter is mandatory when you add a domain name filtering rule. | 1475| appUid | string | No | UID of the application. | 1476| action | [Action](#action) | No | Action to take, that is, receive or discard the data packets.<br>This parameter is mandatory when you add a domain name filtering rule. If it is not specified when you remove a domain name filtering rule, all chains that match the [Action](#action) rule will be removed.<br>If this parameter is empty, **domainName** and **appUid** must also be empty.| 1477