1# @ohos.enterprise.networkManager (Network Management) (System API) 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 of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is [enabled](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin). 12> 13> This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.networkManager](js-apis-enterprise-networkManager.md). 14 15## Modules to Import 16 17```ts 18import { networkManager } from '@kit.MDMKit'; 19``` 20 21## networkManager.getAllNetworkInterfaces 22 23getAllNetworkInterfaces(admin: Want, callback: AsyncCallback<Array<string>>): void 24 25Obtains all activated network ports through the specified device administrator application. This API uses an asynchronous callback to return the result. 26 27**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 28 29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 30 31 32**Parameters** 33 34| Name | Type | Mandatory | Description | 35| -------- | ---------------------------------------- | ---- | ------------------------------- | 36| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 37| callback | AsyncCallback<Array<string>> | Yes | Callback used 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. | 38 39**Error codes** 40 41For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 42 43| ID| Error Message | 44| ------- | ---------------------------------------------------------------------------- | 45| 9200001 | The application is not an administrator application of the device. | 46| 9200002 | The administrator application does not have permission to manage the device. | 47| 201 | Permission verification failed. The application does not have the permission required to call the API. | 48| 202 | Permission verification failed. A non-system application calls a system API. | 49| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 50 51**Example** 52 53```ts 54import { Want } from '@kit.AbilityKit'; 55let wantTemp: Want = { 56 bundleName: 'com.example.myapplication', 57 abilityName: 'EntryAbility', 58}; 59 60networkManager.getAllNetworkInterfaces(wantTemp, (err, result) => { 61 if (err) { 62 console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`); 63 return; 64 } 65 console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`); 66}); 67``` 68 69## networkManager.getAllNetworkInterfaces 70 71getAllNetworkInterfaces(admin: Want): Promise<Array<string>> 72 73Obtains all activated network ports through the specified device administrator application. This API uses a promise to return the result. 74 75**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 76 77**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 78 79 80**Parameters** 81 82| Name | Type | Mandatory | Description | 83| ----- | ----------------------------------- | ---- | ------- | 84| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 85 86**Return value** 87 88| Type | Description | 89| --------------------- | ------------------------- | 90| Promise<Array<string>> | Promise used to return an array of network ports obtained. | 91 92**Error codes** 93 94For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 95 96| ID| Error Message | 97| ------- | ---------------------------------------------------------------------------- | 98| 9200001 | The application is not an administrator application of the device. | 99| 9200002 | The administrator application does not have permission to manage the device. | 100| 201 | Permission verification failed. The application does not have the permission required to call the API. | 101| 202 | Permission verification failed. A non-system application calls a system API. | 102| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 103 104**Example** 105 106```ts 107import { Want } from '@kit.AbilityKit'; 108import { BusinessError } from '@kit.BasicServicesKit'; 109let wantTemp: Want = { 110 bundleName: 'com.example.myapplication', 111 abilityName: 'EntryAbility', 112}; 113 114networkManager.getAllNetworkInterfaces(wantTemp).then((result) => { 115 console.info(`Succeeded in getting all network interfaces, result : ${JSON.stringify(result)}`); 116}).catch((err: BusinessError) => { 117 console.error(`Failed to get all network interfaces. Code: ${err.code}, message: ${err.message}`); 118}); 119``` 120 121## networkManager.getIpAddress 122 123getIpAddress(admin: Want, networkInterface: string, callback: AsyncCallback<string>): void 124 125Obtains 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. 126 127**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 128 129**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 130 131 132**Parameters** 133 134| Name | Type | Mandatory | Description | 135| -------- | ---------------------------------------- | ---- | ------------------------------- | 136| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 137| networkInterface | string | Yes | Network port. | 138| callback | AsyncCallback<string> | Yes | Callback used 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. | 139 140**Error codes** 141 142For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 143 144| ID| Error Message | 145| ------- | ---------------------------------------------------------------------------- | 146| 9200001 | The application is not an administrator application of the device. | 147| 9200002 | The administrator application does not have permission to manage the device. | 148| 201 | Permission verification failed. The application does not have the permission required to call the API. | 149| 202 | Permission verification failed. A non-system application calls a system API. | 150| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 151 152**Example** 153 154```ts 155import { Want } from '@kit.AbilityKit'; 156let wantTemp: Want = { 157 bundleName: 'com.example.myapplication', 158 abilityName: 'EntryAbility', 159}; 160 161networkManager.getIpAddress(wantTemp, 'eth0', (err, result) => { 162 if (err) { 163 console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`); 164 return; 165 } 166 console.info(`Succeeded in getting ip address, result : ${result}`); 167}); 168``` 169 170## networkManager.getIpAddress 171 172getIpAddress(admin: Want, networkInterface: string): Promise<string> 173 174Obtains the device IP address based on the network port through the specified device administrator application. This API uses a promise to return the result. 175 176**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 177 178**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 179 180 181**Parameters** 182 183| Name | Type | Mandatory | Description | 184| ----- | ----------------------------------- | ---- | ------- | 185| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 186| networkInterface | string | Yes | Network port. | 187 188**Return value** 189 190| Type | Description | 191| --------------------- | ------------------------- | 192| Promise<string> | Promise used to return the device IP address obtained. | 193 194**Error codes** 195 196For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 197 198| ID| Error Message | 199| ------- | ---------------------------------------------------------------------------- | 200| 9200001 | The application is not an administrator application of the device. | 201| 9200002 | The administrator application does not have permission to manage the device. | 202| 201 | Permission verification failed. The application does not have the permission required to call the API. | 203| 202 | Permission verification failed. A non-system application calls a system API. | 204| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 205 206**Example** 207 208```ts 209import { Want } from '@kit.AbilityKit'; 210import { BusinessError } from '@kit.BasicServicesKit'; 211let wantTemp: Want = { 212 bundleName: 'com.example.myapplication', 213 abilityName: 'EntryAbility', 214}; 215 216networkManager.getIpAddress(wantTemp, 'eth0').then((result) => { 217 console.info(`Succeeded in getting ip address, result : ${result}`); 218}).catch((err: BusinessError) => { 219 console.error(`Failed to get ip address. Code: ${err.code}, message: ${err.message}`); 220}); 221``` 222 223## networkManager.getMac 224 225getMac(admin: Want, networkInterface: string, callback: AsyncCallback<string>): void 226 227Obtains 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. 228 229**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 230 231**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 232 233 234**Parameters** 235 236| Name | Type | Mandatory | Description | 237| -------- | ---------------------------------------- | ---- | ------------------------------- | 238| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 239| networkInterface | string | Yes | Network port. | 240| callback | AsyncCallback<string> | Yes | Callback used 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. | 241 242**Error codes** 243 244For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 245 246| ID| Error Message | 247| ------- | ---------------------------------------------------------------------------- | 248| 9200001 | The application is not an administrator application of the device. | 249| 9200002 | The administrator application does not have permission to manage the device. | 250| 201 | Permission verification failed. The application does not have the permission required to call the API. | 251| 202 | Permission verification failed. A non-system application calls a system API. | 252| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 253 254**Example** 255 256```ts 257import { Want } from '@kit.AbilityKit'; 258let wantTemp: Want = { 259 bundleName: 'com.example.myapplication', 260 abilityName: 'EntryAbility', 261}; 262 263networkManager.getMac(wantTemp, 'eth0', (err, result) => { 264 if (err) { 265 console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`); 266 return; 267 } 268 console.info(`Succeeded in getting mac, result : ${result}`); 269}); 270``` 271 272## networkManager.getMac 273 274getMac(admin: Want, networkInterface: string): Promise\<string> 275 276Obtains the device MAC address based on the network port through the specified device administrator application. This API uses a promise to return the result. 277 278**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 279 280**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 281 282 283**Parameters** 284 285| Name | Type | Mandatory | Description | 286| ----- | ----------------------------------- | ---- | ------- | 287| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 288| networkInterface | string | Yes | Network port. | 289 290**Return value** 291 292| Type | Description | 293| --------------------- | ------------------------- | 294| Promise<string> | Promise used to return the device MAC address obtained. | 295 296**Error codes** 297 298For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 299 300| ID| Error Message | 301| ------- | ---------------------------------------------------------------------------- | 302| 9200001 | The application is not an administrator application of the device. | 303| 9200002 | The administrator application does not have permission to manage the device. | 304| 201 | Permission verification failed. The application does not have the permission required to call the API. | 305| 202 | Permission verification failed. A non-system application calls a system API. | 306| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 307 308**Example** 309 310```ts 311import { Want } from '@kit.AbilityKit'; 312import { BusinessError } from '@kit.BasicServicesKit'; 313let wantTemp: Want = { 314 bundleName: 'com.example.myapplication', 315 abilityName: 'EntryAbility', 316}; 317 318networkManager.getMac(wantTemp, 'eth0').then((result) => { 319 console.info(`Succeeded in getting mac, result : ${result}`); 320}).catch((err: BusinessError) => { 321 console.error(`Failed to get mac. Code: ${err.code}, message: ${err.message}`); 322}); 323``` 324 325## networkManager.isNetworkInterfaceDisabled 326 327isNetworkInterfaceDisabled(admin: Want, networkInterface: string, callback: AsyncCallback<boolean>): void 328 329Checks whether a network port is disabled through the specified device administrator application. This API uses an asynchronous callback to return the result. 330 331**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 332 333**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 334 335 336**Parameters** 337 338| Name | Type | Mandatory | Description | 339| -------- | ---------------------------------------- | ---- | ------------------------------- | 340| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 341| networkInterface | string | Yes | Network port. | 342| callback | AsyncCallback<boolean> | Yes | Callback used 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. | 343 344**Error codes** 345 346For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 347 348| ID| Error Message | 349| ------- | ---------------------------------------------------------------------------- | 350| 9200001 | The application is not an administrator application of the device. | 351| 9200002 | The administrator application does not have permission to manage the device. | 352| 201 | Permission verification failed. The application does not have the permission required to call the API. | 353| 202 | Permission verification failed. A non-system application calls a system API. | 354| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 355 356**Example** 357 358```ts 359import { Want } from '@kit.AbilityKit'; 360let wantTemp: Want = { 361 bundleName: 'com.example.myapplication', 362 abilityName: 'EntryAbility', 363}; 364 365networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0', (err, result) => { 366 if (err) { 367 console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`); 368 return; 369 } 370 console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`); 371}); 372``` 373 374## networkManager.isNetworkInterfaceDisabled 375 376isNetworkInterfaceDisabled(admin: Want, networkInterface: string): Promise<boolean> 377 378Checks whether a network port is disabled through the specified device administrator application. This API uses a promise to return the result. 379 380**Required permissions**: ohos.permission.ENTERPRISE_GET_NETWORK_INFO 381 382**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 383 384 385**Parameters** 386 387| Name | Type | Mandatory | Description | 388| ----- | ----------------------------------- | ---- | ------- | 389| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 390| networkInterface | string | Yes | Network port. | 391 392**Return value** 393 394| Type | Description | 395| --------------------- | ------------------------- | 396| Promise<boolean> | Promise used to return the result. The value **true** means the network port is disabled, and the value **false** means the opposite. | 397 398**Error codes** 399 400For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 401 402| ID| Error Message | 403| ------- | ---------------------------------------------------------------------------- | 404| 9200001 | The application is not an administrator application of the device. | 405| 9200002 | The administrator application does not have permission to manage the device. | 406| 201 | Permission verification failed. The application does not have the permission required to call the API. | 407| 202 | Permission verification failed. A non-system application calls a system API. | 408| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 409 410**Example** 411 412```ts 413import { Want } from '@kit.AbilityKit'; 414import { BusinessError } from '@kit.BasicServicesKit'; 415let wantTemp: Want = { 416 bundleName: 'com.example.myapplication', 417 abilityName: 'EntryAbility', 418}; 419 420networkManager.isNetworkInterfaceDisabled(wantTemp, 'eth0').then((result) => { 421 console.info(`Succeeded in querying network interface is disabled or not, result : ${result}`); 422}).catch((err: BusinessError) => { 423 console.error(`Failed to query network interface is disabled or not. Code: ${err.code}, message: ${err.message}`); 424}); 425``` 426 427## networkManager.setNetworkInterfaceDisabled 428 429setNetworkInterfaceDisabled(admin: Want, networkInterface: string, isDisabled: boolean, callback: AsyncCallback<void>): void 430 431Disables a network port through the specified device administrator application. This API uses an asynchronous callback to return the result. 432 433**Required permissions**: ohos.permission.ENTERPRISE_SET_NETWORK 434 435**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 436 437 438**Parameters** 439 440| Name | Type | Mandatory | Description | 441| -------- | ---------------------------------------- | ---- | ------------------------------- | 442| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 443| networkInterface | string | Yes | Network port. | 444| 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. | 445| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 446 447**Error codes** 448 449For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 450 451| ID| Error Message | 452| ------- | ---------------------------------------------------------------------------- | 453| 9200001 | The application is not an administrator application of the device. | 454| 9200002 | The administrator application does not have permission to manage the device. | 455| 201 | Permission verification failed. The application does not have the permission required to call the API. | 456| 202 | Permission verification failed. A non-system application calls a system API. | 457| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 458 459**Example** 460 461```ts 462import { Want } from '@kit.AbilityKit'; 463let wantTemp: Want = { 464 bundleName: 'com.example.myapplication', 465 abilityName: 'EntryAbility', 466}; 467 468networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true, (err) => { 469 if (err) { 470 console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`); 471 return; 472 } 473 console.info(`Succeeded in setting network interface disabled`); 474}); 475``` 476 477## networkManager.setNetworkInterfaceDisabled 478 479setNetworkInterfaceDisabled(admin: Want, networkInterface: string, isDisabled: boolean): Promise<void> 480 481Disables a network port through the specified device administrator application. This API uses a promise to return the result. 482 483**Required permissions**: ohos.permission.ENTERPRISE_SET_NETWORK 484 485**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 486 487 488**Parameters** 489 490| Name | Type | Mandatory | Description | 491| ----- | ----------------------------------- | ---- | ------- | 492| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 493| networkInterface | string | Yes | Network port. | 494| 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. | 495 496**Return value** 497 498| Type | Description | 499| --------------------- | ------------------------- | 500| Promise<void> | Promise that returns no value. An error object is thrown if the network port fails to be disabled. | 501 502**Error codes** 503 504For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 505 506| ID| Error Message | 507| ------- | ---------------------------------------------------------------------------- | 508| 9200001 | The application is not an administrator application of the device. | 509| 9200002 | The administrator application does not have permission to manage the device. | 510| 201 | Permission verification failed. The application does not have the permission required to call the API. | 511| 202 | Permission verification failed. A non-system application calls a system API. | 512| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 513 514**Example** 515 516```ts 517import { Want } from '@kit.AbilityKit'; 518import { BusinessError } from '@kit.BasicServicesKit'; 519let wantTemp: Want = { 520 bundleName: 'com.example.myapplication', 521 abilityName: 'EntryAbility', 522}; 523 524networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true).then(() => { 525 console.info(`Succeeded in setting network interface disabled`); 526}).catch((err: BusinessError) => { 527 console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`); 528}); 529``` 530 531## networkManager.setGlobalProxy 532 533setGlobalProxy(admin: Want, httpProxy: connection.HttpProxy, callback: AsyncCallback\<void>): void 534 535Sets the global network proxy through the specified device administrator application. This API uses an asynchronous callback to return the result. 536 537**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 538 539**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 540 541 542**Parameters** 543 544| Name | Type | Mandatory | Description | 545| -------- | ---------------------------------------- | ---- | ------------------------------- | 546| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 547| httpProxy | [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | Yes | Global HTTP proxy to set. | 548| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 549 550**Error codes** 551 552For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 553 554| ID| Error Message | 555| ------- | ---------------------------------------------------------------------------- | 556| 9200001 | The application is not an administrator application of the device. | 557| 9200002 | The administrator application does not have permission to manage the device. | 558| 201 | Permission verification failed. The application does not have the permission required to call the API. | 559| 202 | Permission verification failed. A non-system application calls a system API. | 560| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 561 562**Example** 563 564```ts 565import { Want } from '@kit.AbilityKit'; 566import { connection } from '@kit.NetworkKit'; 567let wantTemp: Want = { 568 bundleName: 'com.example.myapplication', 569 abilityName: 'EntryAbility', 570}; 571let exclusionStr: string = "192.168,baidu.com" 572let exclusionArray: Array<string> = exclusionStr.split(','); 573let httpProxy: connection.HttpProxy = { 574 host: "192.168.xx.xxx", 575 port: 8080, 576 exclusionList: exclusionArray 577}; 578 579networkManager.setGlobalProxy(wantTemp, httpProxy, (err) => { 580 if (err) { 581 console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`); 582 return; 583 } 584 console.info(`Succeeded in setting network global proxy`); 585}); 586``` 587 588## networkManager.setGlobalProxy 589 590setGlobalProxy(admin: Want, httpProxy: connection.HttpProxy): Promise\<void> 591 592Sets the global network proxy through the specified device administrator application. This API uses a promise to return the result. 593 594**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 595 596**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 597 598 599**Parameters** 600 601| Name | Type | Mandatory | Description | 602| ----- | ----------------------------------- | ---- | ------- | 603| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 604| httpProxy | [connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10) | Yes | Global HTTP proxy to set. | 605 606**Return value** 607 608| Type | Description | 609| --------------------- | ------------------------- | 610| Promise<void> | Promise that returns no value. An error object will be thrown if the operation fails. | 611 612**Error codes** 613 614For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 615 616| ID| Error Message | 617| ------- | ---------------------------------------------------------------------------- | 618| 9200001 | The application is not an administrator application of the device. | 619| 9200002 | The administrator application does not have permission to manage the device. | 620| 201 | Permission verification failed. The application does not have the permission required to call the API. | 621| 202 | Permission verification failed. A non-system application calls a system API. | 622| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 623 624**Example** 625 626```ts 627import { Want } from '@kit.AbilityKit'; 628import { BusinessError } from '@kit.BasicServicesKit'; 629import { connection } from '@kit.NetworkKit'; 630let wantTemp: Want = { 631 bundleName: 'com.example.myapplication', 632 abilityName: 'EntryAbility', 633}; 634let exclusionStr: string = "192.168,baidu.com" 635let exclusionArray: Array<string> = exclusionStr.split(','); 636let httpProxy: connection.HttpProxy = { 637 host: "192.168.xx.xxx", 638 port: 8080, 639 exclusionList: exclusionArray 640}; 641 642networkManager.setGlobalProxy(wantTemp, httpProxy).then(() => { 643 console.info(`Succeeded in setting network global proxy`); 644}).catch((err: BusinessError) => { 645 console.error(`Failed to set network global proxy. Code: ${err.code}, message: ${err.message}`); 646}); 647``` 648 649## networkManager.getGlobalProxy 650 651getGlobalProxy(admin: Want, callback: AsyncCallback\<connection.HttpProxy>): void 652 653Obtains the global network proxy through the specified device administrator application. This API uses an asynchronous callback to return the result. 654 655**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 656 657**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 658 659 660**Parameters** 661 662| Name | Type | Mandatory | Description | 663| -------- | ---------------------------------------- | ---- | ------------------------------- | 664| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 665| callback | AsyncCallback<[connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 666 667**Error codes** 668 669For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 670 671| ID| Error Message | 672| ------- | ---------------------------------------------------------------------------- | 673| 9200001 | The application is not an administrator application of the device. | 674| 9200002 | The administrator application does not have permission to manage the device. | 675| 201 | Permission verification failed. The application does not have the permission required to call the API. | 676| 202 | Permission verification failed. A non-system application calls a system API. | 677| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 678 679**Example** 680 681```ts 682import { Want } from '@kit.AbilityKit'; 683let wantTemp: Want = { 684 bundleName: 'com.example.myapplication', 685 abilityName: 'EntryAbility', 686}; 687 688networkManager.getGlobalProxy(wantTemp, (err, result) => { 689 if (err) { 690 console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`); 691 return; 692 } 693 console.info(`Succeeded in getting network global proxy, result : ${JSON.stringify(result)}`); 694}); 695``` 696 697## networkManager.getGlobalProxy 698 699getGlobalProxy(admin: Want): Promise\<connection.HttpProxy> 700 701Obtains the global network proxy through the specified device administrator application. This API uses a promise to return the result. 702 703**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 704 705**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 706 707 708**Parameters** 709 710| Name | Type | Mandatory | Description | 711| ----- | ----------------------------------- | ---- | ------- | 712| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 713 714**Return value** 715 716| Type | Description | 717| --------------------- | ------------------------- | 718| Promise<[connection.HttpProxy](../apis-network-kit/js-apis-net-connection.md#httpproxy10)> | Promise used to return the global HTTP proxy information obtained. | 719 720**Error codes** 721 722For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 723 724| ID| Error Message | 725| ------- | ---------------------------------------------------------------------------- | 726| 9200001 | The application is not an administrator application of the device. | 727| 9200002 | The administrator application does not have permission to manage the device. | 728| 201 | Permission verification failed. The application does not have the permission required to call the API. | 729| 202 | Permission verification failed. A non-system application calls a system API. | 730| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 731 732**Example** 733 734```ts 735import { Want } from '@kit.AbilityKit'; 736import { BusinessError } from '@kit.BasicServicesKit'; 737let wantTemp: Want = { 738 bundleName: 'com.example.myapplication', 739 abilityName: 'EntryAbility', 740}; 741 742networkManager.getGlobalProxy(wantTemp).then(() => { 743 console.info(`Succeeded in getting network global proxy`); 744}).catch((err: BusinessError) => { 745 console.error(`Failed to get network global proxy. Code: ${err.code}, message: ${err.message}`); 746}); 747``` 748 749## networkManager.addIptablesFilterRule 750 751addIptablesFilterRule(admin: Want, filterRule: AddFilterRule, callback: AsyncCallback\<void>): void 752 753Adds a network packet filtering rule for devices through the specified device administrator application. This API uses an asynchronous callback to return the result. 754 755**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 756 757**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 758 759 760**Parameters** 761 762| Name | Type | Mandatory | Description | 763| -------- | ---------------------------------------- | ---- | ------------------------------- | 764| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 765| filterRule | [AddFilterRule](#addfilterrule) | Yes | Network packet filtering rule to add. | 766| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 767 768**Error codes** 769 770For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 771 772| ID| Error Message | 773| ------- | ---------------------------------------------------------------------------- | 774| 9200001 | The application is not an administrator application of the device. | 775| 9200002 | The administrator application does not have permission to manage the device. | 776| 201 | Permission verification failed. The application does not have the permission required to call the API. | 777| 202 | Permission verification failed. A non-system application calls a system API. | 778| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 779 780**Example** 781 782```ts 783import { Want } from '@kit.AbilityKit'; 784let wantTemp: Want = { 785 bundleName: 'com.example.myapplication', 786 abilityName: 'EntryAbility', 787}; 788let filterRule: networkManager.AddFilterRule = { 789 "ruleNo": 1, 790 "srcAddr": "192.168.1.1-192.168.255.255", 791 "destAddr": "10.1.1.1", 792 "srcPort": "8080", 793 "destPort": "8080", 794 "uid": "9696", 795 "method": networkManager.AddMethod.APPEND, 796 "direction": networkManager.Direction.OUTPUT, 797 "action": networkManager.Action.DENY, 798 "protocol": networkManager.Protocol.UDP, 799} 800 801networkManager.addIptablesFilterRule(wantTemp, filterRule, (err) => { 802 if (err) { 803 console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`); 804 return; 805 } 806 console.info(`Succeeded in setting iptables filter rule`); 807}); 808``` 809 810## networkManager.addIptablesFilterRule 811 812addIptablesFilterRule(admin: Want, filterRule: AddFilterRule): Promise\<void> 813 814Adds a network packet filtering rule for devices through the specified device administrator application. This API uses a promise to return the result. 815 816**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 817 818**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 819 820 821**Parameters** 822 823| Name | Type | Mandatory | Description | 824| ----- | ----------------------------------- | ---- | ------- | 825| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 826| filterRule | [AddFilterRule](#addfilterrule) | Yes | Network packet filtering rule to add. | 827 828**Return value** 829 830| Type | Description | 831| --------------------- | ------------------------- | 832| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown. | 833 834**Error codes** 835 836For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 837 838| ID| Error Message | 839| ------- | ---------------------------------------------------------------------------- | 840| 9200001 | The application is not an administrator application of the device. | 841| 9200002 | The administrator application does not have permission to manage the device. | 842| 201 | Permission verification failed. The application does not have the permission required to call the API. | 843| 202 | Permission verification failed. A non-system application calls a system API. | 844| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 845 846**Example** 847 848```ts 849import { Want } from '@kit.AbilityKit'; 850import { BusinessError } from '@kit.BasicServicesKit'; 851let wantTemp: Want = { 852 bundleName: 'com.example.myapplication', 853 abilityName: 'EntryAbility', 854}; 855let filterRule: networkManager.AddFilterRule = { 856 "ruleNo": 1, 857 "srcAddr": "192.168.1.1-192.168.255.255", 858 "destAddr": "10.1.1.1", 859 "srcPort": "8080", 860 "destPort": "8080", 861 "uid": "9696", 862 "method": networkManager.AddMethod.APPEND, 863 "direction": networkManager.Direction.OUTPUT, 864 "action": networkManager.Action.DENY, 865 "protocol": networkManager.Protocol.UDP, 866} 867 868networkManager.addIptablesFilterRule(wantTemp, filterRule).then(() => { 869 console.info(`Succeeded in setting iptables filter rule`); 870}).catch((err: BusinessError) => { 871 console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`); 872}); 873``` 874 875## networkManager.removeIptablesFilterRule 876 877removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule, callback: AsyncCallback\<void>): void 878 879Removes a network packet filtering rule through the specified device administrator application. This API uses an asynchronous callback to return the result. 880 881**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 882 883**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 884 885 886**Parameters** 887 888| Name | Type | Mandatory | Description | 889| -------- | ---------------------------------------- | ---- | ------------------------------- | 890| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 891| filterRule | [RemoveFilterRule](#removefilterrule) | Yes | Network packet filtering rule to remove. | 892| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 893 894**Error codes** 895 896For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 897 898| ID| Error Message | 899| ------- | ---------------------------------------------------------------------------- | 900| 9200001 | The application is not an administrator application of the device. | 901| 9200002 | The administrator application does not have permission to manage the device. | 902| 201 | Permission verification failed. The application does not have the permission required to call the API. | 903| 202 | Permission verification failed. A non-system application calls a system API. | 904| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 905 906**Example** 907 908```ts 909import { Want } from '@kit.AbilityKit'; 910let wantTemp: Want = { 911 bundleName: 'com.example.myapplication', 912 abilityName: 'EntryAbility', 913}; 914let filterRule: networkManager.RemoveFilterRule = { 915 "srcAddr": "192.168.1.1-192.168.255.255", 916 "destAddr": "10.1.1.1", 917 "srcPort": "8080", 918 "destPort": "8080", 919 "uid": "9696", 920 "direction": networkManager.Direction.OUTPUT, 921 "action": networkManager.Action.DENY, 922 "protocol": networkManager.Protocol.UDP, 923} 924 925networkManager.removeIptablesFilterRule(wantTemp, filterRule, (err) => { 926 if (err) { 927 console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 928 return; 929 } 930 console.info(`Succeeded in removing iptables filter rule`); 931}); 932``` 933 934## networkManager.removeIptablesFilterRule 935 936removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule): Promise\<void> 937 938Removes a network packet filtering rule through the specified device administrator application. This API uses a promise to return the result. 939 940**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 941 942**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 943 944 945**Parameters** 946 947| Name | Type | Mandatory | Description | 948| ----- | ----------------------------------- | ---- | ------- | 949| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 950| filterRule | [RemoveFilterRule](#removefilterrule) | Yes | Network packet filtering rule to remove. | 951 952**Return value** 953 954| Type | Description | 955| --------------------- | ------------------------- | 956| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown. | 957 958**Error codes** 959 960For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 961 962| ID| Error Message | 963| ------- | ---------------------------------------------------------------------------- | 964| 9200001 | The application is not an administrator application of the device. | 965| 9200002 | The administrator application does not have permission to manage the device. | 966| 201 | Permission verification failed. The application does not have the permission required to call the API. | 967| 202 | Permission verification failed. A non-system application calls a system API. | 968| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 969 970**Example** 971 972```ts 973import { Want } from '@kit.AbilityKit'; 974import { BusinessError } from '@kit.BasicServicesKit'; 975let wantTemp: Want = { 976 bundleName: 'com.example.myapplication', 977 abilityName: 'EntryAbility', 978}; 979let filterRule: networkManager.RemoveFilterRule = { 980 "srcAddr": "192.168.1.1-192.168.255.255", 981 "destAddr": "10.1.1.1", 982 "srcPort": "8080", 983 "destPort": "8080", 984 "uid": "9696", 985 "direction": networkManager.Direction.OUTPUT, 986 "action": networkManager.Action.DENY, 987 "protocol": networkManager.Protocol.UDP, 988} 989 990networkManager.removeIptablesFilterRule(wantTemp, filterRule).then(() => { 991 console.info(`Succeeded in removing iptables filter rule`); 992}).catch((err: BusinessError) => { 993 console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 994}); 995``` 996 997## networkManager.listIptablesFilterRules 998 999listIptablesFilterRules(admin: Want, callback: AsyncCallback\<string>): void 1000 1001Obtains network packet filtering rules through the specified device administrator application. This API uses an asynchronous callback to return the result. 1002 1003**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1004 1005**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1006 1007 1008**Parameters** 1009 1010| Name | Type | Mandatory | Description | 1011| -------- | ---------------------------------------- | ---- | ------------------------------- | 1012| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 1013| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 1014 1015**Error codes** 1016 1017For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 1018 1019| ID| Error Message | 1020| ------- | ---------------------------------------------------------------------------- | 1021| 9200001 | The application is not an administrator application of the device. | 1022| 9200002 | The administrator application does not have permission to manage the device. | 1023| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1024| 202 | Permission verification failed. A non-system application calls a system API. | 1025| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1026 1027**Example** 1028 1029```ts 1030import { Want } from '@kit.AbilityKit'; 1031let wantTemp: Want = { 1032 bundleName: 'com.example.myapplication', 1033 abilityName: 'EntryAbility', 1034}; 1035 1036networkManager.listIptablesFilterRules(wantTemp, (err, result) => { 1037 if (err) { 1038 console.error(`Failed to get iptables filter rule. Code: ${err.code}, message: ${err.message}`); 1039 return; 1040 } 1041 console.info(`Succeeded in getting iptables filter rule, result : ${result}`); 1042}); 1043``` 1044 1045## networkManager.listIptablesFilterRules 1046 1047listIptablesFilterRules(admin: Want): Promise\<string> 1048 1049Obtains network packet filtering rules through the specified device administrator application. This API uses a promise to return the result. 1050 1051**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_NETWORK 1052 1053**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1054 1055 1056**Parameters** 1057 1058| Name | Type | Mandatory | Description | 1059| ----- | ----------------------------------- | ---- | ------- | 1060| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 1061 1062**Return value** 1063 1064| Type | Description | 1065| --------------------- | ------------------------- | 1066| Promise<string> | Promise used to return the network packet filtering rules obtained. | 1067 1068**Error codes** 1069 1070For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 1071 1072| ID| Error Message | 1073| ------- | ---------------------------------------------------------------------------- | 1074| 9200001 | The application is not an administrator application of the device. | 1075| 9200002 | The administrator application does not have permission to manage the device. | 1076| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1077| 202 | Permission verification failed. A non-system application calls a system API. | 1078| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1079 1080**Example** 1081 1082```ts 1083import { Want } from '@kit.AbilityKit'; 1084import { BusinessError } from '@kit.BasicServicesKit'; 1085let wantTemp: Want = { 1086 bundleName: 'com.example.myapplication', 1087 abilityName: 'EntryAbility', 1088}; 1089 1090networkManager.listIptablesFilterRules(wantTemp).then((result) => { 1091 console.info(`Succeeded in getting iptables filter rule, result: ${result}`); 1092}).catch((err: BusinessError) => { 1093 console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`); 1094}); 1095``` 1096 1097## AddFilterRule 1098 1099Network packet filtering rule to add. 1100 1101**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1102 1103 1104| Name | Type | Mandatory| Description | 1105| ----------- | --------| ---- | ------------------------------- | 1106| ruleNo | number | No | Sequence number of the rule.| 1107| srcAddr | string | No | Source IP address.| 1108| destAddr | string | No | Destination IP address.| 1109| srcPort | string | No | Port of the source IP address.| 1110| destPort | string | No | Port of the destination IP address.| 1111| uid | string | No | UID of the application.| 1112| method | [AddMethod](#addmethod) | Yes | Method used to add the data packets.| 1113| direction | [Direction](js-apis-enterprise-networkManager.md#direction) | Yes | Direction chains to which the rule applies.| 1114| action | [Action](js-apis-enterprise-networkManager.md#action) | Yes | Action to take, that is, receive or discard data packets.| 1115| protocol | [Protocol](js-apis-enterprise-networkManager.md#protocol) | No | Network protocol.| 1116 1117## RemoveFilterRule 1118 1119Network packet filtering rule to remove. 1120 1121**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1122 1123 1124| Name | Type | Mandatory| Description | 1125| ----------- | --------| ---- | ------------------------------- | 1126| srcAddr | string | No | Source IP address.| 1127| destAddr | string | No | Destination IP address.| 1128| srcPort | string | No | Port of the source IP address.| 1129| destPort | string | No | Port of the destination IP address.| 1130| uid | string | No | UID of the application.| 1131| direction | [Direction](js-apis-enterprise-networkManager.md#direction) | Yes | Direction chains to which the rule applies.| 1132| action | [Action](js-apis-enterprise-networkManager.md#action) | No | Action to take, that is, receive or discard data packets.| 1133| protocol | [Protocol](js-apis-enterprise-networkManager.md#protocol) | No | Network protocol.| 1134 1135## AddMethod 1136 1137Enumerates the methods used to add the network packets. 1138 1139**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1140 1141 1142| Name| Value| Description| 1143| -------- | -------- | -------- | 1144| APPEND | 0 | Append the packet.| 1145| INSERT | 1 | Insert the packet.| 1146