1# @ohos.enterprise.applicationManager (Application Management) (System API)
2
3The **applicationManager** module provides application management capabilities, including adding, removing, and obtaining the applications that are forbidden to run.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 10. 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 of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is [enabled](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin).
12>
13> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.applicationManager](js-apis-enterprise-applicationManager.md).
14
15## Modules to Import
16
17```ts
18import { applicationManager } from '@kit.MDMKit';
19```
20
21## applicationManager.addDisallowedRunningBundles
22
23addDisallowedRunningBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void
24
25Adds the applications that are not allowed to run by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
26
27**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
28
29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
30
31
32
33**Parameters**
34
35| Name     | Type                                      | Mandatory  | Description                      |
36| -------- | ---------------------------------------- | ---- | ------------------------------- |
37| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
38| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
39| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
40
41**Error codes**
42
43For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
44
45| ID| Error Message                                                                      |
46| ------- | ---------------------------------------------------------------------------- |
47| 9200001 | The application is not an administrator application of the device.            |
48| 9200002 | The administrator application does not have permission to manage the device. |
49| 201 | Permission verification failed. The application does not have the permission required to call the API. |
50| 202 | Permission verification failed. A non-system application calls a system API. |
51| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
52
53
54**Example**
55
56```ts
57import { Want } from '@kit.AbilityKit';
58let wantTemp: Want = {
59  bundleName: 'com.example.myapplication',
60  abilityName: 'EntryAbility',
61};
62let appIds: Array<string> = ['com.example.myapplication'];
63
64applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (err) => {
65  if (err) {
66    console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
67    return;
68  }
69  console.info('Succeeded in adding disallowed running bundles');
70});
71```
72
73## applicationManager.addDisallowedRunningBundles
74
75addDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void
76
77Adds the applications that are not allowed to run by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
78
79**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
80
81**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
82
83
84
85**Parameters**
86
87| Name  | Type                                 | Mandatory  | Description     |
88| ----- | ----------------------------------- | ---- | ------- |
89| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
90| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
91| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
92| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback used 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](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
97
98| ID| Error Message                                                                    |
99| ------- | ---------------------------------------------------------------------------- |
100| 9200001 | The application is not an administrator application of the device.            |
101| 9200002 | The administrator application does not have permission to manage the device. |
102| 201 | Permission verification failed. The application does not have the permission required to call the API. |
103| 202 | Permission verification failed. A non-system application calls a system API. |
104| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
105
106**Example**
107
108```ts
109import { Want } from '@kit.AbilityKit';
110let wantTemp: Want = {
111  bundleName: 'com.example.myapplication',
112  abilityName: 'EntryAbility',
113};
114let appIds: Array<string> = ['com.example.myapplication'];
115
116applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (err) => {
117  if (err) {
118    console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
119    return;
120  }
121  console.info('Succeeded in adding disallowed running bundles');
122});
123```
124
125## applicationManager.addDisallowedRunningBundles
126
127addDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;
128
129Adds the applications that are not allowed to run by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
130
131**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
132
133**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
134
135
136
137**Parameters**
138
139| Name  | Type                                 | Mandatory  | Description     |
140| ----- | ----------------------------------- | ---- | ------- |
141| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
142| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
143| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br>- If **userId** is passed in, the applications cannot be run by the specified user.<br>- If **userId** is not passed in, the applications cannot be run by the current user.|
144
145**Return value**
146
147| Type                  | Description                     |
148| --------------------- | ------------------------- |
149| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
150
151**Error codes**
152
153For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
154
155| ID| Error Message                                                                    |
156| ------- | ---------------------------------------------------------------------------- |
157| 9200001 | The application is not an administrator application of the device.            |
158| 9200002 | The administrator application does not have permission to manage the device. |
159| 201 | Permission verification failed. The application does not have the permission required to call the API. |
160| 202 | Permission verification failed. A non-system application calls a system API. |
161| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
162
163**Example**
164
165```ts
166import { Want } from '@kit.AbilityKit';
167import { BusinessError } from '@kit.BasicServicesKit';
168let wantTemp: Want = {
169  bundleName: 'com.example.myapplication',
170  abilityName: 'EntryAbility',
171};
172let appIds: Array<string> = ['com.example.myapplication'];
173
174applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
175  console.info('Succeeded in adding disallowed running bundles');
176}).catch((err: BusinessError) => {
177  console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
178});
179```
180
181## applicationManager.removeDisallowedRunningBundles
182
183removeDisallowedRunningBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void
184
185Removes the applications that are not allowed to run by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
186
187**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
188
189**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
190
191
192
193**Parameters**
194
195| Name     | Type                                      | Mandatory  | Description                      |
196| -------- | ---------------------------------------- | ---- | ------------------------------- |
197| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
198| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
199| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
200
201**Error codes**
202
203For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
204
205| ID| Error Message                                                                      |
206| ------- | ---------------------------------------------------------------------------- |
207| 9200001 | The application is not an administrator application of the device.            |
208| 9200002 | The administrator application does not have permission to manage the device. |
209| 201 | Permission verification failed. The application does not have the permission required to call the API. |
210| 202 | Permission verification failed. A non-system application calls a system API. |
211| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
212
213**Example**
214
215```ts
216import { Want } from '@kit.AbilityKit';
217let wantTemp: Want = {
218  bundleName: 'com.example.myapplication',
219  abilityName: 'EntryAbility',
220};
221let appIds: Array<string> = ['com.example.myapplication'];
222
223applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (err) => {
224  if (err) {
225    console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
226    return;
227  }
228  console.info('Succeeded in removing disallowed running bundles');
229});
230```
231
232## applicationManager.removeDisallowedRunningBundles
233
234removeDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void
235
236Removes the applications that are not allowed to run by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
237
238**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
239
240**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
241
242
243
244**Parameters**
245
246| Name  | Type                                 | Mandatory  | Description     |
247| ----- | ----------------------------------- | ---- | ------- |
248| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
249| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
250| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
251| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
252
253**Error codes**
254
255For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
256
257| ID| Error Message                                                                    |
258| ------- | ---------------------------------------------------------------------------- |
259| 9200001 | The application is not an administrator application of the device.            |
260| 9200002 | The administrator application does not have permission to manage the device. |
261| 201 | Permission verification failed. The application does not have the permission required to call the API. |
262| 202 | Permission verification failed. A non-system application calls a system API. |
263| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
264
265**Example**
266
267```ts
268import { Want } from '@kit.AbilityKit';
269let wantTemp: Want = {
270  bundleName: 'com.example.myapplication',
271  abilityName: 'EntryAbility',
272};
273let appIds: Array<string> = ['com.example.myapplication'];
274
275applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (err) => {
276  if (err) {
277    console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
278    return;
279  }
280  console.info('Succeeded in removing disallowed running bundles');
281});
282```
283
284## applicationManager.removeDisallowedRunningBundles
285
286removeDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;
287
288Removes the applications that are not allowed to run by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
289
290**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
291
292**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
293
294
295
296**Parameters**
297
298| Name  | Type                                 | Mandatory  | Description     |
299| ----- | ----------------------------------- | ---- | ------- |
300| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
301| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
302| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br>- If **userId** is passed in, the applications cannot be run by the specified user.<br>- If **userId** is not passed in, the applications cannot be run by the current user.|
303
304**Return value**
305
306| Type                  | Description                     |
307| --------------------- | ------------------------- |
308| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
309
310**Error codes**
311
312For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
313
314| ID| Error Message                                                                    |
315| ------- | ---------------------------------------------------------------------------- |
316| 9200001 | The application is not an administrator application of the device.            |
317| 9200002 | The administrator application does not have permission to manage the device. |
318| 201 | Permission verification failed. The application does not have the permission required to call the API. |
319| 202 | Permission verification failed. A non-system application calls a system API. |
320| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
321
322**Example**
323
324```ts
325import { Want } from '@kit.AbilityKit';
326import { BusinessError } from '@kit.BasicServicesKit';
327let wantTemp: Want = {
328  bundleName: 'com.example.myapplication',
329  abilityName: 'EntryAbility',
330};
331let appIds: Array<string> = ['com.example.myapplication'];
332
333applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
334  console.info('Succeeded in removing disallowed running bundles');
335}).catch((err: BusinessError) => {
336  console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
337});
338```
339
340## applicationManager.getDisallowedRunningBundles
341
342getDisallowedRunningBundles(admin: Want, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
343
344Obtains the applications that are not allowed to run by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
345
346**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
347
348**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
349
350
351
352**Parameters**
353
354| Name     | Type                                      | Mandatory  | Description                      |
355| -------- | ---------------------------------------- | ---- | ------------------------------- |
356| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
357| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;       | Yes   | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |
358
359**Error codes**
360
361For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
362
363| ID| Error Message                                                                      |
364| ------- | ---------------------------------------------------------------------------- |
365| 9200001 | The application is not an administrator application of the device.            |
366| 9200002 | The administrator application does not have permission to manage the device. |
367| 201 | Permission verification failed. The application does not have the permission required to call the API. |
368| 202 | Permission verification failed. A non-system application calls a system API. |
369| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
370
371**Example**
372
373```ts
374import { Want } from '@kit.AbilityKit';
375let wantTemp: Want = {
376  bundleName: 'com.example.myapplication',
377  abilityName: 'EntryAbility',
378};
379
380applicationManager.getDisallowedRunningBundles(wantTemp, (err, result) => {
381  if (err) {
382    console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
383    return;
384  }
385  console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
386});
387```
388
389## applicationManager.getDisallowedRunningBundles
390
391getDisallowedRunningBundles(admin: Want, userId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
392
393Obtains the applications that are not allowed to run by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
394
395**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
396
397**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
398
399
400
401**Parameters**
402
403| Name     | Type                                      | Mandatory  | Description                      |
404| -------- | ---------------------------------------- | ---- | ------------------------------- |
405| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
406| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
407| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;       | Yes   | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |
408
409**Error codes**
410
411For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
412
413| ID| Error Message                                                                      |
414| ------- | ---------------------------------------------------------------------------- |
415| 9200001 | The application is not an administrator application of the device.            |
416| 9200002 | The administrator application does not have permission to manage the device. |
417| 201 | Permission verification failed. The application does not have the permission required to call the API. |
418| 202 | Permission verification failed. A non-system application calls a system API. |
419| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
420
421**Example**
422
423```ts
424import { Want } from '@kit.AbilityKit';
425let wantTemp: Want = {
426  bundleName: 'com.example.myapplication',
427  abilityName: 'EntryAbility',
428};
429
430applicationManager.getDisallowedRunningBundles(wantTemp, 100, (err, result) => {
431  if (err) {
432    console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
433    return;
434  }
435  console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
436});
437```
438
439## applicationManager.getDisallowedRunningBundles
440
441getDisallowedRunningBundles(admin: Want, userId?: number): Promise&lt;Array&lt;string&gt;&gt;
442
443Obtains the applications that are not allowed to run by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
444
445**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
446
447**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
448
449
450
451**Parameters**
452
453| Name  | Type                                 | Mandatory  | Description     |
454| ----- | ----------------------------------- | ---- | ------- |
455| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes   | Device administrator application.|
456| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br>- If **userId** is passed in, the applications cannot be run by the specified user.<br>- If **userId** is not passed in, the applications cannot be run by the current user.|
457
458**Return value**
459
460| Type                  | Description                     |
461| --------------------- | ------------------------- |
462| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the application blocklist of the current user.|
463
464**Error codes**
465
466For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
467
468| ID| Error Message                                                                    |
469| ------- | ---------------------------------------------------------------------------- |
470| 9200001 | The application is not an administrator application of the device.            |
471| 9200002 | The administrator application does not have permission to manage the device. |
472| 201 | Permission verification failed. The application does not have the permission required to call the API. |
473| 202 | Permission verification failed. A non-system application calls a system API. |
474| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
475
476**Example**
477
478```ts
479import { Want } from '@kit.AbilityKit';
480import { BusinessError } from '@kit.BasicServicesKit';
481let wantTemp: Want = {
482  bundleName: 'com.example.myapplication',
483  abilityName: 'EntryAbility',
484};
485
486applicationManager.getDisallowedRunningBundles(wantTemp, 100).then((result) => {
487  console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
488}).catch((err: BusinessError) => {
489  console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
490});
491```
492