• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.restrictions (限制类策略)
2
3本模块提供设置通用限制类策略能力,包括禁用或启用设备打印、HDC等能力。
4
5> **说明**:
6>
7> 本模块首批接口从API version 10 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 本模块接口仅可在Stage模型下使用。
10>
11> 本模块接口仅对[设备管理应用](enterpriseDeviceManagement-overview.md#基本概念)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager.md#adminmanagerenableadmin)后调用,实现相应功能。
12
13## 导入模块
14
15```ts
16import restrictions from '@ohos.enterprise.restrictions';
17```
18
19## restrictions.setPrinterDisabled
20
21setPrinterDisabled(admin: Want, disabled: boolean, callback: AsyncCallback\<void>): void
22
23指定设备管理应用使设备禁用或启用打印能力。使用callback异步回调。
24
25**需要权限:** ohos.permission.ENTERPRISE_RESTRICT_POLICY
26
27**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
28
29**系统API**: 此接口为系统接口。
30
31**参数:**
32
33| 参数名   | 类型                                  | 必填   | 说明      |
34| ----- | ----------------------------------- | ---- | ------- |
35| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
36| disabled  | boolean | 是 | true表示禁止使用打印能力,false表示允许使用打印能力。 |
37| callback | AsyncCallback\<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 |
38
39**错误码**:
40
41以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
42
43| 错误码ID | 错误信息                                                                      |
44| ------- | ---------------------------------------------------------------------------- |
45| 9200001 | the application is not an administrator of the device.                       |
46| 9200002 | the administrator application does not have permission to manage the device. |
47
48**示例:**
49
50```ts
51import Want from '@ohos.app.ability.Want';
52let wantTemp: Want = {
53  bundleName: 'bundleName',
54  abilityName: 'abilityName',
55};
56
57restrictions.setPrinterDisabled(wantTemp, true, (err) => {
58  if (err) {
59    console.error(`Failed to set printer disabled. Code is ${err.code}, message is ${err.message}`);
60    return;
61  }
62  console.info('Succeeded in setting printer disabled');
63})
64```
65
66## restrictions.setPrinterDisabled
67
68setPrinterDisabled(admin: Want, disabled: boolean): Promise\<void>
69
70指定设备管理应用使设备禁用或启用打印能力。使用Promise异步回调。
71
72**需要权限:** ohos.permission.ENTERPRISE_RESTRICT_POLICY
73
74**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
75
76**系统API**: 此接口为系统接口。
77
78**参数:**
79
80| 参数名   | 类型                                  | 必填   | 说明      |
81| ----- | ----------------------------------- | ---- | ------- |
82| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
83| disabled  | boolean | 是 | true表示禁止使用打印能力,false表示允许使用打印能力。 |
84
85**返回值:**
86
87| 类型   | 说明                                  |
88| ----- | ----------------------------------- |
89| Promise\<void> | 无返回结果的Promise对象。当指定设备管理应用禁止或允许使用打印能力失败时抛出错误对象。 |
90
91**错误码**:
92
93以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
94
95| 错误码ID | 错误信息                                                                      |
96| ------- | ---------------------------------------------------------------------------- |
97| 9200001 | the application is not an administrator of the device.                        |
98| 9200002 | the administrator application does not have permission to manage the device. |
99
100**示例:**
101
102```ts
103import Want from '@ohos.app.ability.Want';
104import { BusinessError } from '@ohos.base';
105let wantTemp: Want = {
106  bundleName: 'bundleName',
107  abilityName: 'abilityName',
108};
109
110restrictions.setPrinterDisabled(wantTemp, true).then(() => {
111  console.info('Succeeded in setting printer disabled');
112}).catch((err: BusinessError) => {
113  console.error(`Failed to set printer disabled. Code is ${err.code}, message is ${err.message}`);
114})
115```
116
117## restrictions.isPrinterDisabled
118
119isPrinterDisabled(admin: Want, callback: AsyncCallback\<boolean>): void
120
121指定设备管理应用查询设备打印能力是否被禁用。使用callback异步回调。
122
123**需要权限:** ohos.permission.ENTERPRISE_RESTRICT_POLICY
124
125**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
126
127**系统API**: 此接口为系统接口。
128
129**参数:**
130
131| 参数名   | 类型                                  | 必填   | 说明      |
132| ----- | ----------------------------------- | ---- | ------- |
133| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
134| callback | AsyncCallback\<boolean> | 是 | 回调函数,callback方式返回设备打印能力是否被禁用,true表示设备打印能力被禁用,false表示设备打印能力未被禁用。 |
135
136**错误码**:
137
138以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
139
140| 错误码ID | 错误信息                                                                      |
141| ------- | ---------------------------------------------------------------------------- |
142| 9200001 | the application is not an administrator of the device.                       |
143| 9200002 | the administrator application does not have permission to manage the device. |
144
145**示例:**
146
147```ts
148import Want from '@ohos.app.ability.Want';
149let wantTemp: Want = {
150  bundleName: 'bundleName',
151  abilityName: 'abilityName',
152};
153
154restrictions.isPrinterDisabled(wantTemp, (err, result) => {
155  if (err) {
156    console.error(`Failed to query is the printing function disabled or not. Code is ${err.code}, message is ${err.message}`);
157    return;
158  }
159  console.info(`Succeeded in querying is the printing function disabled : ${result}`);
160})
161```
162
163## restrictions.isPrinterDisabled
164
165isPrinterDisabled(admin: Want): Promise\<boolean>
166
167指定设备管理应用查询设备打印能力是否被禁用。使用Promise异步回调。
168
169**需要权限:** ohos.permission.ENTERPRISE_RESTRICT_POLICY
170
171**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
172
173**系统API**: 此接口为系统接口。
174
175**参数:**
176
177| 参数名   | 类型                                  | 必填   | 说明      |
178| ----- | ----------------------------------- | ---- | ------- |
179| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
180
181**返回值:**
182
183| 类型   | 说明                                  |
184| ----- | ----------------------------------- |
185| Promise\<boolean> | Promise对象。promise方式返回设备打印能力是否被禁用,true表示设备打印能力被禁用,false表示设备打印能力未被禁用。 |
186
187**错误码**:
188
189以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
190
191| 错误码ID | 错误信息                                                                      |
192| ------- | ---------------------------------------------------------------------------- |
193| 9200001 | the application is not an administrator of the device.                        |
194| 9200002 | the administrator application does not have permission to manage the device. |
195
196**示例:**
197
198```ts
199import Want from '@ohos.app.ability.Want';
200import { BusinessError } from '@ohos.base';
201let wantTemp: Want = {
202  bundleName: 'bundleName',
203  abilityName: 'abilityName',
204};
205
206restrictions.isPrinterDisabled(wantTemp).then((result) => {
207  console.info(`Succeeded in querying is the printing function disabled : ${result}`);
208}).catch((err: BusinessError) => {
209  console.error(`Failed to query is the printing function disabled or not. Code is ${err.code}, message is ${err.message}`);
210})
211```
212
213## restrictions.setHdcDisabled
214
215setHdcDisabled(admin: Want, disabled: boolean, callback: AsyncCallback\<void>): void
216
217指定设备管理应用使设备禁用或启用HDC。使用callback异步回调。
218
219**需要权限:** ohos.permission.ENTERPRISE_RESTRICT_POLICY
220
221**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
222
223**系统API**: 此接口为系统接口。
224
225**参数:**
226
227| 参数名   | 类型                                  | 必填   | 说明      |
228| ----- | ----------------------------------- | ---- | ------- |
229| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
230| disabled  | boolean | 是 | true表示禁止使用HDC,false表示允许使用HDC。 |
231| callback | AsyncCallback\<void> | 是 | 回调函数。当接口调用成功,err为null,否则为错误对象。 |
232
233**错误码**:
234
235以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
236
237| 错误码ID | 错误信息                                                                      |
238| ------- | ---------------------------------------------------------------------------- |
239| 9200001 | the application is not an administrator of the device.                       |
240| 9200002 | the administrator application does not have permission to manage the device. |
241
242**示例:**
243
244```ts
245import Want from '@ohos.app.ability.Want';
246let wantTemp: Want = {
247  bundleName: 'bundleName',
248  abilityName: 'abilityName',
249};
250
251restrictions.setHdcDisabled(wantTemp, true, (err) => {
252  if (err) {
253    console.error(`Failed to set hdc disabled. Code is ${err.code}, message is ${err.message}`);
254    return;
255  }
256  console.info('Succeeded in setting hdc disabled');
257})
258```
259
260## restrictions.setHdcDisabled
261
262setHdcDisabled(admin: Want, disabled: boolean): Promise\<void>
263
264指定设备管理应用使设备禁用或启用HDC。使用Promise异步回调。
265
266**需要权限:** ohos.permission.ENTERPRISE_RESTRICT_POLICY
267
268**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
269
270**系统API**: 此接口为系统接口。
271
272**参数:**
273
274| 参数名   | 类型                                  | 必填   | 说明      |
275| ----- | ----------------------------------- | ---- | ------- |
276| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
277| disabled  | boolean | 是 | true表示禁止使用HDC,false表示允许使用HDC。 |
278
279**返回值:**
280
281| 类型   | 说明                                  |
282| ----- | ----------------------------------- |
283| Promise\<void> | 无返回结果的Promise对象。当指定设备管理应用禁止或允许使用HDC失败时,抛出错误对象。 |
284
285**错误码**:
286
287以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
288
289| 错误码ID | 错误信息                                                                      |
290| ------- | ---------------------------------------------------------------------------- |
291| 9200001 | the application is not an administrator of the device.                        |
292| 9200002 | the administrator application does not have permission to manage the device. |
293
294**示例:**
295
296```ts
297import Want from '@ohos.app.ability.Want';
298import { BusinessError } from '@ohos.base';
299let wantTemp: Want = {
300  bundleName: 'bundleName',
301  abilityName: 'abilityName',
302};
303
304restrictions.setHdcDisabled(wantTemp, true).then(() => {
305  console.info('Succeeded in setting hdc disabled');
306}).catch((err: BusinessError) => {
307  console.error(`Failed to set hdc disabled. Code is ${err.code}, message is ${err.message}`);
308})
309```
310
311## restrictions.isHdcDisabled
312
313isHdcDisabled(admin: Want, callback: AsyncCallback\<boolean>): void
314
315指定设备管理应用查询HDC是否被禁用。使用callback异步回调。
316
317**需要权限:** ohos.permission.ENTERPRISE_RESTRICT_POLICY
318
319**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
320
321**系统API**: 此接口为系统接口。
322
323**参数:**
324
325| 参数名   | 类型                                  | 必填   | 说明      |
326| ----- | ----------------------------------- | ---- | ------- |
327| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
328| callback | AsyncCallback\<boolean> | 是 | 回调函数,callbac方式返回HDC是否被禁用,true表示HDC被禁用,false表示HDC未被禁用。 |
329
330**错误码**:
331
332以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
333
334| 错误码ID | 错误信息                                                                      |
335| ------- | ---------------------------------------------------------------------------- |
336| 9200001 | the application is not an administrator of the device.                       |
337| 9200002 | the administrator application does not have permission to manage the device. |
338
339**示例:**
340
341```ts
342import Want from '@ohos.app.ability.Want';
343let wantTemp: Want = {
344  bundleName: 'bundleName',
345  abilityName: 'abilityName',
346};
347
348restrictions.isHdcDisabled(wantTemp, (err, result) => {
349  if (err) {
350    console.error(`Failed to query is hdc disabled or not. Code is ${err.code}, message is ${err.message}`);
351    return;
352  }
353  console.info(`Succeeded in querying is hdc disabled : ${result}`);
354})
355```
356
357## restrictions.isHdcDisabled
358
359isHdcDisabled(admin: Want): Promise\<boolean>
360
361指定设备管理应用查询HDC是否被禁用。使用Promise异步回调。
362
363**需要权限:** ohos.permission.ENTERPRISE_RESTRICT_POLICY
364
365**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
366
367**系统API**: 此接口为系统接口。
368
369**参数:**
370
371| 参数名   | 类型                                  | 必填   | 说明      |
372| ----- | ----------------------------------- | ---- | ------- |
373| admin | [Want](js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
374
375**返回值:**
376
377| 类型   | 说明                                  |
378| ----- | ----------------------------------- |
379| Promise\<boolean> | Promise对象。promise方式返回HDC是否被禁用,true表示HDC被禁用,false表示HDC未被禁用。 |
380
381**错误码**:
382
383以下错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
384
385| 错误码ID | 错误信息                                                                      |
386| ------- | ---------------------------------------------------------------------------- |
387| 9200001 | the application is not an administrator of the device.                        |
388| 9200002 | the administrator application does not have permission to manage the device. |
389
390**示例:**
391
392```ts
393import Want from '@ohos.app.ability.Want';
394import { BusinessError } from '@ohos.base';
395let wantTemp: Want = {
396  bundleName: 'bundleName',
397  abilityName: 'abilityName',
398};
399
400restrictions.isHdcDisabled(wantTemp).then((result) => {
401  console.info(`Succeeded in querying is hdc disabled : ${result}`);
402}).catch((err: BusinessError) => {
403  console.error(`Failed to query is hdc disabled or not. Code is ${err.code}, message is ${err.message}`);
404})
405```
406