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