1# @ohos.enterprise.restrictions (限制类策略) 2<!--Kit: MDM Kit--> 3<!--Subsystem: Customization--> 4<!--Owner: @huanleima--> 5<!--Designer: @liuzuming--> 6<!--Tester: @lpw_work--> 7<!--Adviser: @Brilliantry_Rui--> 8 9本模块提供设置通用限制类策略能力。可以全局禁用和解除禁用蓝牙、HDC、USB、Wi-Fi等特性。 10 11> **说明**: 12> 13> 本模块首批接口从API version 12 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14> 15> 本模块接口仅可在Stage模型下使用。 16> 17> 本模块接口仅对设备管理应用开放,且调用接口前需激活设备管理应用,具体请参考[MDM Kit开发指南](../../mdm/mdm-kit-guide.md)。 18 19## 导入模块 20 21```ts 22import { restrictions } from '@kit.MDMKit'; 23``` 24 25## restrictions.setDisallowedPolicy 26 27setDisallowedPolicy(admin: Want, feature: string, disallow: boolean): void 28 29设置禁用/启用某特性。 30 31**需要权限:** ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 或者 ohos.permission.PERSONAL_MANAGE_RESTRICTIONS<sup>15+</sup> 32 33**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 34 35**模型约束:** 此接口仅可在Stage模型下使用。 36 37**参数:** 38 39| 参数名 | 类型 | 必填 | 说明 | 40| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 41| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 42| feature | string | 是 | 支持设置的特性清单参考表1。<br/> **说明:** 从API version 15开始,应用申请权限ohos.permission.PERSONAL_MANAGE_RESTRICTIONS并[激活为自带设备管理应用](./js-apis-enterprise-adminManager.md#adminmanagerstartadminprovision15),可以使用此接口设置以下特性:bluetooth、hdc、microphone、usb、wifi、tethering、camera<!--RP3--><!--RP3End-->。 | 43| disallow | boolean | 是 | true表示禁止使用,false表示允许使用。 | 44 45**表1 支持设置的特性清单:** 46|特性|说明| 47|--------------|---------------------| 48|bluetooth|设备蓝牙能力。当已经通过[addDisallowedBluetoothDevices](js-apis-enterprise-bluetoothManager.md#bluetoothmanageradddisallowedbluetoothdevices20)接口或者[addAllowedBluetoothDevices](js-apis-enterprise-bluetoothManager.md#bluetoothmanageraddallowedbluetoothdevices)接口设置了蓝牙设备禁用名单或者允许名单,再通过本接口禁用设备蓝牙能力,会优先生效禁用设备蓝牙能力。直到设备蓝牙能力启用后,禁止或允许名单才会生效。| 49|modifyDateTime|设备修改系统时间能力。| 50|printer|设备打印能力,当前仅支持PC/2in1设备使用。本接口禁用了设备打印能力时,通过[setDisallowedPolicyForAccount](#restrictionssetdisallowedpolicyforaccount14)接口开启某用户的打印能力,该用户下的打印能力仍然被禁用。| 51|hdc|设备HDC能力。| 52|microphone|设备麦克风能力。| 53|fingerprint|设备指纹认证能力。当已经通过[setDisallowedPolicyForAccount](#restrictionssetdisallowedpolicyforaccount14)设置了某用户禁用设备指纹认证能力时,再通过本接口启用设备指纹认证能力,会报策略冲突。| 54|usb|设备USB能力。禁用后外接的USB设备无法使用,即在当前设备为HOST模式时,无法外接其他DEVICE设备。<br/>以下四种情况再通过本接口禁用设备USB能力,会报策略冲突。<br/>1)通过[addAllowedUsbDevices](js-apis-enterprise-usbManager.md#usbmanageraddallowedusbdevices)接口添加了USB设备可用名单。<br/>2)通过[setUsbStorageDeviceAccessPolicy](js-apis-enterprise-usbManager.md#usbmanagersetusbstoragedeviceaccesspolicy)接口设置了USB存储设备访问策略为只读/禁用。<br/>3)通过[addDisallowedUsbDevices](js-apis-enterprise-usbManager.md#usbmanageradddisallowedusbdevices14)接口添加了禁止使用的USB设备类型。<br/>4)通过[setDisallowedPolicyForAccount](#restrictionssetdisallowedpolicyforaccount14)接口禁用了某用户USB存储设备写入能力。| 55|wifi|设备Wi-Fi能力。| 56|tethering<sup>14+</sup>|网络共享能力(设备已有网络共享给其他设备的能力,即共享热点能力)。| 57|inactiveUserFreeze<sup>14+</sup>|非活跃用户运行能力,当前仅支持PC/2in1设备使用。企业空间场景下,系统切换到企业空间用户,个人空间用户属于非活跃用户。| 58|camera<sup>14+</sup>|设备相机能力。| 59|mtpClient<sup>18+</sup>|MTP客户端能力(包含读取和写入),当前仅支持PC/2in1设备使用。MTP(MediaTransferProtocol,媒体传输协议),该协议允许用户在移动设备上线性访问媒体文件。当已经通过[setDisallowedPolicyForAccount](#restrictionssetdisallowedpolicyforaccount14)设置了某用户禁用MTP客户端写入能力时,再通过本接口禁用MTP客户端能力,会报策略冲突。| 60|mtpServer<sup>18+</sup>|MTP服务端能力。| 61|sambaClient<sup>20+</sup>|samba客户端能力,当前仅支持PC/2in1设备使用。samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。SMB协议是客户机/服务器型协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。| 62|sambaServer<sup>20+</sup>|samba服务端能力,当前仅支持PC/2in1设备使用。| 63|backupAndRestore<sup>20+</sup>|备份和恢复能力,禁用后设备的"设置--系统--备份和恢复"、"设置--云空间"置灰,当前仅支持手机、平板使用。如果要完全禁用设备的备份和恢复能力,建议同时调用[applicationManager.addDisallowedRunningBundlesSync](./js-apis-enterprise-applicationManager.md#applicationmanageradddisallowedrunningbundlessync)接口禁止具备备份和恢复能力的应用运行,如备份和恢复、手机助手、云空间应用。| 64|maintenanceMode<sup>20+</sup>|设备维修模式能力。| 65|mms<sup>20+</sup>|multimedia messaging service,设备接收、发送彩信的能力,当前仅支持手机、平板设备使用。| 66|sms<sup>20+</sup>|short messaging service,设备接收、发送短信的能力,当前仅支持手机、平板设备使用。| 67|mobileData<sup>20+</sup>|蜂窝数据能力,当前仅支持手机、平板设备使用。| 68|airplaneMode<sup>20+</sup>|飞行模式能力,当前仅支持手机、平板设备使用。| 69|vpn<sup>20+</sup>|Virtual Private Network(虚拟专用网络),VPN能力。| 70|notification<sup>20+</sup>|设备通知能力。禁用后,由三方应用自身发出的通知将不会显示。| 71|nfc<sup>20+</sup>|Near Field Communication(近距离无线通信),NFC能力。| 72|privateSpace<sup>20+</sup>|创建隐私空间能力,当前仅支持手机、平板使用。对已创建的隐私空间无效。| 73|telephoneCall<sup>20+</sup>|设备通话能力,禁用后电话无法呼入和呼出。当前仅支持手机、平板设备使用。| 74<!--RP1--><!--RP1End--> 75 76**错误码**: 77 78以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 79 80| 错误码ID | 错误信息 | 81| -------- | ------------------------------------------------------------ | 82| 9200001 | The application is not an administrator application of the device. | 83| 9200002 | The administrator application does not have permission to manage the device. | 84| 201 | Permission verification failed. The application does not have the permission required to call the API. | 85 86**示例:** 87 88```ts 89import { restrictions } from '@kit.MDMKit'; 90import { Want } from '@kit.AbilityKit'; 91 92let wantTemp: Want = { 93 // 需根据实际情况进行替换 94 bundleName: 'com.example.myapplication', 95 abilityName: 'EntryAbility' 96}; 97 98try { 99 // 参数需根据实际情况进行替换 100 restrictions.setDisallowedPolicy(wantTemp, 'printer', true); 101 console.info('Succeeded in setting printer disabled'); 102} catch (err) { 103 console.error(`Failed to set printer disabled. Code is ${err.code}, message is ${err.message}`); 104} 105``` 106 107## restrictions.getDisallowedPolicy 108 109getDisallowedPolicy(admin: Want, feature: string): boolean 110 111查询某特性是否被禁用。 112 113**需要权限:** ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 或者 ohos.permission.PERSONAL_MANAGE_RESTRICTIONS<sup>15+</sup> 114 115**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 116 117**模型约束:** 此接口仅可在Stage模型下使用。 118 119**参数:** 120 121| 参数名 | 类型 | 必填 | 说明 | 122| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 123| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 124| feature | string | 是 | 支持查询的特性清单参考下表2。 <br/> **说明:** 从API version 15开始,应用申请权限ohos.permission.PERSONAL_MANAGE_RESTRICTIONS并[激活为自带设备管理应用](./js-apis-enterprise-adminManager.md#adminmanagerstartadminprovision15),可以使用此接口获取以下特性状态:bluetooth、hdc、microphone、usb、wifi、tethering、camera<!--RP4--><!--RP4End-->。 | 125 126**表2 支持查询的特性清单:** 127|特性|说明| 128|--------------|---------------------| 129|bluetooth|设备蓝牙能力。| 130|modifyDateTime|设备修改系统时间能力。| 131|printer|设备打印能力,当前仅支持PC/2in1设备使用。| 132|hdc|设备HDC能力。| 133|microphone|设备麦克风能力。| 134|fingerprint|设备指纹认证能力。| 135|usb|设备USB能力。禁用后外接的USB设备无法使用,即在当前设备为HOST模式时,无法外接其他DEVICE设备。| 136|wifi|设备Wi-Fi能力。| 137|tethering<sup>14+</sup>|网络共享能力(设备已有网络共享给其他设备的能力,即共享热点能力)。 | 138|inactiveUserFreeze<sup>14+</sup>|非活跃用户运行能力,当前仅支持PC/2in1设备使用。企业空间场景下,系统切换到企业空间用户,个人空间用户属于非活跃用户。| 139|camera<sup>14+</sup>|设备相机能力。| 140|mtpClient<sup>18+</sup>|MTP客户端能力(包含读取和写入),当前仅支持PC/2in1设备使用。MTP(MediaTransferProtocol,媒体传输协议),该协议允许用户在移动设备上线性访问媒体文件。| 141|mtpServer<sup>18+</sup>|MTP服务端能力。| 142|sambaClient<sup>20+</sup>|samba客户端能力,当前仅支持PC/2in1设备使用。samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。SMB协议是客户机/服务器型协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。| 143|sambaServer<sup>20+</sup>|samba服务端能力,当前仅支持PC/2in1设备使用。| 144|backupAndRestore<sup>20+</sup>|备份和恢复能力,禁用后设备的"设置--系统--备份和恢复"、"设置--云空间"置灰,当前仅支持手机、平板使用。| 145|maintenanceMode<sup>20+</sup>|设备维修模式能力。| 146|mms<sup>20+</sup>|multimedia messaging service,设备接收、发送彩信的能力,当前仅支持手机、平板设备使用。| 147|sms<sup>20+</sup>|short messaging service,设备接收、发送短信的能力,当前仅支持手机、平板设备使用。| 148|mobileData<sup>20+</sup>|蜂窝数据能力,当前仅支持手机、平板设备使用。| 149|airplaneMode<sup>20+</sup>|飞行模式能力,当前仅支持手机、平板设备使用。| 150|vpn<sup>20+</sup>|Virtual Private Network(虚拟专用网络),VPN能力。| 151|notification<sup>20+</sup>|设备通知能力。| 152|nfc<sup>20+</sup>|Near Field Communication(近距离无线通信),NFC能力。| 153|privateSpace<sup>20+</sup>|创建隐私空间能力,当前仅支持手机、平板使用。| 154|telephoneCall<sup>20+</sup>|设备通话能力,禁用后电话无法呼入和呼出。当前仅支持手机、平板设备使用。| 155<!--RP2--><!--RP2End--> 156 157**返回值:** 158 159| 类型 | 说明 | 160| ------- | ------------------------------------------------------------ | 161| boolean | 返回true表示feature对应的某种特性被禁用,false表示feature对应的某种特性未被禁用。 | 162 163**错误码**: 164 165以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 166 167| 错误码ID | 错误信息 | 168| -------- | ------------------------------------------------------------ | 169| 9200001 | The application is not an administrator application of the device. | 170| 9200002 | The administrator application does not have permission to manage the device. | 171| 201 | Permission verification failed. The application does not have the permission required to call the API. | 172 173**示例:** 174 175```ts 176import { restrictions } from '@kit.MDMKit'; 177import { Want } from '@kit.AbilityKit'; 178 179let wantTemp: Want = { 180 // 需根据实际情况进行替换 181 bundleName: 'com.example.myapplication', 182 abilityName: 'EntryAbility' 183}; 184 185try { 186 // 参数需根据实际情况进行替换 187 let result: boolean = restrictions.getDisallowedPolicy(wantTemp, 'printer'); 188 console.info(`Succeeded in querying whether the printing function is disabled. Disabled status: ${result}`); 189} catch (err) { 190 console.error(`Failed to get printer disabled status. Code is ${err.code}, message is ${err.message}`); 191} 192``` 193 194## restrictions.setDisallowedPolicyForAccount<sup>14+</sup> 195 196setDisallowedPolicyForAccount(admin: Want, feature: string, disallow: boolean, accountId: number): void 197 198设置禁用/启用指定用户的某特性。 199 200**需要权限:** ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 201 202**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 203 204**模型约束:** 此接口仅可在Stage模型下使用。 205 206**参数:** 207 208| 参数名 | 类型 | 必填 | 说明 | 209| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 210| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 211| feature | string | 是 | feature名称。<br/>- fingerprint:设备指纹认证能力,当前仅支持PC/2in1设备使用。使用此参数时有以下规则:<br/>1. 通过[setDisallowedPolicy](#restrictionssetdisallowedpolicy)接口禁用了设备指纹认证能力,再使用本接口传入此参数,会报策略冲突。<br/>2. 通过本接口设置禁用/启用指定用户的设备指纹认证能力后,再通过[setDisallowedPolicy](#restrictionssetdisallowedpolicy)接口禁用设备指纹认证能力时,后者会覆盖前者的策略。此后再通过[setDisallowedPolicy](#restrictionssetdisallowedpolicy)接口启用设备指纹认证能力,则所有用户都允许使用设备指纹认证能力。<br/>- print<sup>20+</sup>:设备打印能力,当前仅支持PC/2in1设备使用。如果使用本接口禁用了指定用户的设备打印能力,再通过[setDisallowedPolicy](#restrictionssetdisallowedpolicy)接口启用设备打印能力,该用户下的设备打印能力仍然被禁用。<br/>- mtpClient<sup>20+</sup>:MTP客户端能力(仅包含写入),当前仅支持PC/2in1设备使用。MTP(MediaTransferProtocol,媒体传输协议),该协议允许用户在移动设备上线性访问媒体文件。当已经通过[setDisallowedPolicy](#restrictionssetdisallowedpolicy)接口禁用了设备MTP客户端能力时,再通过本接口禁用某用户MTP客户端写入能力,会报策略冲突。<br/>- usbStorageDeviceWrite<sup>20+</sup>:USB存储设备写入能力,当前仅支持PC/2in1设备使用。<!--RP5--><!--RP5End--><br/> 以下三种情况再通过本接口禁用某用户USB存储设备写入能力,会报策略冲突。<br/> 1)通过[setDisallowedPolicy](#restrictionssetdisallowedpolicy)接口设置了设备USB能力禁用。<br/> 2)通过[setUsbStorageDeviceAccessPolicy](js-apis-enterprise-usbManager.md#usbmanagersetusbstoragedeviceaccesspolicy)接口设置了USB存储设备访问策略为只读/禁用。<br/> 3)通过[addDisallowedUsbDevices](js-apis-enterprise-usbManager.md#usbmanageradddisallowedusbdevices14)接口添加了存储类型的USB设备禁用。 <br/>- diskRecoveryKey<sup>20+</sup>:恢复[密钥导出](../../security/UniversalKeystoreKit/huks-export-key-arkts.md)能力,当前仅支持2in1设备使用。<br/>- sudo<sup>20+</sup>:superuser do,表示以超级用户执行,当前仅支持PC/2in1设备使用。禁用后企业空间或个人空间不能以超级用户执行。<br/>- distributedTransmissionOutgoing<sup>20+</sup>:设备间单向传输数据的能力(仅包含向其他设备传输数据)。 | 212| disallow | boolean | 是 | true表示禁用,false表示启用。 | 213| accountId | number | 是 | 用户ID,取值范围:大于等于0。<br/>accountId可以通过[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)等接口来获取。 | 214 215**错误码**: 216 217以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 218 219| 错误码ID | 错误信息 | 220| -------- | ------------------------------------------------------------ | 221| 9200001 | The application is not an administrator application of the device. | 222| 9200002 | the administrator application does not have permission to manage the device. | 223| 9200010 | A conflict policy has been configured. | 224| 201 | Permission verification failed. The application does not have the permission required to call the API. | 225 226**示例:** 227 228```ts 229import { restrictions } from '@kit.MDMKit'; 230import { Want } from '@kit.AbilityKit'; 231 232let wantTemp: Want = { 233 // 需根据实际情况进行替换 234 bundleName: 'com.example.myapplication', 235 abilityName: 'EntryAbility' 236}; 237 238try { 239 // 参数需根据实际情况进行替换 240 restrictions.setDisallowedPolicyForAccount(wantTemp, 'fingerprint', true, 100); 241 console.info('Succeeded in setting fingerprint disabled'); 242} catch (err) { 243 console.error(`Failed to set fingerprint disabled. Code is ${err.code}, message is ${err.message}`); 244} 245``` 246 247## restrictions.getDisallowedPolicyForAccount<sup>14+</sup> 248 249getDisallowedPolicyForAccount(admin: Want | null, feature: string, accountId: number): boolean 250 251获取指定用户的某特性状态。 252 253**需要权限:** ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 254 255**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 256 257**模型约束:** 此接口仅可在Stage模型下使用。 258 259**参数:** 260 261| 参数名 | 类型 | 必填 | 说明 | 262| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 263| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) \| null | 是 | 企业设备管理扩展组件。 | 264| feature | string | 是 | feature名称。<br/>- fingerprint:设备指纹认证能力,当前仅支持PC/2in1设备使用。使用此参数时有以下规则:当已经通过[setDisallowedPolicyForAccount](#restrictionssetdisallowedpolicyforaccount14)接口设置禁用/启用指定用户的设备指纹认证能力后,再通过[setDisallowedPolicy](#restrictionssetdisallowedpolicy)接口禁用设备指纹认证能力时,后者会覆盖前者的策略。即此时调用本接口结果为false。<br/>- mtpClient<sup>20+</sup>:MTP客户端能力(仅包含写入),当前仅支持PC/2in1设备使用。MTP(MediaTransferProtocol,媒体传输协议),该协议允许用户在移动设备上线性访问媒体文件。<br/>- usbStorageDeviceWrite<sup>20+</sup>:USB存储设备写入能力,当前仅支持PC/2in1设备使用。<br/>- diskRecoveryKey<sup>20+</sup>:恢复[密钥导出](../../security/UniversalKeystoreKit/huks-export-key-arkts.md)能力,当前仅支持2in1设备使用。<br/>- sudo<sup>20+</sup>:superuser do,表示以超级用户执行,当前仅支持PC/2in1设备使用。禁用后企业空间或个人空间不能以超级用户执行。<br/>- distributedTransmissionOutgoing<sup>20+</sup>:设备间单向传输数据的能力(仅包含向其他设备传输数据)。<br/>- print<sup>20+</sup>:设备打印能力,当前仅支持PC/2in1设备使用。如果使用[setDisallowedPolicy](#restrictionssetdisallowedpolicy)接口禁用了设备打印能力,再通过[setDisallowedPolicyForAccount](#restrictionssetdisallowedpolicyforaccount14)接口启用某用户下的设备打印能力,通过本接口查询结果是该用户已启用打印能力,但实际打印能力已被禁用。 | 265| accountId | number | 是 | 用户ID,取值范围:大于等于0。<br/>accountId可以通过[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)等接口来获取。 | 266 267**返回值:** 268 269| 类型 | 说明 | 270| ------- | ------------------------------------------------------------ | 271| boolean | 返回true表示参数feature对应的特性被禁用,false表示参数feature对应的特性未被禁用。 | 272 273**错误码**: 274 275以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 276 277| 错误码ID | 错误信息 | 278| -------- | ------------------------------------------------------------ | 279| 9200001 | The application is not an administrator application of the device. | 280| 9200002 | the administrator application does not have permission to manage the device. | 281| 201 | Permission verification failed. The application does not have the permission required to call the API. | 282 283**示例:** 284 285```ts 286import { restrictions } from '@kit.MDMKit'; 287import { Want } from '@kit.AbilityKit'; 288 289let wantTemp: Want = { 290 // 需根据实际情况进行替换 291 bundleName: 'com.example.myapplication', 292 abilityName: 'EntryAbility' 293}; 294 295try { 296 // 参数需根据实际情况进行替换 297 let result: boolean = restrictions.getDisallowedPolicyForAccount(wantTemp, 'fingerprint', 100); 298 console.info(`Succeeded in querying is the fingerprint function disabled : ${result}`); 299} catch (err) { 300 console.error(`Failed to set fingerprint disabled. Code is ${err.code}, message is ${err.message}`); 301} 302``` 303 304## restrictions.addDisallowedListForAccount<sup>14+</sup> 305 306addDisallowedListForAccount(admin: Want, feature: string, list: Array\<string>, accountId: number): void 307 308为指定用户添加禁止使用某特性的应用名单。指定用户下,添加到名单中的应用不允许使用指定的特性能力。 309 310**需要权限:** ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 311 312**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 313 314**模型约束:** 此接口仅可在Stage模型下使用。 315 316**参数:** 317 318| 参数名 | 类型 | 必填 | 说明 | 319| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 320| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 321| feature | string | 是 | feature名称。<br/>- snapshotSkip:屏幕快照能力。 | 322| list | Array\<string> | 是 | 包名等内容的名单集合。 | 323| accountId | number | 是 | 用户ID,取值范围:大于等于0。<br/>accountId可以通过[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)等接口来获取。 | 324 325**错误码**: 326 327以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 328 329| 错误码ID | 错误信息 | 330| -------- | ------------------------------------------------------------ | 331| 9200001 | The application is not an administrator application of the device. | 332| 9200002 | The administrator application does not have permission to manage the device. | | 333| 201 | Permission verification failed. The application does not have the permission required to call the API. | 334| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 335 336**示例:** 337 338```ts 339import { restrictions } from '@kit.MDMKit'; 340import { Want } from '@kit.AbilityKit'; 341 342let wantTemp: Want = { 343 // 需根据实际情况进行替换 344 bundleName: 'com.example.myapplication', 345 abilityName: 'EntryAbility' 346}; 347// 需根据实际情况进行替换 348let valueList:Array<string> = ["com.xx.aa.", "com.xx.bb"]; 349try { 350 // 参数需根据实际情况进行替换 351 restrictions.addDisallowedListForAccount(wantTemp, 'snapshotSkip', valueList, 100); 352 console.info('Succeeded in adding disallowed snapshotSkip feature'); 353} catch (err) { 354 console.error(`Failed to add disallowed snapshotSkip feature. Code is ${err.code}, message is ${err.message}`); 355} 356``` 357 358## restrictions.removeDisallowedListForAccount<sup>14+</sup> 359 360removeDisallowedListForAccount(admin: Want, feature: string, list: Array\<string>, accountId: number): void 361 362为指定用户移除禁止使用某特性的应用名单。 363 364**需要权限:** ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 365 366**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 367 368**模型约束:** 此接口仅可在Stage模型下使用。 369 370**参数:** 371 372| 参数名 | 类型 | 必填 | 说明 | 373| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 374| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 375| feature | string | 是 | feature名称。<br/>- snapshotSkip:屏幕快照能力。 | 376| list | Array\<string> | 是 | 包名等内容的名单集合。 | 377| accountId | number | 是 | 用户ID,取值范围:大于等于0。<br/>accountId可以通过[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)等接口来获取。 | 378 379**错误码**: 380 381以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 382 383| 错误码ID | 错误信息 | 384| -------- | ------------------------------------------------------------ | 385| 9200001 | The application is not an administrator application of the device. | 386| 9200002 | The administrator application does not have permission to manage the device. | | 387| 201 | Permission verification failed. The application does not have the permission required to call the API. | 388| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 389 390**示例:** 391 392```ts 393import { restrictions } from '@kit.MDMKit'; 394import { Want } from '@kit.AbilityKit'; 395 396let wantTemp: Want = { 397 // 需根据实际情况进行替换 398 bundleName: 'com.example.myapplication', 399 abilityName: 'EntryAbility' 400}; 401// 需根据实际情况进行替换 402let valueList:Array<string> = ["com.xx.aa.", "com.xx.bb"]; 403try { 404 // 参数需根据实际情况进行替换 405 restrictions.removeDisallowedListForAccount(wantTemp, 'snapshotSkip', valueList, 100); 406 console.info('Succeeded in removing disallowed snapshotSkip feature'); 407} catch (err) { 408 console.error(`Failed to remove disallowed snapshotSkip feature. Code is ${err.code}, message is ${err.message}`); 409} 410``` 411 412## restrictions.getDisallowedListForAccount<sup>14+</sup> 413 414getDisallowedListForAccount(admin: Want, feature: string, accountId: number): Array\<string> 415 416获取指定用户禁止使用某特性的应用名单。 417 418**需要权限:** ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 419 420**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 421 422**模型约束:** 此接口仅可在Stage模型下使用。 423 424**参数:** 425 426| 参数名 | 类型 | 必填 | 说明 | 427| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 428| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 429| feature | string | 是 | feature名称。<br/>- snapshotSkip:屏幕快照能力。 | 430| accountId | number | 是 | 用户ID,取值范围:大于等于0。<br/>accountId可以通过[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)等接口来获取。 | 431 432**返回值:** 433 434| 类型 | 说明 | 435| ------- | ------------------------------------------------------------ | 436| Array\<string> | 用户已添加的禁用某特征的应用名单。 | 437 438**错误码**: 439 440以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 441 442| 错误码ID | 错误信息 | 443| -------- | ------------------------------------------------------------ | 444| 9200001 | The application is not an administrator application of the device. | 445| 9200002 | The administrator application does not have permission to manage the device. | 446| 201 | Permission verification failed. The application does not have the permission required to call the API. | 447| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 448 449**示例:** 450 451```ts 452import { restrictions } from '@kit.MDMKit'; 453import { Want } from '@kit.AbilityKit'; 454 455let wantTemp: Want = { 456 // 需根据实际情况进行替换 457 bundleName: 'com.example.myapplication', 458 abilityName: 'EntryAbility' 459}; 460 461try { 462 // 参数需根据实际情况进行替换 463 let result: Array<string> = restrictions.getDisallowedListForAccount(wantTemp, 'snapshotSkip', 100); 464 console.info('Succeeded in querying disallowed list for account'); 465} catch (err) { 466 console.error(`Failed to query disallowed list for account. Code is ${err.code}, message is ${err.message}`); 467} 468``` 469 470## restrictions.setUserRestriction<sup>20+</sup> 471 472setUserRestriction(admin: Want, settingsItem: string, restricted: boolean): void 473 474设置用户行为的限制规则。 475 476**需要权限:** ohos.permission.ENTERPRISE_SET_USER_RESTRICTION 477 478**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 479 480**模型约束:** 此接口仅可在Stage模型下使用。 481 482**参数:** 483 484| 参数名 | 类型 | 必填 | 说明 | 485| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 486| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 487| settingsItem | string | 是 | 行为名称。<br/>- setApn:APN设置,当前仅支持手机、平板使用。<br/>- powerLongPress:长按电源键打开电源菜单,当前仅支持手机、平板使用。<br/>- setEthernetIp:修改以太网IP地址,当前仅支持PC/2in1设备使用。<br/>- setDeviceName:修改设备名称,当前仅支持PC/2in1设备、手机、平板使用。禁用后,PC/2in1设备的设置中以下设备名称无法修改,包括关于本机、蓝牙、多设备协同->星闪。手机、平板设备设置中的关于本机、蓝牙、个人热点的设备名称无法修改。<br/>- setBiometricsAndScreenLock:修改锁屏密码,当前仅支持PC/2in1设备、手机、平板使用。| 488| restricted | boolean | 是 | 是否禁用行为。true表示禁用,false表示不禁用。 | 489 490**错误码**: 491 492以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 493 494| 错误码ID | 错误信息 | 495| -------- | ------------------------------------------------------------ | 496| 9200001 | The application is not an administrator application of the device. | 497| 9200002 | The administrator application does not have permission to manage the device. | | 498| 201 | Permission verification failed. The application does not have the permission required to call the API. | 499 500**示例:** 501 502```ts 503import { Want } from '@kit.AbilityKit'; 504import { restrictions } from '@kit.MDMKit'; 505 506let wantTemp: Want = { 507 // 需根据实际情况进行替换 508 bundleName: 'com.example.myapplication', 509 abilityName: 'EntryAbility' 510}; 511 512try { 513 // 参数需根据实际情况进行替换 514 restrictions.setUserRestriction(wantTemp, 'setApn', true); 515 console.info('Succeeded in restricting from setting apn'); 516} catch (err) { 517 console.error(`Failed to restrict from setting apn. Code is ${err.code}, message is ${err.message}`); 518} 519``` 520## restrictions.getUserRestricted<sup>20+</sup> 521 522getUserRestricted(admin: Want, settingsItem: string): boolean 523 524获取设置项的禁用状态。 525 526 527**需要权限:** ohos.permission.ENTERPRISE_SET_USER_RESTRICTION 528 529**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 530 531**模型约束:** 此接口仅可在Stage模型下使用。 532 533**参数:** 534 535| 参数名 | 类型 | 必填 | 说明 | 536| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 537| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 企业设备管理扩展组件。 | 538| settingsItem | string | 是 | 指定设置项。<br/>- setEthernetIp:修改以太网IP地址,当前仅支持PC/2in1设备使用。<br/>- setDeviceName:修改设备名称,当前仅支持PC/2in1设备、手机、平板使用。PC/2in1设备设置中关于本机、蓝牙、多设备协同->星闪中的设备名称。手机、平板设备设置中关于本机、蓝牙、个人热点的设备名称。<br/>- setBiometricsAndScreenLock:修改锁屏密码,当前仅支持PC/2in1设备、手机、平板使用。| 539 540**返回值:** 541 542| 类型 | 说明 | 543| ------- | ------------------------------------------------------------ | 544| boolean | 返回指定设置项的禁用状态,true表示已禁用,false表示未禁用。 | 545 546**错误码**: 547 548以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 549 550| 错误码ID | 错误信息 | 551| -------- | ------------------------------------------------------------ | 552| 9200001 | The application is not an administrator application of the device. | 553| 9200002 | The administrator application does not have permission to manage the device. | 554| 201 | Permission verification failed. The application does not have the permission required to call the API. | 555 556**示例:** 557 558```ts 559import { Want } from '@kit.AbilityKit'; 560import { restrictions } from '@kit.MDMKit'; 561 562let wantTemp: Want = { 563 // 需根据实际情况替换 564 bundleName: 'com.example.myapplication', 565 abilityName: 'EntryAbility' 566}; 567 568try { 569 // 入参需根据实际情况替换 570 let result: boolean = restrictions.getUserRestricted(wantTemp, 'setEthernetIp'); 571 console.info('Succeeded in getting user restricted'); 572} catch (err) { 573 console.error(`Failed to get user restricted. Code is ${err.code}, message is ${err.message}`); 574} 575```