1# @ohos.bundle.appControl (appControl) (System API) 2 3The **appControl** module provides APIs for setting, obtaining, and deleting the disposed status of an application. An application in the disposed status is forbidden to run. When a user clicks the application icon on the home screen, the corresponding page is displayed based on the disposal intent. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13``` ts 14import appControl from '@ohos.bundle.appControl' 15``` 16 17## appControl.setDisposedStatus 18 19setDisposedStatus(appId: string, disposedWant: Want): Promise\<void> 20 21Sets the disposed status for an application. This API uses a promise to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 22 23**System API**: This is a system API. 24 25**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 26 27**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 28 29**Parameters** 30 31| Name | Type | Mandatory | Description | 32| ----------- | ------ | ---- | --------------------------------------- | 33| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 34| disposedWant | Want | Yes| Disposal intent of the application.| 35 36**Return value** 37 38| Type | Description | 39| ------------------------- | ------------------ | 40| Promise\<void> | Promise that returns no value.| 41 42**Error codes** 43 44For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 45 46| ID| Error Message | 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**Example** 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 82Sets the disposed status for an application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 83 84**System API**: This is a system API. 85 86**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 87 88**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 89 90**Parameters** 91 92| Name | Type | Mandatory | Description | 93| ----------- | ------------------------------- | ---- | --------------------------------------- | 94| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 95| disposedWant | Want | Yes| Disposal intent of the application.| 96| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.| 97 98**Error codes** 99 100For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 101 102| ID| Error Message | 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**Example** 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 139Sets the disposed status for an application. This API returns the result synchronously. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 140 141**System API**: This is a system API. 142 143**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 144 145**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 146 147 148**Parameters** 149 150| Name | Type | Mandatory | Description | 151| ----------- | ------------------------------- | ---- | --------------------------------------- | 152| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 153| disposedWant | Want | Yes| Disposal intent of the application.| 154 155**Error codes** 156 157For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 158 159| ID| Error Message | 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**Example** 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 189Obtains the disposed status of an application. This API uses a promise to return the result. If the operation is successful, the disposed status of the application is returned. If the operation fails, an error message is returned. 190 191**System API**: This is a system API. 192 193**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 194 195**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 196 197**Parameters** 198 199| Name | Type | Mandatory | Description | 200| ----------- | ------ | ---- | --------------------------------------- | 201| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 202 203**Return value** 204 205| Type | Description | 206| ------------------------- | ------------------ | 207| Promise\<Want> | Promise used to return the disposed status.| 208 209**Error codes** 210 211For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 212 213| ID| Error Message | 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**Example** 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 247Obtains the disposed status of an application. This API uses an asynchronous callback to return the result. If the operation is successful, the disposed status of the application is returned. If the operation fails, an error message is returned. 248 249**System API**: This is a system API. 250 251**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 252 253**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 254 255**Parameters** 256 257| Name | Type | Mandatory | Description | 258| ----------- | ------ | ---- | --------------------------------------- | 259| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 260| callback | AsyncCallback\<Want> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the disposed status obtained; otherwise, **err** is an error object. | 261 262**Error codes** 263 264For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 265 266| ID| Error Message | 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**Example** 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 301Obtains the disposed status of an application. This API returns the result synchronously. If the operation is successful, the disposed status of the application is returned. If the operation fails, an error message is returned. 302 303**System API**: This is a system API. 304 305**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 306 307**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 308 309**Parameters** 310 311| Name | Type | Mandatory | Description | 312| ----------- | ------ | ---- | --------------------------------------- | 313| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 314 315**Return value** 316 317| Type | Description | 318| ------------------------- | ------------------ | 319| Want | Disposed status.| 320 321**Error codes** 322 323For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 324 325| ID| Error Message | 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**Example** 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 355Deletes the disposed status for an application. This API uses a promise to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 356 357**System API**: This is a system API. 358 359**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 360 361**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 362 363**Parameters** 364 365| Name | Type | Mandatory | Description | 366| ----------- | ------ | ---- | --------------------------------------- | 367| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 368 369**Return value** 370 371| Type | Description | 372| ------------------------- | ------------------ | 373| Promise\<void> | Promise that returns no value.| 374 375**Error codes** 376 377For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 378 379| ID| Error Message | 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**Example** 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 413Deletes the disposed status for an application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 414 415**System API**: This is a system API. 416 417**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 418 419**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 420 421**Parameters** 422 423| Name | Type | Mandatory | Description | 424| ----------- | ------ | ---- | --------------------------------------- | 425| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 426| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object. | 427 428**Error codes** 429 430For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 431 432| ID| Error Message | 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**Example** 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 465Deletes the disposed status for an application. This API returns the result synchronously. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 466 467**System API**: This is a system API. 468 469**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 470 471**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 472 473**Parameters** 474 475| Name | Type | Mandatory | Description | 476| ----------- | ------ | ---- | --------------------------------------- | 477| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 478 479**Error codes** 480 481For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 482 483| ID| Error Message | 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**Example** 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 511Deletes the disposed status for an application or an application clone. This API returns the result synchronously. If the operation is successful, **null** is returned. If the operation fails, an error message is returned. 512 513**System API**: This is a system API. 514 515**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 516 517**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 518 519**Parameters** 520 521| Name | Type | Mandatory | Description | 522| ----------- | ------ | ---- | --------------------------------------- | 523| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 524| appIndex | number | No | Index of the application clone.<br>If this parameter is set to **0**, the API is used to delete the disposed status of the application. | 525 526**Error codes** 527 528For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 529 530| ID| Error Message | 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**Example** 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## Obtaining appId of an Application 556 557**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. It can be obtained by calling [getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo14). 558 559**Example** 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 586Obtains the disposed rule of an application. 587 588**System API**: This is a system API. 589 590**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 591 592**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 593 594**Parameters** 595 596| Name | Type | Mandatory | Description | 597| ----------- | ------ | ---- | --------------------------------------- | 598| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 599 600**Return value** 601 602| Type | Description | 603| ------------------------- | ------------------ | 604| [DisposedRule](#disposedrule11) | Disposed rule of the application.| 605 606**Error codes** 607 608For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 609 610| ID| Error Message | 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**Example** 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 640Obtains the disposed rule of an application or an application clone. 641 642**System API**: This is a system API. 643 644**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 645 646**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 647 648**Parameters** 649 650| Name | Type | Mandatory | Description | 651| ----------- | ------ | ---- | --------------------------------------- | 652| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 653| appIndex | number | No | Index of the application clone.<br>If this parameter is set to **0**, the API is used to obtain the disposed rule of an application, rather than an application clone. | 654 655**Return value** 656 657| Type | Description | 658| ------------------------- | ------------------ | 659| [DisposedRule](#disposedrule11) | Disposed rule of the application.| 660 661**Error codes** 662 663For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 664 665| ID| Error Message | 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**Example** 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 696Sets a disposed rule for an application. 697 698**System API**: This is a system API. 699 700**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 701 702**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 703 704**Parameters** 705 706| Name | Type | Mandatory | Description | 707| ----------- | ------ | ---- | --------------------------------------- | 708| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 709| rule | [DisposedRule](#disposedrule11) | Yes| Disposed rule to set.| 710 711**Error codes** 712 713For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 714 715| ID| Error Message | 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**Example** 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 765Sets the disposed rule for an application or an application clone. 766 767**System API**: This is a system API. 768 769**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS 770 771**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 772 773**Parameters** 774 775| Name | Type | Mandatory | Description | 776| ----------- | ------ | ---- | --------------------------------------- | 777| appId | string | Yes | ID of the target application.<br>**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). | 778| rule | [DisposedRule](#disposedrule11) | Yes| Disposed rule to set.| 779| appIndex | number | No | Index of the application clone.<br>If this parameter is set to **0**, the API is used to set the disposed rule for an application, rather than an application clone. | 780 781**Error codes** 782 783For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 784 785| ID| Error Message | 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**Example** 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 834Defines a disposed rule. 835 836**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 837 838**System API**: This is a system API. 839 840| Name | Type | Readable| Writable| Description | 841| --------- | -------------- | ---- | ---- | --------------------------- | 842| want | [Want](js-apis-app-ability-want.md) | Yes | Yes | Page displayed when the application is disposed of.| 843| componentType | [ComponentType](#componenttype11) | Yes | Yes | Type of application component that functions as the displayed page.| 844| disposedType | [DisposedType](#disposedrule11) | Yes| Yes| Type of application disposal.| 845| controlType | [ControlType](#controltype11) | Yes| Yes| Control type of application disposal.| 846| elementList | Array\<[ElementName](js-apis-bundleManager-elementName.md)> | Yes| Yes| List of application components to be disposed of or exempted.| 847| priority | number | Yes| Yes| Priority of the disposed rule.| 848 849### ComponentType<sup>11+</sup> 850 851Enumerates the types of application components that function as the displayed page. 852 853**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 854 855**System API**: This is a system API. 856 857| Name | Value | Description | 858| ------- | ---- | -------------------- | 859| UI_ABILITY | 1 | UIAbility component.| 860| UI_EXTENSION | 2 | UIExtensionAbility component.| 861 862### DisposedType<sup>11+</sup> 863 864Enumerates the types of application disposals. 865 866**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 867 868**System API**: This is a system API. 869 870| Name | Value | Description | 871| ------- | ---- | -------------------- | 872| BLOCK_APPLICATION | 1 | All abilities of the application are blocked. That is, the entire application is blocked.| 873| BLOCK_ABILITY | 2 | A specific ability of the application is blocked.| 874| NON_BLOCK | 3 | The application is not blocked.| 875 876### ControlType<sup>11+</sup> 877 878Enumerates the control type of application disposal. 879 880**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl 881 882**System API**: This is a system API. 883 884| Name | Value | Description | 885| ------- | ---- | -------------------- | 886| ALLOWED_LIST | 1 | A trustlist is used, which means that the application components in the list are allowed to run.| 887| DISALLOWED_LIST | 2 | A blocklist is used, which means that the application components in the list are forbidden to run.| 888