1# @ohos.enterprise.restrictions (Restrictions) 2 3This **restrictions** module provides APIs for setting general restriction policies, including disabling or enabling device printing and HDC. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 10. 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 provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin). 12 13## Modules to Import 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 23Enables or disables device printing through the specified device administrator application. This API uses an asynchronous callback to return the result. 24 25**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY 26 27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 28 29**System API**: This is a system API. 30 31**Parameters** 32 33| Name | Type | Mandatory | Description | 34| ----- | ----------------------------------- | ---- | ------- | 35| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 36| disabled | boolean | Yes| Whether to disable device printing. The value **true** means to disable device printing; the value **false** means the opposite.| 37| callback | AsyncCallback\<void> | Yes| Callback invoked to return the result.<br> If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 38 39**Error codes** 40 41For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 42 43| ID| Error Message | 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**Example** 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 70Enables or disables device printing through the specified device administrator application. This API uses a promise to return the result. 71 72**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY 73 74**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 75 76**System API**: This is a system API. 77 78**Parameters** 79 80| Name | Type | Mandatory | Description | 81| ----- | ----------------------------------- | ---- | ------- | 82| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 83| disabled | boolean | Yes| Whether to disable device printing. The value **true** means to disable device printing; the value **false** means the opposite.| 84 85**Return value** 86 87| Type | Description | 88| ----- | ----------------------------------- | 89| Promise\<void> | Promise that returns no value. An error object will be thrown if the specified device administrator application fails to disable or enable the device printing function.| 90 91**Error codes** 92 93For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 94 95| ID| Error Message | 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**Example** 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 121Checks whether printing is disabled for devices through the specified device administrator application. This API uses an asynchronous callback to return the result. 122 123**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY 124 125**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 126 127**System API**: This is a system API. 128 129**Parameters** 130 131| Name | Type | Mandatory | Description | 132| ----- | ----------------------------------- | ---- | ------- | 133| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 134| callback | AsyncCallback\<boolean> | Yes| Callback invoked to return the result. The value **true** means that device printing is disabled; the value **false** means the opposite.| 135 136**Error codes** 137 138For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 139 140| ID| Error Message | 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**Example** 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 167Checks whether printing is disabled for devices through the specified device administrator application. This API uses a promise to return the result. 168 169**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY 170 171**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 172 173**System API**: This is a system API. 174 175**Parameters** 176 177| Name | Type | Mandatory | Description | 178| ----- | ----------------------------------- | ---- | ------- | 179| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 180 181**Return value** 182 183| Type | Description | 184| ----- | ----------------------------------- | 185| Promise\<boolean> | Promise used to return the result. The value **true** means that device printing is disabled; the value **false** means the opposite.| 186 187**Error codes** 188 189For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 190 191| ID| Error Message | 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**Example** 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 217Enables or disables HDC through the specified device administrator application. This API uses an asynchronous callback to return the result. 218 219**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY 220 221**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 222 223**System API**: This is a system API. 224 225**Parameters** 226 227| Name | Type | Mandatory | Description | 228| ----- | ----------------------------------- | ---- | ------- | 229| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 230| disabled | boolean | Yes| Whether to disable HDC. The value **true** means to disable HDC; the value **false** means the opposite.| 231| callback | AsyncCallback\<void> | Yes| Callback invoked to return the result.<br> If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 232 233**Error codes** 234 235For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 236 237| ID| Error Message | 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**Example** 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 264Enables or disables HDC through the specified device administrator application. This API uses a promise to return the result. 265 266**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY 267 268**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 269 270**System API**: This is a system API. 271 272**Parameters** 273 274| Name | Type | Mandatory | Description | 275| ----- | ----------------------------------- | ---- | ------- | 276| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 277| disabled | boolean | Yes| Whether to disable HDC. The value **true** means to disable HDC; the value **false** means the opposite.| 278 279**Return value** 280 281| Type | Description | 282| ----- | ----------------------------------- | 283| Promise\<void> | Promise that returns no value. An error object will be thrown if the specified device administrator application fails to disable or enable HDC.| 284 285**Error codes** 286 287For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 288 289| ID| Error Message | 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**Example** 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 315Checks whether HDC is disabled through the specified device administrator application. This API uses an asynchronous callback to return the result. 316 317**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY 318 319**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 320 321**System API**: This is a system API. 322 323**Parameters** 324 325| Name | Type | Mandatory | Description | 326| ----- | ----------------------------------- | ---- | ------- | 327| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 328| callback | AsyncCallback\<boolean> | Yes| Callback invoked to return the result. The value **true** means HDC is disabled; the value **false** means the opposite.| 329 330**Error codes** 331 332For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 333 334| ID| Error Message | 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**Example** 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 361Checks whether HDC is disabled through the specified device administrator application. This API uses a promise to return the result. 362 363**Required permissions**: ohos.permission.ENTERPRISE_RESTRICT_POLICY 364 365**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 366 367**System API**: This is a system API. 368 369**Parameters** 370 371| Name | Type | Mandatory | Description | 372| ----- | ----------------------------------- | ---- | ------- | 373| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 374 375**Return value** 376 377| Type | Description | 378| ----- | ----------------------------------- | 379| Promise\<boolean> | Promise used to return the result. The value **true** means HDC is disabled; the value **false** means the opposite.| 380 381**Error codes** 382 383For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 384 385| ID| Error Message | 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**Example** 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