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