1# @ohos.enterprise.applicationManager(应用管理)(系统接口)
2
3本模块提供应用管理能力,包括添加应用运行黑名单、获取应用运行黑名单、移除应用运行黑名单等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 本模块接口仅可在Stage模型下使用。
10>
11> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-guide.md#功能介绍)开放,需将[设备管理应用激活](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin)后调用,实现相应功能。
12>
13> 当前页面仅包含本模块的系统接口,其他公开接口参见。其他公开接口参见[@ohos.enterprise.applicationManager](js-apis-enterprise-applicationManager.md)。
14
15## 导入模块
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
25指定设备管理应用添加应用至应用运行黑名单,添加至黑名单的应用不允许在当前用户下运行,否则允许运行。使用callback异步回调。
26
27**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
28
29**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
30
31
32
33**参数:**
34
35| 参数名      | 类型                                       | 必填   | 说明                       |
36| -------- | ---------------------------------------- | ---- | ------------------------------- |
37| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
38| appIds    | Array&lt;string&gt;                | 是    | 应用ID数组,指定具体应用。                  |
39| callback | AsyncCallback&lt;void&gt;            | 是    | 回调函数。当接口调用成功,err为null,否则为错误对象。 |
40
41**错误码**:
42
43以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
44
45| 错误码ID | 错误信息                                                                       |
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**示例:**
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.******_******/******5t5CoBM='];
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
77指定设备管理应用添加应用至应用运行黑名单,添加至黑名单的应用不允许在指定用户(通过userId指定)下运行,否则允许运行。使用callback异步回调。
78
79**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
80
81**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
82
83
84
85**参数:**
86
87| 参数名   | 类型                                  | 必填   | 说明      |
88| ----- | ----------------------------------- | ---- | ------- |
89| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
90| appIds    | Array&lt;string&gt;                | 是    | 应用ID数组,指定具体应用。                  |
91| userId     | number                             | 是    | 用户ID,指定具体用户。取值范围:大于等于0。 |
92| callback | AsyncCallback&lt;void&gt;            | 是    | 回调函数,当接口调用成功,err为null,否则为错误对象。 |
93
94**错误码**:
95
96以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
97
98| 错误码ID | 错误信息                                                                     |
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**示例:**
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.******_******/******5t5CoBM='];
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
129指定设备管理应用添加应用至应用运行黑名单,添加至黑名单的应用不允许在当前/指定用户下运行。使用promise异步回调。
130
131**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
132
133**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
134
135
136
137**参数:**
138
139| 参数名   | 类型                                  | 必填   | 说明      |
140| ----- | ----------------------------------- | ---- | ------- |
141| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
142| appIds    | Array&lt;string&gt;                | 是    | 应用ID数组,指定具体应用。                  |
143| userId     | number                             | 否    | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 |
144
145**返回值:**
146
147| 类型                   | 说明                      |
148| --------------------- | ------------------------- |
149| Promise&lt;void&gt; | 无返回结果的Promise对象。当指定设备管理应用添加应用运行黑名单失败时,会抛出错误对象。  |
150
151**错误码**:
152
153以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
154
155| 错误码ID | 错误信息                                                                     |
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**示例:**
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.******_******/******5t5CoBM='];
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
185指定设备管理应用在应用运行黑名单中移除应用,在黑名单存在的情况下,在应用运行黑名单中的应用不允许在当前用户下运行。使用callback异步回调。
186
187**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
188
189**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
190
191
192
193**参数:**
194
195| 参数名      | 类型                                       | 必填   | 说明                       |
196| -------- | ---------------------------------------- | ---- | ------------------------------- |
197| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
198| appIds    | Array&lt;string&gt;                | 是    | 应用ID数组,指定具体应用。                  |
199| callback | AsyncCallback&lt;void&gt;            | 是    | 回调函数。当接口调用成功,err为null,否则为错误对象。 |
200
201**错误码**:
202
203以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
204
205| 错误码ID | 错误信息                                                                       |
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**示例:**
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.******_******/******5t5CoBM='];
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
236指定设备管理应用在应用运行黑名单中移除应用,在黑名单存在的情况下,在应用运行黑名单中的应用不允许在指定用户(通过userId指定)下运行。使用callback异步回调。
237
238**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
239
240**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
241
242
243
244**参数:**
245
246| 参数名   | 类型                                  | 必填   | 说明      |
247| ----- | ----------------------------------- | ---- | ------- |
248| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
249| appIds    | Array&lt;string&gt;                | 是    | 应用ID数组,指定具体应用。                  |
250| userId     | number                             | 是    | 用户ID,指定具体用户。取值范围:大于等于0。 |
251| callback | AsyncCallback&lt;void&gt;            | 是    | 回调函数。当接口调用成功,err为null,否则为错误对象。 |
252
253**错误码**:
254
255以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
256
257| 错误码ID | 错误信息                                                                     |
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**示例:**
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.******_******/******5t5CoBM='];
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
288指定当前/指定用户下的设备管理应用在应用运行黑名单中移除应用,使用promise异步回调。
289
290**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
291
292**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
293
294
295
296**参数:**
297
298| 参数名   | 类型                                  | 必填   | 说明      |
299| ----- | ----------------------------------- | ---- | ------- |
300| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
301| appIds    | Array&lt;string&gt;                | 是    | 应用ID数组,指定具体应用。                  |
302| userId     | number                             | 否    | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 |
303
304**返回值:**
305
306| 类型                   | 说明                      |
307| --------------------- | ------------------------- |
308| Promise&lt;void&gt; | 无返回结果的Promise对象。当指定设备管理应用移除应用运行黑名单失败时,会抛出错误对象。  |
309
310**错误码**:
311
312以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
313
314| 错误码ID | 错误信息                                                                     |
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**示例:**
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.******_******/******5t5CoBM='];
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
344指定设备管理应用获取当前用户下的应用运行黑名单。使用callback异步回调。
345
346**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
347
348**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
349
350
351
352**参数:**
353
354| 参数名      | 类型                                       | 必填   | 说明                       |
355| -------- | ---------------------------------------- | ---- | ------------------------------- |
356| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
357| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;       | 是    | 回调函数,当接口调用成功,err为null,否则为错误对象。       |
358
359**错误码**:
360
361以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
362
363| 错误码ID | 错误信息                                                                       |
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**示例:**
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
393指定设备管理应用获取指定用户(通过userId指定)下的应用运行黑名单。使用callback异步回调。
394
395**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
396
397**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
398
399
400
401**参数:**
402
403| 参数名      | 类型                                       | 必填   | 说明                       |
404| -------- | ---------------------------------------- | ---- | ------------------------------- |
405| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md)     | 是    | 设备管理应用。                  |
406| userId     | number                             | 是    | 用户ID,指定具体用户。取值范围:大于等于0。 |
407| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;       | 是    | 回调函数,当接口调用成功,err为null,否则为错误对象。       |
408
409**错误码**:
410
411以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
412
413| 错误码ID | 错误信息                                                                       |
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**示例:**
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
443指定设备管理应用获取当前/指定用户下的应用运行黑名单,使用promise异步回调。
444
445**需要权限:** ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
446
447**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
448
449
450
451**参数:**
452
453| 参数名   | 类型                                  | 必填   | 说明      |
454| ----- | ----------------------------------- | ---- | ------- |
455| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是    | 设备管理应用。 |
456| userId     | number                             | 否    | 用户ID,取值范围:大于等于0。<br> - 调用接口时,若传入userId,表示指定用户。<br> - 调用接口时,若未传入userId,表示当前用户。 |
457
458**返回值:**
459
460| 类型                   | 说明                      |
461| --------------------- | ------------------------- |
462| Promise&lt;Array&lt;string&gt;&gt; | Promise对象,返回当前用户下的应用运行黑名单。 |
463
464**错误码**:
465
466以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。
467
468| 错误码ID | 错误信息                                                                     |
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**示例:**
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