diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md index b85ef4f7720cafff83c67fe2aee848dcd046c23c..e9cdf59666c6c9a27af9484ecbc401f131bd0bfc 100644 --- a/en/application-dev/reference/apis/Readme-EN.md +++ b/en/application-dev/reference/apis/Readme-EN.md @@ -259,6 +259,7 @@ - File Management - [@ohos.file.backup (Backup and Restoration)](js-apis-file-backup.md) + - [@ohos.file.cloudSync (Device-Cloud Synchronization)](js-apis-file-cloudsync.md) - [@ohos.file.cloudSyncManager (Device-Cloud Synchronization Management)](js-apis-file-cloudsyncmanager.md) - [@ohos.file.environment (Directory Environment Capability)](js-apis-file-environment.md) - [@ohos.file.fileAccess (User File Access and Management)](js-apis-fileAccess.md) diff --git a/en/application-dev/reference/apis/js-apis-file-cloudsync.md b/en/application-dev/reference/apis/js-apis-file-cloudsync.md new file mode 100644 index 0000000000000000000000000000000000000000..e1a210c41c198c94539f427dbab3fdb5365b3ab5 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-file-cloudsync.md @@ -0,0 +1,642 @@ +# @ohos.file.cloudSync (Device-Cloud Synchronization) + +The **cloudSync** module provides the device-cloud synchronization capabilities for applications. You can use the APIs to start or stop device-cloud synchronization and start or stop the download of images. + +> **NOTE** +> +> - 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. +> - The APIs of this module are system APIs and cannot be called by third-party applications. + +## Modules to Import + +```js +import cloudSync from '@ohos.file.cloudSync' +``` + +## SyncState + +Enumerates the device-cloud synchronization states. + +> **NOTE** +> +> If a synchronization process event listener is registered for an application, a callback will be invoked to notify the application when any of the following states is changed. + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +| Name| Value| Description| +| ----- | ---- | ---- | +| UPLOADING | 0 | Uploading.| +| UPLOAD_FAILED | 1 | Upload failed.| +| DOWNLOADING | 2 | Downloading.| +| DOWNLOAD_FAILED | 3 | Download failed.| +| COMPLETED | 4 | Synchronization completed.| +| STOPPED | 5 | Synchronization stopped.| + +## ErrorType + +Enumerates the device-cloud synchronization error types. + +- Currently, **NETWORK_UNAVAILABLE** is returned only when both the mobile network and Wi-Fi are unavailable during synchronization. If either network is available, synchronization can be performed normally. +- During the synchronization process, if the battery level is lower than 15% in non-charging scenarios, **BATTERY_LEVEL_LOW** will be return when the current upload is complete; if the battery level is lower than 10% in non-charging scenarios, **BATTERY_LEVEL_WARNING** will be returned when the current upload is complete. +- When synchronization is triggered, if the battery level is lower than 15% in non-charging scenarios, synchronization is not allowed and an error code will be returned by **start()**. +- If the cloud space is insufficient when a file is uploaded, the upload will fail. +- If the local space is insufficient when a file is downloaded, the download will fail. After the local space is released, the file will be downloaded again when synchronization starts. + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +| Name| Value| Description| +| ----- | ---- | ---- | +| NO_ERROR | 0 | No error.| +| NETWORK_UNAVAILABLE | 1 | No network is available.| +| WIFI_UNAVAILABLE | 2 | Wi-Fi is unavailable.| +| BATTERY_LEVEL_LOW | 3 | The battery level is lower than 15%.| +| BATTERY_LEVEL_WARNING | 4 | The battery level is lower than 10%.| +| CLOUD_STORAGE_FULL | 5 | The cloud space is insufficient.| +| LOCAL_STORAGE_FULL | 6 | The local space is insufficient.| + +## SyncProgress + +Defines the device-cloud synchronization process. + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| state | [SyncState](#syncstate) | Yes | Device-cloud synchronization state.| +| error | [ErrorType](#errortype) | Yes | Synchronization error type.| + +## GallerySync + +Provides APIs to implement device-cloud synchronization of media resources of the Gallery. Before using the APIs of **GallerySync**, you need to create a **GallerySync** instance. + +### constructor + +constructor() + +A constructor used to create a **GallerySync** instance. + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Example** + + ```js + let gallerySync = new cloudSync.GallerySync() + ``` + +### on + +on(evt: 'progress', callback: (pg: SyncProgress) => void): void + +Subscribes to the synchronization process event. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| evt | string | Yes | Type of the event to subscribe to. The value is **progress**, which indicates the synchronization process event.| +| callback | (pg: SyncProgress) => void | Yes | Callback invoked to return the result. The input parameter is [SyncProgress](#syncprogress), and the return value is **void**.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | + +**Example** + + ```js + let gallerySync = new cloudSync.GallerySync(); + + gallerySync.on('progress', (pg: SyncProgress) => { + console.info("syncState: " + pg.syncState); + }); + ``` + +### off + +off(evt: 'progress'): void + +Unsubscribes from the synchronization process event. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| evt | string | Yes | Type of the event to unsubscribe from. The value is **progress**, which indicates the synchronization process event.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | + +**Example** + + ```js + let gallerySync = new cloudSync.GallerySync(); + + gallerySync.on('progress', (pg: SyncProgress) => { + console.info("syncState: " + pg.syncState); + }); + + gallerySync.off('progress'); + ``` + +### start + +start(): Promise<void> + +Starts device-cloud synchronization. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Return value** + +| Type | Description | +| --------------------- | ---------------- | +| Promise<void> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 22400001 | Cloud status not ready. | +| 22400002 | Network unavailable. | +| 22400003 | Battery level warning. | + +**Example** + + ```js + let gallerySync = new cloudSync.GallerySync(); + + gallerySync.on('progress', (pg: SyncProgress) => { + console.info("syncState: " + pg.syncState); + }); + + gallerySync.start().then(function() { + console.info("start sync successfully"); + }).catch(function(err) { + console.info("start sync failed with error message: " + err.message + ", error code: " + err.code); + }); + ``` + +### start + +start(callback: AsyncCallback<void>): void + +Starts device-cloud synchronization. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 22400001 | Cloud status not ready. | +| 22400002 | Network unavailable. | +| 22400003 | Battery level warning. | + +**Example** + + ```js + let gallerySync = new cloudSync.GallerySync(); + + gallerySync.start((err) => { + if (err) { + console.info("start sync failed with error message: " + err.message + ", error code: " + err.code); + } else { + console.info("start sync successfully"); + } + }); + ``` + +### stop + +stop(): Promise<void> + +Stops device-cloud synchronization. This API uses a promise to return the result. + +> **NOTE** +> +> Calling **stop** will stop the synchronization process. To resume the synchronization, call [start](#start). + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Return value** + +| Type | Description | +| --------------------- | ---------------- | +| Promise<void> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | + +**Example** + + ```js + let gallerySync = new cloudSync.GallerySync(); + + gallerySync.stop().then(function() { + console.info("stop sync successfully"); + }).catch(function(err) { + console.info("stop sync failed with error message: " + err.message + ", error code: " + err.code); + }); + ``` + +### stop + +stop(callback: AsyncCallback<void>): void + +Stops device-cloud synchronization. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> Calling **stop** will stop the synchronization process. To resume the synchronization, call [start](#start-1). + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | + +**Example** + + ```js + let gallerySync = new cloudSync.GallerySync(); + + gallerySync.stop((err) => { + if (err) { + console.info("stop sync failed with error message: " + err.message + ", error code: " + err.code); + } else { + console.info("stop sync successfully"); + } + }); + ``` + +## State + +Enumerates the download states of a cloud file. + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +| Name| Value| Description| +| ----- | ---- | ---- | +| RUNNING | 0 | The cloud file is being downloaded.| +| COMPLETED | 1 | The cloud file download is complete.| +| FAILED | 2 | The cloud file download failed.| +| STOPPED | 3 | The cloud file download is stopped.| + +## DownloadProgress + +Defines the download process of a cloud file. + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| state | [State](#state) | Yes | File download state.| +| processed | number | Yes | Size of data downloaded.| +| size | number | Yes | Current size of the file.| +| uri | string | Yes | URI of the file.| + +## Download + +Provides APIs for downloading the image files in Gallery. Before using the APIs of **Download**, you need to create a **Download** instance. + +### constructor + +constructor() + +A constructor used to create a **Download** instance. + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Example** + + ```js + let download = new cloudSync.Download() + ``` + +### on + +on(evt: 'progress', callback: (pg: DownloadProgress) => void): void + +Subscribes to the cloud file download event. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| evt | string | Yes | Type of the event to subscribe to. The value is **progress**, which indicates the download process event.| +| callback | (pg: DownloadProgress) => void | Yes | Callback invoked to return the result. The input parameter is [DownloadProgress](#downloadprogress), and the return value is **void**.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | + +**Example** + + ```js + let download = new cloudSync.Download(); + + download.on('progress', (pg: DownloadProgress) => { + console.info("download state: " + pg.state); + }); + ``` + +### off + +off(evt: 'progress'): void + +Unsubscribes from the cloud file download event. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| evt | string | Yes | Type of the event to unsubscribe from. The value is **progress**, which indicates the download process event.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13600001 | IPC error. | + +**Example** + + ```js + let download = new cloudSync.Download(); + + download.on('progress', (pg: DownloadProgress) => { + console.info("download state:" + pg.state); + }); + + download.off('progress'); + ``` + +### start + +start(uri: string): Promise<void> + +Starts to download a cloud file. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| uri | string | Yes | URI of the file to download.| + +**Return value** + +| Type | Description | +| --------------------- | ---------------- | +| Promise<void> | Promise used to return the result.| + +**Example** + + ```js + let download = new cloudSync.Download(); + + download.on('progress', (pg: DownloadProgress) => { + console.info("download state:" + pg.state); + }); + + download.start().then(function() { + console.info("start download successfully"); + }).catch(function(err) { + console.info("start download failed with error message: " + err.message + ", error code: " + err.code); + }); + ``` + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13900002 | No such file or directory. | +| 13900025 | No space left on device. | + +### start + +start(uri: string, callback: AsyncCallback<void>): void + +Starts to download a cloud file. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| uri | string | Yes | URI of the file to download.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | +| 13900002 | No such file or directory. | +| 13900025 | No space left on device. | + +**Example** + + ```js + let download = new cloudSync.Download(); + + download.start((err) => { + if (err) { + console.info("start download failed with error message: " + err.message + ", error code: " + err.code); + } else { + console.info("start download successfully"); + } + }); + ``` + +### stop + +stop(uri: string): Promise<void> + +Stops downloading a cloud file. This API uses a promise to return the result. + +> **NOTE** +> +> Calling **stop** will terminate the download of the current file and clear the cached file. You can use [start](#start-3) to start the download again. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| uri | string | Yes | URI of the file to download.| + +**Return value** + +| Type | Description | +| --------------------- | ---------------- | +| Promise<void> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | + +**Example** + + ```js + let download = new cloudSync.Download(); + + download.stop().then(function() { + console.info("stop download successfully"); + }).catch(function(err) { + console.info("stop download failed with error message: " + err.message + ", error code: " + err.code); + }); + ``` + +### stop + +stop(uri: string, callback: AsyncCallback<void>): void + +Stops downloading a cloud file. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> Calling **stop** will terminate the download of the current file and clear the cached file. You can use [start](#start-4) to start the download again. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| uri | string | Yes | URI of the file to download.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | + +**Example** + + ```js + let download = new cloudSync.Download(); + + download.stop((err) => { + if (err) { + console.info("stop download failed with error message: " + err.message + ", error code: " + err.code); + } else { + console.info("stop download successfully"); + } + }); + ``` diff --git a/en/application-dev/reference/apis/js-apis-file-cloudsyncmanager.md b/en/application-dev/reference/apis/js-apis-file-cloudsyncmanager.md index 4942ff0b537c71b02ccdc20700dc31978f12c990..aefe586ca9d7dbbb7e23c5c0478a88ca5b1834b9 100644 --- a/en/application-dev/reference/apis/js-apis-file-cloudsyncmanager.md +++ b/en/application-dev/reference/apis/js-apis-file-cloudsyncmanager.md @@ -1,20 +1,21 @@ # @ohos.file.cloudSyncManager (Device-Cloud Synchronization Management) -The **cloudSyncManager** module provides APIs for changing the cloud and device service status and notifying the data changes. +The **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. > **NOTE** +> > - 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. > - The APIs of this module are system APIs and cannot be called by third-party applications. ## Modules to Import ```js -import cloudSyncManager from '@ohos.file.cloudSyncManager'; +import cloudSyncManager from '@ohos.file.cloudSyncManager' ``` ## cloudSyncManager.changeAppCloudSwitch -changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise<void>; +changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean): Promise<void> Changes the device-cloud file synchronization switch for an application. This API uses a promise to return the result. @@ -37,6 +38,7 @@ Changes the device-cloud file synchronization switch for an application. This AP **Error codes** For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + | ID | Error Message | | ---------------------------- | ---------- | | 201 | Permission verification failed. | @@ -57,7 +59,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod ## cloudSyncManager.changeAppCloudSwitch -changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean, callback: AsyncCallback<void>): void; +changeAppCloudSwitch(accountId: string, bundleName: string, status: boolean, callback: AsyncCallback<void>): void Changes the device-cloud file synchronization switch for an application. This API uses an asynchronous callback to return the result. @@ -75,6 +77,7 @@ Changes the device-cloud file synchronization switch for an application. This AP **Error codes** For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + | ID | Error Message | | ---------------------------- | ---------- | | 201 | Permission verification failed. | @@ -97,7 +100,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod ## cloudSyncManager.notifyDataChange -notifyDataChange(accountId: string, bundleName: string): Promise<void>; +notifyDataChange(accountId: string, bundleName: string): Promise<void> Notifies the cloud and device services of the application data change in the cloud. This API uses a promise to return the result. @@ -119,6 +122,7 @@ Notifies the cloud and device services of the application data change in the clo **Error codes** For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + | ID | Error Message | | ---------------------------- | ---------- | | 201 | Permission verification failed. | @@ -139,7 +143,7 @@ For details about the error codes, see [File Management Error Codes](../errorcod ## cloudSyncManager.notifyDataChange -notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback<void>): void; +notifyDataChange(accountId: string, bundleName: string, callback: AsyncCallback<void>): void Notifies the cloud and device services of the application data change in the cloud. This API uses a promise to return the result. @@ -156,6 +160,7 @@ Notifies the cloud and device services of the application data change in the clo **Error codes** For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + | ID | Error Message | | ---------------------------- | ---------- | | 201 | Permission verification failed. | @@ -175,3 +180,275 @@ For details about the error codes, see [File Management Error Codes](../errorcod } }); ``` + +## cloudSyncManager.enableCloud + +enableCloud(accountId: string, switches: { [bundleName: string]: boolean }): Promise<void> + +Enables device-cloud synergy. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| accountId | string | Yes | Account ID.| +| switches | object | Yes | Whether to enable the device-cloud synergy feature. **bundleName** indicates the application bundle name. The switch status is a Boolean value.| + +**Return value** + +| Type | Description | +| --------------------- | ---------------- | +| Promise<void> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | + +**Example** + + ```js + let accountId = "testAccount"; + let switches = {"com.example.bundleName1": true, "com.example.bundleName2": false}; + cloudSyncManager.enableCloud(accountId, switches).then(function() { + console.info("enableCloud successfully"); + }).catch(function(err) { + console.info("enableCloud failed with error message: " + err.message + ", error code: " + err.code); + }); + ``` + +## cloudSyncManager.enableCloud + +enableCloud(accountId: string, switches: { [bundleName: string]: boolean }, callback: AsyncCallback<void>): void + +Enables device-cloud synergy. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| accountId | string | Yes | Account ID.| +| switches | object | Yes | Whether to enable the device-cloud synergy feature. **bundleName** indicates the application bundle name. The switch status is a Boolean value.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | + +**Example** + + ```js + let accountId = "testAccount"; + let switches = {"com.example.bundleName1": true, "com.example.bundleName2": false}; + cloudSyncManager.enableCloud(accountId, switches, (err) => { + if (err) { + console.info("enableCloud failed with error message: " + err.message + ", error code: " + err.code); + } else { + console.info("enableCloud successfully"); + } + }); + ``` + +## cloudSyncManager.disableCloud + +disableCloud(accountId: string): Promise<void> + +Disables device-cloud synergy. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| accountId | string | Yes | Account ID.| + +**Return value** + +| Type | Description | +| --------------------- | ---------------- | +| Promise<void> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | + +**Example** + + ```js + let accountId = "testAccount"; + cloudSyncManager.disableCloud(accountId).then(function() { + console.info("disableCloud successfully"); + }).catch(function(err) { + console.info("disableCloud failed with error message: " + err.message + ", error code: " + err.code); + }); + ``` + +## cloudSyncManager.disableCloud + +disableCloud(accountId: string, callback: AsyncCallback<void>): void + +Disables device-cloud synergy. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| accountId | string | Yes | Account ID.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | + +**Example** + + ```js + let accountId = "testAccount"; + cloudSyncManager.disableCloud(accountId, (err) => { + if (err) { + console.info("disableCloud failed with error message: " + err.message + ", error code: " + err.code); + } else { + console.info("disableCloud successfully"); + } + }); + ``` + +## Action + +Enumerates the actions that can be taken to clear local cloud data. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager + +| Name| Value| Description| +| ----- | ---- | ---- | +| RETAIN_DATA | 0 | Clear the cloud identifier but retain the files cached locally.| +| CLEAR_DATA | 1 | Clear the cloud identifier and the files cached locally.| + +## cloudSyncManager.clean + +clean(accountId: string, appActions: { [bundleName: string]: Action }): Promise<void> + +Clears the cloud data locally. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| accountId | string | Yes | Account ID.| +| appActions | object | Yes | Action to take. **bundleName** indicates the application bundle to clear, and [Action](#action) indicates the action to take.| + +**Return value** + +| Type | Description | +| --------------------- | ---------------- | +| Promise<void> | Promise used to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | + +**Example** + + ```js + let accountId = "testAccount"; + let appActions = {"com.example.bundleName1": cloudSyncManager.Action.RETAIN_DATA, + "com.example.bundleName2": cloudSyncManager.Action.CLEAR_DATA}; + cloudSyncManager.clean(accountId, appActions).then(function() { + console.info("clean successfully"); + }).catch(function(err) { + console.info("clean failed with error message: " + err.message + ", error code: " + err.code); + }); + ``` + +## cloudSyncManager.clean + +clean(accountId: string, appActions: { [bundleName: string]: Action }, callback: AsyncCallback<void>): void + +Clears the cloud data locally. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER + +**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSyncManager + +**Parameters** + +| Name | Type | Mandatory| Description| +| ---------- | ------ | ---- | ---- | +| accountId | string | Yes | Account ID.| +| appActions | object | Yes | Action to take. **bundleName** indicates the application bundle to clear, and [Action](#action) indicates the action to take.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| + +**Error codes** + +For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). + +| ID | Error Message | +| ---------------------------- | ---------- | +| 201 | Permission verification failed. | +| 202 | The caller is not a system application. | +| 401 | The input parameter is invalid. | + +**Example** + + ```js + let accountId = "testAccount"; + let appActions = {"com.example.bundleName1": cloudSyncManager.Action.RETAIN_DATA, + "com.example.bundleName2": cloudSyncManager.Action.CLEAR_DATA}; + cloudSyncManager.clean(accountId, appActions, (err) => { + if (err) { + console.info("clean failed with error message: " + err.message + ", error code: " + err.code); + } else { + console.info("clean successfully"); + } + }); + ``` diff --git a/en/application-dev/reference/errorcodes/errorcode-filemanagement.md b/en/application-dev/reference/errorcodes/errorcode-filemanagement.md index 219f56460536de918a7bf5b631000e562ce2e507..a6e026d158f7911247d89418d32cac803e3b3c4a 100644 --- a/en/application-dev/reference/errorcodes/errorcode-filemanagement.md +++ b/en/application-dev/reference/errorcodes/errorcode-filemanagement.md @@ -10,6 +10,7 @@ The error codes of the file management subsystem include the following: - [User Data Management Error Codes](#user-data-management-error-code) - [User File Access Error Codes](#user-file-access-error-codes) - [Space Statistics Error Codes](#space-statistics-error-codes) +- [Device-Cloud Synchronization Error Codes](#device-cloud-synchronization-error-codes) ## Basic File IO Error Codes @@ -155,7 +156,7 @@ The resources are blocked. **Solution** -Request resources. +Request the resource again. ### 13900011 Memory Overflow @@ -273,7 +274,7 @@ The specified directory is invalid. **Solution** -Check that the directory is correct. +Check that the specified directory is correct. ### 13900019 The Specified Object Is a Directory @@ -297,7 +298,7 @@ Invalid argument **Possible Causes** -Invalid input parameter is detected. +The input parameter is invalid. **Solution** @@ -477,7 +478,7 @@ The specified directory is not empty. **Error Message** -Too many symbolic links +Too many symbolic links encountered **Possible Causes** @@ -593,7 +594,7 @@ Quota exceeded **Possible Causes** -The disk space is insufficient. +The storage space is insufficient. **Solution** @@ -926,3 +927,51 @@ Fail to notify agent **Solution** Check whether the client is normal. + +## Device-Cloud Synchronization Error Codes + +### 22400001 Cloud Unavailable + +**Error Message** + +Cloud status not ready + +**Possible Causes** + +1. The cloud is not enabled. + +2. The cloud synchronization switch is not enabled for the application. + +**Solution** + +1. Check that the user has logged in with a cloud account. + +2. Check that the cloud synchronization switch is enabled. + +### 22400002 Network Unavailable + +**Error Message** + +Network unavailable + +**Possible Causes** + +The device is not connected to the network or the network is unavailable. + +**Solution** + +Check the network status. + +### 22400003 Low Battery Level + +**Error Message** + +Battery level warning + +**Possible Causes** + +The battery level is low. + +**Solution** + +Perform the operation after the battery is being charged or the battery level is restored.