1# @ohos.file.cloudSyncManager (Device-Cloud Sync Management) (System API) 2<!--Kit: Core File Kit--> 3<!--Subsystem: FileManagement--> 4<!--Owner: @zsyztt; @Hermits; @reminder2352--> 5<!--Designer: @yunlanying--> 6<!--Tester: @liuhonggang123--> 7<!--Adviser: @foryourself--> 8 9The **cloudSyncManager** module provides APIs for managing device-cloud synergy for applications. You can use the APIs to enable or disable device-cloud synergy, change the device-cloud sync switch for an application, notify cloud data changes, and clear or retain cloud files when a cloud account exits. 10 11> **NOTE** 12> 13> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 14> - The APIs provided by this module are system APIs. 15 16## Modules to Import 17 18```ts 19import { cloudSyncManager } from '@kit.CoreFileKit'; 20``` 21 22## cloudSyncManager.changeAppCloudSwitch 23 24changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise<void> 25 26Changes the device-cloud file sync switch for an application. This API uses a promise to return the result. 27 28**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 29 30**Parameters** 31 32| Name | Type | Mandatory| Description| 33| ---------- | ------ | ---- | ---- | 34| accountId | string | Yes | Account ID.| 35| bundleName | string | Yes | Bundle name.| 36| status | boolean | Yes | State of the cloud-device file sync switch to set. The value **true** means to enable this function; the value **false** means the opposite.| 37 38**Return value** 39 40| Type | Description | 41| --------------------- | ---------------- | 42| Promise<void> | Promise used to return the result.| 43 44**Error codes** 45 46For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 47 48| ID | Error Message | 49| ---------------------------- | ---------- | 50| 201 | Permission verification failed. | 51| 202 | The caller is not a system application. | 52| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 53 54**Example** 55 56 ```ts 57 import { BusinessError } from '@kit.BasicServicesKit'; 58 let accountId: string = "testAccount"; 59 let bundleName: string = "com.example.bundle"; 60 cloudSyncManager.changeAppCloudSwitch(accountId, bundleName, true).then(() => { 61 console.info("changeAppCloudSwitch successfully"); 62 }).catch((err: BusinessError) => { 63 console.error("changeAppCloudSwitch failed with error message: " + err.message + ", error code: " + err.code); 64 }); 65 ``` 66 67## cloudSyncManager.changeAppCloudSwitch 68 69changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean, callback: AsyncCallback<void>): void 70 71Changes the device-cloud file sync switch for an application. This API uses an asynchronous callback to return the result. 72 73**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 74 75**Parameters** 76 77| Name | Type | Mandatory| Description| 78| ---------- | ------ | ---- | ---- | 79| accountId | string | Yes | Account ID.| 80| bundleName | string | Yes | Bundle name of the application.| 81| status | boolean | Yes | State of the cloud-device file sync switch to set. The value **true** means to enable this function; the value **false** means the opposite.| 82| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 83 84**Error codes** 85 86For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 87 88| ID | Error Message | 89| ---------------------------- | ---------- | 90| 201 | Permission verification failed. | 91| 202 | The caller is not a system application. | 92| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 93 94**Example** 95 96 ```ts 97 import { BusinessError } from '@kit.BasicServicesKit'; 98 let accountId: string = "testAccount"; 99 let bundleName: string = "com.example.bundle"; 100 cloudSyncManager.changeAppCloudSwitch(accountId, bundleName, true, (err: BusinessError) => { 101 if (err) { 102 console.error("changeAppCloudSwitch failed with error message: " + err.message + ", error code: " + err.code); 103 } else { 104 console.info("changeAppCloudSwitch successfully"); 105 } 106 }); 107 ``` 108 109## cloudSyncManager.notifyDataChange 110 111notifyDataChange(accountId: string, bundleName: string): Promise<void> 112 113Notifies the cloud sync service of the application data change in the cloud. This API uses a promise to return the result. 114 115**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 116 117**Parameters** 118 119| Name | Type | Mandatory| Description| 120| ---------- | ------ | ---- | ---- | 121| accountId | string | Yes | Account ID.| 122| bundleName | string | Yes | Bundle name.| 123 124**Return value** 125 126| Type | Description | 127| --------------------- | ---------------- | 128| Promise<void> | Promise used to return the application data change in the cloud.| 129 130**Error codes** 131 132For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 133 134| ID | Error Message | 135| ---------------------------- | ---------- | 136| 201 | Permission verification failed. | 137| 202 | The caller is not a system application. | 138| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 139 140**Example** 141 142 ```ts 143 import { BusinessError } from '@kit.BasicServicesKit'; 144 let accountId: string = "testAccount"; 145 let bundleName: string = "com.example.bundle"; 146 cloudSyncManager.notifyDataChange(accountId, bundleName).then(() => { 147 console.info("notifyDataChange successfully"); 148 }).catch((err: BusinessError) => { 149 console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code); 150 }); 151 ``` 152 153## cloudSyncManager.notifyDataChange 154 155notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback<void>): void 156 157Notifies the cloud sync service of the application data change in the cloud. This API uses an asynchronous callback to return the result. 158 159**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 160 161**Parameters** 162 163| Name | Type | Mandatory| Description| 164| ---------- | ------ | ---- | ---- | 165| accountId | string | Yes | Account ID.| 166| bundleName | string | Yes | Bundle name.| 167| callback | AsyncCallback<void> | Yes | Callback used to return the application data change in the cloud.| 168 169**Error codes** 170 171For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 172 173| ID | Error Message | 174| ---------------------------- | ---------- | 175| 201 | Permission verification failed. | 176| 202 | The caller is not a system application. | 177| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 178 179**Example** 180 181 ```ts 182 import { BusinessError } from '@kit.BasicServicesKit'; 183 let accountId: string = "testAccount"; 184 let bundleName: string = "com.example.bundle"; 185 cloudSyncManager.notifyDataChange(accountId, bundleName, (err: BusinessError) => { 186 if (err) { 187 console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code); 188 } else { 189 console.info("notifyDataChange successfully"); 190 } 191 }); 192 ``` 193 194## ExtraData<sup>11+</sup> 195 196Represents the cloud data change information. 197 198**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 199 200| Name | Type | Mandatory| Description| 201| ---------- | ------ | ---- | ---- | 202| eventId | string | Yes | Change event ID.| 203| extraData | ExtraData | Yes | Represents the cloud data change information.| 204 205## cloudSyncManager.notifyDataChange<sup>11+</sup> 206 207notifyDataChange(userId: number, extraData: ExtraData): Promise<void> 208 209Notifies the cloud sync service of the application data change in the cloud. This API uses a promise to return the result. 210 211**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 212 213**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 214 215**Parameters** 216 217| Name | Type | Mandatory| Description| 218| ---------- | ------ | ---- | ---- | 219| userId | number | Yes | User ID.| 220| extraData | ExtraData | Yes | Represents the cloud data change information.| 221 222**Return value** 223 224| Type | Description | 225| --------------------- | ---------------- | 226| Promise<void> | Promise used to return the application data change in the cloud.| 227 228**Error codes** 229 230For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 231 232| ID | Error Message | 233| ---------------------------- | ---------- | 234| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 235| 202 | Permission verification failed, application which is not a system application uses system API. | 236| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 237| 13600001 | IPC error. | 238 239**Example** 240 241 ```ts 242 import { BusinessError } from '@kit.BasicServicesKit'; 243 let userId: number = 100; 244 let extraData: cloudSyncManager.ExtraData = {eventId: "eventId", extraData: "data"}; 245 cloudSyncManager.notifyDataChange(userId, extraData).then(() => { 246 console.info("notifyDataChange successfully"); 247 }).catch((err: BusinessError) => { 248 console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code); 249 }); 250 ``` 251 252## cloudSyncManager.notifyDataChange<sup>11+</sup> 253 254notifyDataChange(userId: number, extraData: ExtraData, callback: AsyncCallback<void>): void 255 256Notifies the cloud sync service of the application data change in the cloud. This API uses an asynchronous callback to return the result. 257 258**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 259 260**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 261 262**Parameters** 263 264| Name | Type | Mandatory| Description| 265| ---------- | ------ | ---- | ---- | 266| userId | number | Yes | User ID.| 267| extraData | ExtraData | Yes | Represents the cloud data change information.| 268| callback | AsyncCallback<void> | Yes | Callback used to return the application data change in the cloud.| 269 270**Error codes** 271 272For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 273 274| ID | Error Message | 275| ---------------------------- | ---------- | 276| 201 | Permission verification failed. | 277| 202 | The caller is not a system application. | 278| 401 | The input parameter is invalid. | 279| 13600001 | IPC error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 280 281**Example** 282 283 ```ts 284 import { BusinessError } from '@kit.BasicServicesKit'; 285 let userId: number = 100; 286 let extraData: cloudSyncManager.ExtraData = {eventId: "eventId", extraData: "data"}; 287 cloudSyncManager.notifyDataChange(userId, extraData, (err: BusinessError) => { 288 if (err) { 289 console.error("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code); 290 } else { 291 console.info("notifyDataChange successfully"); 292 } 293 }); 294 ``` 295 296## cloudSyncManager.enableCloud 297 298enableCloud(accountId: string, switches: Record<string, boolean>): Promise<void> 299 300Enables device-cloud synergy. This API uses a promise to return the result. 301 302**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 303 304**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 305 306**Parameters** 307 308| Name | Type | Mandatory| Description| 309| ---------- | ------ | ---- | ---- | 310| accountId | string | Yes | Account ID.| 311| switches | Record<string, boolean> | Yes | Whether to enable the device-cloud synergy feature. The application bundle name is a string. The switch status is a Boolean value. The value **true** means to enable this function; the value **false** means the opposite.| 312 313**Return value** 314 315| Type | Description | 316| --------------------- | ---------------- | 317| Promise<void> | Promise used to return the result.| 318 319**Error codes** 320 321For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 322 323| ID | Error Message | 324| ---------------------------- | ---------- | 325| 201 | Permission verification failed. | 326| 202 | The caller is not a system application. | 327| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 328 329**Example** 330 331 ```ts 332 import { BusinessError } from '@kit.BasicServicesKit'; 333 let accountId: string = "testAccount"; 334 let switches: Record<string, boolean> = { 335 'com.example.bundleName1': true, 336 'com.example.bundleName2': false 337 } 338 cloudSyncManager.enableCloud(accountId, switches).then(() => { 339 console.error("enableCloud successfully"); 340 }).catch((err: BusinessError) => { 341 console.info("enableCloud failed with error message: " + err.message + ", error code: " + err.code); 342 }); 343 ``` 344 345## cloudSyncManager.enableCloud 346 347enableCloud(accountId: string, switches: Record<string, boolean>, callback: AsyncCallback<void>): void 348 349Enables device-cloud synergy. This API uses an asynchronous callback to return the result. 350 351**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 352 353**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 354 355**Parameters** 356 357| Name | Type | Mandatory| Description| 358| ---------- | ------ | ---- | ---- | 359| accountId | string | Yes | Account ID.| 360| switches | Record<string, boolean> | Yes | Whether to enable the device-cloud synergy feature. The application bundle name is a string. The switch status is a Boolean value. The value **true** means to enable this function; the value **false** means the opposite.| 361| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 362 363**Error codes** 364 365For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 366 367| ID | Error Message | 368| ---------------------------- | ---------- | 369| 201 | Permission verification failed. | 370| 202 | The caller is not a system application. | 371| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 372 373**Example** 374 375 ```ts 376 import { BusinessError } from '@kit.BasicServicesKit'; 377 let accountId: string = "testAccount"; 378 let switches: Record<string, boolean> = { 379 'com.example.bundleName1': true, 380 'com.example.bundleName2': false 381 } 382 cloudSyncManager.enableCloud(accountId, switches, (err: BusinessError) => { 383 if (err) { 384 console.error("enableCloud failed with error message: " + err.message + ", error code: " + err.code); 385 } else { 386 console.info("enableCloud successfully"); 387 } 388 }); 389 ``` 390 391## cloudSyncManager.disableCloud 392 393disableCloud(accountId: string): Promise<void> 394 395Disables device-cloud synergy. This API uses a promise to return the result. 396 397**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 398 399**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 400 401**Parameters** 402 403| Name | Type | Mandatory| Description| 404| ---------- | ------ | ---- | ---- | 405| accountId | string | Yes | Account ID.| 406 407**Return value** 408 409| Type | Description | 410| --------------------- | ---------------- | 411| Promise<void> | Promise used to return the result.| 412 413**Error codes** 414 415For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 416 417| ID | Error Message | 418| ---------------------------- | ---------- | 419| 201 | Permission verification failed. | 420| 202 | The caller is not a system application. | 421| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 422 423**Example** 424 425 ```ts 426 import { BusinessError } from '@kit.BasicServicesKit'; 427 let accountId: string = "testAccount"; 428 cloudSyncManager.disableCloud(accountId).then(() => { 429 console.info("disableCloud successfully"); 430 }).catch((err: BusinessError) => { 431 console.error("disableCloud failed with error message: " + err.message + ", error code: " + err.code); 432 }); 433 ``` 434 435## cloudSyncManager.disableCloud 436 437disableCloud(accountId: string, callback: AsyncCallback<void>): void 438 439Disables device-cloud synergy. This API uses an asynchronous callback to return the result. 440 441**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 442 443**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 444 445**Parameters** 446 447| Name | Type | Mandatory| Description| 448| ---------- | ------ | ---- | ---- | 449| accountId | string | Yes | Account ID.| 450| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 451 452**Error codes** 453 454For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 455 456| ID | Error Message | 457| ---------------------------- | ---------- | 458| 201 | Permission verification failed. | 459| 202 | The caller is not a system application. | 460| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 461 462**Example** 463 464 ```ts 465 import { BusinessError } from '@kit.BasicServicesKit'; 466 let accountId: string = "testAccount"; 467 cloudSyncManager.disableCloud(accountId, (err: BusinessError) => { 468 if (err) { 469 console.error("disableCloud failed with error message: " + err.message + ", error code: " + err.code); 470 } else { 471 console.info("disableCloud successfully"); 472 } 473 }); 474 ``` 475 476## Action 477 478Enumerates the actions that can be taken to clear local cloud data. 479 480**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 481 482**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 483 484| Name| Value| Description| 485| ----- | ---- | ---- | 486| RETAIN_DATA | 0 | Clear the cloud identifier but retain the files cached locally.| 487| CLEAR_DATA | 1 | Clear the cloud identifier and the files cached locally.| 488 489## cloudSyncManager.clean 490 491clean(accountId: string, appActions: Record<string, Action>): Promise<void> 492 493Clears the cloud data locally. This API uses a promise to return the result. 494 495**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 496 497**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 498 499**Parameters** 500 501| Name | Type | Mandatory| Description| 502| ---------- | ------ | ---- | ---- | 503| accountId | string | Yes | Account ID.| 504| appActions | Record<string, Action> | Yes | Action to perform. The bundle name of the application whose data is to be cleared is a string. [Action](#action) specifies the action to perform.| 505 506**Return value** 507 508| Type | Description | 509| --------------------- | ---------------- | 510| Promise<void> | Promise used to return the result.| 511 512**Error codes** 513 514For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 515 516| ID | Error Message | 517| ---------------------------- | ---------- | 518| 201 | Permission verification failed. | 519| 202 | The caller is not a system application. | 520| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 521 522**Example** 523 524 ```ts 525 import { BusinessError } from '@kit.BasicServicesKit'; 526 let accountId: string = "testAccount"; 527 let appActions: Record<string, cloudSyncManager.Action> = { 528 'com.example.bundleName1': cloudSyncManager.Action.RETAIN_DATA, 529 'com.example.bundleName2': cloudSyncManager.Action.CLEAR_DATA 530 }; 531 cloudSyncManager.clean(accountId, appActions).then(() => { 532 console.info("clean successfully"); 533 }).catch((err: BusinessError) => { 534 console.error("clean failed with error message: " + err.message + ", error code: " + err.code); 535 }); 536 ``` 537 538## cloudSyncManager.clean 539 540clean(accountId: string, appActions: Record<string, Action>, callback: AsyncCallback<void>): void 541 542Clears the cloud data locally. This API uses an asynchronous callback to return the result. 543 544**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 545 546**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 547 548**Parameters** 549 550| Name | Type | Mandatory| Description| 551| ---------- | ------ | ---- | ---- | 552| accountId | string | Yes | Account ID.| 553| appActions | Record<string, Action> | Yes | Action to perform. The bundle name of the application whose data is to be cleared is a string. [Action](#action) specifies the action to perform.| 554| callback | AsyncCallback<void> | Yes | Callback used to clear the cloud data locally.| 555 556**Error codes** 557 558For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 559 560| ID | Error Message | 561| ---------------------------- | ---------- | 562| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 563| 202 | Permission verification failed, application which is not a system application uses system API. | 564| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 565 566**Example** 567 568 ```ts 569 import { BusinessError } from '@kit.BasicServicesKit'; 570 let accountId: string = "testAccount"; 571 let appActions: Record<string, cloudSyncManager.Action> = { 572 'com.example.bundleName1': cloudSyncManager.Action.RETAIN_DATA, 573 'com.example.bundleName2': cloudSyncManager.Action.CLEAR_DATA 574 }; 575 cloudSyncManager.clean(accountId, appActions, (err: BusinessError) => { 576 if (err) { 577 console.error("clean failed with error message: " + err.message + ", error code: " + err.code); 578 } else { 579 console.info("clean successfully"); 580 } 581 }); 582 ``` 583 584## DowngradeDownload<sup>20+</sup> 585 586Represents the downgrade download for cloud data to prevent data loss when Cloud Premium expires. 587 588It supports the download of cloud application files. 589 590**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 591 592### constructor<sup>20+</sup> 593 594constructor(bundleName: string) 595 596A constructor used to create a **DowngradeDownload** instance with a specified bundle name. 597 598**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 599 600**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 601 602**Parameters** 603 604| Name | Type | Mandatory| Description | 605| ---------- | ------ | ---- | ---------- | 606| bundleName | string | Yes | Bundle name.| 607 608**Error codes** 609 610For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md) and [Universal Error Codes](../errorcode-universal.md). 611 612| ID| Error Message | 613| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 614| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 615| 202 | Permission verification failed, application which is not a system application uses system API. | 616| 13900020 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 617| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. | 618 619**Example** 620 621 ```ts 622 let bundleName = 'com.demo.a'; 623 try { 624 let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName); 625 } catch (e) { 626 let error = e as BusinessError; 627 console.error(`Failed to create downgrade manager object, error code: ${error.code}, message: ${error.message}`); 628 } 629 ``` 630 631### getCloudFileInfo<sup>20+</sup> 632 633getCloudFileInfo(): Promise<CloudFileInfo> 634 635Obtains the size and count of files for applications requiring downgrade download, including those stored only locally, only in the cloud, or both locally and in the cloud. This API uses a promise to return the result. 636 637**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 638 639**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 640 641**Return value** 642 643 | Type | Description | 644 | --------------------------------- | ------------------------ | 645 | Promise<[CloudFileInfo](#cloudfileinfo20)> | Promise used to return the local and cloud file information.| 646 647**Error codes** 648 649For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md) and [Universal Error Codes](../errorcode-universal.md). 650 651| ID| Error Message | 652| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 653| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 654| 202 | Permission verification failed, application which is not a system application uses system API. | 655| 13600001 | IPC error. Possible causes: 1.IPC failed or timed out. 2.Failed to load the service. | 656| 13900010 | Try again. | 657| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. | 658 659**Example** 660 661 ```ts 662 import { BusinessError } from '@kit.BasicServicesKit'; 663 664 let bundleName: string = "com.demo.a"; 665 let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName); 666 downgradeMgr.getCloudFileInfo().then((fileInfo: cloudSyncManager.CloudFileInfo) => { 667 console.info("cloud file info: " + JSON.stringify(fileInfo)); 668 }).catch((err: BusinessError) => { 669 console.error(`Failed to get downgrade info, error message: ${err.message}, error code: ${err.code}`); 670 }); 671 ``` 672 673### startDownload<sup>20+</sup> 674 675startDownload(callback: Callback<DownloadProgress>): Promise<void> 676 677Starts the downgrade download for the specified application's cloud files. This API uses a promise to return the result. 678 679Repeated triggering of a downgrade download task will throw an error (22400006). 680 681**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 682 683**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 684 685**Parameters** 686 687| Name | Type | Mandatory| Description | 688| -------- | -------------------------------- | ---- | ----------------------------------------------------------------------------------- | 689| callback | Callback<[DownloadProgress](#downloadprogress20)> | Yes | Callback used to return the download progress. The parameter is **DownloadProgress**, and the return value is **void**.| 690 691**Return value** 692 693 | Type | Description | 694 | ------------------- | ------------------------- | 695 | Promise<void> | Promise that returns no value.| 696 697**Error codes** 698 699For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md) and [Universal Error Codes](../errorcode-universal.md). 700 701| ID| Error Message | 702| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 703| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 704| 202 | Permission verification failed, application which is not a system application uses system API. | 705| 13600001 | IPC error. Possible causes: 1.IPC failed or timed out. 2.Failed to load the service. | 706| 13900010 | Try again. | 707| 13900020 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 708| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. | 709| 22400006 | The same task is already in progress. | 710 711**Example** 712 713 ```ts 714 import { BusinessError } from '@kit.BasicServicesKit'; 715 716 let bundleName: string = "com.demo.a"; 717 let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName); 718 let callback = (data: cloudSyncManager.DownloadProgress) => { 719 console.info(`Dwongrade progress: downloadedSize: ${data.downloadedSize}, totalSize: ${data.totalSize}`); 720 if (data.state == cloudSyncManager.DownloadState.COMPLETED) { 721 console.info('Dwongrade finished.'); 722 } else if (data.state == cloudSyncManager.DownloadState.STOPPED) { 723 console.info(`Dwongrade stopped, reason: ${data.stopReason}.`); 724 } 725 }; 726 downgradeMgr.startDownload(callback).then(() => { 727 console.info("Downgrade started successfully."); 728 }).catch((err: BusinessError) => { 729 console.error(`Failed to start downgrade, error message: ${err.message}, error code: ${err.code}`); 730 }); 731 ``` 732 733### stopDownload<sup>20+</sup> 734 735stopDownload(): Promise<void> 736 737Stops the downgrade download task triggered by [startDownload](#startdownload20). This API uses a promise to return the result. 738 739**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 740 741**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 742 743**Return value** 744 745 | Type | Description | 746 | ------------------- | ------------------------- | 747 | Promise<void> | Promise that returns no value.| 748 749**Error codes** 750 751For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md) and [Universal Error Codes](../errorcode-universal.md). 752 753| ID| Error Message | 754| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 755| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 756| 202 | Permission verification failed, application which is not a system application uses system API. | 757| 13600001 | IPC error. Possible causes: 1.IPC failed or timed out. 2.Failed to load the service. | 758| 22400005 | Inner error. Possible causes: 1.Failed to access the database or execute the SQL statement. 2.System error, such as a null pointer, insufficient memory or a JS engine exception. | 759 760**Example** 761 762 ```ts 763 import { BusinessError } from '@kit.BasicServicesKit'; 764 765 let bundleName: string = "com.demo.a"; 766 let downgradeMgr = new cloudSyncManager.DowngradeDownload(bundleName); 767 downgradeMgr.startDownload((data: cloudSyncManager.DownloadProgress) => { 768 console.info(`Dwongrade progress: downloadedSize: ${data.downloadedSize}, totalSize: ${data.totalSize}`); 769 }).then(() => { 770 console.info("Downgrade started successfully."); 771 }).catch((err: BusinessError) => { 772 console.error(`Failed to start downgrade, error message: ${err.message}, error code: ${err.code}`); 773 }); 774 775 let needStop = true; 776 if (needStop) { 777 downgradeMgr.stopDownload().then(() => { 778 console.info("Downgrade stopped successfully."); 779 }).catch((err: BusinessError) => { 780 console.error(`Failed to stop downgrade, error message: ${err.message}, error code: ${err.code}`); 781 }); 782 } 783 ``` 784## DownloadStopReason<sup>20+</sup> 785 786Enumerates the reasons why the download stops. The default value is **NO_STOP**. 787 788**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 789 790| Name | Value | Description | 791| ------------------- | --- | ------------------------------------------------------ | 792| NO_STOP | 0 | Downloading. | 793| NETWORK_UNAVAILABLE | 1 | Downloading. Mobile network and Wi-Fi are unavailable. | 794| LOCAL_STORAGE_FULL | 2 | Downloading. The device storage is full. | 795| TEMPERATURE_LIMIT | 3 | Downloading. The device temperature exceeds the upper limit. | 796| USER_STOPPED | 4 | Downloading. The user stops the download. | 797| APP_UNLOAD | 5 | Downloading. The application is uninstalled. | 798| OTHER_REASON | 6 | Downloading. The download stops due to other reasons, for example, the cloud server does not respond.| 799 800## DownloadState<sup>20+</sup> 801 802Enumerates the download states. 803 804**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 805 806| Name | Value | Description | 807| --------- | --- | ---------- | 808| RUNNING | 0 | Downloading. | 809| COMPLETED | 1 | Downloaded.| 810| STOPPED | 2 | Downloading stopped.| 811 812## DownloadProgress<sup>20+</sup> 813 814Represents the downgrade download progress. 815 816**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 817 818### Property 819 820| Name | Type | Read-Only| Optional| Description | 821| --------------- | ------------------------------------------- | ---- | ---- | ----------------------------------------------------------------------------- | 822| state | [DownloadState](#downloadstate20) | No | No | Download state. | 823| successfulCount | number | No | No | Number of downloaded files. The value range is [0, INT32_MAX]. If the progress is abnormal, **-1** is returned. | 824| failedCount | number | No | No | Number of files that fail to be downloaded. The value range is [0, INT32_MAX]. If the progress is abnormal, **-1** is returned. | 825| totalCount | number | No | No | Total number of files to be downloaded. The value range is [0, INT32_MAX]. If the progress is abnormal, **-1** is returned. | 826| downloadedSize | number | No | No | Size of the downloaded data, in bytes. The value range is [0, INT64_MAX). If the progress is abnormal, **INT64_MAX** is returned.| 827| totalSize | number | No | No | Total size of the files to be downloaded, in bytes. The value range is [0, INT64_MAX). If the progress is abnormal, **INT64_MAX** is returned.| 828| stopReason | [DownloadStopReason](#downloadstopreason20) | No | No | Reason why the download stops. | 829 830## CloudFileInfo<sup>20+</sup> 831 832Represents the number and size of local and cloud files of an application. 833 834**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 835 836### Property 837 838| Name | Type | Read-Only| Optional| Description | 839| ------------------ | ------ | ---- | ---- | ---------------------------------------------------------------- | 840| cloudFileCount | number | No | No | Total number of cloud files that are not downloaded locally. The value range is [0, INT32_MAX]. | 841| cloudFileTotalSize | number | No | No | Total size of cloud files that are not downloaded locally, in bytes. The value range is [0, INT64_MAX].| 842| localFileCount | number | No | No | Total number of local files that are not uploaded to the cloud. The value range is [0, INT32_MAX]. | 843| localFileTotalSize | number | No | No | Total size of local files that are not uploaded to the cloud, in bytes. The value range is [0, INT64_MAX].| 844| bothFileCount | number | No | No | Total number of local files that have been uploaded to the cloud. The value range is [0, INT32_MAX]. | 845| bothlFileTotalSize | number | No | No | Total size of local files that have been uploaded to the cloud, in bytes. The value range is [0, INT64_MAX].| 846