• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)
2
3The **EnterpriseAdminExtensionAbility** module provides extended enterprise device management capabilities.
4
5To have the capabilities provided by this module, for example, to receive a notification when a device administrator application is enabled or disabled, you need to create an **EnterpriseAdminExtensionAbility** instance for the enterprise administrator application and overload related APIs.
6
7> **NOTE**
8>
9> - 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.
10>
11> - The APIs of this module can be used only in the stage model.
12>
13
14## Modules to Import
15
16```ts
17import { EnterpriseAdminExtensionAbility } from '@kit.MDMKit'
18```
19
20## EnterpriseAdminExtensionAbility.onAdminEnabled
21
22onAdminEnabled(): void
23
24Called when a device administrator application is enabled.
25
26**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
27
28
29
30**Example**
31
32```ts
33export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
34  onAdminEnabled() {
35  }
36};
37```
38
39## EnterpriseAdminExtensionAbility.onAdminDisabled
40
41onAdminDisabled(): void
42
43Called when a device administrator application is disabled.
44
45**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
46
47
48
49**Example**
50
51```ts
52export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
53  onAdminDisabled() {
54  }
55};
56```
57
58## EnterpriseAdminExtensionAbility.onBundleAdded
59
60onBundleAdded(bundleName: string): void
61
62Called when applications are installed. The application bundle name is included. You should register the **MANAGED_EVENT_BUNDLE_ADDED** event through [adminManager.subscribeManagedEventSync](js-apis-enterprise-adminManager.md#adminmanagersubscribemanagedeventsync).
63
64**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
65
66
67
68**Parameters**
69
70| Name  | Type                                 | Mandatory  | Description     |
71| ----- | ----------------------------------- | ---- | ------- |
72| bundleName | string | Yes   | Bundle name of the application installed.|
73
74**Example**
75
76```ts
77export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
78  onBundleAdded(bundleName: string) {
79    console.info(`Succeeded in calling onBundleAdded callback, added bundle name : ${bundleName}`);
80  }
81};
82```
83
84## EnterpriseAdminExtensionAbility.onBundleAdded<sup>14+</sup>
85
86onBundleAdded(bundleName: string, accountId: number): void
87
88Called when applications are installed. The application bundle name and account ID are included. You should register the **MANAGED_EVENT_BUNDLE_ADDED** event through [adminManager.subscribeManagedEventSync](js-apis-enterprise-adminManager.md#adminmanagersubscribemanagedeventsync).
89
90**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
91
92
93
94**Parameters**
95
96| Name  | Type                                 | Mandatory  | Description     |
97| ----- | ----------------------------------- | ---- | ------- |
98| bundleName | string | Yes   | Bundle name of the application installed.|
99| accountId | number | Yes   | Account ID of the application installed.|
100
101**Example**
102
103```ts
104export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
105  onBundleAdded(bundleName: string, accountId?: number) {
106    console.info(`Succeeded in calling onBundleAdded callback, added bundle name : ${bundleName}, accountId: ${accountId}`);
107  }
108};
109```
110
111## EnterpriseAdminExtensionAbility.onBundleRemoved
112
113onBundleRemoved(bundleName: string): void
114
115Called when applications are uninstalled. The application bundle name is included. You should register the **MANAGED_EVENT_BUNDLE_REMOVED** event through [adminManager.subscribeManagedEventSync](js-apis-enterprise-adminManager.md#adminmanagersubscribemanagedeventsync).
116
117**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
118
119
120
121**Parameters**
122
123| Name  | Type                                 | Mandatory  | Description     |
124| ----- | ----------------------------------- | ---- | ------- |
125| bundleName | string | Yes   | Bundle name of the application uninstalled.|
126
127**Example**
128
129```ts
130export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
131  onBundleRemoved(bundleName: string) {
132    console.info(`Succeeded in calling onBundleRemoved callback, removed bundle name : ${bundleName}`);
133  }
134};
135```
136
137## EnterpriseAdminExtensionAbility.onBundleRemoved<sup>14+</sup>
138
139onBundleRemoved(bundleName: string, accountId: number): void
140
141Called when applications are uninstalled. The application bundle name and account ID are included. You should register the **MANAGED_EVENT_BUNDLE_REMOVED** event through [adminManager.subscribeManagedEventSync](js-apis-enterprise-adminManager.md#adminmanagersubscribemanagedeventsync).
142
143**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
144
145
146
147**Parameters**
148
149| Name  | Type                                 | Mandatory  | Description     |
150| ----- | ----------------------------------- | ---- | ------- |
151| bundleName | string | Yes   | Bundle name of the application uninstalled.|
152| accountId | number | Yes   | Account ID of the application uninstalled.|
153
154**Example**
155
156```ts
157export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
158  onBundleRemoved(bundleName: string, accountId?: number) {
159    console.info(`Succeeded in calling onBundleRemoved callback, removed bundle name : ${bundleName}, accountId: ${accountId}`);
160  }
161};
162```
163
164## EnterpriseAdminExtensionAbility.onAppStart
165
166onAppStart(bundleName: string): void
167
168Called when an application is started. You should register the **MANAGED_EVENT_APP_START** event through [adminManager.subscribeManagedEventSync](js-apis-enterprise-adminManager.md#adminmanagersubscribemanagedeventsync).
169
170**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
171
172
173
174**Parameters**
175
176| Name  | Type                                 | Mandatory  | Description     |
177| ----- | ----------------------------------- | ---- | ------- |
178| bundleName | string | Yes   | Bundle name of the application started.|
179
180**Example**
181
182```ts
183export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
184  onAppStart(bundleName: string) {
185    console.info(`Succeeded in calling onAppStart callback, started bundle name : ${bundleName}`);
186  }
187};
188```
189
190## EnterpriseAdminExtensionAbility.onAppStop
191
192onAppStop(bundleName: string): void
193
194Called when an application is stopped. You should register the **MANAGED_EVENT_APP_STOP** event through [adminManager.subscribeManagedEventSync](js-apis-enterprise-adminManager.md#adminmanagersubscribemanagedeventsync).
195
196**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
197
198
199
200**Parameters**
201
202| Name  | Type                                 | Mandatory  | Description     |
203| ----- | ----------------------------------- | ---- | ------- |
204| bundleName | string | Yes   | Bundle name of the application stopped.|
205
206**Example**
207
208```ts
209export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
210  onAppStop(bundleName: string) {
211    console.info(`Succeeded in calling onAppStop callback, stopped bundle name : ${bundleName}`);
212  }
213};
214```
215## EnterpriseAdminExtensionAbility.onSystemUpdate
216
217onSystemUpdate(systemUpdateInfo: systemManager.SystemUpdateInfo): void
218
219Called to report a system update event. You should register the **MANAGED_EVENT_SYSTEM_UPDATE** event through [adminManager.subscribeManagedEventSync](js-apis-enterprise-adminManager.md#adminmanagersubscribemanagedeventsync).
220
221**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
222
223
224
225**Parameters**
226
227| Name          | Type                                                        | Mandatory| Description                |
228| ---------------- | ------------------------------------------------------------ | ---- | -------------------- |
229| systemUpdateInfo | [systemManager.SystemUpdateInfo](js-apis-enterprise-systemManager.md#systemupdateinfo) | Yes  | Information about the version update.|
230
231**Example**
232
233```ts
234import { systemManager } from '@kit.MDMKit';
235export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
236  onSystemUpdate(systemUpdateInfo: systemManager.SystemUpdateInfo) {
237    console.info(`Succeeded in calling onSystemUpdate callback, version name  : ${systemUpdateInfo.versionName}`);
238  }
239};
240```
241
242## EnterpriseAdminExtensionAbility.onStart
243
244onStart(): void
245
246Called when EnterpriseAdminExtensionAbility starts.
247
248**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
249
250
251
252**Example**
253
254```ts
255export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
256  onStart() {
257    console.info(`Succeeded in calling onStart callback.`);
258  }
259};
260```
261
262## EnterpriseAdminExtensionAbility.onAccountAdded<sup>18+</sup>
263
264onAccountAdded(accountId: number): void
265
266Called when a system account is added. You should register the **MANAGED_EVENT_ACCOUNT_ADDED** event through [adminManager.subscribeManagedEventSync](js-apis-enterprise-adminManager.md#adminmanagersubscribemanagedeventsync).
267
268**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
269
270**Parameters**
271
272| Name  | Type                                 | Mandatory  | Description     |
273| ----- | ----------------------------------- | ---- | ------- |
274| accountId | number | Yes   | Account ID added.|
275
276**Example**
277
278```ts
279export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
280  onAccountAdded(accountId: number) {
281    console.info(`Succeeded in calling onAccountAdded callback, added accountId: ${accountId}`);
282  }
283};
284```
285
286## EnterpriseAdminExtensionAbility.onAccountSwitched<sup>18+</sup>
287
288onAccountSwitched(accountId: number): void
289
290Called when the system account is switched. You should register the **MANAGED_EVENT_ACCOUNT_SWITCHED** event through [adminManager.subscribeManagedEventSync](js-apis-enterprise-adminManager.md#adminmanagersubscribemanagedeventsync).
291
292**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
293
294**Parameters**
295
296| Name  | Type                                 | Mandatory  | Description     |
297| ----- | ----------------------------------- | ---- | ------- |
298| accountId | number | Yes   | Account ID switched.|
299
300**Example**
301
302```ts
303export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
304  onAccountSwitched(accountId: number) {
305    console.info(`Succeeded in calling onAccountSwitched callback, switched accountId: ${accountId}`);
306  }
307};
308```
309
310## EnterpriseAdminExtensionAbility.onAccountRemoved<sup>18+</sup>
311
312onAccountRemoved(accountId: number): void
313
314Called when the system account is removed. You should register the **MANAGED_EVENT_ACCOUNT_REMOVED** event through [adminManager.subscribeManagedEventSync](js-apis-enterprise-adminManager.md#adminmanagersubscribemanagedeventsync).
315
316**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
317
318**Parameters**
319
320| Name  | Type                                 | Mandatory  | Description     |
321| ----- | ----------------------------------- | ---- | ------- |
322| accountId | number | Yes   | Account ID removed.|
323
324**Example**
325
326```ts
327export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility {
328  onAccountRemoved(accountId: number) {
329    console.info(`Succeeded in calling onAccountRemoved callback, removed accountId: ${accountId}`);
330  }
331};
332```
333