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