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