• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.restrictions (限制类策略)
2
3本模块提供设置通用限制类策略能力。可以全局禁用和解除禁用蓝牙、HDC、USB、Wi-Fi等特性。
4
5> **说明**:
6>
7> 本模块首批接口从API version 12 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 本模块接口仅可在Stage模型下使用。
10>
11> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-guide.md#功能介绍)开放,需将设备管理应用激活后调用,实现相应功能。
12
13## 导入模块
14
15```ts
16import { restrictions } from '@kit.MDMKit';
17```
18
19## restrictions.setDisallowedPolicy
20
21setDisallowedPolicy(admin: Want, feature: string, disallow: boolean): void
22
23设置禁用/启用某特性。
24
25**需要权限:** ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS
26
27**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
28
29**参数:**
30
31| 参数名   | 类型                                                    | 必填 | 说明                                                         |
32| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
33| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。                                               |
34| feature  | string                                                  | 是   | feature名称。<br/>- bluetooth:设备蓝牙能力。<br/>- modifyDateTime:设备修改系统时间能力,当前仅支持2in1使用。<br/>- printer:设备打印能力,当前仅支持2in1使用。<br/>- hdc:设备HDC能力。<br/>- microphone:设备麦克风能力。<br/>- fingerprint:设备指纹认证能力。<br/>- usb:设备USB能力。禁用后外接的USB设备无法使用。<br/>- wifi:设备WIFI能力。 <!--RP1--><!--RP1End--> |
35| disallow | boolean                                                 | 是   | true表示禁止使用,false表示允许使用。                        |
36
37**错误码**:
38
39以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
40
41| 错误码ID | 错误信息                                                     |
42| -------- | ------------------------------------------------------------ |
43| 9200001  | The application is not an administrator application of the device. |
44| 9200002  | The administrator application does not have permission to manage the device. |
45| 201      | Permission verification failed. The application does not have the permission required to call the API. |
46| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
47
48**示例:**
49
50```ts
51import { Want } from '@kit.AbilityKit';
52let wantTemp: Want = {
53  bundleName: 'bundleName',
54  abilityName: 'abilityName',
55};
56
57try {
58  restrictions.setDisallowedPolicy(wantTemp, 'printer', true);
59  console.info('Succeeded in setting printer disabled');
60} catch (err) {
61  console.error(`Failed to set printer disabled. Code is ${err.code}, message is ${err.message}`);
62}
63```
64
65## restrictions.getDisallowedPolicy
66
67getDisallowedPolicy(admin: Want, feature: string): boolean
68
69获取某特性状态。
70
71**需要权限:** ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS
72
73**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
74
75**参数:**
76
77| 参数名  | 类型                                                    | 必填 | 说明                                                         |
78| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
79| admin   | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是   | 设备管理应用。                                               |
80| feature | string                                                  | 是   | feature名称。<br/>- bluetooth:设备蓝牙能力。<br/>- modifyDateTime:设备修改系统时间能力,当前仅支持2in1使用。<br/>- printer:设备打印能力,当前仅支持2in1使用。<br/>- hdc:设备HDC能力。<br/>- microphone:设备麦克风能力。<br/>- fingerprint:设备指纹认证能力。<br/>- usb:设备USB能力。禁用后外接的USB设备无法使用。<br/>- wifi:设备WIFI能力。<!--RP2--><!--RP2End--> |
81
82**返回值:**
83
84| 类型    | 说明                                                         |
85| ------- | ------------------------------------------------------------ |
86| boolean | 返回true表示feature对应的某种特性被禁用,false表示feature对应的某种特性未被禁用。 |
87
88**错误码**:
89
90以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
91
92| 错误码ID | 错误信息                                                     |
93| -------- | ------------------------------------------------------------ |
94| 9200001  | The application is not an administrator application of the device. |
95| 9200002  | The administrator application does not have permission to manage the device. |
96| 201      | Permission verification failed. The application does not have the permission required to call the API. |
97| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
98
99**示例:**
100
101```ts
102import { Want } from '@kit.AbilityKit';
103let wantTemp: Want = {
104  bundleName: 'bundleName',
105  abilityName: 'abilityName',
106};
107
108try {
109  let result: boolean = restrictions.getDisallowedPolicy(wantTemp, 'printer');
110  console.info(`Succeeded in querying is the printing function disabled : ${result}`);
111} catch (err) {
112  console.error(`Failed to set printer disabled. Code is ${err.code}, message is ${err.message}`);
113}
114```
115