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| Operation to perform. 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| Operation to perform. 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| Operation to perform. 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| Operation to perform. 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 407## restrictions.isMicrophoneDisabled<sup>11+</sup> 408 409isMicrophoneDisabled(admin: Want): boolean 410 411Checks whether the microphone is disabled through the specified device administrator application. 412 413**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 414 415**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 416 417**System API**: This is a system API. 418 419**Parameters** 420 421| Name | Type | Mandatory | Description | 422| ----- | ----------------------------------- | ---- | ------- | 423| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 424 425**Return value** 426 427| Type | Description | 428| ----- | ----------------------------------- | 429| boolean | Returns **true** if the microphone is disabled; returns **false** otherwise.| 430 431**Error codes** 432 433For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 434 435| ID| Error Message | 436| ------- | ---------------------------------------------------------------------------- | 437| 9200001 | the application is not an administrator of the device. | 438| 9200002 | the administrator application does not have permission to manage the device. | 439 440**Example** 441 442```ts 443import Want from '@ohos.app.ability.Want'; 444let wantTemp: Want = { 445 bundleName: 'com.example.myapplication', 446 abilityName: 'EntryAbility', 447}; 448 449try { 450 let result = restrictions.isMicrophoneDisabled(wantTemp); 451 console.info(`Succeeded in querying is microphone disabled : ${result}`); 452} catch (err) { 453 console.error(`Failed to query is microphone disabled or not. Code is ${err.code}, message is ${err.message}`); 454} 455``` 456 457## restrictions.disableMicrophone<sup>11+</sup> 458 459disableMicrophone(admin: Want, disable: boolean): void 460 461Disables or enables the device microphone through the specified device administrator application. 462 463**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 464 465**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 466 467**System API**: This is a system API. 468 469**Parameters** 470 471| Name | Type | Mandatory | Description | 472| ----- | ----------------------------------- | ---- | ------- | 473| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 474| disable | boolean | Yes| Operation to perform. The value **true** means to disable the microphone; the value **false** means the opposite.| 475 476**Error codes** 477 478For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 479 480| ID| Error Message | 481| ------- | ---------------------------------------------------------------------------- | 482| 9200001 | the application is not an administrator of the device. | 483| 9200002 | the administrator application does not have permission to manage the device. | 484 485**Example** 486 487```ts 488import Want from '@ohos.app.ability.Want'; 489import { BusinessError } from '@ohos.base'; 490let wantTemp: Want = { 491 bundleName: 'com.example.myapplication', 492 abilityName: 'EntryAbility', 493}; 494 495try { 496 restrictions.disableMicrophone(wantTemp, true); 497 console.info('Succeeded in setting microphone disabled'); 498} catch (err) { 499 console.error(`Failed to disable microphone. Code is ${err.code}, message is ${err.message}`); 500} 501``` 502 503## restrictions.setFingerprintAuthDisabled<sup>11+</sup> 504 505setFingerprintAuthDisabled(admin: Want, disabled: boolean): void 506 507Disables or enables fingerprint authentication through the specified device administrator application. This API returns the result synchronously. 508 509**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 510 511**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 512 513**System API**: This is a system API. 514 515**Parameters** 516 517| Name | Type | Mandatory | Description | 518| ----- | ----------------------------------- | ---- | ------- | 519| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 520| disabled | boolean | Yes| Operation to perform. The value **true** means to disable fingerprint authentication; the value **false** the opposite.| 521 522**Error codes** 523 524For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 525 526| ID| Error Message | 527| ------- | ---------------------------------------------------------------------------- | 528| 9200001 | the application is not an administrator of the device. | 529| 9200002 | the administrator application does not have permission to manage the device. | 530 531**Example** 532 533```ts 534import Want from '@ohos.app.ability.Want'; 535 536let wantTemp: Want = { 537 bundleName: 'bundleName', 538 abilityName: 'abilityName', 539}; 540 541try { 542 restrictions.setFingerprintAuthDisabled(wantTemp, true); 543 console.info('Succeeded in disabling the fingerprint auth'); 544} catch (err) { 545 console.error(`Failed to disable fingerprint auth. Code: ${err.code}, message: ${err.message}`); 546}; 547 548``` 549 550## restrictions.isFingerprintAuthDisabled<sup>11+</sup> 551 552isFingerprintAuthDisabled(admin: Want): boolean 553 554Checks whether fingerprint authentication is disabled through the specified device administrator application. This API returns the result synchronously. 555 556**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_RESTRICTIONS 557 558**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 559 560**System API**: This is a system API. 561 562**Parameters** 563 564| Name | Type | Mandatory | Description | 565| ----- | ----------------------------------- | ---- | ------- | 566| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 567 568**Return value** 569 570| Type | Description | 571| ----- | ----------------------------------- | 572| boolean | Returns **true** if fingerprint authentication is disabled; returns **false** otherwise.| 573 574**Error codes** 575 576For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 577 578| ID| Error Message | 579| ------- | ---------------------------------------------------------------------------- | 580| 9200001 | the application is not an administrator of the device. | 581| 9200002 | the administrator application does not have permission to manage the device. | 582 583**Example** 584 585```ts 586import Want from '@ohos.app.ability.Want'; 587 588let wantTemp: Want = { 589 bundleName: 'bundleName', 590 abilityName: 'abilityName', 591}; 592 593try { 594 let result: boolean = restrictions.isFingerprintAuthDisabled(wantTemp); 595 console.info(`Succeeded in getting the state of fingerprint auth. result : ${result}`); 596} catch (err) { 597 console.error(`Failed to get the state of fingerprint auth. Code: ${err.code}, message: ${err.message}`); 598}; 599``` 600