1# @ohos.update (Update) 2 3The **update** module applies to updates throughout the entire system, including built-in resources and preset applications, but not third-party applications. 4 5There are two types of updates: SD card update and over the air (OTA) update. 6 7- The SD card update depends on the update packages and SD cards. 8- The OTA update depends on the server deployed by the device manufacturer for managing update packages. The OTA server IP address is passed by the caller. The request interface is fixed and developed by the device manufacturer. 9 10> **NOTE** 11> 12> 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. 13> 14> The APIs provided by this module are system APIs. 15 16## Modules to Import 17 18```js 19import update from '@ohos.update' 20``` 21 22## update.getOnlineUpdater 23 24getOnlineUpdater(upgradeInfo: UpgradeInfo): Updater 25 26Obtains an **OnlineUpdater** object. 27 28**System capability**: SystemCapability.Update.UpdateService 29 30**Parameters** 31 32| Name | Type | Mandatory | Description | 33| ----------- | --------------------------- | ---- | ------ | 34| upgradeInfo | [UpgradeInfo](#upgradeinfo) | Yes | **UpgradeInfo** object.| 35 36**Return value** 37 38| Type | Description | 39| ------------------- | ---- | 40| [Updater](#updater) | **OnlineUpdater** object.| 41 42**Error codes** 43 44For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 45 46| ID | Error Message | 47| ------- | ---------------------------------------------------- | 48| 11500104 | BusinessError 11500104: IPC error. | 49 50**Example** 51 52```ts 53try { 54 const upgradeInfo = { 55 upgradeApp: "com.ohos.ota.updateclient", 56 businessType: { 57 vendor: update.BusinessVendor.PUBLIC, 58 subType: update.BusinessSubType.FIRMWARE 59 } 60 }; 61 let updater = update.getOnlineUpdater(upgradeInfo); 62} catch(error) { 63 console.error(`Fail to get updater error: ${error}`); 64} 65``` 66 67## update.getRestorer 68 69getRestorer(): Restorer 70 71Obtains a **Restorer** object for restoring factory settings. 72 73**System capability**: SystemCapability.Update.UpdateService 74 75 76**Return value** 77 78| Type | Description | 79| --------------------- | ------ | 80| [Restorer](#restorer) | **Restorer** object for restoring factory settings.| 81 82**Error codes** 83 84For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 85 86| ID | Error Message | 87| ------- | ---------------------------------------------------- | 88| 11500104 | BusinessError 11500104: IPC error. | 89 90**Example** 91 92```ts 93try { 94 let restorer = update.getRestorer(); 95} catch(error) { 96 console.error(`Fail to get restorer: ${error}`); 97} 98``` 99 100## update.getLocalUpdater 101 102getLocalUpdater(): LocalUpdater 103 104Obtains a **LocalUpdater** object. 105 106**System capability**: SystemCapability.Update.UpdateService 107 108**Return value** 109 110| Type | Description | 111| ----------------------------- | ------ | 112| [LocalUpdater](#localupdater) | **LocalUpdater** object.| 113 114**Error codes** 115 116For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 117 118| ID | Error Message | 119| ------- | ---------------------------------------------------- | 120| 11500104 | BusinessError 11500104: IPC error. | 121 122**Example** 123 124```ts 125try { 126 let localUpdater = update.getLocalUpdater(); 127} catch(error) { 128 console.error(`Fail to get localUpdater error: ${error}`); 129}; 130``` 131 132## Updater 133 134### checkNewVersion 135 136checkNewVersion(callback: AsyncCallback\<CheckResult>): void 137 138Checks whether a new version is available. This API uses an asynchronous callback to return the result. 139 140**System capability**: SystemCapability.Update.UpdateService 141 142**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 143 144**Parameters** 145 146| Name | Type | Mandatory | Description | 147| -------- | ---------------------------------------- | ---- | -------------- | 148| callback | AsyncCallback\<[CheckResult](#checkresult)> | Yes | Callback used to return the result.| 149 150**Error codes** 151 152For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 153 154| ID | Error Message | 155| ------- | ---------------------------------------------------- | 156| 11500104 | BusinessError 11500104: IPC error. | 157 158**Example** 159 160```ts 161updater.checkNewVersion((err, result) => { 162 console.log(`checkNewVersion isExistNewVersion ${result?.isExistNewVersion}`); 163}); 164``` 165 166### checkNewVersion 167 168checkNewVersion(): Promise\<CheckResult> 169 170Checks whether a new version is available. This API uses a promise to return the result. 171 172**System capability**: SystemCapability.Update.UpdateService 173 174**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 175 176**Return value** 177 178| Type | Description | 179| ------------------------------------- | ------------------- | 180| Promise\<[CheckResult](#checkresult)> | Promise used to return the result.| 181 182**Error codes** 183 184For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 185 186| ID | Error Message | 187| ------- | ---------------------------------------------------- | 188| 11500104 | BusinessError 11500104: IPC error. | 189 190**Example** 191 192```ts 193updater.checkNewVersion().then(result => { 194 console.log(`checkNewVersion isExistNewVersion: ${result.isExistNewVersion}`); 195 // Version digest information 196 console.log(`checkNewVersion versionDigestInfo: ${result.newVersionInfo.versionDigestInfo.versionDigest}`); 197}).catch(err => { 198 console.log(`checkNewVersion promise error ${JSON.stringify(err)}`); 199}); 200``` 201 202### getNewVersionInfo 203 204getNewVersionInfo(callback: AsyncCallback\<NewVersionInfo>): void 205 206Obtains information about the new version. This API uses an asynchronous callback to return the result. 207 208**System capability**: SystemCapability.Update.UpdateService 209 210**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 211 212**Parameters** 213 214| Name | Type | Mandatory | Description | 215| -------- | ---------------------------------------- | ---- | --------------- | 216| callback | AsyncCallback\<[NewVersionInfo](#newversioninfo)> | Yes | Callback used to return the result.| 217 218**Error codes** 219 220For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 221 222| ID | Error Message | 223| ------- | ---------------------------------------------------- | 224| 11500104 | BusinessError 11500104: IPC error. | 225 226**Example** 227 228```ts 229updater.getNewVersionInfo((err, info) => { 230 console.log(`info displayVersion = ${info?.versionComponents[0].displayVersion}`); 231 console.log(`info innerVersion = ${info?.versionComponents[0].innerVersion}`); 232}); 233``` 234 235### getNewVersionInfo 236 237getNewVersionInfo(): Promise\<NewVersionInfo> 238 239Obtains information about the new version. This API uses a promise to return the result. 240 241**System capability**: SystemCapability.Update.UpdateService 242 243**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 244 245**Return value** 246 247| Type | Description | 248| ---------------------------------------- | -------------------- | 249| Promise\<[NewVersionInfo](#newversioninfo)> | Promise used to return the result.| 250 251**Error codes** 252 253For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 254 255| ID | Error Message | 256| ------- | ---------------------------------------------------- | 257| 11500104 | BusinessError 11500104: IPC error. | 258 259**Example** 260 261```ts 262updater.getNewVersionInfo().then(info => { 263 console.log(`info displayVersion = ${info.versionComponents[0].displayVersion}`); 264 console.log(`info innerVersion = ${info.versionComponents[0].innerVersion}`); 265}).catch(err => { 266 console.log(`getNewVersionInfo promise error ${JSON.stringify(err)}`); 267}); 268``` 269 270### getNewVersionDescription 271 272getNewVersionDescription(versionDigestInfo: VersionDigestInfo, descriptionOptions: DescriptionOptions, callback: AsyncCallback\<Array\<ComponentDescription>>): void 273 274Obtains the description file of the new version. This API uses an asynchronous callback to return the result. 275 276**System capability**: SystemCapability.Update.UpdateService 277 278**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 279 280**Parameters** 281 282| Name | Type | Mandatory | Description | 283| ------------------ | ---------------------------------------- | ---- | -------------- | 284| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information. | 285| descriptionOptions | [DescriptionOptions](#descriptionoptions) | Yes | Options of the description file. | 286| callback | AsyncCallback\<Array\<[ComponentDescription](#componentdescription)>> | Yes | Callback used to return the result.| 287 288**Error codes** 289 290For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 291 292| ID | Error Message | 293| ------- | ---------------------------------------------------- | 294| 11500104 | BusinessError 11500104: IPC error. | 295 296**Example** 297 298```ts 299// Version digest information 300const versionDigestInfo = { 301 versionDigest: "versionDigest" // Version digest information in the check result 302}; 303 304// Options of the description file 305const descriptionOptions = { 306 format: update.DescriptionFormat.STANDARD, // Standard format 307 language: "zh-cn" // Chinese 308}; 309 310updater.getNewVersionDescription(versionDigestInfo, descriptionOptions, (err, info) => { 311 console.log(`getNewVersionDescription info ${JSON.stringify(info)}`); 312 console.log(`getNewVersionDescription err ${JSON.stringify(err)}`); 313}); 314``` 315 316### getNewVersionDescription 317 318getNewVersionDescription(versionDigestInfo: VersionDigestInfo, descriptionOptions: DescriptionOptions): Promise\<Array\<ComponentDescription>>; 319 320Obtains the description file of the new version. This API uses a promise to return the result. 321 322**System capability**: SystemCapability.Update.UpdateService 323 324**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 325 326**Parameters** 327 328| Name | Type | Mandatory | Description | 329| ------------------ | ---------------------------------------- | ---- | ------ | 330| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information.| 331| descriptionOptions | [DescriptionOptions](#descriptionoptions) | Yes | Options of the description file.| 332 333**Return value** 334 335| Type | Description | 336| ---------------------------------------- | ------------------- | 337| Promise\<Array\<[ComponentDescription](#componentdescription)>> | Promise used to return the result.| 338 339**Error codes** 340 341For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 342 343| ID | Error Message | 344| ------- | ---------------------------------------------------- | 345| 11500104 | BusinessError 11500104: IPC error. | 346 347**Example** 348 349```ts 350// Version digest information 351const versionDigestInfo = { 352 versionDigest: "versionDigest" // Version digest information in the check result 353}; 354 355// Options of the description file 356const descriptionOptions = { 357 format: update.DescriptionFormat.STANDARD, // Standard format 358 language: "zh-cn" // Chinese 359}; 360 361updater.getNewVersionDescription(versionDigestInfo, descriptionOptions).then(info => { 362 console.log(`getNewVersionDescription promise info ${JSON.stringify(info)}`); 363}).catch(err => { 364 console.log(`getNewVersionDescription promise error ${JSON.stringify(err)}`); 365}); 366``` 367 368### getCurrentVersionInfo 369 370getCurrentVersionInfo(callback: AsyncCallback\<CurrentVersionInfo>): void 371 372Obtains information about the current version. This API uses an asynchronous callback to return the result. 373 374**System capability**: SystemCapability.Update.UpdateService 375 376**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 377 378**Parameters** 379 380| Name | Type | Mandatory | Description | 381| -------- | ---------------------------------------- | ---- | ---------------- | 382| callback | AsyncCallback\<[CurrentVersionInfo](#currentversioninfo)> | Yes | Callback used to return the result.| 383 384**Error codes** 385 386For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 387 388| ID | Error Message | 389| ------- | ---------------------------------------------------- | 390| 11500104 | BusinessError 11500104: IPC error. | 391 392**Example** 393 394```ts 395updater.getCurrentVersionInfo((err, info) => { 396 console.log(`info osVersion = ${info?.osVersion}`); 397 console.log(`info deviceName = ${info?.deviceName}`); 398 console.log(`info displayVersion = ${info?.versionComponents[0].displayVersion}`); 399}); 400``` 401 402### getCurrentVersionInfo 403 404getCurrentVersionInfo(): Promise\<CurrentVersionInfo> 405 406Obtains information about the current version. This API uses a promise to return the result. 407 408**System capability**: SystemCapability.Update.UpdateService 409 410**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 411 412**Return value** 413 414| Type | Description | 415| ---------------------------------------- | ------------------- | 416| Promise\<[CurrentVersionInfo](#currentversioninfo)> | Promise used to return the result.| 417 418**Error codes** 419 420For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 421 422| ID | Error Message | 423| ------- | ---------------------------------------------------- | 424| 11500104 | BusinessError 11500104: IPC error. | 425 426**Example** 427 428```ts 429updater.getCurrentVersionInfo().then(info => { 430 console.log(`info osVersion = ${info.osVersion}`); 431 console.log(`info deviceName = ${info.deviceName}`); 432 console.log(`info displayVersion = ${info.versionComponents[0].displayVersion}`); 433}).catch(err => { 434 console.log(`getCurrentVersionInfo promise error ${JSON.stringify(err)}`); 435}); 436``` 437 438### getCurrentVersionDescription 439 440getCurrentVersionDescription(descriptionOptions: DescriptionOptions, callback: AsyncCallback\<Array\<ComponentDescription>>): void 441 442Obtains the description file of the current version. This API uses an asynchronous callback to return the result. 443 444**System capability**: SystemCapability.Update.UpdateService 445 446**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 447 448**Parameters** 449 450| Name | Type | Mandatory | Description | 451| ------------------ | ---------------------------------------- | ---- | --------------- | 452| descriptionOptions | [DescriptionOptions](#descriptionoptions) | Yes | Options of the description file. | 453| callback | AsyncCallback\<Array\<[ComponentDescription](#componentdescription)>> | Yes | Callback used to return the result.| 454 455**Error codes** 456 457For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 458 459| ID | Error Message | 460| ------- | ---------------------------------------------------- | 461| 11500104 | BusinessError 11500104: IPC error. | 462 463**Example** 464 465```ts 466// Options of the description file 467const descriptionOptions = { 468 format: update.DescriptionFormat.STANDARD, // Standard format 469 language: "zh-cn" // Chinese 470}; 471 472updater.getCurrentVersionDescription(descriptionOptions, (err, info) => { 473 console.log(`getCurrentVersionDescription info ${JSON.stringify(info)}`); 474 console.log(`getCurrentVersionDescription err ${JSON.stringify(err)}`); 475}); 476``` 477 478### getCurrentVersionDescription 479 480getCurrentVersionDescription(descriptionOptions: DescriptionOptions): Promise\<Array\<ComponentDescription>> 481 482Obtains the description file of the current version. This API uses a promise to return the result. 483 484**System capability**: SystemCapability.Update.UpdateService 485 486**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 487 488**Parameters** 489 490| Name | Type | Mandatory | Description | 491| ------------------ | ---------------------------------------- | ---- | ------ | 492| descriptionOptions | [DescriptionOptions](#descriptionoptions) | Yes | Options of the description file.| 493 494**Return value** 495 496| Type | Description | 497| ---------------------------------------- | -------------------- | 498| Promise\<Array\<[ComponentDescription](#componentdescription)>> | Promise used to return the result.| 499 500**Error codes** 501 502For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 503 504| ID | Error Message | 505| ------- | ---------------------------------------------------- | 506| 11500104 | BusinessError 11500104: IPC error. | 507 508**Example** 509 510```ts 511// Options of the description file 512const descriptionOptions = { 513 format: update.DescriptionFormat.STANDARD, // Standard format 514 language: "zh-cn" // Chinese 515}; 516 517updater.getCurrentVersionDescription(descriptionOptions).then(info => { 518 console.log(`getCurrentVersionDescription promise info ${JSON.stringify(info)}`); 519}).catch(err => { 520 console.log(`getCurrentVersionDescription promise error ${JSON.stringify(err)}`); 521}); 522``` 523 524### getTaskInfo 525 526getTaskInfo(callback: AsyncCallback\<TaskInfo>): void 527 528Obtains information about the update task. This API uses an asynchronous callback to return the result. 529 530**System capability**: SystemCapability.Update.UpdateService 531 532**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 533 534**Parameters** 535 536| Name | Type | Mandatory | Description | 537| -------- | ------------------------------------- | ---- | ---------------- | 538| callback | AsyncCallback\<[TaskInfo](#taskinfo)> | Yes | Callback used to return the result.| 539 540**Error codes** 541 542For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 543 544| ID | Error Message | 545| ------- | ---------------------------------------------------- | 546| 11500104 | BusinessError 11500104: IPC error. | 547 548**Example** 549 550```ts 551updater.getTaskInfo((err, info) => { 552 console.log(`getTaskInfo isexistTask= ${info?.existTask}`); 553}); 554``` 555 556### getTaskInfo 557 558getTaskInfo(): Promise\<TaskInfo> 559 560Obtains information about the update task. This API uses a promise to return the result. 561 562**System capability**: SystemCapability.Update.UpdateService 563 564**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 565 566**Return value** 567 568| Type | Description | 569| ------------------------------- | ------------------- | 570| Promise\<[TaskInfo](#taskinfo)> | Promise used to return the result.| 571 572**Error codes** 573 574For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 575 576| ID | Error Message | 577| ------- | ---------------------------------------------------- | 578| 11500104 | BusinessError 11500104: IPC error. | 579 580**Example** 581 582```ts 583updater.getTaskInfo().then(info => { 584 console.log(`getTaskInfo isexistTask= ${info.existTask}`); 585}).catch(err => { 586 console.log(`getTaskInfo promise error ${JSON.stringify(err)}`); 587}); 588``` 589 590### download 591 592download(versionDigestInfo: VersionDigestInfo, downloadOptions: DownloadOptions, callback: AsyncCallback\<void>): void 593 594Downloads the new version. This API uses an asynchronous callback to return the result. 595 596**System capability**: SystemCapability.Update.UpdateService 597 598**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 599 600**Parameters** 601 602| Name | Type | Mandatory | Description | 603| ----------------- | --------------------------------------- | ---- | ---------------------------------- | 604| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information. | 605| downloadOptions | [DownloadOptions](#downloadoptions) | Yes | Download options. | 606| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.| 607 608**Error codes** 609 610For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 611 612| ID | Error Message | 613| ------- | ---------------------------------------------------- | 614| 11500104 | BusinessError 11500104: IPC error. | 615 616**Example** 617 618```ts 619// Version digest information 620const versionDigestInfo = { 621 versionDigest: "versionDigest" // Version digest information in the check result 622}; 623 624// Download options 625const downloadOptions = { 626 allowNetwork: update.NetType.CELLULAR, // Whether to allow download over data network 627 order: update.Order.DOWNLOAD // Download 628}; 629updater.download(versionDigestInfo, downloadOptions, (err) => { 630 console.log(`download error ${JSON.stringify(err)}`); 631}); 632``` 633 634### download 635 636download(versionDigestInfo: VersionDigestInfo, downloadOptions: DownloadOptions): Promise\<void> 637 638Downloads the new version. This API uses a promise to return the result. 639 640**System capability**: SystemCapability.Update.UpdateService 641 642**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 643 644**Parameters** 645 646| Name | Type | Mandatory | Description | 647| ----------------- | --------------------------------------- | ---- | ------ | 648| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information.| 649| downloadOptions | [DownloadOptions](#downloadoptions) | Yes | Download options. | 650 651**Return value** 652 653| Type | Description | 654| -------------- | -------------------------- | 655| Promise\<void> | Promise that returns no value.| 656 657**Error codes** 658 659For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 660 661| ID | Error Message | 662| ------- | ---------------------------------------------------- | 663| 11500104 | BusinessError 11500104: IPC error. | 664 665**Example** 666 667```ts 668// Version digest information 669const versionDigestInfo = { 670 versionDigest: "versionDigest" // Version digest information in the check result 671}; 672 673// Download options 674const downloadOptions = { 675 allowNetwork: update.NetType.CELLULAR, // Whether to allow download over data network 676 order: update.Order.DOWNLOAD // Download 677}; 678updater.download(versionDigestInfo, downloadOptions).then(() => { 679 console.log(`download start`); 680}).catch(err => { 681 console.log(`download error ${JSON.stringify(err)}`); 682}); 683``` 684 685### resumeDownload 686 687resumeDownload(versionDigestInfo: VersionDigestInfo, resumeDownloadOptions: ResumeDownloadOptions, callback: AsyncCallback\<void>): void 688 689Resumes download of the new version. This API uses an asynchronous callback to return the result. 690 691**System capability**: SystemCapability.Update.UpdateService 692 693**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 694 695**Parameters** 696 697| Name | Type | Mandatory | Description | 698| --------------------- | ---------------------------------------- | ---- | ------------------------------------ | 699| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information. | 700| resumeDownloadOptions | [ResumeDownloadOptions](#resumedownloadoptions) | Yes | Options for resuming download. | 701| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.| 702 703**Error codes** 704 705For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 706 707| ID | Error Message | 708| ------- | ---------------------------------------------------- | 709| 11500104 | BusinessError 11500104: IPC error. | 710 711**Example** 712 713```ts 714// Version digest information 715const versionDigestInfo = { 716 versionDigest: "versionDigest" // Version digest information in the check result 717}; 718 719// Options for resuming download 720const resumeDownloadOptions = { 721 allowNetwork: update.NetType.CELLULAR, // Whether to allow download over data network 722}; 723updater.resumeDownload(versionDigestInfo, resumeDownloadOptions, (err) => { 724 console.log(`resumeDownload error ${JSON.stringify(err)}`); 725}); 726``` 727 728### resumeDownload 729 730resumeDownload(versionDigestInfo: VersionDigestInfo, resumeDownloadOptions: ResumeDownloadOptions): Promise\<void> 731 732Resumes download of the new version. This API uses a promise to return the result. 733 734**System capability**: SystemCapability.Update.UpdateService 735 736**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 737 738**Parameters** 739 740| Name | Type | Mandatory | Description | 741| --------------------- | ---------------------------------------- | ---- | ------ | 742| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information.| 743| resumeDownloadOptions | [ResumeDownloadOptions](#resumedownloadoptions) | Yes | Options for resuming download.| 744 745**Return value** 746 747| Type | Description | 748| -------------- | -------------------------- | 749| Promise\<void> | Promise that returns no value.| 750 751**Error codes** 752 753For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 754 755| ID | Error Message | 756| ------- | ---------------------------------------------------- | 757| 11500104 | BusinessError 11500104: IPC error. | 758 759**Example** 760 761```ts 762// Version digest information 763const versionDigestInfo = { 764 versionDigest: "versionDigest" // Version digest information in the check result 765}; 766 767// Options for resuming download 768const resumeDownloadOptions = { 769 allowNetwork: update.NetType.CELLULAR, // Whether to allow download over data network 770}; 771updater.resumeDownload(versionDigestInfo, resumeDownloadOptions).then(value => { 772 console.log(`resumeDownload start`); 773}).catch(err => { 774 console.log(`resumeDownload error ${JSON.stringify(err)}`); 775}); 776``` 777 778### pauseDownload 779 780pauseDownload(versionDigestInfo: VersionDigestInfo, pauseDownloadOptions: PauseDownloadOptions, callback: AsyncCallback\<void>): void 781 782Pauses download of the new version. This API uses an asynchronous callback to return the result. 783 784**System capability**: SystemCapability.Update.UpdateService 785 786**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 787 788**Parameters** 789 790| Name | Type | Mandatory | Description | 791| -------------------- | ---------------------------------------- | ---- | ------------------------------------ | 792| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information. | 793| pauseDownloadOptions | [PauseDownloadOptions](#pausedownloadoptions) | Yes | Options for pausing download. | 794| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.| 795 796**Error codes** 797 798For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 799 800| ID | Error Message | 801| ------- | ---------------------------------------------------- | 802| 11500104 | BusinessError 11500104: IPC error. | 803 804**Example** 805 806```ts 807// Version digest information 808const versionDigestInfo = { 809 versionDigest: "versionDigest" // Version digest information in the check result 810}; 811 812// Options for pausing download 813const pauseDownloadOptions = { 814 isAllowAutoResume: true // Whether to allow automatic resuming of download 815}; 816updater.pauseDownload(versionDigestInfo, pauseDownloadOptions, (err) => { 817 console.log(`pauseDownload error ${JSON.stringify(err)}`); 818}); 819``` 820 821### pauseDownload 822 823pauseDownload(versionDigestInfo: VersionDigestInfo, pauseDownloadOptions: PauseDownloadOptions): Promise\<void> 824 825Resumes download of the new version. This API uses a promise to return the result. 826 827**System capability**: SystemCapability.Update.UpdateService 828 829**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 830 831**Parameters** 832 833| Name | Type | Mandatory | Description | 834| -------------------- | ---------------------------------------- | ---- | ------ | 835| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information.| 836| pauseDownloadOptions | [PauseDownloadOptions](#pausedownloadoptions) | Yes | Options for pausing download.| 837 838**Return value** 839 840| Type | Description | 841| -------------- | -------------------------- | 842| Promise\<void> | Promise that returns no value.| 843 844**Error codes** 845 846For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 847 848| ID | Error Message | 849| ------- | ---------------------------------------------------- | 850| 11500104 | BusinessError 11500104: IPC error. | 851 852**Example** 853 854```ts 855// Version digest information 856const versionDigestInfo = { 857 versionDigest: "versionDigest" // Version digest information in the check result 858}; 859 860// Options for pausing download 861const pauseDownloadOptions = { 862 isAllowAutoResume: true // Whether to allow automatic resuming of download 863}; 864updater.pauseDownload(versionDigestInfo, pauseDownloadOptions).then(value => { 865 console.log(`pauseDownload`); 866}).catch(err => { 867 console.log(`pauseDownload error ${JSON.stringify(err)}`); 868}); 869``` 870 871### upgrade 872 873upgrade(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions, callback: AsyncCallback\<void>): void 874 875Updates the version. This API uses an asynchronous callback to return the result. 876 877**System capability**: SystemCapability.Update.UpdateService 878 879**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 880 881**Parameters** 882 883| Name | Type | Mandatory | Description | 884| ----------------- | --------------------------------------- | ---- | ------------------------------------ | 885| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information. | 886| upgradeOptions | [UpgradeOptions](#upgradeoptions) | Yes | Update options. | 887| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.| 888 889**Error codes** 890 891For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 892 893| ID | Error Message | 894| ------- | ---------------------------------------------------- | 895| 11500104 | BusinessError 11500104: IPC error. | 896 897**Example** 898 899```ts 900// Version digest information 901const versionDigestInfo = { 902 versionDigest: "versionDigest" // Version digest information in the check result 903}; 904 905// Installation options 906const upgradeOptions = { 907 order: update.Order.INSTALL // Installation command 908}; 909updater.upgrade(versionDigestInfo, upgradeOptions, (err) => { 910 console.log(`upgrade error ${JSON.stringify(err)}`); 911}); 912``` 913 914### upgrade 915 916upgrade(versionDigestInfo: VersionDigestInfo, upgradeOptions: UpgradeOptions): Promise\<void> 917 918Updates the version. This API uses a promise to return the result. 919 920**System capability**: SystemCapability.Update.UpdateService 921 922**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 923 924**Parameters** 925 926| Name | Type | Mandatory | Description | 927| ----------------- | --------------------------------------- | ---- | ------ | 928| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information.| 929| upgradeOptions | [UpgradeOptions](#upgradeoptions) | Yes | Update options. | 930 931**Return value** 932 933| Type | Description | 934| -------------- | -------------------------- | 935| Promise\<void> | Promise that returns no value.| 936 937**Error codes** 938 939For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 940 941| ID | Error Message | 942| ------- | ---------------------------------------------------- | 943| 11500104 | BusinessError 11500104: IPC error. | 944 945**Example** 946 947```ts 948// Version digest information 949const versionDigestInfo = { 950 versionDigest: "versionDigest" // Version digest information in the check result 951}; 952 953// Installation options 954const upgradeOptions = { 955 order: update.Order.INSTALL // Installation command 956}; 957updater.upgrade(versionDigestInfo, upgradeOptions).then(() => { 958 console.log(`upgrade start`); 959}).catch(err => { 960 console.log(`upgrade error ${JSON.stringify(err)}`); 961}); 962``` 963 964### clearError 965 966clearError(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions, callback: AsyncCallback\<void>): void 967 968Clears errors. This API uses an asynchronous callback to return the result. 969 970**System capability**: SystemCapability.Update.UpdateService 971 972**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 973 974**Parameters** 975 976| Name | Type | Mandatory | Description | 977| ----------------- | --------------------------------------- | ---- | ------------------------------------ | 978| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information. | 979| clearOptions | [ClearOptions](#clearoptions) | Yes | Clear options. | 980| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.| 981 982**Error codes** 983 984For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 985 986| ID | Error Message | 987| ------- | ---------------------------------------------------- | 988| 11500104 | BusinessError 11500104: IPC error. | 989 990**Example** 991 992```ts 993// Version digest information 994const versionDigestInfo = { 995 versionDigest: "versionDigest" // Version digest information in the check result 996}; 997 998// Options for clearing errors 999const clearOptions = { 1000 status: update.UpgradeStatus.UPGRADE_FAIL, 1001}; 1002updater.clearError(versionDigestInfo, clearOptions, (err) => { 1003 console.log(`clearError error ${JSON.stringify(err)}`); 1004}); 1005``` 1006 1007### clearError 1008 1009clearError(versionDigestInfo: VersionDigestInfo, clearOptions: ClearOptions): Promise\<void> 1010 1011Clears errors. This API uses a promise to return the result. 1012 1013**System capability**: SystemCapability.Update.UpdateService 1014 1015**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1016 1017**Parameters** 1018 1019| Name | Type | Mandatory | Description | 1020| ----------------- | --------------------------------------- | ---- | ------ | 1021| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information.| 1022| clearOptions | [ClearOptions](#clearoptions) | Yes | Update options. | 1023 1024**Return value** 1025 1026| Type | Description | 1027| -------------- | -------------------------- | 1028| Promise\<void> | Promise that returns no value.| 1029 1030**Error codes** 1031 1032For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1033 1034| ID | Error Message | 1035| ------- | ---------------------------------------------------- | 1036| 11500104 | BusinessError 11500104: IPC error. | 1037 1038**Example** 1039 1040```ts 1041// Version digest information 1042const versionDigestInfo = { 1043 versionDigest: "versionDigest" // Version digest information in the check result 1044}; 1045 1046// Options for clearing errors 1047const clearOptions = { 1048 status: update.UpgradeStatus.UPGRADE_FAIL, 1049}; 1050updater.clearError(versionDigestInfo, clearOptions).then(() => { 1051 console.log(`clearError success`); 1052}).catch(err => { 1053 console.log(`clearError error ${JSON.stringify(err)}`); 1054}); 1055``` 1056 1057### getUpgradePolicy 1058 1059getUpgradePolicy(callback: AsyncCallback\<UpgradePolicy>): void 1060 1061Obtains the update policy. This API uses an asynchronous callback to return the result. 1062 1063**System capability**: SystemCapability.Update.UpdateService 1064 1065**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1066 1067**Parameters** 1068 1069| Name | Type | Mandatory | Description | 1070| -------- | ---------------------------------------- | ---- | --------------- | 1071| callback | AsyncCallback\<[UpgradePolicy](#upgradepolicy)> | Yes | Callback used to return the result.| 1072 1073**Error codes** 1074 1075For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1076 1077| ID | Error Message | 1078| ------- | ---------------------------------------------------- | 1079| 11500104 | BusinessError 11500104: IPC error. | 1080 1081**Example** 1082 1083```ts 1084updater.getUpgradePolicy((err, policy) => { 1085 console.log(`policy downloadStrategy = ${policy?.downloadStrategy}`); 1086 console.log(`policy autoUpgradeStrategy = ${policy?.autoUpgradeStrategy}`); 1087}); 1088``` 1089 1090### getUpgradePolicy 1091 1092getUpgradePolicy(): Promise\<UpgradePolicy> 1093 1094Obtains the update policy. This API uses a promise to return the result. 1095 1096**System capability**: SystemCapability.Update.UpdateService 1097 1098**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1099 1100**Return value** 1101 1102| Type | Description | 1103| ---------------------------------------- | --------------------- | 1104| Promise\<[UpgradePolicy](#upgradepolicy)> | Promise used to return the result.| 1105 1106**Error codes** 1107 1108For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1109 1110| ID | Error Message | 1111| ------- | ---------------------------------------------------- | 1112| 11500104 | BusinessError 11500104: IPC error. | 1113 1114**Example** 1115 1116```ts 1117updater.getUpgradePolicy().then(policy => { 1118 console.log(`policy downloadStrategy = ${policy.downloadStrategy}`); 1119 console.log(`policy autoUpgradeStrategy = ${policy.autoUpgradeStrategy}`); 1120}).catch(err => { 1121 console.log(`getUpgradePolicy promise error ${JSON.stringify(err)}`); 1122}); 1123``` 1124 1125### setUpgradePolicy 1126 1127setUpgradePolicy(policy: UpgradePolicy, callback: AsyncCallback\<void>): void 1128 1129Sets the update policy. This API uses an asynchronous callback to return the result. 1130 1131**System capability**: SystemCapability.Update.UpdateService 1132 1133**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1134 1135**Parameters** 1136 1137| Name | Type | Mandatory | Description | 1138| -------- | ------------------------------- | ---- | ------------- | 1139| policy | [UpgradePolicy](#upgradepolicy) | Yes | Update policy. | 1140| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 1141 1142**Error codes** 1143 1144For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1145 1146| ID | Error Message | 1147| ------- | ---------------------------------------------------- | 1148| 11500104 | BusinessError 11500104: IPC error. | 1149 1150**Example** 1151 1152```ts 1153const policy = { 1154 downloadStrategy: false, 1155 autoUpgradeStrategy: false, 1156 autoUpgradePeriods: [ { start: 120, end: 240 } ] // Automatic update period, in minutes 1157}; 1158updater.setUpgradePolicy(policy, (err) => { 1159 console.log(`setUpgradePolicy result: ${err}`); 1160}); 1161``` 1162 1163### setUpgradePolicy 1164 1165setUpgradePolicy(policy: UpgradePolicy): Promise\<void> 1166 1167Sets the update policy. This API uses a promise to return the result. 1168 1169**System capability**: SystemCapability.Update.UpdateService 1170 1171**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1172 1173**Parameters** 1174 1175| Name | Type | Mandatory | Description | 1176| ------ | ------------------------------- | ---- | ---- | 1177| policy | [UpgradePolicy](#upgradepolicy) | Yes | Update policy.| 1178 1179**Return value** 1180 1181| Type | Description | 1182| -------------- | ------------------- | 1183| Promise\<void> | Promise used to return the result.| 1184 1185**Error codes** 1186 1187For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1188 1189| ID | Error Message | 1190| ------- | ---------------------------------------------------- | 1191| 11500104 | BusinessError 11500104: IPC error. | 1192 1193**Example** 1194 1195```ts 1196const policy = { 1197 downloadStrategy: false, 1198 autoUpgradeStrategy: false, 1199 autoUpgradePeriods: [ { start: 120, end: 240 } ] // Automatic update period, in minutes 1200}; 1201updater.setUpgradePolicy(policy).then(() => { 1202 console.log(`setUpgradePolicy success`); 1203}).catch(err => { 1204 console.log(`setUpgradePolicy promise error ${JSON.stringify(err)}`); 1205}); 1206``` 1207 1208### terminateUpgrade 1209 1210terminateUpgrade(callback: AsyncCallback\<void>): void 1211 1212Terminates the update. This API uses an asynchronous callback to return the result. 1213 1214**System capability**: SystemCapability.Update.UpdateService 1215 1216**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1217 1218**Parameters** 1219 1220| Name | Type | Mandatory | Description | 1221| -------- | -------------------- | ---- | -------------------------------------- | 1222| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.| 1223 1224**Error codes** 1225 1226For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1227 1228| ID | Error Message | 1229| ------- | ---------------------------------------------------- | 1230| 11500104 | BusinessError 11500104: IPC error. | 1231 1232**Example** 1233 1234```ts 1235updater.terminateUpgrade((err) => { 1236 console.log(`terminateUpgrade error ${JSON.stringify(err)}`); 1237}); 1238``` 1239 1240### terminateUpgrade 1241 1242terminateUpgrade(): Promise\<void> 1243 1244Terminates the update. This API uses a promise to return the result. 1245 1246**System capability**: SystemCapability.Update.UpdateService 1247 1248**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1249 1250**Return value** 1251 1252| Type | Description | 1253| -------------- | -------------------------- | 1254| Promise\<void> | Promise that returns no value.| 1255 1256**Error codes** 1257 1258For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1259 1260| ID | Error Message | 1261| ------- | ---------------------------------------------------- | 1262| 11500104 | BusinessError 11500104: IPC error. | 1263 1264**Example** 1265 1266```ts 1267updater.terminateUpgrade().then(() => { 1268 console.log(`terminateUpgrade success`); 1269}).catch(err => { 1270 console.log(`terminateUpgrade error ${JSON.stringify(err)}`); 1271}); 1272``` 1273 1274 1275### on 1276on(eventClassifyInfo: EventClassifyInfo, taskCallback: UpgradeTaskCallback): void 1277 1278Enables listening for update events. This API uses an asynchronous callback to return the result. 1279 1280**System capability**: SystemCapability.Update.UpdateService 1281 1282**Parameters** 1283 1284| Name | Type | Mandatory | Description | 1285| ----------------- | ---------------------------------------- | ---- | ---- | 1286| eventClassifyInfo | [EventClassifyInfo](#eventclassifyinfo) | Yes | Event information.| 1287| taskCallback | [UpgradeTaskCallback](#upgradetaskcallback) | Yes | Event callback.| 1288 1289**Error codes** 1290 1291For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1292 1293| ID | Error Message | 1294| ------- | ---------------------------------------------------- | 1295| 11500104 | BusinessError 11500104: IPC error. | 1296 1297**Example** 1298 1299```ts 1300const eventClassifyInfo = { 1301 eventClassify: update.EventClassify.TASK, // Listening for update events 1302 extraInfo: "" 1303}; 1304 1305updater.on(eventClassifyInfo, (eventInfo) => { 1306 console.log("updater on " + JSON.stringify(eventInfo)); 1307}); 1308``` 1309 1310### off 1311off(eventClassifyInfo: EventClassifyInfo, taskCallback?: UpgradeTaskCallback): void 1312 1313Disables listening for update events. This API uses an asynchronous callback to return the result. 1314 1315**System capability**: SystemCapability.Update.UpdateService 1316 1317**Parameters** 1318 1319| Name | Type | Mandatory | Description | 1320| ----------------- | ---------------------------------------- | ---- | ---- | 1321| eventClassifyInfo | [EventClassifyInfo](#eventclassifyinfo) | Yes | Event information.| 1322| taskCallback | [UpgradeTaskCallback](#upgradetaskcallback) | No | Event callback.| 1323 1324**Error codes** 1325 1326For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1327 1328| ID | Error Message | 1329| ------- | ---------------------------------------------------- | 1330| 11500104 | BusinessError 11500104: IPC error. | 1331 1332**Example** 1333 1334```ts 1335const eventClassifyInfo = { 1336 eventClassify: update.EventClassify.TASK, // Listening for update events 1337 extraInfo: "" 1338}; 1339 1340updater.off(eventClassifyInfo, (eventInfo) => { 1341 console.log("updater off " + JSON.stringify(eventInfo)); 1342}); 1343``` 1344 1345## Restorer 1346 1347### factoryReset 1348 1349factoryReset(callback: AsyncCallback\<void>): void 1350 1351Restores the scale to its factory settings. This API uses an asynchronous callback to return the result. 1352 1353**System capability**: SystemCapability.Update.UpdateService 1354 1355**Required permission**: ohos.permission.FACTORY_RESET (a system permission) 1356 1357**Parameters** 1358 1359| Name | Type | Mandatory | Description | 1360| -------- | -------------------- | ---- | -------------------------------------- | 1361| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.| 1362 1363**Error codes** 1364 1365For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1366 1367| ID | Error Message | 1368| ------- | ---------------------------------------------------- | 1369| 11500104 | BusinessError 11500104: IPC error. | 1370 1371**Example** 1372 1373```ts 1374restorer.factoryReset((err) => { 1375 console.log(`factoryReset error ${JSON.stringify(err)}`); 1376}); 1377``` 1378 1379### factoryReset 1380 1381factoryReset(): Promise\<void> 1382 1383Restores the scale to its factory settings. This API uses a promise to return the result. 1384 1385**System capability**: SystemCapability.Update.UpdateService 1386 1387**Required permission**: ohos.permission.FACTORY_RESET (a system permission) 1388 1389**Return value** 1390 1391| Type | Description | 1392| -------------- | -------------------------- | 1393| Promise\<void> | Promise that returns no value.| 1394 1395**Error codes** 1396 1397For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1398 1399| ID | Error Message | 1400| ------- | ---------------------------------------------------- | 1401| 11500104 | BusinessError 11500104: IPC error. | 1402 1403**Example** 1404 1405```ts 1406restorer.factoryReset().then(() => { 1407 console.log(`factoryReset success`); 1408}).catch(err => { 1409 console.log(`factoryReset error ${JSON.stringify(err)}`); 1410}); 1411``` 1412 1413## LocalUpdater 1414 1415### verifyUpgradePackage 1416 1417verifyUpgradePackage(upgradeFile: UpgradeFile, certsFile: string, callback: AsyncCallback\<void>): void 1418 1419Verifies the update package. This API uses an asynchronous callback to return the result. 1420 1421**System capability**: SystemCapability.Update.UpdateService 1422 1423**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1424 1425**Parameters** 1426 1427| Name | Type | Mandatory | Description | 1428| ----------- | --------------------------- | ---- | ---------------- | 1429| upgradeFile | [UpgradeFile](#upgradefile) | Yes | Update file. | 1430| certsFile | string | Yes | Path of the certificate file. | 1431| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 1432 1433**Error codes** 1434 1435For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1436 1437| ID | Error Message | 1438| ------- | ---------------------------------------------------- | 1439| 11500104 | BusinessError 11500104: IPC error. | 1440 1441**Example** 1442 1443```ts 1444const upgradeFile = { 1445 fileType: update.ComponentType.OTA, // OTA package 1446 filePath: "path" // Path of the local update package 1447}; 1448 1449localUpdater.verifyUpgradePackage(upgradeFile, "cerstFilePath", (err) => { 1450 console.log(`factoryReset error ${JSON.stringify(err)}`); 1451}); 1452``` 1453 1454### verifyUpgradePackage 1455 1456verifyUpgradePackage(upgradeFile: UpgradeFile, certsFile: string): Promise\<void> 1457 1458Verifies the update package. This API uses a promise to return the result. 1459 1460**System capability**: SystemCapability.Update.UpdateService 1461 1462**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1463 1464**Parameters** 1465 1466| Name | Type | Mandatory | Description | 1467| ----------- | --------------------------- | ---- | ------ | 1468| upgradeFile | [UpgradeFile](#upgradefile) | Yes | Update file. | 1469| certsFile | string | Yes | Path of the certificate file.| 1470 1471**Return value** 1472 1473| Type | Description | 1474| -------------- | ---------------------- | 1475| Promise\<void> | Promise used to return the result.| 1476 1477**Error codes** 1478 1479For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1480 1481| ID | Error Message | 1482| ------- | ---------------------------------------------------- | 1483| 11500104 | BusinessError 11500104: IPC error. | 1484 1485**Example** 1486 1487```ts 1488const upgradeFile = { 1489 fileType: update.ComponentType.OTA, // OTA package 1490 filePath: "path" // Path of the local update package 1491}; 1492localUpdater.verifyUpgradePackage(upgradeFile, "cerstFilePath").then(() => { 1493 console.log(`verifyUpgradePackage success`); 1494}).catch(err => { 1495 console.log(`verifyUpgradePackage error ${JSON.stringify(err)}`); 1496}); 1497``` 1498 1499### applyNewVersion 1500applyNewVersion(upgradeFiles: Array<[UpgradeFile](#upgradefile)>, callback: AsyncCallback\<void>): void 1501 1502Installs the update package. This API uses an asynchronous callback to return the result. 1503 1504**System capability**: SystemCapability.Update.UpdateService 1505 1506**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1507 1508**Parameters** 1509 1510| Name | Type | Mandatory | Description | 1511| ----------- | ---------------------------------- | ---- | --------------------------------------- | 1512| upgradeFile | Array<[UpgradeFile](#upgradefile)> | Yes | Update file. | 1513| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, `err` is `undefined`; otherwise, `err` is an `Error` object.| 1514 1515**Error codes** 1516 1517For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1518 1519| ID | Error Message | 1520| ------- | ---------------------------------------------------- | 1521| 11500104 | BusinessError 11500104: IPC error. | 1522 1523**Example** 1524 1525```ts 1526const upgradeFiles = [{ 1527 fileType: update.ComponentType.OTA, // OTA package 1528 filePath: "path" // Path of the local update package 1529}]; 1530 1531localUpdater.applyNewVersion(upgradeFiles, (err) => { 1532 console.log(`applyNewVersion error ${JSON.stringify(err)}`); 1533}); 1534``` 1535 1536### applyNewVersion 1537 1538applyNewVersion(upgradeFiles: Array<[UpgradeFile](#upgradefile)>): Promise\<void> 1539 1540Installs the update package. This API uses a promise to return the result. 1541 1542**System capability**: SystemCapability.Update.UpdateService 1543 1544**Required permission**: ohos.permission.UPDATE_SYSTEM (a system permission) 1545 1546**Return value** 1547 1548| Type | Description | 1549| -------------- | -------------------------- | 1550| Promise\<void> | Promise that returns no value.| 1551 1552**Error codes** 1553 1554For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1555 1556| ID | Error Message | 1557| ------- | ---------------------------------------------------- | 1558| 11500104 | BusinessError 11500104: IPC error. | 1559 1560**Example** 1561 1562```ts 1563const upgradeFiles = [{ 1564 fileType: update.ComponentType.OTA, // OTA package 1565 filePath: "path" // Path of the local update package 1566}]; 1567localUpdater.applyNewVersion(upgradeFiles).then(() => { 1568 console.log(`applyNewVersion success`); 1569}).catch(err => { 1570 console.log(`applyNewVersion error ${JSON.stringify(err)}`); 1571}); 1572``` 1573 1574### on 1575on(eventClassifyInfo: EventClassifyInfo, taskCallback: UpgradeTaskCallback): void 1576 1577Enables listening for update events. This API uses an asynchronous callback to return the result. 1578 1579**System capability**: SystemCapability.Update.UpdateService 1580 1581**Parameters** 1582 1583| Name | Type | Mandatory | Description | 1584| ----------------- | ---------------------------------------- | ---- | ---- | 1585| eventClassifyInfo | [EventClassifyInfo](#eventclassifyinfo) | Yes | Event information.| 1586| taskCallback | [UpgradeTaskCallback](#upgradetaskcallback) | Yes | Event callback.| 1587 1588**Error codes** 1589 1590For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1591 1592| ID | Error Message | 1593| ------- | ---------------------------------------------------- | 1594| 11500104 | BusinessError 11500104: IPC error. | 1595 1596**Example** 1597 1598```ts 1599const eventClassifyInfo = { 1600 eventClassify: update.EventClassify.TASK, // Listening for update events 1601 extraInfo: "" 1602}; 1603 1604function onTaskUpdate(eventInfo) { 1605 console.log(`on eventInfo id `, eventInfo.eventId); 1606} 1607 1608localUpdater.on(eventClassifyInfo, onTaskUpdate); 1609``` 1610 1611### off 1612off(eventClassifyInfo: EventClassifyInfo, taskCallback?: UpgradeTaskCallback): void 1613 1614Disables listening for update events. This API uses an asynchronous callback to return the result. 1615 1616**System capability**: SystemCapability.Update.UpdateService 1617 1618**Parameters** 1619 1620| Name | Type | Mandatory | Description | 1621| ----------------- | ---------------------------------------- | ---- | ---- | 1622| eventClassifyInfo | [EventClassifyInfo](#eventclassifyinfo) | Yes | Event information.| 1623| taskCallback | [UpgradeTaskCallback](#upgradetaskcallback) | No | Event callback.| 1624 1625**Error codes** 1626 1627For details about the error codes, see [Update Error Codes](../errorcodes/errorcode-update.md). 1628 1629| ID | Error Message | 1630| ------- | ---------------------------------------------------- | 1631| 11500104 | BusinessError 11500104: IPC error. | 1632 1633**Example** 1634 1635```ts 1636const eventClassifyInfo = { 1637 eventClassify: update.EventClassify.TASK, // Listening for update events 1638 extraInfo: "" 1639}; 1640 1641function onTaskUpdate(eventInfo) { 1642 console.log(`on eventInfo id `, eventInfo.eventId); 1643} 1644 1645localUpdater.off(eventClassifyInfo, onTaskUpdate); 1646``` 1647 1648## UpgradeInfo 1649 1650Represents update information. 1651 1652**System capability**: SystemCapability.Update.UpdateService 1653 1654| Name | Type | Mandatory | Description | 1655| ------------ | ----------------------------- | ---- | ------ | 1656| upgradeApp | string | Yes | Application package name. | 1657| businessType | [BusinessType](#businesstype) | Yes | Update service type.| 1658 1659## BusinessType 1660 1661Enumerates update service types. 1662 1663**System capability**: SystemCapability.Update.UpdateService 1664 1665| Name | Type | Mandatory | Description | 1666| ------- | ----------------------------------- | ---- | ---- | 1667| vendor | [BusinessVendor](#businessvendor) | Yes | Application vendor. | 1668| subType | [BusinessSubType](#businesssubtype) | Yes | Update service type. | 1669 1670## CheckResult 1671 1672Represents the package check result. 1673 1674**System capability**: SystemCapability.Update.UpdateService 1675 1676| Name | Type | Mandatory | Description | 1677| ----------------- | --------------------------------- | ---- | ------ | 1678| isExistNewVersion | bool | Yes | Whether a new version is available.| 1679| newVersionInfo | [NewVersionInfo](#newversioninfo) | No | Information about the new version. | 1680 1681## NewVersionInfo 1682 1683Represents information about the new version. 1684 1685**System capability**: SystemCapability.Update.UpdateService 1686 1687| Name | Type | Mandatory | Description | 1688| ----------------- | ---------------------------------------- | ---- | ---- | 1689| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information.| 1690| versionComponents | Array\<[VersionComponent](#versioncomponent)> | Yes | Version components.| 1691 1692## VersionDigestInfo 1693 1694Represents version digest information. 1695 1696**System capability**: SystemCapability.Update.UpdateService 1697 1698| Name | Type | Mandatory | Description | 1699| ------------- | ------ | ---- | ---- | 1700| versionDigest | string | Yes | Version digest information.| 1701 1702## VersionComponent 1703 1704Represents a version component. 1705 1706**System capability**: SystemCapability.Update.UpdateService 1707 1708| Name | Type | Mandatory | Description | 1709| --------------- | ----------------------------------- | ---- | -------- | 1710| componentId | string | Yes | Component ID. | 1711| componentType | [ComponentType](#componenttype) | Yes | Component type. | 1712| upgradeAction | [UpgradeAction](#upgradeaction) | Yes | Update mode. | 1713| displayVersion | string | Yes | Display version number. | 1714| innerVersion | string | Yes | Internal version number. | 1715| size | number | Yes | Update package size. | 1716| effectiveMode | [EffectiveMode](#effectivemode) | Yes | Effective mode. | 1717| descriptionInfo | [DescriptionInfo](#descriptioninfo) | Yes | Information about the version description file.| 1718 1719## DescriptionOptions 1720 1721Represents options of the description file. 1722 1723**System capability**: SystemCapability.Update.UpdateService 1724 1725| Name | Type | Mandatory | Description | 1726| -------- | --------------------------------------- | ---- | ------ | 1727| format | [DescriptionFormat](#descriptionformat) | Yes | Format of the description file.| 1728| language | string | Yes | Language of the description file.| 1729 1730## ComponentDescription 1731 1732Represents a component description file. 1733 1734**System capability**: SystemCapability.Update.UpdateService 1735 1736| Name | Type | Mandatory | Description | 1737| --------------- | ----------------------------------- | ---- | ------ | 1738| componentId | string | Yes | Component ID. | 1739| descriptionInfo | [DescriptionInfo](#descriptioninfo) | Yes | Information about the description file.| 1740 1741## DescriptionInfo 1742 1743Represents information about the version description file. 1744 1745**System capability**: SystemCapability.Update.UpdateService 1746 1747| Name | Type | Mandatory | Description | 1748| --------------- | ----------------------------------- | ---- | ------ | 1749| descriptionType | [DescriptionType](#descriptiontype) | Yes | Type of the description file.| 1750| content | string | Yes | Content of the description file.| 1751 1752## CurrentVersionInfo 1753 1754Represents information about the current version. 1755 1756**System capability**: SystemCapability.Update.UpdateService 1757 1758| Name | Type | Mandatory | Description | 1759| ----------------- | ---------------------------------------- | ---- | ----- | 1760| osVersion | string | Yes | System version number.| 1761| deviceName | string | Yes | Device name. | 1762| versionComponents | Array\<[VersionComponent](#versioncomponent)> | No | Version components. | 1763 1764## DownloadOptions 1765 1766Represents download options. 1767 1768**System capability**: SystemCapability.Update.UpdateService 1769 1770| Name | Type | Mandatory | Description | 1771| ------------ | ------------------- | ---- | ---- | 1772| allowNetwork | [NetType](#nettype) | Yes | Network type.| 1773| order | [Order](#order) | Yes | Update command.| 1774 1775## ResumeDownloadOptions 1776 1777Represents options for resuming download. 1778 1779**System capability**: SystemCapability.Update.UpdateService 1780 1781| Name | Type | Mandatory | Description | 1782| ------------ | ------------------- | ---- | ---- | 1783| allowNetwork | [NetType](#nettype) | Yes | Network type.| 1784 1785## PauseDownloadOptions 1786 1787Represents options for pausing download. 1788 1789**System capability**: SystemCapability.Update.UpdateService 1790 1791| Name | Type| Mandatory | Description | 1792| ----------------- | ---- | ---- | -------- | 1793| isAllowAutoResume | bool | Yes | Whether to allow automatic resuming of download.| 1794 1795## UpgradeOptions 1796 1797Represents update options. 1798 1799**System capability**: SystemCapability.Update.UpdateService 1800 1801| Name | Type | Mandatory | Description | 1802| ----- | --------------- | ---- | ---- | 1803| order | [Order](#order) | Yes | Update command.| 1804 1805## ClearOptions 1806 1807Represents options for clearing errors. 1808 1809**System capability**: SystemCapability.Update.UpdateService 1810 1811| Name | Type | Mandatory | Description | 1812| ------ | ------------------------------- | ---- | ---- | 1813| status | [UpgradeStatus](#upgradestatus) | Yes | Error status.| 1814 1815## UpgradePolicy 1816 1817Represents an update policy. 1818 1819**System capability**: SystemCapability.Update.UpdateService 1820 1821| Name | Type | Mandatory | Description | 1822| ------------------- | --------------------------------------- | ---- | ------- | 1823| downloadStrategy | bool | Yes | Automatic download policy. | 1824| autoUpgradeStrategy | bool | Yes | Automatic update policy. | 1825| autoUpgradePeriods | Array\<[UpgradePeriod](#upgradeperiod)> | Yes | Automatic update period.| 1826 1827## UpgradePeriod 1828 1829Represents an automatic update period. 1830 1831**System capability**: SystemCapability.Update.UpdateService 1832 1833| Name | Type | Mandatory | Description | 1834| ----- | ------ | ---- | ---- | 1835| start | number | Yes | Start time.| 1836| end | number | Yes | End time.| 1837 1838## TaskInfo 1839 1840Task information. 1841 1842**System capability**: SystemCapability.Update.UpdateService 1843 1844| Name | Type | Mandatory | Description | 1845| --------- | --------------------- | ---- | ------ | 1846| existTask | bool | Yes | Whether a task exists.| 1847| taskBody | [TaskBody](#taskinfo) | Yes | Task data. | 1848 1849## EventInfo 1850 1851Represents event information. 1852 1853**System capability**: SystemCapability.Update.UpdateService 1854 1855| Name | Type | Mandatory | Description | 1856| -------- | --------------------- | ---- | ---- | 1857| eventId | [EventId](#eventid) | Yes | Event ID.| 1858| taskBody | [TaskBody](#taskinfo) | Yes | Task data.| 1859 1860## TaskBody 1861 1862Represents task data. 1863 1864**System capability**: SystemCapability.Update.UpdateService 1865 1866| Name | Type | Mandatory | Description | 1867| ----------------- | ---------------------------------------- | ---- | ---- | 1868| versionDigestInfo | [VersionDigestInfo](#versiondigestinfo) | Yes | Version digest information.| 1869| status | [UpgradeStatus](#upgradestatus) | Yes | Update status.| 1870| subStatus | number | No | Sub-status. | 1871| progress | number | Yes | Progress. | 1872| installMode | number | Yes | Installation mode.| 1873| errorMessages | Array\<[ErrorMessage](#errormessage)> | No | Error message.| 1874| versionComponents | Array\<[VersionComponent](#versioncomponent)> | Yes | Version components.| 1875 1876## ErrorMessage 1877 1878Represents an error message. 1879 1880**System capability**: SystemCapability.Update.UpdateService 1881 1882| Name | Type | Mandatory | Description | 1883| ------------ | ------ | ---- | ---- | 1884| errorCode | number | Yes | Error code. | 1885| errorMessage | string | Yes | Error message.| 1886 1887## EventClassifyInfo 1888 1889Represents event type information. 1890 1891**System capability**: SystemCapability.Update.UpdateService 1892 1893| Name | Type | Mandatory | Description | 1894| ------------- | ------------------------------- | ---- | ---- | 1895| eventClassify | [EventClassify](#eventclassify) | Yes | Event type.| 1896| extraInfo | string | Yes | Additional information.| 1897 1898## UpgradeFile 1899 1900Represents an update file. 1901 1902**System capability**: SystemCapability.Update.UpdateService 1903 1904| Name | Type | Mandatory | Description | 1905| -------- | ------------------------------- | ---- | ---- | 1906| fileType | [ComponentType](#componenttype) | Yes | File type.| 1907| filePath | string | Yes | File path.| 1908 1909## UpgradeTaskCallback 1910 1911(eventInfo: EventInfo): void 1912 1913Represents an event callback. 1914 1915**System capability**: SystemCapability.Update.UpdateService 1916 1917| Name | Type | Mandatory | Description | 1918| --------- | ----------------------- | ---- | ---- | 1919| eventInfo | [EventInfo](#eventinfo) | Yes | Event information.| 1920 1921## BusinessVendor 1922 1923Represents a device vendor. 1924 1925**System capability**: SystemCapability.Update.UpdateService 1926 1927| Name | Value | Description | 1928| ------ | -------- | ---- | 1929| PUBLIC | "public" | Open source. | 1930 1931## BusinessSubType 1932 1933Represents an update type. 1934 1935**System capability**: SystemCapability.Update.UpdateService 1936 1937| Name | Value | Description | 1938| -------- | ---- | ---- | 1939| FIRMWARE | 1 | Firmware. | 1940 1941## ComponentType 1942 1943Represents a component type. 1944 1945**System capability**: SystemCapability.Update.UpdateService 1946 1947| Name | Value | Description | 1948| ---- | ---- | ---- | 1949| OTA | 1 | Firmware. | 1950 1951## UpgradeAction 1952 1953Represents an update mode. 1954 1955**System capability**: SystemCapability.Update.UpdateService 1956 1957| Name | Value | Description | 1958| -------- | ---------- | ---- | 1959| UPGRADE | "upgrade" | Differential package. | 1960| RECOVERY | "recovery" | Recovery package. | 1961 1962## EffectiveMode 1963 1964Represents an effective mode. 1965 1966**System capability**: SystemCapability.Update.UpdateService 1967 1968| Name | Value | Description | 1969| ------------- | ---- | ---- | 1970| COLD | 1 | Cold update. | 1971| LIVE | 2 | Live update. | 1972| LIVE_AND_COLD | 3 | Hybrid live and cold update.| 1973 1974## DescriptionType 1975 1976Represents a description file type. 1977 1978**System capability**: SystemCapability.Update.UpdateService 1979 1980| Name | Value | Description | 1981| ------- | ---- | ---- | 1982| CONTENT | 0 | Content. | 1983| URI | 1 | Link. | 1984 1985## DescriptionFormat 1986 1987Represents a description file format. 1988 1989**System capability**: SystemCapability.Update.UpdateService 1990 1991| Name | Value | Description | 1992| ---------- | ---- | ---- | 1993| STANDARD | 0 | Standard format.| 1994| SIMPLIFIED | 1 | Simple format.| 1995 1996## NetType 1997 1998Represents a network type. 1999 2000**System capability**: SystemCapability.Update.UpdateService 2001 2002| Name | Value | Description | 2003| ----------------- | ---- | --------- | 2004| CELLULAR | 1 | Data network. | 2005| METERED_WIFI | 2 | Wi-Fi hotspot. | 2006| NOT_METERED_WIFI | 4 | Non Wi-Fi hotspot. | 2007| WIFI | 6 | Wi-Fi. | 2008| CELLULAR_AND_WIFI | 7 | Data network and Wi-Fi.| 2009 2010## Order 2011 2012Represents an update command. 2013 2014**System capability**: SystemCapability.Update.UpdateService 2015 2016| Name | Value | Description | 2017| -------------------- | ---- | ----- | 2018| DOWNLOAD | 1 | Download. | 2019| INSTALL | 2 | Install. | 2020| DOWNLOAD_AND_INSTALL | 3 | Download and install.| 2021| APPLY | 4 | Apply. | 2022| INSTALL_AND_APPLY | 6 | Install and apply.| 2023 2024## UpgradeStatus 2025 2026Enumerates update states. 2027 2028**System capability**: SystemCapability.Update.UpdateService 2029 2030| Name | Value | Description | 2031| ---------------- | ---- | ---- | 2032| WAITING_DOWNLOAD | 20 | Waiting for download. | 2033| DOWNLOADING | 21 | Downloading. | 2034| DOWNLOAD_PAUSED | 22 | Download paused.| 2035| DOWNLOAD_FAIL | 23 | Download failed.| 2036| WAITING_INSTALL | 30 | Waiting for installation. | 2037| UPDATING | 31 | Updating. | 2038| WAITING_APPLY | 40 | Waiting for applying the update. | 2039| APPLYING | 41 | Applying the update. | 2040| UPGRADE_SUCCESS | 50 | Update succeeded.| 2041| UPGRADE_FAIL | 51 | Update failed.| 2042 2043## EventClassify 2044 2045Represents an event type. 2046 2047**System capability**: SystemCapability.Update.UpdateService 2048 2049| Name | Value | Description | 2050| ---- | ---------- | ---- | 2051| TASK | 0x01000000 | Task event.| 2052 2053## EventId 2054 2055Enumerates event IDs. 2056 2057**System capability**: SystemCapability.Update.UpdateService 2058 2059| Name | Value | Description | 2060| ---------------------- | ---------- | ------ | 2061| EVENT_TASK_BASE | EventClassify.TASK | Task event. | 2062| EVENT_TASK_RECEIVE | 0x01000001 | Task received. | 2063| EVENT_TASK_CANCEL | 0x01000010 | Task cancelled. | 2064| EVENT_DOWNLOAD_WAIT | 0x01000011 | Waiting for download. | 2065| EVENT_DOWNLOAD_START | 0x01000100 | Download started. | 2066| EVENT_DOWNLOAD_UPDATE | 0x01000101 | Download progress update.| 2067| EVENT_DOWNLOAD_PAUSE | 0x01000110 | Download paused. | 2068| EVENT_DOWNLOAD_RESUME | 0x01000111 | Download resumed. | 2069| EVENT_DOWNLOAD_SUCCESS | 0x01001000 | Download succeeded. | 2070| EVENT_DOWNLOAD_FAIL | 0x01001001 | Download failed. | 2071| EVENT_UPGRADE_WAIT | 0x01001010 | Waiting for update. | 2072| EVENT_UPGRADE_START | 0x01001011 | Update started. | 2073| EVENT_UPGRADE_UPDATE | 0x01001100 | Update in progress. | 2074| EVENT_APPLY_WAIT | 0x01001101 | Waiting for applying the update. | 2075| EVENT_APPLY_START | 0x01001110 | Applying the update. | 2076| EVENT_UPGRADE_SUCCESS | 0x01001111 | Update succeeded. | 2077| EVENT_UPGRADE_FAIL | 0x01010000 | Update failed. | 2078