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) : 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 479**错误码:** 480 481以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 482 483| 错误码ID | 错误信息 | 484| ------ | -------------------------------------- | 485| 201 | Permission denied. | 486| 202 | Permission denied, non-system app called system api. | 487| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 488| 801 | Capability not supported. | 489| 17700005 | The specified app ID is an empty string. | 490 491**示例:** 492 493```ts 494import appControl from '@ohos.bundle.appControl'; 495import { BusinessError } from '@ohos.base'; 496 497let appId: string = "com.example.myapplication_xxxxx"; 498 499try { 500 appControl.deleteDisposedStatusSync(appId); 501} catch (error) { 502 let message = (error as BusinessError).message; 503 console.error('deleteDisposedStatusSync failed ' + message); 504} 505``` 506 507## appControl.deleteDisposedStatusSync<sup>12+</sup> 508 509deleteDisposedStatusSync(appId: string, appIndex:? number) : void 510 511以同步方法删除指定应用或分身应用的处置状态。成功返回null,失败抛出对应异常。 512 513**系统接口:** 此接口为系统接口。 514 515**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS 516 517**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl 518 519**参数:** 520 521| 参数名 | 类型 | 必填 | 说明 | 522| ----------- | ------ | ---- | --------------------------------------- | 523| appId | string | 是 | 要查询的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。 | 524| appIndex | number | 否 | 表示分身应用的索引。<br> appIndex为0时,表示删除指定应用的处置状态。 | 525 526**错误码:** 527 528以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 529 530| 错误码ID | 错误信息 | 531| ------ | -------------------------------------- | 532| 201 | Permission denied. | 533| 202 | Permission denied, non-system app called system api. | 534| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 535| 801 | Capability not supported. | 536| 17700005 | The specified app ID is an empty string. | 537| 17700061 | AppIndex is not in the valid range. | 538 539**示例:** 540 541```ts 542import appControl from '@ohos.bundle.appControl'; 543import { BusinessError } from '@ohos.base'; 544 545let appId: string = "com.example.myapplication_xxxxx"; 546 547try { 548 appControl.deleteDisposedStatusSync(appId, 1); 549} catch (error) { 550 let message = (error as BusinessError).message; 551 console.error('deleteDisposedStatusSync failed ' + message); 552} 553``` 554 555## 获取应用的appId 556 557appId是应用的唯一标识,由应用Bundle名称和签名信息决定,可以通过[getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo14)接口获取。 558 559**示例:** 560 561```ts 562import bundleManager from '@ohos.bundle.bundleManager'; 563import { BusinessError } from '@ohos.base'; 564 565let bundleName = 'com.example.myapplication'; 566let appId: string; 567try { 568 bundleManager.getBundleInfo(bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO) 569 .then((data) => { 570 appId = data.signatureInfo.appId; 571 console.info("appId is " + appId); 572 }).catch((error: BusinessError) => { 573 let message = (error as BusinessError).message; 574 console.error("getBundleInfo failed " + message); 575 }); 576} catch (error) { 577 let message = (error as BusinessError).message; 578 console.error("getBundleInfo failed " + message); 579} 580``` 581 582## appControl.getDisposedRule<sup>11+</sup> 583 584getDisposedRule(appId: string): DisposedRule 585 586获取指定应用已设置的拦截规则。 587 588**系统接口:** 此接口为系统接口。 589 590**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS 591 592**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl 593 594**参数:** 595 596| 参数名 | 类型 | 必填 | 说明 | 597| ----------- | ------ | ---- | --------------------------------------- | 598| appId | string | 是 | 要获取拦截规则的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。 | 599 600**返回值:** 601 602| 类型 | 说明 | 603| ------------------------- | ------------------ | 604| [DisposedRule](#disposedrule11) | 对应用的拦截规则。 | 605 606**错误码:** 607 608以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 609 610| 错误码ID | 错误信息 | 611| ------ | -------------------------------------- | 612| 201 | Permission denied. | 613| 202 | Permission denied, non-system app called system api. | 614| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 615| 801 | Capability not supported. | 616| 17700005 | The specified app ID is an empty string. | 617 618**示例:** 619 620```ts 621import appControl from '@ohos.bundle.appControl'; 622import { BusinessError } from '@ohos.base'; 623import Want from '@ohos.app.ability.Want'; 624 625let appId = "com.example.myapplication_xxxxx"; 626 627try { 628 let data = appControl.getDisposedRule(appId); 629 console.info('getDisposedRule successfully. Data: ' + JSON.stringify(data)); 630} catch (error) { 631 let message = (error as BusinessError).message; 632 console.error('getDisposedRule failed ' + message); 633} 634``` 635 636## appControl.getDisposedRule<sup>12+</sup> 637 638getDisposedRule(appId: string, appIndex:? number): DisposedRule 639 640获取指定应用或分身应用已设置的拦截规则。 641 642**系统接口:** 此接口为系统接口。 643 644**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS 645 646**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl 647 648**参数:** 649 650| 参数名 | 类型 | 必填 | 说明 | 651| ----------- | ------ | ---- | --------------------------------------- | 652| appId | string | 是 | 要获取拦截规则的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。 | 653| appIndex | number | 否 | 表示分身应用的索引。<br> appIndex为0时,表示获取指定应用的拦截规则。 | 654 655**返回值:** 656 657| 类型 | 说明 | 658| ------------------------- | ------------------ | 659| [DisposedRule](#disposedrule11) | 对应用的拦截规则。 | 660 661**错误码:** 662 663以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 664 665| 错误码ID | 错误信息 | 666| ------ | -------------------------------------- | 667| 201 | Permission denied. | 668| 202 | Permission denied, non-system app called system api. | 669| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 670| 801 | Capability not supported. | 671| 17700005 | The specified app ID is an empty string. | 672| 17700061 | AppIndex is not in the valid range. | 673 674**示例:** 675 676```ts 677import appControl from '@ohos.bundle.appControl'; 678import { BusinessError } from '@ohos.base'; 679import Want from '@ohos.app.ability.Want'; 680 681let appId = "com.example.myapplication_xxxxx"; 682 683try { 684 let data = appControl.getDisposedRule(appId, 1); 685 console.info('getDisposedRule successfully. Data: ' + JSON.stringify(data)); 686} catch (error) { 687 let message = (error as BusinessError).message; 688 console.error('getDisposedRule failed ' + message); 689} 690``` 691 692## appControl.setDisposedRule<sup>11+</sup> 693 694setDisposedRule(appId: string, rule: DisposedRule): void 695 696设置指定应用的拦截规则。 697 698**系统接口:** 此接口为系统接口。 699 700**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS 701 702**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl 703 704**参数:** 705 706| 参数名 | 类型 | 必填 | 说明 | 707| ----------- | ------ | ---- | --------------------------------------- | 708| appId | string | 是 | 要设置拦截规则的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。 | 709| rule | [DisposedRule](#disposedrule11) | 是 | 指示对应用的拦截规则。 | 710 711**错误码:** 712 713以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 714 715| 错误码ID | 错误信息 | 716| ------ | -------------------------------------- | 717| 201 | Permission denied. | 718| 202 | Permission denied, non-system app called system api. | 719| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 720| 801 | Capability not supported. | 721| 17700005 | The specified app ID is an empty string. | 722 723**示例:** 724 725```ts 726import appControl from '@ohos.bundle.appControl'; 727import { BusinessError } from '@ohos.base'; 728import Want from '@ohos.app.ability.Want'; 729import bundleManager from '@ohos.bundle.bundleManager'; 730 731let appId = "com.example.myapplication_xxxxx"; 732let want: Want = { 733 bundleName: "com.example.myapplication", 734 moduleName: "entry", 735 abilityName: "EntryAbility" 736}; 737let elementName: bundleManager.ElementName = { 738 bundleName: "com.example.myapplication", 739 moduleName: "entry", 740 abilityName: "EntryAbility" 741}; 742let rule: appControl.DisposedRule = { 743 want: want, 744 componentType: appControl.ComponentType.UI_ABILITY, 745 disposedType: appControl.DisposedType.BLOCK_APPLICATION, 746 controlType: appControl.ControlType.ALLOWED_LIST, 747 elementList: [ 748 elementName 749 ], 750 priority: 100 751}; 752 753try { 754 appControl.setDisposedRule(appId, rule); 755} catch (error) { 756 let message = (error as BusinessError).message; 757 console.error('setDisposedRule failed ' + message); 758} 759``` 760 761## appControl.setDisposedRule<sup>12+</sup> 762 763setDisposedRule(appId: string, rule: DisposedRule, appIndex:? number): void 764 765设置指定应用或分身应用的拦截规则。 766 767**系统接口:** 此接口为系统接口。 768 769**需要权限:** ohos.permission.MANAGE_DISPOSED_APP_STATUS 770 771**系统能力:** SystemCapability.BundleManager.BundleFramework.AppControl 772 773**参数:** 774 775| 参数名 | 类型 | 必填 | 说明 | 776| ----------- | ------ | ---- | --------------------------------------- | 777| appId | string | 是 | 要设置拦截规则的应用的appId。<br> appId是应用的唯一标识,由应用Bundle名称和签名信息决定,获取方法参见[获取应用的appId](#获取应用的appid)。 | 778| rule | [DisposedRule](#disposedrule11) | 是 | 指示对应用的拦截规则。 | 779| appIndex | number | 否 | 表示分身应用的索引。<br> appIndex为0时,表示设置指定应用的拦截规则。 | 780 781**错误码:** 782 783以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 784 785| 错误码ID | 错误信息 | 786| ------ | -------------------------------------- | 787| 201 | Permission denied. | 788| 202 | Permission denied, non-system app called system api. | 789| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 790| 801 | Capability not supported. | 791| 17700005 | The specified app ID is an empty string. | 792| 17700061 | AppIndex is not in the valid range. | 793 794**示例:** 795 796```ts 797import appControl from '@ohos.bundle.appControl'; 798import { BusinessError } from '@ohos.base'; 799import Want from '@ohos.app.ability.Want'; 800import bundleManager from '@ohos.bundle.bundleManager'; 801 802let appId = "com.example.myapplication_xxxxx"; 803let want: Want = { 804 bundleName: "com.example.myapplication", 805 moduleName: "entry", 806 abilityName: "EntryAbility" 807}; 808let elementName: bundleManager.ElementName = { 809 bundleName: "com.example.myapplication", 810 moduleName: "entry", 811 abilityName: "EntryAbility" 812}; 813let rule: appControl.DisposedRule = { 814 want: want, 815 componentType: appControl.ComponentType.UI_ABILITY, 816 disposedType: appControl.DisposedType.BLOCK_APPLICATION, 817 controlType: appControl.ControlType.ALLOWED_LIST, 818 elementList: [ 819 elementName 820 ], 821 priority: 100 822}; 823 824try { 825 appControl.setDisposedRule(appId, rule, 1); 826} catch (error) { 827 let message = (error as BusinessError).message; 828 console.error('setDisposedRule failed ' + message); 829} 830``` 831 832## DisposedRule<sup>11+</sup> 833 834标识拦截规则。 835 836 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.AppControl。 837 838 **系统接口:** 此接口为系统接口。 839 840| 名称 | 类型 | 可读 | 可写 | 说明 | 841| --------- | -------------- | ---- | ---- | --------------------------- | 842| want | [Want](js-apis-app-ability-want.md) | 是 | 是 | 指定应用被拦截时,跳转到的页面。 | 843| componentType | [ComponentType](#componenttype11) | 是 | 是 | 拦截时将提升的能力的类型。 | 844| disposedType | [DisposedType](#disposedrule11) | 是 | 是 | 对应用的拦截规则。 | 845| controlType | [ControlType](#controltype11) | 是 | 是 | 拦截指定应用程序的不同策略。 | 846| elementList | Array\<[ElementName](js-apis-bundleManager-elementName.md)> | 是 | 是 | 拦截指定应用程序能力的列表。 | 847| priority | number | 是 | 是 | 拦截规则的优先级。 | 848 849### ComponentType<sup>11+</sup> 850 851标识功能组件类型。 852 853 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.AppControl。 854 855 **系统接口:** 此接口为系统接口。 856 857| 名称 | 值 | 说明 | 858| ------- | ---- | -------------------- | 859| UI_ABILITY | 1 | UI基础功能类型。 | 860| UI_EXTENSION | 2 | UI扩展能力类型。 | 861 862### DisposedType<sup>11+</sup> 863 864标识拦截应用程序的方式,例如禁用应用的全部能力、禁用应用的指定能力、或者不禁用。 865 866 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.AppControl。 867 868 **系统接口:** 此接口为系统接口。 869 870| 名称 | 值 | 说明 | 871| ------- | ---- | -------------------- | 872| BLOCK_APPLICATION | 1 | 应用所有能力都将被禁用。 | 873| BLOCK_ABILITY | 2 | 应用指定的能力才会被禁用。 | 874| NON_BLOCK | 3 | 应用所有能力不会被禁用。 | 875 876### ControlType<sup>11+</sup> 877 878标识拦截指定应用程序的不同策略。 879 880 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.AppControl。 881 882 **系统接口:** 此接口为系统接口。 883 884| 名称 | 值 | 说明 | 885| ------- | ---- | -------------------- | 886| ALLOWED_LIST | 1 | 允许运行指定功能的列表。 | 887| DISALLOWED_LIST | 2 | 不允许运行指定功能的列表。 | 888