1e41f4b71Sopenharmony_ci# @ohos.enterprise.adminManager (Enterprise Device Management) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **adminManager** module provides enterprise device management capabilities so that devices have the custom capabilities required in enterprise settings. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> - The APIs of this module are available only to [device administrator applications](../../mdm/mdm-kit-guide.md#introduction). 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport { adminManager } from '@kit.MDMKit'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## adminManager.disableAdmin 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_cidisableAdmin(admin: Want, userId?: number): Promise\<void> 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciDisables a common administrator application for the current or specified user. This API uses a promise to return the result. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**Parameters** 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 34e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 35e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Common administrator application to disable. | 36e41f4b71Sopenharmony_ci| userId | number | No | User ID, which must be greater than or equal to 0.<br>- If **userId** is passed in, this API applies to the specified user.<br>- If **userId** is not passed in, this API applies to the current user.| 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci**Return value** 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci| Type | Description | 41e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ | 42e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci**Error codes** 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci| ID| Error Message | 49e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 50e41f4b71Sopenharmony_ci| 9200005 | Failed to deactivate the administrator application of the device. | 51e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 52e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**Example** 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci```ts 57e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 58e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 59e41f4b71Sopenharmony_cilet wantTemp: Want = { 60e41f4b71Sopenharmony_ci bundleName: 'bundleName', 61e41f4b71Sopenharmony_ci abilityName: 'abilityName', 62e41f4b71Sopenharmony_ci}; 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ciadminManager.disableAdmin(wantTemp, 100).catch((err: BusinessError) => { 65e41f4b71Sopenharmony_ci console.error(`Failed to disable admin. Code: ${err.code}, message: ${err.message}`); 66e41f4b71Sopenharmony_ci}); 67e41f4b71Sopenharmony_ci``` 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci## adminManager.subscribeManagedEventSync 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_cisubscribeManagedEventSync(admin: Want, managedEvents: Array\<ManagedEvent>): void 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ciSubscribes to system management events of a device administrator application. 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**Parameters** 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 86e41f4b71Sopenharmony_ci| ------------- | ------------------------------------------------------- | ---- | -------------- | 87e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| 88e41f4b71Sopenharmony_ci| managedEvents | Array\<[ManagedEvent](#managedevent)> | Yes | Array of events to subscribe to.| 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**Error codes** 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci| ID| Error Message | 95e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 96e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 97e41f4b71Sopenharmony_ci| 9200008 | The specified system event is invalid. | 98e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 99e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci**Example** 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci```ts 104e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 105e41f4b71Sopenharmony_cilet wantTemp: Want = { 106e41f4b71Sopenharmony_ci bundleName: 'bundleName', 107e41f4b71Sopenharmony_ci abilityName: 'abilityName', 108e41f4b71Sopenharmony_ci}; 109e41f4b71Sopenharmony_cilet events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED]; 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_citry { 112e41f4b71Sopenharmony_ci adminManager.subscribeManagedEventSync(wantTemp, events); 113e41f4b71Sopenharmony_ci console.info('Succeeded in subscribe managed event.'); 114e41f4b71Sopenharmony_ci} catch (err) { 115e41f4b71Sopenharmony_ci console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`); 116e41f4b71Sopenharmony_ci} 117e41f4b71Sopenharmony_ci``` 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci## adminManager.unsubscribeManagedEventSync 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ciunsubscribeManagedEventSync(admin: Want, managedEvents: Array\<ManagedEvent>): void 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ciUnsubscribes from system management events of a device administrator application. 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model. 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci**Parameters** 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 136e41f4b71Sopenharmony_ci| ------------- | ------------------------------------------------------- | ---- | ------------------ | 137e41f4b71Sopenharmony_ci| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | 138e41f4b71Sopenharmony_ci| managedEvents | Array\<[ManagedEvent](#managedevent)> | Yes | Array of events to unsubscribe from.| 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**Error codes** 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ciFor details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci| ID| Error Message | 145e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 146e41f4b71Sopenharmony_ci| 9200001 | The application is not an administrator application of the device. | 147e41f4b71Sopenharmony_ci| 9200008 | The specified system event is invalid. | 148e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. | 149e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci**Example** 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci```ts 154e41f4b71Sopenharmony_ciimport { Want } from '@kit.AbilityKit'; 155e41f4b71Sopenharmony_cilet wantTemp: Want = { 156e41f4b71Sopenharmony_ci bundleName: 'bundleName', 157e41f4b71Sopenharmony_ci abilityName: 'abilityName', 158e41f4b71Sopenharmony_ci}; 159e41f4b71Sopenharmony_cilet events: Array<adminManager.ManagedEvent> = [adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_ADDED, adminManager.ManagedEvent.MANAGED_EVENT_BUNDLE_REMOVED]; 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_citry { 162e41f4b71Sopenharmony_ci adminManager.unsubscribeManagedEventSync(wantTemp, events); 163e41f4b71Sopenharmony_ci console.info('Succeeded in subscribe managed event.'); 164e41f4b71Sopenharmony_ci} catch (err) { 165e41f4b71Sopenharmony_ci console.error(`Failed to subscribe managed event. Code: ${err.code}, message: ${err.message}`); 166e41f4b71Sopenharmony_ci} 167e41f4b71Sopenharmony_ci``` 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci## ManagedEvent 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ciEnumerates the system management events that can be subscribed to. 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci| Name | Value | Description | 178e41f4b71Sopenharmony_ci| ---------------------------- | ---- | -------------- | 179e41f4b71Sopenharmony_ci| MANAGED_EVENT_BUNDLE_ADDED | 0 | An application is installed.| 180e41f4b71Sopenharmony_ci| MANAGED_EVENT_BUNDLE_REMOVED | 1 | An application is uninstalled.| 181e41f4b71Sopenharmony_ci| MANAGED_EVENT_APP_START | 2 | An application is started.| 182e41f4b71Sopenharmony_ci| MANAGED_EVENT_APP_STOP | 3 | An application is stopped.| 183e41f4b71Sopenharmony_ci| MANAGED_EVENT_SYSTEM_UPDATE | 4 | The system is updated. | 184