1# @ohos.enterprise.adminManager (Enterprise Device Management) (System API) 2 3The **adminManager** module provides enterprise device management capabilities so that devices have the custom capabilities required in enterprise settings. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs of this module are available only to [device administrator applications](../../mdm/mdm-kit-guide.md#introduction). 10> 11> This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.adminManager](js-apis-enterprise-adminManager.md). 12 13## Modules to Import 14 15```ts 16import { adminManager } from '@kit.MDMKit'; 17``` 18 19## adminManager.enableAdmin 20 21enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, callback: AsyncCallback\<void>): void 22 23Enables a device administrator application for the current user. The super device administrator application can be activated only by the administrator. This API uses an asynchronous callback to return the result. 24 25**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 26 27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 28 29 30 31**Model restriction**: This API can be used only in the stage model. 32 33**Parameters** 34 35| Name | Type | Mandatory | Description | 36| -------------- | ----------------------------------- | ---- | ------------------ | 37| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 38| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application. | 39| type | [AdminType](#admintype) | Yes | Type of the device administrator application to enable. | 40| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 41 42**Error codes** 43 44For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 45 46| ID| Error Message | 47| ------- | --------------------------------------------------------------- | 48| 9200003 | The administrator ability component is invalid. | 49| 9200004 | Failed to activate the administrator application of the device. | 50| 9200007 | The system ability works abnormally. | 51| 201 | Permission verification failed. The application does not have the permission required to call the API. | 52| 202 | Permission verification failed. A non-system application calls a system API. | 53| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 54 55**Example** 56 57```ts 58import { Want } from '@kit.AbilityKit'; 59 60let wantTemp: Want = { 61 bundleName: 'com.example.myapplication', 62 abilityName: 'EntryAbility', 63}; 64let enterpriseInfo: adminManager.EnterpriseInfo = { 65 name: 'enterprise name', 66 description: 'enterprise description' 67} 68 69adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_SUPER, (err) => { 70 if (err) { 71 console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`); 72 return; 73 } 74 console.info('Succeeded in enabling admin'); 75}); 76``` 77 78## adminManager.enableAdmin 79 80enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId: number, callback: AsyncCallback\<void>): void 81 82Enables a device administrator application for the specified user. The super device administrator application can be activated only by the administrator. This API uses an asynchronous callback to return the result. 83 84**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 85 86**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 87 88 89 90**Model restriction**: This API can be used only in the stage model. 91 92**Parameters** 93 94| Name | Type | Mandatory | Description | 95| -------------- | ----------------------------------- | ---- | ---------------------------- | 96| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 97| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application. | 98| type | [AdminType](#admintype) | Yes | Type of the device administrator application to enable. | 99| userId | number | Yes | User ID, which must be greater than or equal to 0.<br>The default value is the user ID of the caller. | 100| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 101 102**Error codes** 103 104For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 105 106| ID| Error Message | 107| ------- | --------------------------------------------------------------- | 108| 9200003 | The administrator ability component is invalid. | 109| 9200004 | Failed to activate the administrator application of the device. | 110| 9200007 | The system ability works abnormally. | 111| 201 | Permission verification failed. The application does not have the permission required to call the API. | 112| 202 | Permission verification failed. A non-system application calls a system API. | 113| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 114 115**Example** 116 117```ts 118import { Want } from '@kit.AbilityKit'; 119 120let wantTemp: Want = { 121 bundleName: 'com.example.myapplication', 122 abilityName: 'EntryAbility', 123}; 124let enterpriseInfo: adminManager.EnterpriseInfo = { 125 name: 'enterprise name', 126 description: 'enterprise description' 127} 128 129adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100, (err) => { 130 if (err) { 131 console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`); 132 return; 133 } 134 console.info('Succeeded in enabling admin'); 135}); 136``` 137 138## adminManager.enableAdmin 139 140enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId?: number): Promise\<void> 141 142Enables a device administrator application for the current or specified user. The super device administrator application can be activated only by the administrator. This API uses a promise to return the result. 143 144**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 145 146**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 147 148 149 150**Model restriction**: This API can be used only in the stage model. 151 152**Parameters** 153 154| Name | Type | Mandatory | Description | 155| -------------- | ----------------------------------- | ---- | ---------------------------- | 156| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 157| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application. | 158| type | [AdminType](#admintype) | Yes | Type of the device administrator application to enable. | 159| userId | number | No | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, this API applies to the specified user.<br> - If **userId** is not passed in, this API applies to the current user.| 160 161**Return value** 162 163| Type | Description | 164| ----------------- | ----------------- | 165| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 166 167**Error codes** 168 169For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 170 171| ID| Error Message | 172| ------- | --------------------------------------------------------------- | 173| 9200003 | The administrator ability component is invalid. | 174| 9200004 | Failed to activate the administrator application of the device. | 175| 9200007 | The system ability works abnormally. | 176| 201 | Permission verification failed. The application does not have the permission required to call the API. | 177| 202 | Permission verification failed. A non-system application calls a system API. | 178| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 179 180**Example** 181 182```ts 183import { Want } from '@kit.AbilityKit'; 184import { BusinessError } from '@kit.BasicServicesKit'; 185 186let wantTemp: Want = { 187 bundleName: 'com.example.myapplication', 188 abilityName: 'EntryAbility', 189}; 190let enterpriseInfo: adminManager.EnterpriseInfo = { 191 name: 'enterprise name', 192 description: 'enterprise description' 193} 194 195adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100).catch( 196 (err: BusinessError) => { 197 console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`); 198 }); 199``` 200 201## adminManager.disableAdmin 202 203disableAdmin(admin: Want, callback: AsyncCallback\<void>): void 204 205Disables a common device administrator application for the current user. This API uses an asynchronous callback to return the result. 206 207**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 208 209**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 210 211 212 213**Model restriction**: This API can be used only in the stage model. 214 215**Parameters** 216 217| Name | Type | Mandatory | Description | 218| -------- | ----------------------------------- | ---- | ------------------- | 219| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 220| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 221 222**Error codes** 223 224For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 225 226| ID| Error Message | 227| ------- | ----------------------------------------------------------------- | 228| 9200005 | Failed to deactivate the administrator application of the device. | 229| 201 | Permission verification failed. The application does not have the permission required to call the API. | 230| 202 | Permission verification failed. A non-system application calls a system API. | 231| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 232 233**Example** 234 235```ts 236import { Want } from '@kit.AbilityKit'; 237 238let wantTemp: Want = { 239 bundleName: 'com.example.myapplication', 240 abilityName: 'EntryAbility', 241}; 242 243adminManager.disableAdmin(wantTemp, (err) => { 244 if (err) { 245 console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); 246 return; 247 } 248 console.info('Succeeded in disabling admin'); 249}); 250``` 251 252## adminManager.disableAdmin 253 254disableAdmin(admin: Want, userId: number, callback: AsyncCallback\<void>): void 255 256Disables a common device administrator application for the user specified by **userId**. This API uses an asynchronous callback to return the result. 257 258**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 259 260**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 261 262 263 264**Model restriction**: This API can be used only in the stage model. 265 266**Parameters** 267 268| Name | Type | Mandatory | Description | 269| -------- | ----------------------------------- | ---- | ---------------------------- | 270| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 271| userId | number | Yes | User ID, which must be greater than or equal to 0.<br>The default value is the user ID of the caller. | 272| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 273 274**Error codes** 275 276For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 277 278| ID| Error Message | 279| ------- | ----------------------------------------------------------------- | 280| 9200005 | Failed to deactivate the administrator application of the device. | 281| 201 | Permission verification failed. The application does not have the permission required to call the API. | 282| 202 | Permission verification failed. A non-system application calls a system API. | 283| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 284 285**Example** 286 287```ts 288import { Want } from '@kit.AbilityKit'; 289 290let wantTemp: Want = { 291 bundleName: 'com.example.myapplication', 292 abilityName: 'EntryAbility', 293}; 294 295adminManager.disableAdmin(wantTemp, 100, (err) => { 296 if (err) { 297 console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); 298 return; 299 } 300 console.info('Succeeded in disabling admin'); 301}); 302``` 303 304## adminManager.disableSuperAdmin 305 306disableSuperAdmin(bundleName: String, callback: AsyncCallback\<void>): void 307 308Disables a super device administrator application based on **bundleName**. This API uses an asynchronous callback to return the result. 309 310**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 311 312**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 313 314 315 316**Model restriction**: This API can be used only in the stage model. 317 318**Parameters** 319 320| Name | Type | Mandatory | Description | 321| ---------- | ----------------------- | ---- | ------------------- | 322| bundleName | String | Yes | Bundle name of the super device administrator application to disable. | 323| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 324 325**Error codes** 326 327For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 328 329| ID| Error Message | 330| ------- | ----------------------------------------------------------------- | 331| 9200005 | Failed to deactivate the administrator application of the device. | 332| 201 | Permission verification failed. The application does not have the permission required to call the API. | 333| 202 | Permission verification failed. A non-system application calls a system API. | 334| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 335 336**Example** 337 338```ts 339import { Want } from '@kit.AbilityKit'; 340 341let bundleName: string = 'com.example.myapplication'; 342 343adminManager.disableSuperAdmin(bundleName, (err) => { 344 if (err) { 345 console.error(`Failed to disable super admin. Code: ${err.code}, message: ${err.message}`); 346 return; 347 } 348 console.info('Succeeded in disabling super admin'); 349}); 350``` 351 352## adminManager.disableSuperAdmin 353 354disableSuperAdmin(bundleName: String): Promise\<void> 355 356Disables a super device administrator application based on **bundleName**. This API uses a promise to return the result. 357 358**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 359 360**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 361 362 363 364**Model restriction**: This API can be used only in the stage model. 365 366**Parameters** 367 368| Name | Type | Mandatory | Description | 369| ---------- | ------ | ---- | ------------ | 370| bundleName | String | Yes | Bundle name of the super device administrator application to disable.| 371 372**Return value** 373 374| Type | Description | 375| ----------------- | ----------------- | 376| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 377 378**Error codes** 379 380For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 381 382| ID| Error Message | 383| ------- | ----------------------------------------------------------------- | 384| 9200005 | Failed to deactivate the administrator application of the device. | 385| 201 | Permission verification failed. The application does not have the permission required to call the API. | 386| 202 | Permission verification failed. A non-system application calls a system API. | 387| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 388 389**Example** 390 391```ts 392import { Want } from '@kit.AbilityKit'; 393import { BusinessError } from '@kit.BasicServicesKit'; 394 395let bundleName: string = 'com.example.myapplication'; 396 397adminManager.disableSuperAdmin(bundleName).catch((err: BusinessError) => { 398 console.error(`Failed to disable super admin. Code: ${err.code}, message: ${err.message}`); 399}); 400``` 401 402## adminManager.isAdminEnabled 403 404isAdminEnabled(admin: Want, callback: AsyncCallback\<boolean>): void 405 406Checks whether a device administrator application of the current user is enabled. This API uses an asynchronous callback to return the result. 407 408**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 409 410 411 412**Model restriction**: This API can be used only in the stage model. 413 414**Parameters** 415 416| Name | Type | Mandatory | Description | 417| -------- | ----------------------------------- | ---- | -------------------- | 418| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 419| callback | AsyncCallback\<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a Boolean value (**true** means that the device administrator application is enabled; and **false** means the opposite). If the operation fails, **err** is an error object.| 420 421**Error codes** 422 423For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 424 425| ID| Error Message | 426| -------- | ------------------------------------------------------------ | 427| 202 | Permission verification failed. A non-system application calls a system API. | 428| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 429 430**Example** 431 432```ts 433import { Want } from '@kit.AbilityKit'; 434 435let wantTemp: Want = { 436 bundleName: 'com.example.myapplication', 437 abilityName: 'EntryAbility', 438}; 439 440adminManager.isAdminEnabled(wantTemp, (err, result) => { 441 if (err) { 442 console.error(`Failed to query admin is enabled or not. Code: ${err.code}, message: ${err.message}`); 443 return; 444 } 445 console.info(`Succeeded in querying admin is enabled or not, result : ${result}`); 446}); 447``` 448 449## adminManager.isAdminEnabled 450 451isAdminEnabled(admin: Want, userId: number, callback: AsyncCallback\<boolean>): void 452 453Checks whether a device administrator application of the specified user is enabled. This API uses an asynchronous callback to return the result. 454 455**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 456 457 458 459**Model restriction**: This API can be used only in the stage model. 460 461**Parameters** 462 463| Name | Type | Mandatory | Description | 464| -------- | ----------------------------------- | ---- | ---------------------------- | 465| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 466| userId | number | Yes | User ID, which must be greater than or equal to 0.<br> The default value is the user ID of the caller. | 467| callback | AsyncCallback\<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a Boolean value (**true** means that the device administrator application is enabled; and **false** means the opposite). If the operation fails, **err** is an error object. | 468 469**Error codes** 470 471For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 472 473| ID| Error Message | 474| -------- | ------------------------------------------------------------ | 475| 202 | Permission verification failed. A non-system application calls a system API. | 476| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 477 478**Example** 479 480```ts 481import { Want } from '@kit.AbilityKit'; 482 483let wantTemp: Want = { 484 bundleName: 'com.example.myapplication', 485 abilityName: 'EntryAbility', 486}; 487 488adminManager.isAdminEnabled(wantTemp, 100, (err, result) => { 489 if (err) { 490 console.error(`Failed to query admin is enabled. Code: ${err.code}, message: ${err.message}`); 491 return; 492 } 493 console.info(`Succeeded in querying admin is enabled or not, result : ${result}`); 494}); 495``` 496 497## adminManager.isAdminEnabled 498 499isAdminEnabled(admin: Want, userId?: number): Promise\<boolean> 500 501Checks whether a device administrator application of the current or specified user is enabled. This API uses a promise to return the result. 502 503**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 504 505 506 507**Model restriction**: This API can be used only in the stage model. 508 509**Parameters** 510 511| Name| Type | Mandatory| Description | 512| ------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 513| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 514| userId | number | No | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, this API applies to the specified user.<br> - If **userId** is not passed in, this API applies to the current user.| 515 516**Return value** 517 518| Type | Description | 519| ----------------- | ------------------- | 520| Promise\<boolean> | Promise used to return the result. The value **true** means the device administrator application is enabled; the value **false** means the opposite.| 521 522**Error codes** 523 524For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 525 526| ID| Error Message | 527| -------- | ------------------------------------------------------------ | 528| 202 | Permission verification failed. A non-system application calls a system API. | 529| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 530 531**Example** 532 533```ts 534import { Want } from '@kit.AbilityKit'; 535import { BusinessError } from '@kit.BasicServicesKit'; 536 537let wantTemp: Want = { 538 bundleName: 'com.example.myapplication', 539 abilityName: 'EntryAbility', 540}; 541 542adminManager.isAdminEnabled(wantTemp, 100).then((result) => { 543 console.info(`Succeeded in querying admin is enabled or not, result : ${result}`); 544}).catch((err: BusinessError) => { 545 console.error(`Failed to query admin is enabled or not. Code: ${err.code}, message: ${err.message}`); 546}); 547``` 548 549## adminManager.isSuperAdmin 550 551isSuperAdmin(bundleName: String, callback: AsyncCallback\<boolean>): void 552 553Checks whether a super device administrator application is enabled based on **bundleName**. This API uses an asynchronous callback to return the result. 554 555**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 556 557 558 559**Model restriction**: This API can be used only in the stage model. 560 561**Parameters** 562 563| Name | Type | Mandatory | Description | 564| ---------- | ----------------------- | ---- | -------------------- | 565| bundleName | String | Yes | Super device administrator application to check. | 566| callback | AsyncCallback\<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a Boolean value (**true** means that the device administrator application is enabled; and **false** means the opposite). If the operation fails, **err** is an error object.| 567 568**Error codes** 569 570For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 571 572| ID| Error Message | 573| -------- | ------------------------------------------------------------ | 574| 202 | Permission verification failed. A non-system application calls a system API. | 575| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 576 577**Example** 578 579```ts 580import { Want } from '@kit.AbilityKit'; 581 582let bundleName: string = 'com.example.myapplication'; 583 584adminManager.isSuperAdmin(bundleName, (err, result) => { 585 if (err) { 586 console.error(`Failed to query admin is super admin or not. Code: ${err.code}, message: ${err.message}`); 587 return; 588 } 589 console.info(`Succeeded in querying admin is super admin or not, result : ${result}`); 590}); 591``` 592 593## adminManager.isSuperAdmin 594 595isSuperAdmin(bundleName: String): Promise\<boolean> 596 597Checks whether a super device administrator application is enabled based on **bundleName**. This API uses a promise to return the result. 598 599**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 600 601 602 603**Model restriction**: This API can be used only in the stage model. 604 605**Parameters** 606 607| Name | Type | Mandatory | Description | 608| ---------- | ------ | ---- | --------- | 609| bundleName | String | Yes | Super device administrator application to check.| 610 611**Return value** 612 613| ID | Error Message | 614| ----------------- | ------------------- | 615| Promise\<boolean> | Promise used to return the result. The value **true** means the super device administrator application is enabled; the value **false** means the opposite.| 616 617**Error codes** 618 619For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 620 621| ID| Error Message | 622| -------- | ------------------------------------------------------------ | 623| 202 | Permission verification failed. A non-system application calls a system API. | 624| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 625 626**Example** 627 628```ts 629import { Want } from '@kit.AbilityKit'; 630import { BusinessError } from '@kit.BasicServicesKit'; 631 632let bundleName: string = 'com.example.myapplication'; 633 634adminManager.isSuperAdmin(bundleName).then((result) => { 635 console.info(`Succeeded in querying admin is super admin or not, result : ${result}`); 636}).catch((err: BusinessError) => { 637 console.error(`Failed to query admin is super admin or not. Code: ${err.code}, message: ${err.message}`); 638}); 639``` 640 641## adminManager.getSuperAdmin<sup>12+</sup> 642 643getSuperAdmin(): Promise\<Want> 644 645Obtains the super device administrator application of this administrator. This API uses a promise to return the result. 646 647**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 648 649 650 651**Model restriction**: This API can be used only in the stage model. 652 653**Return value** 654 655| Type | Description | 656| ------------------------------------------------------------ | ------------------------------------------------------------ | 657| Promise\<[Want](../apis-ability-kit/js-apis-app-ability-want.md)> | Promise used to return the super device administrator application obtained. If no super device administrator application is activated on the device, **bundleName** and **abilityName** in **Want** returned are empty strings.| 658 659**Error codes** 660 661For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 662 663| ID| Error Message | 664| -------- | ------------------------------------------------------------ | 665| 202 | Permission verification failed. A non-system application calls a system API. | 666 667**Example** 668 669```ts 670import { BusinessError } from '@kit.BasicServicesKit'; 671 672adminManager.getSuperAdmin().then((result) => { 673 console.info(`Succeeded in getting super admin :${JSON.stringify(result)}`); 674}).catch((err: BusinessError) => { 675 console.error(`Failed to get super admin. Code: ${err.code}, message: ${err.message}`); 676}) 677``` 678 679## adminManager.setEnterpriseInfo 680 681setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo, callback: AsyncCallback\<void>): void 682 683Sets the enterprise information of the device administrator application. This API uses an asynchronous callback to return the result. 684 685**Required permissions**: ohos.permission.SET_ENTERPRISE_INFO 686 687**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 688 689 690 691**Model restriction**: This API can be used only in the stage model. 692 693**Parameters** 694 695| Name | Type | Mandatory | Description | 696| -------------- | ----------------------------------- | ---- | ---------------------- | 697| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 698| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information to set. | 699| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 700 701**Error codes** 702 703For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 704 705| ID| Error Message | 706| ------- | ----------------------------------------------------- | 707| 9200001 | The application is not an administrator application of the device. | 708| 201 | Permission verification failed. The application does not have the permission required to call the API. | 709| 202 | Permission verification failed. A non-system application calls a system API. | 710| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 711 712**Example** 713 714```ts 715import { Want } from '@kit.AbilityKit'; 716 717let wantTemp: Want = { 718 bundleName: 'com.example.myapplication', 719 abilityName: 'EntryAbility', 720}; 721let enterpriseInfo: adminManager.EnterpriseInfo = { 722 name: 'enterprise name', 723 description: 'enterprise description' 724} 725 726adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo, (err) => { 727 if (err) { 728 console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`); 729 return; 730 } 731 console.info('Succeeded in setting enterprise info'); 732}); 733``` 734 735## adminManager.setEnterpriseInfo 736 737setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo): Promise\<void> 738 739Sets the enterprise information of the device administrator application. This API uses a promise to return the result. 740 741**Required permissions**: ohos.permission.SET_ENTERPRISE_INFO 742 743**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 744 745 746 747**Model restriction**: This API can be used only in the stage model. 748 749**Parameters** 750 751| Name | Type | Mandatory | Description | 752| -------------- | ----------------------------------- | ---- | ------------ | 753| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 754| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information to set.| 755 756**Return value** 757 758| Type | Description | 759| ----------------- | --------------------- | 760| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 761 762**Error codes** 763 764For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 765 766| ID| Error Message | 767| ------- | ----------------------------------------------------- | 768| 9200001 | The application is not an administrator application of the device. | 769| 201 | Permission verification failed. The application does not have the permission required to call the API. | 770| 202 | Permission verification failed. A non-system application calls a system API. | 771| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 772 773**Example** 774 775```ts 776import { Want } from '@kit.AbilityKit'; 777import { BusinessError } from '@kit.BasicServicesKit'; 778 779let wantTemp: Want = { 780 bundleName: 'com.example.myapplication', 781 abilityName: 'EntryAbility', 782}; 783let enterpriseInfo: adminManager.EnterpriseInfo = { 784 name: 'enterprise name', 785 description: 'enterprise description' 786} 787 788adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo).catch((err: BusinessError) => { 789 console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`); 790}); 791``` 792 793## adminManager.getEnterpriseInfo 794 795getEnterpriseInfo(admin: Want, callback: AsyncCallback<EnterpriseInfo>): void 796 797Obtains the enterprise information of the device administrator application. This API uses an asynchronous callback to return the result. 798 799**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 800 801 802 803**Model restriction**: This API can be used only in the stage model. 804 805**Parameters** 806 807| Name | Type | Mandatory | Description | 808| -------- | ---------------------------------------- | ---- | ------------------------ | 809| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 810| callback | AsyncCallback<[EnterpriseInfo](#enterpriseinfo)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the enterprise information of the device administrator application obtained. If the operation fails, **err** is an error object.| 811 812**Error codes** 813 814For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 815 816| ID| Error Message | 817| ------- | ----------------------------------------------------- | 818| 9200001 | The application is not an administrator application of the device. | 819| 202 | Permission verification failed. A non-system application calls a system API. | 820| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 821 822**Example** 823 824```ts 825import { Want } from '@kit.AbilityKit'; 826 827let wantTemp: Want = { 828 bundleName: 'com.example.myapplication', 829 abilityName: 'EntryAbility', 830}; 831 832adminManager.getEnterpriseInfo(wantTemp, (err, result) => { 833 if (err) { 834 console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`); 835 return; 836 } 837 console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`); 838}); 839``` 840 841## adminManager.getEnterpriseInfo 842 843getEnterpriseInfo(admin: Want): Promise<EnterpriseInfo> 844 845Obtains the enterprise information of the device administrator application. This API uses a promise to return the result. 846 847**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 848 849 850 851**Model restriction**: This API can be used only in the stage model. 852 853**Parameters** 854 855| Name | Type | Mandatory | Description | 856| ----- | ----------------------------------- | ---- | ------- | 857| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 858 859**Return value** 860 861| Type | Description | 862| ---------------------------------------- | ------------------------- | 863| Promise<[EnterpriseInfo](#enterpriseinfo)> | Promise used to return the enterprise information of the device administrator application.| 864 865**Error codes** 866 867For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 868 869| ID| Error Message | 870| ------- | ----------------------------------------------------- | 871| 9200001 | The application is not an administrator application of the device. | 872| 202 | Permission verification failed. A non-system application calls a system API. | 873| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 874 875**Example** 876 877```ts 878import { Want } from '@kit.AbilityKit'; 879import { BusinessError } from '@kit.BasicServicesKit'; 880 881let wantTemp: Want = { 882 bundleName: 'com.example.myapplication', 883 abilityName: 'EntryAbility', 884}; 885 886adminManager.getEnterpriseInfo(wantTemp).then((result) => { 887 console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`); 888}).catch((err: BusinessError) => { 889 console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`); 890}); 891``` 892 893## adminManager.subscribeManagedEvent 894 895subscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>, callback: AsyncCallback\<void>): void 896 897Subscribes to system management events. This API uses an asynchronous callback to return the result. 898 899**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 900 901**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 902 903 904 905**Model restriction**: This API can be used only in the stage model. 906 907**Parameters** 908 909| Name | Type | Mandatory | Description | 910| ----- | ----------------------------------- | ---- | ------- | 911| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 912| managedEvents | Array\<[ManagedEvent](js-apis-enterprise-adminManager.md#managedevent)> | Yes| Array of events to subscribe to.| 913| callback | AsyncCallback\<void> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 914 915**Error codes** 916 917For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 918 919| ID| Error Message | 920| -------- | ------------------------------------------------------------ | 921| 9200001 | The application is not an administrator application of the device. | 922| 9200008 | The specified system event is invalid. | 923| 201 | Permission verification failed. The application does not have the permission required to call the API. | 924| 202 | Permission verification failed. A non-system application calls a system API. | 925| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 926 927**Example** 928 929```ts 930import { Want } from '@kit.AbilityKit'; 931 932let wantTemp: Want = { 933 bundleName: 'com.example.myapplication', 934 abilityName: 'EntryAbility', 935}; 936let events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED]; 937 938adminManager.subscribeManagedEvent(wantTemp, events, (err) => { 939 if (err) { 940 console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`); 941 return; 942 } 943 console.info('Succeeded in subscribe managed event'); 944}); 945``` 946 947## adminManager.subscribeManagedEvent 948 949subscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>): Promise\<void> 950 951Subscribes to system management events. This API uses a promise to return the result. 952 953**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 954 955**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 956 957 958 959**Model restriction**: This API can be used only in the stage model. 960 961**Parameters** 962 963| Name | Type | Mandatory | Description | 964| ----- | ----------------------------------- | ---- | ------- | 965| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 966| managedEvents | Array\<[ManagedEvent](js-apis-enterprise-adminManager.md#managedevent)> | Yes| Array of events to subscribe to.| 967 968**Return value** 969 970| Type | Description | 971| ----- | ----------------------------------- | 972| Promise\<void> | Promise that returns no value. When a system event fails to be subscribed to, an error object is thrown.| 973 974**Error codes** 975 976For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 977 978| ID| Error Message | 979| ------- | ----------------------------------------------------- | 980| 9200001 | The application is not an administrator application of the device. | 981| 9200008 | The specified system event is invalid. | 982| 201 | Permission verification failed. The application does not have the permission required to call the API. | 983| 202 | Permission verification failed. A non-system application calls a system API. | 984| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 985 986**Example** 987 988```ts 989import { Want } from '@kit.AbilityKit'; 990import { BusinessError } from '@kit.BasicServicesKit'; 991 992let wantTemp: Want = { 993 bundleName: 'com.example.myapplication', 994 abilityName: 'EntryAbility', 995}; 996let events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED]; 997 998adminManager.subscribeManagedEvent(wantTemp, events).then(() => { 999}).catch((err: BusinessError) => { 1000 console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`); 1001}) 1002``` 1003 1004## adminManager.unsubscribeManagedEvent 1005 1006unsubscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>, callback: AsyncCallback\<void>): void 1007 1008Unsubscribes from system management events. This API uses an asynchronous callback to return the result. 1009 1010**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 1011 1012**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1013 1014 1015 1016**Model restriction**: This API can be used only in the stage model. 1017 1018**Parameters** 1019 1020| Name | Type | Mandatory | Description | 1021| ----- | ----------------------------------- | ---- | ------- | 1022| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 1023| managedEvents | Array\<[ManagedEvent](js-apis-enterprise-adminManager.md#managedevent)> | Yes| Array of events to unsubscribe from.| 1024| callback | AsyncCallback\<void> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 1025 1026**Error codes** 1027 1028For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 1029 1030| ID| Error Message | 1031| ------- | ----------------------------------------------------- | 1032| 9200001 | The application is not an administrator application of the device. | 1033| 9200008 | The specified system event is invalid. | 1034| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1035| 202 | Permission verification failed. A non-system application calls a system API. | 1036| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1037 1038**Example** 1039 1040```ts 1041import { Want } from '@kit.AbilityKit'; 1042 1043let wantTemp: Want = { 1044 bundleName: 'com.example.myapplication', 1045 abilityName: 'EntryAbility', 1046}; 1047let events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED]; 1048 1049adminManager.unsubscribeManagedEvent(wantTemp, events, (err) => { 1050 if (err) { 1051 console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`); 1052 return; 1053 } 1054 console.info('Succeeded in unsubscribe managed event'); 1055}); 1056``` 1057 1058## adminManager.unsubscribeManagedEvent 1059 1060unsubscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>): Promise\<void> 1061 1062Unsubscribes from system management events. This API uses a promise to return the result. 1063 1064**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 1065 1066**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1067 1068 1069 1070**Model restriction**: This API can be used only in the stage model. 1071 1072**Parameters** 1073 1074| Name | Type | Mandatory | Description | 1075| ----- | ----------------------------------- | ---- | ------- | 1076| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 1077| managedEvents | Array\<[ManagedEvent](js-apis-enterprise-adminManager.md#managedevent)> | Yes| Array of events to unsubscribe from.| 1078 1079**Return value** 1080 1081| Type | Description | 1082| ----- | ----------------------------------- | 1083| Promise\<void> | Promise that returns no value. An error object is thrown when the unsubscription of system management events fails.| 1084 1085**Error codes** 1086 1087For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 1088 1089| ID| Error Message | 1090| ------- | ----------------------------------------------------- | 1091| 9200001 | The application is not an administrator application of the device. | 1092| 9200008 | The specified system event is invalid. | 1093| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1094| 202 | Permission verification failed. A non-system application calls a system API. | 1095| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1096 1097**Example** 1098 1099```ts 1100import { Want } from '@kit.AbilityKit'; 1101import { BusinessError } from '@kit.BasicServicesKit'; 1102 1103let wantTemp: Want = { 1104 bundleName: 'com.example.myapplication', 1105 abilityName: 'EntryAbility', 1106}; 1107let events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED]; 1108 1109adminManager.unsubscribeManagedEvent(wantTemp, events).then(() => { 1110}).catch((err: BusinessError) => { 1111 console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`); 1112}) 1113``` 1114 1115## adminManager.authorizeAdmin<sup>10+</sup> 1116 1117authorizeAdmin(admin: Want, bundleName: string, callback: AsyncCallback<void>): void 1118 1119Authorizes the administrator permission to a specified application. This API uses an asynchronous callback to return the result. 1120 1121**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 1122 1123**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1124 1125 1126 1127**Model restriction**: This API can be used only in the stage model. 1128 1129**Parameters** 1130 1131| Name | Type | Mandatory | Description | 1132| ----- | ----------------------------------- | ---- | ------- | 1133| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 1134| bundleName | string | Yes| Bundle name of the application to be authorized with the administrator rights.| 1135| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 1136 1137**Error codes** 1138 1139For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 1140 1141| ID| Error Message | 1142| ------- | ----------------------------------------------------- | 1143| 9200001 | The application is not an administrator application of the device. | 1144| 9200002 | The administrator application does not have permission to manage the device. | 1145| 9200009 | Failed to grant the permission to the application. | 1146| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1147| 202 | Permission verification failed. A non-system application calls a system API. | 1148| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1149 1150**Example** 1151 1152```ts 1153import { Want } from '@kit.AbilityKit'; 1154 1155let wantTemp: Want = { 1156 bundleName: 'com.example.myapplication', 1157 abilityName: 'EntryAbility', 1158}; 1159let bundleName: string = "com.example.application"; 1160 1161adminManager.authorizeAdmin(wantTemp, bundleName, (err) => { 1162 if (err) { 1163 console.error(`Failed to authorize permission to the application. Code: ${err.code}, message: ${err.message}`); 1164 return; 1165 } 1166 console.info('Successfully authorized permission to the application'); 1167}); 1168``` 1169 1170## adminManager.authorizeAdmin<sup>10+</sup> 1171 1172authorizeAdmin(admin: Want, bundleName: string): Promise<void> 1173 1174Authorizes the administrator permission to a specified application. This API uses a promise to return the result. 1175 1176**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 1177 1178**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1179 1180 1181 1182**Model restriction**: This API can be used only in the stage model. 1183 1184**Parameters** 1185 1186| Name | Type | Mandatory | Description | 1187| ----- | ----------------------------------- | ---- | ------- | 1188| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 1189| bundleName | string | Yes| Bundle name of the application to be authorized with the administrator rights.| 1190 1191**Return value** 1192 1193| Type | Description | 1194| ----- | ----------------------------------- | 1195| Promise<void> | Promise that returns no value. An error object is thrown when the permissions of a specified application administrator fail to be granted.| 1196 1197**Error codes** 1198 1199For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 1200 1201| ID| Error Message | 1202| ------- | ----------------------------------------------------- | 1203| 9200001 | The application is not an administrator application of the device. | 1204| 9200002 | The administrator application does not have permission to manage the device. | 1205| 9200009 | Failed to grant the permission to the application. | 1206| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1207| 202 | Permission verification failed. A non-system application calls a system API. | 1208| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1209 1210**Example** 1211 1212```ts 1213import { Want } from '@kit.AbilityKit'; 1214import { BusinessError } from '@kit.BasicServicesKit'; 1215 1216let wantTemp: Want = { 1217 bundleName: 'com.example.myapplication', 1218 abilityName: 'EntryAbility', 1219}; 1220let bundleName: string = "com.example.application"; 1221 1222adminManager.authorizeAdmin(wantTemp, bundleName).then(() => { 1223}).catch((err: BusinessError) => { 1224 console.error(`Failed to authorize permission to the application. Code: ${err.code}, message: ${err.message}`); 1225}) 1226``` 1227 1228## adminManager.getAdmins<sup>15+</sup> 1229 1230getAdmins(): Promise<Array<Want>> 1231 1232Queries all device administrator applications of the current user. This API uses a promise to return the result. 1233 1234**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1235 1236 1237 1238**Model restriction**: This API can be used only in the stage model. 1239 1240 1241**Return value** 1242 1243| Type | Description | 1244| ----- | ----------------------------------- | 1245| Promise<Array<Want>> | Promise that contains all activated device administrator applications.| 1246 1247**Error codes** 1248 1249For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1250 1251| ID| Error Message | 1252| ------- | ----------------------------------------------------- | 1253| 202 | Permission verification failed. A non-system application calls a system API. | 1254 1255**Example** 1256 1257```ts 1258import { Want } from '@kit.AbilityKit'; 1259import { BusinessError } from '@kit.BasicServicesKit'; 1260 1261adminManager.getAdmins().then((result) => { 1262 console.info(`Succeeded in getting admins :${JSON.stringify(result)}`); 1263}).catch((err: BusinessError) => { 1264 console.error(`Failed to get admins. Code: ${err.code}, message: ${err.message}`); 1265}) 1266``` 1267 1268## adminManager.replaceSuperAdmin<sup>18+</sup> 1269 1270replaceSuperAdmin(oldAdmin: Want, newAdmin: Want, isKeepPolicy: boolean): void 1271 1272Replaces a specified application with a super device administrator application. 1273 1274**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 1275 1276**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1277 1278 1279 1280**Model restriction**: This API can be used only in the stage model. 1281 1282**Parameters** 1283 1284| Name | Type | Mandatory | Description | 1285| -------------- | ----------------------------------- | ---- | ---------------------------- | 1286| oldAdmin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Old EnterpriseAdminExtensionAbility. | 1287| newAdmin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | New EnterpriseAdminExtensionAbility. | 1288| isKeepPolicy | boolean | Yes | A Boolean value indicates whether to retain the policy of the old **EnterpriseAdminExtensionAbility**. The value **true** means that the policy is retained, and the value **false** means the opposite. | 1289 1290**Error codes** 1291 1292For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 1293 1294| ID| Error Message | 1295| ------- | ----------------------------------------------------- | 1296| 9200001 | The application is not an administrator application of the device. | 1297| 9200003 | The administrator ability component is invalid. | 1298| 9200011 | Failed to replace the administrator application of the device. | 1299| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1300| 202 | Permission verification failed. A non-system application calls a system API. | 1301 1302**Example** 1303 1304```ts 1305import { Want } from '@kit.AbilityKit'; 1306import { BusinessError } from '@kit.BasicServicesKit'; 1307 1308let oldAdmin: Want = { 1309 bundleName: 'com.example.myapplication', 1310 abilityName: 'EntryAbility', 1311}; 1312let newAdmin: Want = { 1313 bundleName: 'com.example.myapplication_new', 1314 abilityName: 'NewEntryAbility', 1315}; 1316try { 1317 adminManager.replaceSuperAdmin(oldAdmin, newAdmin, false); 1318 console.info(`Succeeded in replace super admin.`); 1319} catch(err) { 1320 console.error(`Failed to replace super admin. Code: ${err.code}, message: ${err.message}`); 1321} 1322``` 1323 1324## adminManager.setAdminRunningMode<sup>19+</sup> 1325 1326setAdminRunningMode(admin: Want, mode: RunningMode): void 1327 1328Sets the running mode of the device management application. 1329 1330This API takes effect only on 2-in-1 devices. 1331 1332**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 1333 1334**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1335 1336 1337 1338**Model restriction**: This API can be used only in the stage model. 1339 1340**Parameters** 1341 1342| Name | Type | Mandatory | Description | 1343| -------------- | ----------------------------------- | ---- | ---------------------------- | 1344| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 1345| mode | [RunningMode](#runningmode19) | Yes | Running mode. <br>The value **DEFAULT** means the application runs under the default user (user after the first device power-on). The value **MULTI_USER** means the application runs under multiple users at the same time.| 1346 1347 1348 1349**Error codes** 1350 1351For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 1352 1353| ID| Error Message | 1354| ------- | ----------------------------------------------------- | 1355| 9200001 | The application is not an administrator application of the device. | 1356| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1357| 202 | Permission verification failed. A non-system application calls a system API. | 1358 1359**Example** 1360 1361```ts 1362import { Want } from '@kit.AbilityKit'; 1363import { BusinessError } from '@kit.BasicServicesKit'; 1364 1365let admin: Want = { 1366 bundleName: 'com.example.myapplication', 1367 abilityName: 'EntryAbility', 1368}; 1369try { 1370 adminManager.setAdminRunningMode(admin, adminManager.RunningMode.MULTI_USER); 1371 console.info(`Succeeded in set admin running mode.`); 1372} catch(err) { 1373 console.error(`Failed to set admin running mode. Code: ${err.code}, message: ${err.message}`); 1374} 1375``` 1376 1377## EnterpriseInfo 1378 1379Represents the enterprise information of a device administrator application. 1380 1381**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1382 1383 1384 1385| Name | Type | Read-Only| Optional| Description | 1386| ----------- | --------| ---- | -----| -------------------------- | 1387| name | string | No | No| Name of the enterprise.| 1388| description | string | No | No|Description of the enterprise.| 1389 1390## AdminType 1391 1392Enumerates the types of device administrator applications. 1393 1394**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1395 1396 1397 1398| Name | Value | Description | 1399| ----------------- | ---- | ----- | 1400| ADMIN_TYPE_NORMAL | 0x00 | Common device administrator application.| 1401| ADMIN_TYPE_SUPER | 0x01 | Super device administrator application.| 1402 1403## RunningMode<sup>19+</sup> 1404 1405Represents the running mode of a device administrator application. 1406 1407**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1408 1409 1410 1411| Name | Value | Description | 1412| ----------------- | ---- | ----- | 1413| DEFAULT | 0 | Default user running mode, indicating that the application runs under the default user (user after the first device powered-on).| 1414| MULTI_USER | 1 | Multi-user running mode, indicating that the application runs under multiple users at the same time.| 1415