• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.restrictions (Restrictions)
2
3This **restrictions** module provides APIs for disallowing general features of devices.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> The APIs of this module can be used only in the stage model.
10>
11> The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is enabled.
12
13## Modules to Import
14
15```ts
16import { restrictions } from '@kit.MDMKit';
17```
18
19## restrictions.setDisallowedPolicy
20
21setDisallowedPolicy(admin: Want, feature: string, disallow: boolean): void
22
23Disallows a feature.
24
25**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS
26
27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
28
29**Parameters**
30
31| Name  | Type                                                   | Mandatory| Description                                                        |
32| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
33| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.                                              |
34| feature  | string                                                  | Yes  | Feature to set.<br>- **bluetooth**: Bluetooth capability of the device.<br>- **modifyDateTime**: capability of setting the system time of the device.<br>- **printer**: printer capability of the device.<br>- **hdc**: OpenHarmony Device Connector (hdc).<br>- **microphone**: microphone capability of the device.<br>- **fingerprint**: fingerprint authentication capability of the device.<br>- **usb**: USB capability of the device.<br>- **wifi**: Wi-Fi capability of the device. <!--RP1--><!--RP1End--> |
35| disallow | boolean                                                 | Yes  | Whether to disallow the feature. The value **true** means to disallow the feature; the value **false** means the opposite.                       |
36
37**Error codes**
38
39For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
40
41| ID| Error Message                                                    |
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**Example**
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
69Obtains the status of a feature.
70
71**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS
72
73**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
74
75**Parameters**
76
77| Name | Type                                                   | Mandatory| Description                                                        |
78| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
79| admin   | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.                                              |
80| feature | string                                                  | Yes  | Name of the feature, whose status is to be obtained.<br>- **bluetooth**: Bluetooth capability of the device.<br>- **modifyDateTime**: capability of setting the system time of the device.<br>- **printer**: printer capability of the device.<br>- **hdc**: OpenHarmony Device Connector (hdc).<br>- **microphone**: microphone capability of the device.<br>- **fingerprint**: fingerprint authentication capability of the device.<br>- **usb**: USB capability of the device.<br>- **wifi**: Wi-Fi capability of the device.<!--RP2--><!--RP2End--> |
81
82**Return value**
83
84| Type   | Description                                                        |
85| ------- | ------------------------------------------------------------ |
86| boolean | Returns **true** if the feature is disallowed; returns **false** otherwise.|
87
88**Error codes**
89
90For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
91
92| ID| Error Message                                                    |
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**Example**
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