1# @ohos.enterprise.adminManager (Enterprise Device Management) 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 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). 12 13## Modules to Import 14 15```ts 16import adminManager from '@ohos.enterprise.adminManager'; 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**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 to enable. | 36| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application. | 37| type | [AdminType](#admintype) | Yes | Type of the device administrator application to enable. | 38| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 39 40**Error codes** 41 42For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 43 44| ID| Error Message | 45| ------- | --------------------------------------------------------------- | 46| 9200003 | the administrator ability component is invalid. | 47| 9200004 | failed to enable the administrator application of the device. | 48| 9200007 | the system ability work abnormally. | 49 50**Example** 51 52```ts 53import Want from '@ohos.app.ability.Want'; 54let wantTemp: Want = { 55 bundleName: 'com.example.myapplication', 56 abilityName: 'EntryAbility', 57}; 58let enterpriseInfo: adminManager.EnterpriseInfo = { 59 name: 'enterprise name', 60 description: 'enterprise description' 61} 62 63adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_SUPER, (err) => { 64 if (err) { 65 console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`); 66 return; 67 } 68 console.info('Succeeded in enabling admin'); 69}); 70``` 71 72## adminManager.enableAdmin 73 74enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId: number, callback: AsyncCallback\<void>): void 75 76Enables 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. 77 78**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 79 80**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 81 82**System API**: This is a system API. 83 84**Parameters** 85 86| Name | Type | Mandatory | Description | 87| -------------- | ----------------------------------- | ---- | ---------------------------- | 88| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application to enable. | 89| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application. | 90| type | [AdminType](#admintype) | Yes | Type of the device administrator application to enable. | 91| 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. | 92| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 93 94**Error codes** 95 96For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 97 98| ID| Error Message | 99| ------- | --------------------------------------------------------------- | 100| 9200003 | the administrator ability component is invalid. | 101| 9200004 | failed to enable the administrator application of the device. | 102| 9200007 | the system ability work abnormally. | 103 104**Example** 105 106```ts 107import Want from '@ohos.app.ability.Want'; 108let wantTemp: Want = { 109 bundleName: 'com.example.myapplication', 110 abilityName: 'EntryAbility', 111}; 112let enterpriseInfo: adminManager.EnterpriseInfo = { 113 name: 'enterprise name', 114 description: 'enterprise description' 115} 116 117adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100, (err) => { 118 if (err) { 119 console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`); 120 return; 121 } 122 console.info('Succeeded in enabling admin'); 123}); 124``` 125 126## adminManager.enableAdmin 127 128enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId?: number): Promise\<void> 129 130Enables 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. 131 132**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 133 134**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 135 136**System API**: This is a system API. 137 138**Parameters** 139 140| Name | Type | Mandatory | Description | 141| -------------- | ----------------------------------- | ---- | ---------------------------- | 142| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application to enable. | 143| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application. | 144| type | [AdminType](#admintype) | Yes | Type of the device administrator application to enable. | 145| userId | number | No | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the application of the specified user is enabled.<br> - If **userId** is not passed in, the application of the current user is enabled.| 146 147**Return value** 148 149| Type | Description | 150| ----------------- | ----------------- | 151| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 152 153**Error codes** 154 155For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 156 157| ID| Error Message | 158| ------- | --------------------------------------------------------------- | 159| 9200003 | the administrator ability component is invalid. | 160| 9200004 | failed to enable the administrator application of the device. | 161| 9200007 | the system ability work abnormally. | 162 163**Example** 164 165```ts 166import Want from '@ohos.app.ability.Want'; 167import { BusinessError } from '@ohos.base'; 168let wantTemp: Want = { 169 bundleName: 'com.example.myapplication', 170 abilityName: 'EntryAbility', 171}; 172let enterpriseInfo: adminManager.EnterpriseInfo = { 173 name: 'enterprise name', 174 description: 'enterprise description' 175} 176 177adminManager.enableAdmin(wantTemp, enterpriseInfo, adminManager.AdminType.ADMIN_TYPE_NORMAL, 100).catch( 178 (err: BusinessError) => { 179 console.error(`Failed to enable admin. Code: ${err.code}, message: ${err.message}`); 180 }); 181``` 182 183## adminManager.disableAdmin 184 185disableAdmin(admin: Want, callback: AsyncCallback\<void>): void 186 187Disables a common administrator application for the current user. This API uses an asynchronous callback to return the result. 188 189**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 190 191**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 192 193**System API**: This is a system API. 194 195**Parameters** 196 197| Name | Type | Mandatory | Description | 198| -------- | ----------------------------------- | ---- | ------------------- | 199| admin | [Want](js-apis-app-ability-want.md) | Yes | Common administrator application to disable. | 200| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 201 202**Error codes** 203 204For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 205 206| ID| Error Message | 207| ------- | ----------------------------------------------------------------- | 208| 9200005 | failed to disable the administrator application of the device. | 209 210**Example** 211 212```ts 213import Want from '@ohos.app.ability.Want'; 214let wantTemp: Want = { 215 bundleName: 'bundleName', 216 abilityName: 'abilityName', 217}; 218 219adminManager.disableAdmin(wantTemp, (err) => { 220 if (err) { 221 console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); 222 return; 223 } 224 console.info('Succeeded in disabling admin'); 225}); 226``` 227 228## adminManager.disableAdmin 229 230disableAdmin(admin: Want, userId: number, callback: AsyncCallback\<void>): void 231 232Disables a common administrator application for the specified user. This API uses an asynchronous callback to return the result. 233 234**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 235 236**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 237 238**System API**: This is a system API. 239 240**Parameters** 241 242| Name | Type | Mandatory | Description | 243| -------- | ----------------------------------- | ---- | ---------------------------- | 244| admin | [Want](js-apis-app-ability-want.md) | Yes | Common administrator application to disable. | 245| 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. | 246| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 247 248**Error codes** 249 250For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 251 252| ID| Error Message | 253| ------- | ----------------------------------------------------------------- | 254| 9200005 | failed to disable the administrator application of the device. | 255 256**Example** 257 258```ts 259import Want from '@ohos.app.ability.Want'; 260let wantTemp: Want = { 261 bundleName: 'bundleName', 262 abilityName: 'abilityName', 263}; 264 265adminManager.disableAdmin(wantTemp, 100, (err) => { 266 if (err) { 267 console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); 268 return; 269 } 270 console.info('Succeeded in disabling admin'); 271}); 272``` 273 274## adminManager.disableAdmin 275 276disableAdmin(admin: Want, userId?: number): Promise\<void> 277 278Disables a common administrator application for the current or specified user. This API uses a promise to return the result. 279 280**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 281 282**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 283 284**System API**: This is a system API. 285 286**Parameters** 287 288| Name | Type | Mandatory | Description | 289| ------ | ----------------------------------- | ---- | ---------------------------- | 290| admin | [Want](js-apis-app-ability-want.md) | Yes | Common administrator application to disable. | 291| userId | number | No | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the application of the specified user is disabled.<br> - If **userId** is not passed in, the application of the current user is disabled.| 292 293**Return value** 294 295| Type | Description | 296| ----------------- | ----------------- | 297| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 298 299**Error codes** 300 301For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 302 303| ID| Error Message | 304| ------- | ----------------------------------------------------------------- | 305| 9200005 | failed to disable the administrator application of the device. | 306 307**Example** 308 309```ts 310import Want from '@ohos.app.ability.Want'; 311import { BusinessError } from '@ohos.base'; 312let wantTemp: Want = { 313 bundleName: 'bundleName', 314 abilityName: 'abilityName', 315}; 316 317adminManager.disableAdmin(wantTemp, 100).catch((err: BusinessError) => { 318 console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); 319}); 320``` 321 322## adminManager.disableSuperAdmin 323 324disableSuperAdmin(bundleName: String, callback: AsyncCallback\<void>): void 325 326Disables a super administrator application for the administrator based on **bundleName**. This API uses an asynchronous callback to return the result. 327 328**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 329 330**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 331 332**System API**: This is a system API. 333 334**Parameters** 335 336| Name | Type | Mandatory | Description | 337| ---------- | ----------------------- | ---- | ------------------- | 338| bundleName | String | Yes | Bundle name of the super administrator application to disable. | 339| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 340 341**Error codes** 342 343For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 344 345| ID| Error Message | 346| ------- | ----------------------------------------------------------------- | 347| 9200005 | failed to disable the administrator application of the device. | 348 349**Example** 350 351```ts 352import Want from '@ohos.app.ability.Want'; 353let bundleName: string = 'com.example.myapplication'; 354 355adminManager.disableSuperAdmin(bundleName, (err) => { 356 if (err) { 357 console.error(`Failed to disable super admin. Code: ${err.code}, message: ${err.message}`); 358 return; 359 } 360 console.info('Succeeded in disabling super admin'); 361}); 362``` 363 364## adminManager.disableSuperAdmin 365 366disableSuperAdmin(bundleName: String): Promise\<void> 367 368Disables a super administrator application for the administrator based on **bundleName**. This API uses a promise to return the result. 369 370**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 371 372**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 373 374**System API**: This is a system API. 375 376**Parameters** 377 378| Name | Type | Mandatory | Description | 379| ---------- | ------ | ---- | ------------ | 380| bundleName | String | Yes | Bundle name of the super administrator application to disable.| 381 382**Return value** 383 384| Type | Description | 385| ----------------- | ----------------- | 386| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 387 388**Error codes** 389 390For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 391 392| ID| Error Message | 393| ------- | ----------------------------------------------------------------- | 394| 9200005 | failed to disable the administrator application of the device. | 395 396**Example** 397 398```ts 399import Want from '@ohos.app.ability.Want'; 400import { BusinessError } from '@ohos.base'; 401let bundleName: string = 'com.example.myapplication'; 402 403adminManager.disableSuperAdmin(bundleName).catch((err: BusinessError) => { 404 console.error(`Failed to disable super admin. Code: ${err.code}, message: ${err.message}`); 405}); 406``` 407 408## adminManager.isAdminEnabled 409 410isAdminEnabled(admin: Want, callback: AsyncCallback\<boolean>): void 411 412Checks whether a device administrator application of the current user is enabled. This API uses an asynchronous callback to return the result. 413 414**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 415 416**System API**: This is a system API. 417 418**Parameters** 419 420| Name | Type | Mandatory | Description | 421| -------- | ----------------------------------- | ---- | -------------------- | 422| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application to check. | 423| 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.| 424 425**Example** 426 427```ts 428import Want from '@ohos.app.ability.Want'; 429let wantTemp: Want = { 430 bundleName: 'bundleName', 431 abilityName: 'abilityName', 432}; 433 434adminManager.isAdminEnabled(wantTemp, (err, result) => { 435 if (err) { 436 console.error(`Failed to query admin is enabled or not. Code: ${err.code}, message: ${err.message}`); 437 return; 438 } 439 console.info(`Succeeded in querying admin is enabled or not, result : ${result}`); 440}); 441``` 442 443## adminManager.isAdminEnabled 444 445isAdminEnabled(admin: Want, userId: number, callback: AsyncCallback\<boolean>): void 446 447Checks whether a device administrator application of the specified user is enabled. This API uses an asynchronous callback to return the result. 448 449**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 450 451**System API**: This is a system API. 452 453**Parameters** 454 455| Name | Type | Mandatory | Description | 456| -------- | ----------------------------------- | ---- | ---------------------------- | 457| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application to check. | 458| 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. | 459| 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. | 460 461**Example** 462 463```ts 464import Want from '@ohos.app.ability.Want'; 465let wantTemp: Want = { 466 bundleName: 'bundleName', 467 abilityName: 'abilityName', 468}; 469 470adminManager.isAdminEnabled(wantTemp, 100, (err, result) => { 471 if (err) { 472 console.error(`Failed to query admin is enabled. Code: ${err.code}, message: ${err.message}`); 473 return; 474 } 475 console.info(`Succeeded in querying admin is enabled or not, result : ${result}`); 476}); 477``` 478 479## adminManager.isAdminEnabled 480 481isAdminEnabled(admin: Want, userId?: number): Promise\<boolean> 482 483Checks whether a device administrator application of the current or specified user is enabled. This API uses a promise to return the result. 484 485**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 486 487**System API**: This is a system API. 488 489**Parameters** 490 491| Name | Type | Mandatory | Description | 492| ------ | ----------------------------------- | ---- | ---------------------------- | 493| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application to check. | 494| userId | number | No | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the application of the specified user is checked.<br> - If **userId** is not passed in, the application of the current user is checked.| 495 496**Return value** 497 498| Type | Description | 499| ----------------- | ------------------- | 500| Promise\<boolean> | Promise used to return the result. The value **true** means the device administrator application is enabled; the value **false** means the opposite.| 501 502**Example** 503 504```ts 505import Want from '@ohos.app.ability.Want'; 506import { BusinessError } from '@ohos.base'; 507let wantTemp: Want = { 508 bundleName: 'bundleName', 509 abilityName: 'abilityName', 510}; 511 512adminManager.isAdminEnabled(wantTemp, 100).then((result) => { 513 console.info(`Succeeded in querying admin is enabled or not, result : ${result}`); 514}).catch((err: BusinessError) => { 515 console.error(`Failed to query admin is enabled or not. Code: ${err.code}, message: ${err.message}`); 516}); 517``` 518 519## adminManager.isSuperAdmin 520 521isSuperAdmin(bundleName: String, callback: AsyncCallback\<boolean>): void 522 523Checks whether a super administrator application of the administrator is enabled based on **bundleName**. This API uses an asynchronous callback to return the result. 524 525**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 526 527**System API**: This is a system API. 528 529**Parameters** 530 531| Name | Type | Mandatory | Description | 532| ---------- | ----------------------- | ---- | -------------------- | 533| bundleName | String | Yes | Super administrator application to check. | 534| 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.| 535 536**Example** 537 538```ts 539import Want from '@ohos.app.ability.Want'; 540let bundleName: string = 'com.example.myapplication'; 541 542adminManager.isSuperAdmin(bundleName, (err, result) => { 543 if (err) { 544 console.error(`Failed to query admin is super admin or not. Code: ${err.code}, message: ${err.message}`); 545 return; 546 } 547 console.info(`Succeeded in querying admin is super admin or not, result : ${result}`); 548}); 549``` 550 551## adminManager.isSuperAdmin 552 553isSuperAdmin(bundleName: String): Promise\<boolean> 554 555Checks whether a super administrator application of the administrator is enabled based on **bundleName**. This API uses a promise to return the result. 556 557**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 558 559**System API**: This is a system API. 560 561**Parameters** 562 563| Name | Type | Mandatory | Description | 564| ---------- | ------ | ---- | --------- | 565| bundleName | String | Yes | Super administrator application to check.| 566 567**Return value** 568 569| ID | Error Message | 570| ----------------- | ------------------- | 571| Promise\<boolean> | Promise used to return the result. The value **true** means the super administrator application is enabled; the value **false** means the opposite. | 572 573**Example** 574 575```ts 576import Want from '@ohos.app.ability.Want'; 577import { BusinessError } from '@ohos.base'; 578let bundleName: string = 'com.example.myapplication'; 579 580adminManager.isSuperAdmin(bundleName).then((result) => { 581 console.info(`Succeeded in querying admin is super admin or not, result : ${result}`); 582}).catch((err: BusinessError) => { 583 console.error(`Failed to query admin is super admin or not. Code: ${err.code}, message: ${err.message}`); 584}); 585``` 586 587## adminManager.setEnterpriseInfo 588 589setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo, callback: AsyncCallback\<void>;): void 590 591Sets enterprise information for a device administrator application. This API uses an asynchronous callback to return the result. 592 593**Required permissions**: ohos.permission.SET_ENTERPRISE_INFO 594 595**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 596 597**System API**: This is a system API. 598 599**Parameters** 600 601| Name | Type | Mandatory | Description | 602| -------------- | ----------------------------------- | ---- | ---------------------- | 603| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 604| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information to set. | 605| callback | AsyncCallback\<void>; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 606 607**Error codes** 608 609For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 610 611| ID| Error Message | 612| ------- | ----------------------------------------------------- | 613| 9200001 | the application is not an administrator of the device. | 614 615**Example** 616 617```ts 618import Want from '@ohos.app.ability.Want'; 619let wantTemp: Want = { 620 bundleName: 'com.example.myapplication', 621 abilityName: 'EntryAbility', 622}; 623let enterpriseInfo: adminManager.EnterpriseInfo = { 624 name: 'enterprise name', 625 description: 'enterprise description' 626} 627 628adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo, (err) => { 629 if (err) { 630 console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`); 631 return; 632 } 633 console.info('Succeeded in setting enterprise info'); 634}); 635``` 636 637## adminManager.setEnterpriseInfo 638 639setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo): Promise\<void>; 640 641Sets enterprise information for a device administrator application. This API uses a promise to return the result. 642 643**Required permissions**: ohos.permission.SET_ENTERPRISE_INFO 644 645**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 646 647**System API**: This is a system API. 648 649**Parameters** 650 651| Name | Type | Mandatory | Description | 652| -------------- | ----------------------------------- | ---- | ------------ | 653| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 654| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information to set.| 655 656**Return value** 657 658| Type | Description | 659| ----------------- | --------------------- | 660| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 661 662**Error codes** 663 664For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 665 666| ID| Error Message | 667| ------- | ----------------------------------------------------- | 668| 9200001 | the application is not an administrator of the device. | 669 670**Example** 671 672```ts 673import Want from '@ohos.app.ability.Want'; 674import { BusinessError } from '@ohos.base'; 675let wantTemp: Want = { 676 bundleName: 'com.example.myapplication', 677 abilityName: 'EntryAbility', 678}; 679let enterpriseInfo: adminManager.EnterpriseInfo = { 680 name: 'enterprise name', 681 description: 'enterprise description' 682} 683 684adminManager.setEnterpriseInfo(wantTemp, enterpriseInfo).catch((err: BusinessError) => { 685 console.error(`Failed to set enterprise info. Code: ${err.code}, message: ${err.message}`); 686}); 687``` 688 689## adminManager.getEnterpriseInfo 690 691getEnterpriseInfo(admin: Want, callback: AsyncCallback<EnterpriseInfo>): void 692 693Obtains the enterprise information of a device administrator application. This API uses an asynchronous callback to return the result. 694 695**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 696 697**System API**: This is a system API. 698 699**Parameters** 700 701| Name | Type | Mandatory | Description | 702| -------- | ---------------------------------------- | ---- | ------------------------ | 703| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application. | 704| 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.| 705 706**Error codes** 707 708For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 709 710| ID| Error Message | 711| ------- | ----------------------------------------------------- | 712| 9200001 | the application is not an administrator of the device. | 713 714**Example** 715 716```ts 717import Want from '@ohos.app.ability.Want'; 718let wantTemp: Want = { 719 bundleName: 'com.example.myapplication', 720 abilityName: 'EntryAbility', 721}; 722 723adminManager.getEnterpriseInfo(wantTemp, (err, result) => { 724 if (err) { 725 console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`); 726 return; 727 } 728 console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`); 729}); 730``` 731 732## adminManager.getEnterpriseInfo 733 734getEnterpriseInfo(admin: Want): Promise<EnterpriseInfo> 735 736Obtains the enterprise information of a device administrator application. This API uses a promise to return the result. 737 738**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 739 740**System API**: This is a system API. 741 742**Parameters** 743 744| Name | Type | Mandatory | Description | 745| ----- | ----------------------------------- | ---- | ------- | 746| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 747 748**Return value** 749 750| Type | Description | 751| ---------------------------------------- | ------------------------- | 752| Promise<[EnterpriseInfo](#enterpriseinfo)> | Promise used to return the enterprise information obtained.| 753 754**Error codes** 755 756For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 757 758| ID| Error Message | 759| ------- | ----------------------------------------------------- | 760| 9200001 | the application is not an administrator of the device. | 761 762**Example** 763 764```ts 765import Want from '@ohos.app.ability.Want'; 766import { BusinessError } from '@ohos.base'; 767let wantTemp: Want = { 768 bundleName: 'com.example.myapplication', 769 abilityName: 'EntryAbility', 770}; 771 772adminManager.getEnterpriseInfo(wantTemp).then((result) => { 773 console.info(`Succeeded in getting enterprise info, enterprise name : ${result.name}, enterprise description : ${result.description}`); 774}).catch((err: BusinessError) => { 775 console.error(`Failed to get enterprise info. Code: ${err.code}, message: ${err.message}`); 776}); 777``` 778 779## adminManager.subscribeManagedEvent 780 781subscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>, callback: AsyncCallback\<void>): void 782 783Subscribes to system management events of a device administrator application. This API uses an asynchronous callback to return the result. 784 785**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 786 787**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 788 789**System API**: This is a system API. 790 791**Parameters** 792 793| Name | Type | Mandatory | Description | 794| ----- | ----------------------------------- | ---- | ------- | 795| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 796| managedEvents | Array\<[ManagedEvent](#managedevent)> | Yes| Array of events to subscribe to.| 797| callback | AsyncCallback\<void> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 798 799**Error codes** 800 801For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 802 803|ID| Error Message | 804| ------- | ----------------------------------------------------- | 805| 9200001 | the application is not an administrator of the device. | 806| 9200008 | the specified system events enum is invalid. | 807 808**Example** 809 810```ts 811import Want from '@ohos.app.ability.Want'; 812let wantTemp: Want = { 813 bundleName: 'bundleName', 814 abilityName: 'abilityName', 815}; 816let events: Array<adminManager.ManagedEvent> = [0, 1]; 817 818adminManager.subscribeManagedEvent(wantTemp, events, (err) => { 819 if (err) { 820 console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`); 821 return; 822 } 823 console.info('Succeeded in subscribe managed event'); 824}); 825``` 826 827## adminManager.subscribeManagedEvent 828 829subscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>): Promise\<void> 830 831Subscribes to system management events of a device administrator application. This API uses a promise to return the result. 832 833**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 834 835**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 836 837**System API**: This is a system API. 838 839**Parameters** 840 841| Name | Type | Mandatory | Description | 842| ----- | ----------------------------------- | ---- | ------- | 843| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 844| managedEvents | Array\<[ManagedEvent](#managedevent)> | Yes| Array of events to subscribe to.| 845 846**Return value** 847 848| Type | Description | 849| ----- | ----------------------------------- | 850| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 851 852**Error codes** 853 854For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 855 856| ID| Error Message | 857| ------- | ----------------------------------------------------- | 858| 9200001 | the application is not an administrator of the device. | 859| 9200008 | the specified system events enum is invalid. | 860 861**Example** 862 863```ts 864import Want from '@ohos.app.ability.Want'; 865import { BusinessError } from '@ohos.base'; 866let wantTemp: Want = { 867 bundleName: 'bundleName', 868 abilityName: 'abilityName', 869}; 870let events: Array<adminManager.ManagedEvent> = [0, 1]; 871 872adminManager.subscribeManagedEvent(wantTemp, events).then(() => { 873}).catch((err: BusinessError) => { 874 console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`); 875}) 876``` 877 878## adminManager.unsubscribeManagedEvent 879 880unsubscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>, callback: AsyncCallback\<void>): void 881 882Unsubscribes from system management events of a device administrator application. This API uses an asynchronous callback to return the result. 883 884**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 885 886**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 887 888**System API**: This is a system API. 889 890**Parameters** 891 892| Name | Type | Mandatory | Description | 893| ----- | ----------------------------------- | ---- | ------- | 894| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 895| managedEvents | Array\<[ManagedEvent](#managedevent)> | Yes| Array of events to unsubscribe from.| 896| callback | AsyncCallback\<void> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 897 898**Error codes** 899 900For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 901 902| ID| Error Message | 903| ------- | ----------------------------------------------------- | 904| 9200001 | the application is not an administrator of the device. | 905| 9200008 | the specified system events enum is invalid. | 906 907**Example** 908 909```ts 910import Want from '@ohos.app.ability.Want'; 911let wantTemp: Want = { 912 bundleName: 'bundleName', 913 abilityName: 'abilityName', 914}; 915let events: Array<adminManager.ManagedEvent> = [0, 1]; 916 917adminManager.unsubscribeManagedEvent(wantTemp, events, (err) => { 918 if (err) { 919 console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`); 920 return; 921 } 922 console.info('Succeeded in unsubscribe managed event'); 923}); 924``` 925 926## adminManager.unsubscribeManagedEvent 927 928unsubscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>): Promise\<void> 929 930Unsubscribes from system management events of a device administrator application. This API uses a promise to return the result. 931 932**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 933 934**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 935 936**System API**: This is a system API. 937 938**Parameters** 939 940| Name | Type | Mandatory | Description | 941| ----- | ----------------------------------- | ---- | ------- | 942| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 943| managedEvents | Array\<[ManagedEvent](#managedevent)> | Yes| Array of events to unsubscribe from.| 944 945**Return value** 946 947| Type | Description | 948| ----- | ----------------------------------- | 949| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 950 951**Error codes** 952 953For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 954 955| ID| Error Message | 956| ------- | ----------------------------------------------------- | 957| 9200001 | the application is not an administrator of the device. | 958| 9200008 | the specified system events enum is invalid. | 959 960**Example** 961 962```ts 963import Want from '@ohos.app.ability.Want'; 964import { BusinessError } from '@ohos.base'; 965let wantTemp: Want = { 966 bundleName: 'bundleName', 967 abilityName: 'abilityName', 968}; 969let events: Array<adminManager.ManagedEvent> = [0, 1]; 970 971adminManager.unsubscribeManagedEvent(wantTemp, events).then(() => { 972}).catch((err: BusinessError) => { 973 console.error(`Failed to unsubscribe managed event. Code: ${err.code}, message: ${err.message}`); 974}) 975``` 976 977## adminManager.authorizeAdmin<sup>10+</sup> 978 979authorizeAdmin(admin: Want, bundleName: string, callback: AsyncCallback<void>): void 980 981Authorizes the administrator rights to an application through the specified device administrator application. This API uses an asynchronous callback to return the result. 982 983**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 984 985**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 986 987**System API**: This is a system API. 988 989**Parameters** 990 991| Name | Type | Mandatory | Description | 992| ----- | ----------------------------------- | ---- | ------- | 993| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 994| bundleName | string | Yes| Bundle name of the application to be authorized with the administrator rights.| 995| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 996 997**Error codes** 998 999For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 1000 1001| ID| Error Message | 1002| ------- | ----------------------------------------------------- | 1003| 9200001 | the application is not an administrator of the device. | 1004| 9200002 | the administrator application does not have permission to manage the device. | 1005| 9200009 | authorize permission to the application failed. | 1006 1007**Example** 1008 1009```ts 1010import Want from '@ohos.app.ability.Want'; 1011let wantTemp: Want = { 1012 bundleName: 'bundleName', 1013 abilityName: 'abilityName', 1014}; 1015let bundleName: string = "com.example.application"; 1016 1017adminManager.authorizeAdmin(wantTemp, bundleName, (err) => { 1018 if (err) { 1019 console.error(`Failed to authorize permission to the application. Code: ${err.code}, message: ${err.message}`); 1020 return; 1021 } 1022 console.info('Successfully authorized permission to the application'); 1023}); 1024``` 1025 1026## adminManager.authorizeAdmin<sup>10+</sup> 1027 1028authorizeAdmin(admin: Want, bundleName: string): Promise<void> 1029 1030Authorizes the administrator rights to an application through the specified device administrator application. This API uses a promise to return the result. 1031 1032**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 1033 1034**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1035 1036**System API**: This is a system API. 1037 1038**Parameters** 1039 1040| Name | Type | Mandatory | Description | 1041| ----- | ----------------------------------- | ---- | ------- | 1042| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.| 1043| bundleName | string | Yes| Bundle name of the application to be authorized with the administrator rights.| 1044 1045**Return value** 1046 1047| Type | Description | 1048| ----- | ----------------------------------- | 1049| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 1050 1051**Error codes** 1052 1053For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). 1054 1055| ID| Error Message | 1056| ------- | ----------------------------------------------------- | 1057| 9200001 | the application is not an administrator of the device. | 1058| 9200002 | the administrator application does not have permission to manage the device. | 1059| 9200009 | authorize permission to the application failed. | 1060 1061**Example** 1062 1063```ts 1064import Want from '@ohos.app.ability.Want'; 1065import { BusinessError } from '@ohos.base'; 1066let wantTemp: Want = { 1067 bundleName: 'bundleName', 1068 abilityName: 'abilityName', 1069}; 1070let bundleName: string = "com.example.application"; 1071 1072adminManager.authorizeAdmin(wantTemp, bundleName).then(() => { 1073}).catch((err: BusinessError) => { 1074 console.error(`Failed to authorize permission to the application. Code: ${err.code}, message: ${err.message}`); 1075}) 1076``` 1077 1078## EnterpriseInfo 1079 1080Represents the enterprise information of a device administrator application. 1081 1082**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1083 1084**System API**: This is a system API. 1085 1086| Name | Type | Mandatory| Description | 1087| ----------- | --------| ---- | ------------------------------- | 1088| name | string | Yes | Name of the enterprise.| 1089| description | string | Yes | Description of the enterprise.| 1090 1091## AdminType 1092 1093Enumerates the types of device administrator applications. 1094 1095**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1096 1097**System API**: This is a system API. 1098 1099| Name | Value | Description | 1100| ----------------- | ---- | ----- | 1101| ADMIN_TYPE_NORMAL | 0x00 | Common administrator application.| 1102| ADMIN_TYPE_SUPER | 0x01 | Super administrator application.| 1103 1104## ManagedEvent 1105 1106Enumerates the system management events that can be subscribed to. 1107 1108**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 1109 1110**System API**: This is a system API. 1111 1112| Name | Value | Description | 1113| -------------------------- | ---- | ------------- | 1114| MANAGED_EVENT_BUNDLE_ADDED | 0 | Application installed.| 1115| MANAGED_EVENT_BUNDLE_REMOVED | 1 | Application uninstalled.| 1116| MANAGED_EVENT_APP_START<sup>10+</sup> | 2 | Application started.| 1117| MANAGED_EVENT_APP_STOP<sup>10+</sup> | 3 | Application stopped.| 1118