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