1# @ohos.file.cloudSyncManager (Device-Cloud Synchronization Management) 2 3The **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 synchronization switch for an application, notify cloud data changes, and clear or retain cloud files when a cloud account exits. 4 5> **NOTE** 6> 7> - 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. 8> - The APIs of this module are system APIs and cannot be called by third-party applications. 9 10## Modules to Import 11 12```ts 13import cloudSyncManager from '@ohos.file.cloudSyncManager'; 14``` 15 16## cloudSyncManager.changeAppCloudSwitch 17 18changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise<void> 19 20Changes the device-cloud file synchronization switch for an application. This API uses a promise to return the result. 21 22**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 23 24**Parameters** 25 26| Name | Type | Mandatory| Description| 27| ---------- | ------ | ---- | ---- | 28| accountId | string | Yes | Account ID.| 29| bundleName | string | Yes | Bundle name of the application.| 30| status | boolean | Yes | State of the cloud-device file synchronization switch to set. The value **true** means to enable this function; the value **false** means the opposite.| 31 32**Return value** 33 34| Type | Description | 35| --------------------- | ---------------- | 36| Promise<void> | Promise used to return the result.| 37 38**Error codes** 39 40For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 41 42| ID | Error Message | 43| ---------------------------- | ---------- | 44| 201 | Permission verification failed. | 45| 202 | The caller is not a system application. | 46| 401 | The input parameter is invalid. | 47 48**Example** 49 50 ```ts 51 import { BusinessError } from '@ohos.base'; 52 let accountId: string = "testAccount"; 53 let bundleName: string = "com.example.bundle"; 54 cloudSyncManager.changeAppCloudSwitch(accountId, bundleName, true).then(() => { 55 console.info("changeAppCloudSwitch successfully"); 56 }).catch((err: BusinessError) => { 57 console.info("changeAppCloudSwitch failed with error message: " + err.message + ", error code: " + err.code); 58 }); 59 ``` 60 61## cloudSyncManager.changeAppCloudSwitch 62 63changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean, callback: AsyncCallback<void>): void 64 65Changes the device-cloud file synchronization switch for an application. This API uses an asynchronous callback to return the result. 66 67**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 68 69**Parameters** 70 71| Name | Type | Mandatory| Description| 72| ---------- | ------ | ---- | ---- | 73| accountId | string | Yes | Account ID.| 74| bundleName | string | Yes | Bundle name of the application.| 75| status | boolean | Yes | State of the cloud-device file synchronization switch to set. The value **true** means to enable this function; the value **false** means the opposite.| 76| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| 77 78**Error codes** 79 80For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 81 82| ID | Error Message | 83| ---------------------------- | ---------- | 84| 201 | Permission verification failed. | 85| 202 | The caller is not a system application. | 86| 401 | The input parameter is invalid. | 87 88**Example** 89 90 ```ts 91 import { BusinessError } from '@ohos.base'; 92 let accountId: string = "testAccount"; 93 let bundleName: string = "com.example.bundle"; 94 cloudSyncManager.changeAppCloudSwitch(accountId, bundleName, true, (err: BusinessError) => { 95 if (err) { 96 console.info("changeAppCloudSwitch failed with error message: " + err.message + ", error code: " + err.code); 97 } else { 98 console.info("changeAppCloudSwitch successfully"); 99 } 100 }); 101 ``` 102 103## cloudSyncManager.notifyDataChange 104 105notifyDataChange(accountId: string, bundleName: string): Promise<void> 106 107Notifies the cloud and device services of the application data change in the cloud. This API uses a promise to return the result. 108 109**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 110 111**Parameters** 112 113| Name | Type | Mandatory| Description| 114| ---------- | ------ | ---- | ---- | 115| accountId | string | Yes | Account ID.| 116| bundleName | string | Yes | Bundle name of the application.| 117 118**Return value** 119 120| Type | Description | 121| --------------------- | ---------------- | 122| Promise<void> | Promise used to return the application data change in the cloud.| 123 124**Error codes** 125 126For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 127 128| ID | Error Message | 129| ---------------------------- | ---------- | 130| 201 | Permission verification failed. | 131| 202 | The caller is not a system application. | 132| 401 | The input parameter is invalid. | 133 134**Example** 135 136 ```ts 137 import { BusinessError } from '@ohos.base'; 138 let accountId: string = "testAccount"; 139 let bundleName: string = "com.example.bundle"; 140 cloudSyncManager.notifyDataChange(accountId, bundleName).then(() => { 141 console.info("notifyDataChange successfully"); 142 }).catch((err: BusinessError) => { 143 console.info("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code); 144 }); 145 ``` 146 147## cloudSyncManager.notifyDataChange 148 149notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback<void>): void 150 151Notifies the cloud and device services of the application data change in the cloud. This API uses a promise to return the result. 152 153**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 154 155**Parameters** 156 157| Name | Type | Mandatory| Description| 158| ---------- | ------ | ---- | ---- | 159| accountId | string | Yes | Account ID.| 160| bundleName | string | Yes | Bundle name of the application.| 161| callback | AsyncCallback<void> | Yes | Callback invoked to return the application data change in the cloud.| 162 163**Error codes** 164 165For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 166 167| ID | Error Message | 168| ---------------------------- | ---------- | 169| 201 | Permission verification failed. | 170| 202 | The caller is not a system application. | 171| 401 | The input parameter is invalid. | 172 173**Example** 174 175 ```ts 176 import { BusinessError } from '@ohos.base'; 177 let accountId: string = "testAccount"; 178 let bundleName: string = "com.example.bundle"; 179 cloudSyncManager.notifyDataChange(accountId, bundleName, (err: BusinessError) => { 180 if (err) { 181 console.info("notifyDataChange failed with error message: " + err.message + ", error code: " + err.code); 182 } else { 183 console.info("notifyDataChange successfully"); 184 } 185 }); 186 ``` 187 188## cloudSyncManager.enableCloud 189 190enableCloud(accountId: string, switches: { [bundleName: string]: boolean }): Promise<void> 191 192Enables device-cloud synergy. This API uses a promise to return the result. 193 194**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 195 196**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 197 198**Parameters** 199 200| Name | Type | Mandatory| Description| 201| ---------- | ------ | ---- | ---- | 202| accountId | string | Yes | Account ID.| 203| switches | object | Yes | Whether to enable the device-cloud synergy feature. **bundleName** indicates the application bundle name. The switch status is a Boolean value.| 204 205**Return value** 206 207| Type | Description | 208| --------------------- | ---------------- | 209| Promise<void> | Promise used to return the result.| 210 211**Error codes** 212 213For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 214 215| ID | Error Message | 216| ---------------------------- | ---------- | 217| 201 | Permission verification failed. | 218| 202 | The caller is not a system application. | 219| 401 | The input parameter is invalid. | 220 221**Example** 222 223 ```ts 224 import { BusinessError } from '@ohos.base'; 225 let accountId: string = "testAccount"; 226 let switches: Record<string, boolean> = { 227 'com.example.bundleName1': true, 228 'com.example.bundleName2': false 229 } 230 cloudSyncManager.enableCloud(accountId, switches).then(() => { 231 console.info("enableCloud successfully"); 232 }).catch((err: BusinessError) => { 233 console.info("enableCloud failed with error message: " + err.message + ", error code: " + err.code); 234 }); 235 ``` 236 237## cloudSyncManager.enableCloud 238 239enableCloud(accountId: string, switches: { [bundleName: string]: boolean }, callback: AsyncCallback<void>): void 240 241Enables device-cloud synergy. This API uses an asynchronous callback to return the result. 242 243**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 244 245**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 246 247**Parameters** 248 249| Name | Type | Mandatory| Description| 250| ---------- | ------ | ---- | ---- | 251| accountId | string | Yes | Account ID.| 252| switches | object | Yes | Whether to enable the device-cloud synergy feature. **bundleName** indicates the application bundle name. The switch status is a Boolean value.| 253| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| 254 255**Error codes** 256 257For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 258 259| ID | Error Message | 260| ---------------------------- | ---------- | 261| 201 | Permission verification failed. | 262| 202 | The caller is not a system application. | 263| 401 | The input parameter is invalid. | 264 265**Example** 266 267 ```ts 268 import { BusinessError } from '@ohos.base'; 269 let accountId: string = "testAccount"; 270 let switches: Record<string, boolean> = { 271 'com.example.bundleName1': true, 272 'com.example.bundleName2': false 273 } 274 cloudSyncManager.enableCloud(accountId, switches, (err: BusinessError) => { 275 if (err) { 276 console.info("enableCloud failed with error message: " + err.message + ", error code: " + err.code); 277 } else { 278 console.info("enableCloud successfully"); 279 } 280 }); 281 ``` 282 283## cloudSyncManager.disableCloud 284 285disableCloud(accountId: string): Promise<void> 286 287Disables device-cloud synergy. This API uses a promise to return the result. 288 289**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 290 291**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 292 293**Parameters** 294 295| Name | Type | Mandatory| Description| 296| ---------- | ------ | ---- | ---- | 297| accountId | string | Yes | Account ID.| 298 299**Return value** 300 301| Type | Description | 302| --------------------- | ---------------- | 303| Promise<void> | Promise used to return the result.| 304 305**Error codes** 306 307For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 308 309| ID | Error Message | 310| ---------------------------- | ---------- | 311| 201 | Permission verification failed. | 312| 202 | The caller is not a system application. | 313| 401 | The input parameter is invalid. | 314 315**Example** 316 317 ```ts 318 import { BusinessError } from '@ohos.base'; 319 let accountId: string = "testAccount"; 320 cloudSyncManager.disableCloud(accountId).then(() => { 321 console.info("disableCloud successfully"); 322 }).catch((err: BusinessError) => { 323 console.info("disableCloud failed with error message: " + err.message + ", error code: " + err.code); 324 }); 325 ``` 326 327## cloudSyncManager.disableCloud 328 329disableCloud(accountId: string, callback: AsyncCallback<void>): void 330 331Disables device-cloud synergy. This API uses an asynchronous callback to return the result. 332 333**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 334 335**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 336 337**Parameters** 338 339| Name | Type | Mandatory| Description| 340| ---------- | ------ | ---- | ---- | 341| accountId | string | Yes | Account ID.| 342| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| 343 344**Error codes** 345 346For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 347 348| ID | Error Message | 349| ---------------------------- | ---------- | 350| 201 | Permission verification failed. | 351| 202 | The caller is not a system application. | 352| 401 | The input parameter is invalid. | 353 354**Example** 355 356 ```ts 357 import { BusinessError } from '@ohos.base'; 358 let accountId: string = "testAccount"; 359 cloudSyncManager.disableCloud(accountId, (err: BusinessError) => { 360 if (err) { 361 console.info("disableCloud failed with error message: " + err.message + ", error code: " + err.code); 362 } else { 363 console.info("disableCloud successfully"); 364 } 365 }); 366 ``` 367 368## Action 369 370Enumerates the actions that can be taken to clear local cloud data. 371 372**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 373 374**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 375 376| Name| Value| Description| 377| ----- | ---- | ---- | 378| RETAIN_DATA | 0 | Clear the cloud identifier but retain the files cached locally.| 379| CLEAR_DATA | 1 | Clear the cloud identifier and the files cached locally.| 380 381## cloudSyncManager.clean 382 383clean(accountId: string, appActions: { [bundleName: string]: Action }): Promise<void> 384 385Clears the cloud data locally. This API uses a promise to return the result. 386 387**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 388 389**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 390 391**Parameters** 392 393| Name | Type | Mandatory| Description| 394| ---------- | ------ | ---- | ---- | 395| accountId | string | Yes | Account ID.| 396| appActions | object | Yes | Action to take. **bundleName** indicates the application bundle to clear, and [Action](#action) indicates the action to take.| 397 398**Return value** 399 400| Type | Description | 401| --------------------- | ---------------- | 402| Promise<void> | Promise used to return the result.| 403 404**Error codes** 405 406For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 407 408| ID | Error Message | 409| ---------------------------- | ---------- | 410| 201 | Permission verification failed. | 411| 202 | The caller is not a system application. | 412| 401 | The input parameter is invalid. | 413 414**Example** 415 416 ```ts 417 import { BusinessError } from '@ohos.base'; 418 let accountId: string = "testAccount"; 419 let appActions: Record<string, cloudSyncManager.Action> = { 420 'com.example.bundleName1': cloudSyncManager.Action.RETAIN_DATA, 421 'com.example.bundleName2': cloudSyncManager.Action.CLEAR_DATA 422 }; 423 cloudSyncManager.clean(accountId, appActions).then(() => { 424 console.info("clean successfully"); 425 }).catch((err: BusinessError) => { 426 console.info("clean failed with error message: " + err.message + ", error code: " + err.code); 427 }); 428 ``` 429 430## cloudSyncManager.clean 431 432clean(accountId: string, appActions: { [bundleName: string]: Action }, callback: AsyncCallback<void>): void 433 434Clears the cloud data locally. This API uses an asynchronous callback to return the result. 435 436**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER 437 438**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager 439 440**Parameters** 441 442| Name | Type | Mandatory| Description| 443| ---------- | ------ | ---- | ---- | 444| accountId | string | Yes | Account ID.| 445| appActions | object | Yes | Action to take. **bundleName** indicates the application bundle to clear, and [Action](#action) indicates the action to take.| 446| callback | AsyncCallback<void> | Yes | Callback invoked to clear the cloud data locally.| 447 448**Error codes** 449 450For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 451 452| ID | Error Message | 453| ---------------------------- | ---------- | 454| 201 | Permission verification failed. | 455| 202 | The caller is not a system application. | 456| 401 | The input parameter is invalid. | 457 458**Example** 459 460 ```ts 461 import { BusinessError } from '@ohos.base'; 462 let accountId: string = "testAccount"; 463 let appActions: Record<string, cloudSyncManager.Action> = { 464 'com.example.bundleName1': cloudSyncManager.Action.RETAIN_DATA, 465 'com.example.bundleName2': cloudSyncManager.Action.CLEAR_DATA 466 }; 467 cloudSyncManager.clean(accountId, appActions, (err: BusinessError) => { 468 if (err) { 469 console.info("clean failed with error message: " + err.message + ", error code: " + err.code); 470 } else { 471 console.info("clean successfully"); 472 } 473 }); 474 ``` 475