• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle.appControl (appControl模块)(系统接口)
2
3本模块提供应用拦截能力。对应用设置处置状态后,应用会被禁止运行;用户点击桌面图标时,会根据应用的处置状态,跳转到对应的页面。本模块支持对应用的处置状态进行设置、获取、删除。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 本模块为系统接口。
10
11## 导入模块
12
13``` ts
14import appControl from '@ohos.bundle.appControl'
15```
16
17## appControl.setDisposedStatus
18
19setDisposedStatus(appId: string, disposedWant: Want): Promise\<void>
20
21设置应用的处置状态。使用Promise异步回调。成功返回null,失败返回对应错误信息。
22
23**系统接口:** 此接口为系统接口。
24
25**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
26
27**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
28
29**参数:**
30
31| 参数名       | 类型     | 必填   | 说明                                    |
32| ----------- | ------ | ---- | --------------------------------------- |
33| appId  | string | 是    | 需要设置处置状态的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。               |
34| disposedWant | Want  | 是 | 对应用的处置意图。 |
35
36**返回值:**
37
38| 类型                        | 说明                 |
39| ------------------------- | ------------------ |
40| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
41
42**错误码:**
43
44以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
45
46| 错误码ID | 错误信息                                |
47| ------ | -------------------------------------- |
48| 201 | Permission denied. |
49| 202 | Permission denied, non-system app called system api. |
50| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
51| 801 | Capability not supported. |
52| 17700005 |  The specified app ID is an empty string.  |
53
54**示例:**
55
56```ts
57import { BusinessError } from '@ohos.base';
58import Want from '@ohos.app.ability.Want';
59import appControl from '@ohos.bundle.appControl';
60
61let appId = "com.example.myapplication_xxxxx";
62let want:Want = {bundleName: 'com.example.myapplication'};
63
64try {
65    appControl.setDisposedStatus(appId, want)
66        .then(() => {
67            console.info('setDisposedStatus success');
68        }).catch((error: BusinessError) => {
69            let message = (error as BusinessError).message;
70            console.error('setDisposedStatus failed ' + message);
71        });
72} catch (error) {
73    let message = (error as BusinessError).message;
74    console.error('setDisposedStatus failed ' + message);
75}
76```
77
78## appControl.setDisposedStatus
79
80setDisposedStatus(appId: string, disposedWant: Want, callback: AsyncCallback\<void>): void;
81
82设置应用的处置状态。使用callback异步回调。成功返回null,失败返回对应错误信息。
83
84**系统接口:** 此接口为系统接口。
85
86**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
87
88**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
89
90**参数:**
91
92| 参数名       | 类型                              | 必填   | 说明                                    |
93| ----------- | ------------------------------- | ---- | --------------------------------------- |
94| appId  | string | 是    | 需要设置处置的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。                      |
95| disposedWant | Want  | 是 | 对应用的处置意图。 |
96| callback    | AsyncCallback\<void> | 是    | 回调函数,当设置处置状态成功,err为null,否则为错误对象。 |
97
98**错误码:**
99
100以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
101
102| 错误码ID | 错误信息                                |
103| ------ | -------------------------------------- |
104| 201 | Permission denied. |
105| 202 | Permission denied, non-system app called system api. |
106| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
107| 801 | Capability not supported. |
108| 17700005 |  The specified app ID is an empty string.  |
109
110**示例:**
111
112```ts
113import appControl from '@ohos.bundle.appControl';
114import { BusinessError } from '@ohos.base';
115import Want from '@ohos.app.ability.Want';
116
117let appId = "com.example.myapplication_xxxxx";
118let want: Want = {bundleName: 'com.example.myapplication'};
119
120try {
121  appControl.setDisposedStatus(appId, want, (error: BusinessError, data) => {
122    if (error) {
123      let message = (error as BusinessError).message;
124      console.error('setDisposedStatus failed ' + message);
125      return;
126    }
127    console.info('setDisposedStatus success');
128  });
129} catch (error) {
130    let message = (error as BusinessError).message;
131    console.error('setDisposedStatus failed ' + message);
132}
133```
134
135## appControl.setDisposedStatusSync<sup>10+</sup>
136
137setDisposedStatusSync(appId: string, disposedWant: Want): void;
138
139以同步方法设置应用的处置状态。成功返回null,失败抛出对应异常。
140
141**系统接口:** 此接口为系统接口。
142
143**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
144
145**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
146
147
148**参数:**
149
150| 参数名       | 类型                              | 必填   | 说明                                    |
151| ----------- | ------------------------------- | ---- | --------------------------------------- |
152| appId  | string | 是    | 需要设置处置的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。                      |
153| disposedWant | Want  | 是 | 对应用的处置意图。 |
154
155**错误码:**
156
157以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
158
159| 错误码ID | 错误信息                                |
160| ------ | -------------------------------------- |
161| 201 | Permission denied. |
162| 202 | Permission denied, non-system app called system api. |
163| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
164| 801 | Capability not supported. |
165| 17700005 |  The specified app ID is an empty string.  |
166
167**示例:**
168
169```ts
170import appControl from '@ohos.bundle.appControl';
171import { BusinessError } from '@ohos.base';
172import Want from '@ohos.app.ability.Want';
173
174let appId: string = "com.example.myapplication_xxxxx";
175let want: Want = {bundleName: 'com.example.myapplication'};
176
177try {
178  appControl.setDisposedStatusSync(appId, want);
179} catch (error) {
180  let message = (error as BusinessError).message;
181  console.error('setDisposedStatusSync failed ' + message);
182}
183```
184
185## appControl.getDisposedStatus
186
187getDisposedStatus(appId: string): Promise\<Want>;
188
189获取指定应用已设置的处置状态。使用Promise异步回调,成功返回应用的处置状态,失败返回对应错误信息。
190
191**系统接口:** 此接口为系统接口。
192
193**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
194
195**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
196
197**参数:**
198
199| 参数名       | 类型     | 必填   | 说明                                    |
200| ----------- | ------ | ---- | --------------------------------------- |
201| appId  | string | 是    | 要查询的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。  |
202
203**返回值:**
204
205| 类型                        | 说明                 |
206| ------------------------- | ------------------ |
207| Promise\<Want> | Promise对象,返回应用的处置状态。 |
208
209**错误码:**
210
211以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
212
213| 错误码ID | 错误信息                                |
214| ------ | -------------------------------------- |
215| 201 | Permission denied. |
216| 202 | Permission denied, non-system app called system api. |
217| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
218| 801 | Capability not supported. |
219| 17700005 |  The specified app ID is an empty string.  |
220
221**示例:**
222
223```ts
224import appControl from '@ohos.bundle.appControl';
225import { BusinessError } from '@ohos.base';
226
227let appId = "com.example.myapplication_xxxxx";
228
229try {
230  appControl.getDisposedStatus(appId)
231    .then((data) => {
232      console.info('getDisposedStatus success. DisposedStatus: ' + JSON.stringify(data));
233    }).catch((error: BusinessError) => {
234    let message = (error as BusinessError).message;
235    console.error('getDisposedStatus failed ' + message);
236  });
237} catch (error) {
238    let message = (error as BusinessError).message;
239    console.error('getDisposedStatus failed ' + message);
240}
241```
242
243## appControl.getDisposedStatus
244
245getDisposedStatus(appId: string, callback: AsyncCallback\<Want>): void;
246
247获取指定应用的处置状态。使用callback异步回调,成功返回应用的处置状态,失败返回对应错误信息。
248
249**系统接口:** 此接口为系统接口。
250
251**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
252
253**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
254
255**参数:**
256
257| 参数名       | 类型     | 必填   | 说明                                  |
258| ----------- | ------ | ---- | --------------------------------------- |
259| appId  | string | 是    | 要查询的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。  |
260| callback    | AsyncCallback\<Want> | 是    | 回调函数。当获取应用的处置状态成功时,err为null,data为获取到的处置状态;否则为错误对象。                    |
261
262**错误码:**
263
264以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
265
266| 错误码ID | 错误信息                                |
267| ------ | -------------------------------------- |
268| 201 | Permission denied. |
269| 202 | Permission denied, non-system app called system api. |
270| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
271| 801 | Capability not supported. |
272| 17700005 |  The specified app ID is an empty string.  |
273
274**示例:**
275
276```ts
277import appControl from '@ohos.bundle.appControl';
278import { BusinessError } from '@ohos.base';
279
280let appId = "com.example.myapplication_xxxxx";
281
282try {
283  appControl.getDisposedStatus(appId, (error, data) => {
284    if (error) {
285      let message = (error as BusinessError).message;
286      console.error('getDisposedStatus failed ' + message);
287      return;
288    }
289    console.info('getDisposedStatus success. DisposedStatus: ' + JSON.stringify(data));
290  });
291} catch (error) {
292    let message = (error as BusinessError).message;
293    console.error('getDisposedStatus failed ' + message);
294}
295```
296
297## appControl.getDisposedStatusSync<sup>10+</sup>
298
299getDisposedStatusSync(appId: string): Want;
300
301以同步方法获取指定应用已设置的处置状态。成功返回应用的处置状态,失败抛出对应异常。
302
303**系统接口:** 此接口为系统接口。
304
305**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
306
307**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
308
309**参数:**
310
311| 参数名       | 类型     | 必填   | 说明                                    |
312| ----------- | ------ | ---- | --------------------------------------- |
313| appId  | string | 是    | 要查询的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。  |
314
315**返回值:**
316
317| 类型                        | 说明                 |
318| ------------------------- | ------------------ |
319| Want | 返回应用的处置状态。 |
320
321**错误码:**
322
323以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
324
325| 错误码ID | 错误信息                                |
326| ------ | -------------------------------------- |
327| 201 | Permission denied. |
328| 202 | Permission denied, non-system app called system api. |
329| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
330| 801 | Capability not supported. |
331| 17700005 |  The specified app ID is an empty string.  |
332
333**示例:**
334
335```ts
336import appControl from '@ohos.bundle.appControl';
337import { BusinessError } from '@ohos.base';
338import Want from '@ohos.app.ability.Want';
339
340let appId: string = "com.example.myapplication_xxxxx";
341let want: Want;
342
343try {
344    want = appControl.getDisposedStatusSync(appId);
345} catch (error) {
346    let message = (error as BusinessError).message;
347    console.error('getDisposedStatusSync failed ' + message);
348}
349```
350
351## appControl.deleteDisposedStatus
352
353deleteDisposedStatus(appId: string): Promise\<void>
354
355删除应用的处置状态。使用promise异步回调,成功返回null,失败返回对应错误信息。
356
357**系统接口:** 此接口为系统接口。
358
359**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
360
361**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
362
363**参数:**
364
365| 参数名       | 类型     | 必填   | 说明                                    |
366| ----------- | ------ | ---- | --------------------------------------- |
367| appId  | string | 是    | 要删除处置状态的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。  |
368
369**返回值:**
370
371| 类型                        | 说明                 |
372| ------------------------- | ------------------ |
373| Promise\<void> | Promise对象,无返回结果的Promise对象。 |
374
375**错误码:**
376
377以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
378
379| 错误码ID | 错误信息                                |
380| ------ | -------------------------------------- |
381| 201 | Permission denied. |
382| 202 | Permission denied, non-system app called system api. |
383| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
384| 801 | Capability not supported. |
385| 17700005 |  The specified app ID is an empty string.  |
386
387**示例:**
388
389```ts
390import appControl from '@ohos.bundle.appControl';
391import { BusinessError } from '@ohos.base';
392
393let appId = "com.example.myapplication_xxxxx";
394
395try {
396  appControl.deleteDisposedStatus(appId)
397    .then(() => {
398      console.info('deleteDisposedStatus success');
399    }).catch((error: BusinessError) => {
400      let message = (error as BusinessError).message;
401      console.error('deleteDisposedStatus failed ' + message);
402  });
403} catch (error) {
404  let message = (error as BusinessError).message;
405  console.error('deleteDisposedStatus failed ' + message);
406}
407```
408
409## appControl.deleteDisposedStatus
410
411deleteDisposedStatus(appId: string, callback: AsyncCallback\<void>) : void
412
413删除应用的处置状态。使用callback异步回调,成功返回null,失败返回对应错误信息。
414
415**系统接口:** 此接口为系统接口。
416
417**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
418
419**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
420
421**参数:**
422
423| 参数名       | 类型     | 必填   | 说明                                    |
424| ----------- | ------ | ---- | --------------------------------------- |
425| appId  | string | 是    | 要查询的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。  |
426| callback    | AsyncCallback\<void> | 是    | 回调函数,当设置处置状态成功时,err返回null。否则回调函数返回具体错误对象。                   |
427
428**错误码:**
429
430以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
431
432| 错误码ID | 错误信息                                |
433| ------ | -------------------------------------- |
434| 201 | Permission denied. |
435| 202 | Permission denied, non-system app called system api. |
436| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
437| 801 | Capability not supported. |
438| 17700005 |  The specified app ID is an empty string.  |
439
440**示例:**
441
442```ts
443import appControl from '@ohos.bundle.appControl';
444import { BusinessError } from '@ohos.base';
445
446let appId = "com.example.myapplication_xxxxx";
447try {
448  appControl.deleteDisposedStatus(appId, (error: BusinessError, data) => {
449    if (error) {
450      console.error('deleteDisposedStatus failed ' + error.message);
451      return;
452    }
453    console.info('deleteDisposedStatus success');
454  });
455} catch (error) {
456    let message = (error as BusinessError).message;
457    console.error('deleteDisposedStatus failed ' + message);
458}
459```
460
461## appControl.deleteDisposedStatusSync<sup>10+</sup>
462
463deleteDisposedStatusSync(appId: string, appIndex:? number) : void
464
465以同步方法删除指定应用或分身应用的处置状态。成功返回null,失败抛出对应异常。
466
467**系统接口:** 此接口为系统接口。
468
469**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
470
471**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
472
473**参数:**
474
475| 参数名       | 类型     | 必填   | 说明                                    |
476| ----------- | ------ | ---- | --------------------------------------- |
477| appId  | string | 是    | 要查询的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。  |
478| appIndex<sup>12+</sup>   | number  | 否   | 表示分身应用的索引,默认值为0。<br> appIndex为0时,表示删除主应用的处置状态。appIndex大于0时,表示删除指定分身应用的处置状态。  |
479
480**错误码:**
481
482以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
483
484| 错误码ID | 错误信息                                |
485| ------ | -------------------------------------- |
486| 201 | Permission denied. |
487| 202 | Permission denied, non-system app called system api. |
488| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
489| 801 | Capability not supported. |
490| 17700005 |  The specified app ID is an empty string.  |
491| 17700061 | AppIndex is not in the valid range. |
492
493**示例:**
494
495```ts
496import appControl from '@ohos.bundle.appControl';
497import { BusinessError } from '@ohos.base';
498
499let appId: string = "com.example.myapplication_xxxxx";
500
501try {
502    appControl.deleteDisposedStatusSync(appId, 1);
503} catch (error) {
504    let message = (error as BusinessError).message;
505    console.error('deleteDisposedStatusSync failed ' + message);
506}
507```
508
509## 获取应用的appId
510
511appId是应用的唯一标识,由应用Bundle名称和签名信息决定,可以通过[getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo14)接口获取。
512
513**示例:**
514
515```ts
516import bundleManager from '@ohos.bundle.bundleManager';
517import { BusinessError } from '@ohos.base';
518
519let bundleName = 'com.example.myapplication';
520let appId: string;
521try {
522  bundleManager.getBundleInfo(bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)
523    .then((data) => {
524      appId = data.signatureInfo.appId;
525      console.info("appId is " + appId);
526    }).catch((error: BusinessError) => {
527      let message = (error as BusinessError).message;
528      console.error("getBundleInfo failed " + message);
529  });
530} catch (error) {
531    let message = (error as BusinessError).message;
532    console.error("getBundleInfo failed " + message);
533}
534```
535
536## appControl.getDisposedRule<sup>11+</sup>
537
538getDisposedRule(appId: string, appIndex:? number): DisposedRule
539
540获取指定应用或分身应用已设置的拦截规则。
541
542**系统接口:** 此接口为系统接口。
543
544**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
545
546**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
547
548**参数:**
549
550| 参数名       | 类型     | 必填   | 说明                                    |
551| ----------- | ------ | ---- | --------------------------------------- |
552| appId  | string | 是    | 要获取拦截规则的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。  |
553| appIndex<sup>12+</sup>   | number  | 否   | 表示分身应用的索引,默认值为0。<br> appIndex为0时,表示获取主应用的拦截规则。appIndex大于0时,表示获取指定分身应用的拦截规则。    |
554
555**返回值:**
556
557| 类型                        | 说明                 |
558| ------------------------- | ------------------ |
559| [DisposedRule](#disposedrule11) | 对应用的拦截规则。 |
560
561**错误码:**
562
563以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
564
565| 错误码ID | 错误信息                                |
566| ------ | -------------------------------------- |
567| 201 | Permission denied. |
568| 202 | Permission denied, non-system app called system api. |
569| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
570| 801 | Capability not supported. |
571| 17700005 |  The specified app ID is an empty string.  |
572| 17700061 | AppIndex is not in the valid range. |
573
574**示例:**
575
576```ts
577import appControl from '@ohos.bundle.appControl';
578import { BusinessError } from '@ohos.base';
579import Want from '@ohos.app.ability.Want';
580
581let appId = "com.example.myapplication_xxxxx";
582
583try {
584  let data = appControl.getDisposedRule(appId, 1);
585  console.info('getDisposedRule successfully. Data: ' + JSON.stringify(data));
586} catch (error) {
587  let message = (error as BusinessError).message;
588  console.error('getDisposedRule failed ' + message);
589}
590```
591
592## appControl.setDisposedRule<sup>11+</sup>
593
594setDisposedRule(appId: string, rule: DisposedRule, appIndex:? number): void
595
596设置指定应用或分身应用的拦截规则。
597
598**系统接口:** 此接口为系统接口。
599
600**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
601
602**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
603
604**参数:**
605
606| 参数名       | 类型     | 必填   | 说明                                    |
607| ----------- | ------ | ---- | --------------------------------------- |
608| appId  | string | 是    | 要设置拦截规则的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。  |
609| rule | [DisposedRule](#disposedrule11) | 是 | 指示对应用的拦截规则。 |
610| appIndex<sup>12+</sup>   | number  | 否   | 表示分身应用的索引,默认值为0。<br> appIndex为0时,表示设置主应用的拦截规则。appIndex大于0时,表示设置指定分身应用的拦截规则。            |
611
612**错误码:**
613
614以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
615
616| 错误码ID | 错误信息                                |
617| ------ | -------------------------------------- |
618| 201 | Permission denied. |
619| 202 | Permission denied, non-system app called system api. |
620| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
621| 801 | Capability not supported. |
622| 17700005 |  The specified app ID is an empty string.  |
623| 17700061 | AppIndex is not in the valid range. |
624
625**示例:**
626
627```ts
628import appControl from '@ohos.bundle.appControl';
629import { BusinessError } from '@ohos.base';
630import Want from '@ohos.app.ability.Want';
631import bundleManager from '@ohos.bundle.bundleManager';
632
633let appId = "com.example.myapplication_xxxxx";
634let want: Want = {
635  bundleName: "com.example.myapplication",
636  moduleName: "entry",
637  abilityName: "EntryAbility"
638};
639let elementName: bundleManager.ElementName = {
640  bundleName: "com.example.myapplication",
641  moduleName: "entry",
642  abilityName: "EntryAbility"
643};
644let rule: appControl.DisposedRule = {
645  want: want,
646  componentType: appControl.ComponentType.UI_ABILITY,
647  disposedType: appControl.DisposedType.BLOCK_APPLICATION,
648  controlType: appControl.ControlType.ALLOWED_LIST,
649  elementList: [
650    elementName
651  ],
652  priority: 100
653};
654
655try {
656  appControl.setDisposedRule(appId, rule, 1);
657} catch (error) {
658  let message = (error as BusinessError).message;
659  console.error('setDisposedRule failed ' + message);
660}
661```
662
663## appControl.setUninstallDisposedRule<sup>15+</sup>
664
665setUninstallDisposedRule(appIdentifier: string, rule: UninstallDisposedRule, appIndex:? number): void
666
667设置指定应用或分身应用的卸载处置规则。
668
669**系统接口:** 此接口为系统接口。
670
671**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
672
673**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
674
675**参数:**
676
677| 参数名       | 类型     | 必填   | 说明                                    |
678| ----------- | ------ | ---- | --------------------------------------- |
679| appIdentifier  | string | 是    | 要设置卸载处置规则的应用的appIdentifier。<br> 如果应用没有appIdentifier可使用appId代替。appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。  |
680| rule | [UninstallDisposedRule](#uninstalldisposedrule15) | 是 | 表示要设置的卸载处置规则。 |
681| appIndex   | number  | 否   | 表示分身应用的索引,默认值为0。<br> appIndex为0时,表示设置主应用的卸载处置规则。appIndex大于0时,表示设置指定分身应用的卸载处置规则。        |
682
683**错误码:**
684
685以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
686
687| 错误码ID | 错误信息                                |
688| ------ | -------------------------------------- |
689| 201 | Permission denied. |
690| 202 | Permission denied. A non-system application is not allowed to call a system API. |
691| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
692| 801 | Capability not supported. |
693| 17700061 | AppIndex is not in the valid range. |
694| 17700074 | The specified appIdentifier is invalid. |
695| 17700075 | The specified bundleName of want is not the same with caller. |
696
697**示例:**
698
699```ts
700import appControl from '@ohos.bundle.appControl';
701import { BusinessError } from '@ohos.base';
702import Want from '@ohos.app.ability.Want';
703
704let appIdentifier = "com.example.myapplication_xxxxx";
705let want: Want = {
706  bundleName: "com.example.myapplication",
707  moduleName: "entry",
708  abilityName: "EntryAbility"
709};
710let rule: appControl.UninstallDisposedRule = {
711  want: want,
712  uninstallComponentType: appControl.UninstallComponentType.EXTENSION,
713  priority: 100
714};
715
716try {
717  appControl.setUninstallDisposedRule(appIdentifier, rule, 1);
718} catch (error) {
719  let message = (error as BusinessError).message;
720  console.error('setUninstallDisposedRule failed ' + message);
721}
722```
723
724## appControl.getUninstallDisposedRule<sup>15+</sup>
725
726getUninstallDisposedRule(appIdentifier: string, appIndex:? number): UninstallDisposedRule
727
728获取指定应用或分身应用已设置的卸载处置规则。
729
730**系统接口:** 此接口为系统接口。
731
732**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUSohos.permission.GET_DISPOSED_APP_STATUS
733
734**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
735
736**参数:**
737
738| 参数名       | 类型     | 必填   | 说明                                    |
739| ----------- | ------ | ---- | --------------------------------------- |
740| appIdentifier  | string | 是    | 要获取卸载处置规则的应用的appIdentifier。<br> 如果应用没有appIdentifier可使用appId代替。appId是应用的唯一标识,由应用Bundle名称和签名信息决定,设置方法参见[获取应用的appId](#获取应用的appid)。  |
741| appIndex   | number  | 否   | 表示分身应用的索引,默认值为0。<br> appIndex为0时,表示获取主应用的卸载处置规则。appIndex大于0时,表示获取指定分身应用的卸载处置规则。              |
742
743**返回值:**
744
745| 类型                        | 说明                 |
746| ------------------------- | ------------------ |
747| [UninstallDisposedRule](#uninstalldisposedrule15) | 表示应用的卸载处置规则。 |
748
749**错误码:**
750
751以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
752
753| 错误码ID | 错误信息                                |
754| ------ | -------------------------------------- |
755| 201 | Permission denied. |
756| 202 | Permission denied. A non-system application is not allowed to call a system API. |
757| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
758| 801 | Capability not supported. |
759| 17700061 | AppIndex is not in the valid range. |
760| 17700074 | The specified appIdentifier is invalid. |
761
762**示例:**
763
764```ts
765import appControl from '@ohos.bundle.appControl';
766import { BusinessError } from '@ohos.base';
767
768let appIdentifier = "com.example.myapplication_xxxxx";
769
770try {
771  let data = appControl.getUninstallDisposedRule(appIdentifier, 1);
772  console.info('getUninstallDisposedRule successfully. Data: ' + JSON.stringify(data));
773} catch (error) {
774  let message = (error as BusinessError).message;
775  console.error('getUninstallDisposedRule failed ' + message);
776}
777```
778
779## appControl.deleteUninstallDisposedRule<sup>15+</sup>
780
781deleteUninstallDisposedRule(appIdentifier: string, appIndex:? number): void
782
783删除指定应用或分身应用的卸载处置规则。
784
785**系统接口:** 此接口为系统接口。
786
787**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS
788
789**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl
790
791**参数:**
792
793| 参数名       | 类型     | 必填   | 说明                                    |
794| ----------- | ------ | ---- | --------------------------------------- |
795| appIdentifier  | string | 是    | 要删除卸载处置规则的应用的appIdentifier。<br> 如果应用没有appIdentifier可使用appId代替。appId是应用的唯一标识,由应用Bundle名称和签名信息决定,删除方法参见[获取应用的appId](#获取应用的appid)。  |
796| appIndex   | number  | 否   | 表示分身应用的索引,默认值为0。<br> appIndex为0时,表示删除主应用的卸载处置规则。appIndex大于0时,表示删除指定分身应用的卸载处置规则。            |
797
798**错误码:**
799
800以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
801
802| 错误码ID | 错误信息                                |
803| ------ | -------------------------------------- |
804| 201 | Permission denied. |
805| 202 | Permission denied. A non-system application is not allowed to call a system API. |
806| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
807| 801 | Capability not supported. |
808| 17700061 | AppIndex is not in the valid range. |
809| 17700074 | The specified appIdentifier is invalid. |
810
811**示例:**
812
813```ts
814import appControl from '@ohos.bundle.appControl';
815import { BusinessError } from '@ohos.base';
816
817let appIdentifier = "com.example.myapplication_xxxxx";
818
819try {
820  appControl.deleteUninstallDisposedRule(appIdentifier, 1);
821} catch (error) {
822  let message = (error as BusinessError).message;
823  console.error('deleteUninstallDisposedRule failed ' + message);
824}
825```
826
827## DisposedRule<sup>11+</sup>
828
829标识拦截规则。
830
831 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.AppControl832
833 **系统接口:** 此接口为系统接口。
834
835| 名称      | 类型           | 可读 | 可写 | 说明                        |
836| --------- | -------------- | ---- | ---- | --------------------------- |
837| want | [Want](js-apis-app-ability-want.md)     | 是   | 是   | 指定应用被拦截时,跳转到的页面。 |
838| componentType | [ComponentType](#componenttype11)  | 是   | 是   | 拦截时将提升的能力的类型。 |
839| disposedType | [DisposedType](#disposedrule11) | 是 | 是 | 对应用的拦截规则。 |
840| controlType | [ControlType](#controltype11) | 是 | 是 | 拦截指定应用程序的不同策略。 |
841| elementList | Array\<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | 是 | 拦截指定应用程序能力的列表。 |
842| priority | number | 是 | 是 | 拦截规则的优先级。 |
843
844### ComponentType<sup>11+</sup>
845
846标识功能组件类型。
847
848 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.AppControl849
850 **系统接口:** 此接口为系统接口。
851
852| 名称    | 值   | 说明                 |
853| ------- | ---- | -------------------- |
854| UI_ABILITY | 1    | UI基础功能类型。 |
855| UI_EXTENSION | 2    | UI扩展能力类型。 |
856
857### DisposedType<sup>11+</sup>
858
859标识拦截应用程序的方式,例如禁用应用的全部能力、禁用应用的指定能力、或者不禁用。
860
861 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.AppControl862
863 **系统接口:** 此接口为系统接口。
864
865| 名称    | 值   | 说明                 |
866| ------- | ---- | -------------------- |
867| BLOCK_APPLICATION | 1    | 应用所有能力都将被禁用。 |
868| BLOCK_ABILITY | 2    | 应用指定的能力才会被禁用。 |
869| NON_BLOCK | 3 | 应用所有能力不会被禁用。 |
870
871### ControlType<sup>11+</sup>
872
873标识拦截指定应用程序的不同策略。
874
875 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.AppControl876
877 **系统接口:** 此接口为系统接口。
878
879| 名称    | 值   | 说明                 |
880| ------- | ---- | -------------------- |
881| ALLOWED_LIST | 1    | 允许运行指定功能的列表。 |
882| DISALLOWED_LIST | 2    | 不允许运行指定功能的列表。 |
883
884## UninstallDisposedRule<sup>15+</sup>
885
886标识卸载处置规则。
887
888 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.AppControl889
890 **系统接口:** 此接口为系统接口。
891
892| 名称      | 类型           | 可读 | 可写 | 说明                        |
893| --------- | -------------- | ---- | ---- | --------------------------- |
894| want | [Want](js-apis-app-ability-want.md)     | 是   | 是   | 指定应用被拦截时,跳转到的页面。 |
895| UninstallComponentType | [UninstallComponentType](#uninstallcomponenttype15)  | 是   | 是   | 拦截时将拉起能力的类型。 |
896| priority | number | 是 | 是 | 拦截规则的优先级。 |
897
898### UninstallComponentType<sup>15+</sup>
899
900标识卸载时功能组件类型。
901
902 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.AppControl903
904 **系统接口:** 此接口为系统接口。
905
906| 名称    | 值   | 说明                 |
907| ------- | ---- | -------------------- |
908| EXTENSION | 1    | 服务扩展能力类型。 |
909