We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

Deploying the Cloud Environment for Device-Cloud Data Sync

Use Cases

Data syncing allows you to store data to HUAWEI Mobile Cloud in a timely manner and sync data between devices logged in to the same HUAWEI ID. This function is used to meet the following experience requirements:

  • Data security backup: Data will not be permanently lost due to app uninstallation, device loss, or device damage. App data can be automatically restored after app re-installation.
  • Multi-device data consistency: Data is automatically and promptly consistent between devices logged in to the same HUAWEI ID, improving multi-device collaboration efficiency and ensuring consistent experience.
NOTE

You need to go to Settings > Cloud and turn on the syncing switch, and make sure that HUAWEI Mobile Cloud has sufficient storage space.

Service Highlights

  • Easy integration

    Simplified development: Developers can use the device-cloud synchronization function to quickly add the cloud synchronization function for applications.

    Focus on the core: Developers only need to focus on the core service logic of applications. The complexity of data synchronization is handled by ArkData and cloud space.

    Cost saving: You do not need to set up and manage servers, databases, storage resources, or bandwidth resources.

  • Seamless all-scenario synchronization

    Wide coverage: Devices that support synchronization include mobile phones, tablets, and PCs.

    Timely and consistent: Automatic and timely synchronization of user data ensures consistent experience.

    Offline availability: Even if the consumer device is temporarily disconnected from the network, the local data can be accessed and used normally. After the network is restored, the changes are automatically synchronized to the cloud and other devices.

  • Security and privacy

    Secure storage: User data is stored in HUAWEI Mobile Cloud in the form of multiple copies, which is more reliable.

    Privacy protection: Encrypts user data before storing it to the cloud, ensuring that user data can be accessed only by the user.

  • Easy to use

    Easy to use: You only need to log in to your HUAWEI ID and turn on the synchronization switch. The service will be automatically enabled.

    Easy data management: HUAWEI Mobile Cloud provides a unified and easy-to-use settings and data management screen. Users can manage synchronization and data stored on the cloud by choosing Settings > Cloud.

Constraints

  • If synchronization is triggered too frequently, traffic may be limited by the cloud. You are advised to enable this function only for user data items that trigger changes. You are not advised to use this function in background scheduled tasks or other scenarios where changes are frequent and not discrete.
  • Currently, only the Chinese mainland is supported. The system version must be HarmonyOS 6.1.0 or later, and the Cloud version must be 6.3.0 or later.
  • Devices with cloud space services installed, such as mobile phones, tablets, and PCs/2-in-1 devices, are supported.

Basic Concepts

  • Container: Applications use logical space called containers to store and manage data. Generally, each application corresponds to a container. Each container represents the storage space of an application in the cloud space and is isolated from data of other applications.
  • Record Type: data item name defined by the app. It consists of one or more fields and needs to be defined based on the service model. For example, the data item name can be Todo. A container can contain multiple record types. Once deployed in the production environment, data types and fields cannot be deleted or modified.
  • Record Field: column in the record type, which is used to store specific data. For example, the Todo field may contain the Title, Time, and Comment fields.
  • Record: specific data entry stored in the record type. Each record corresponds to a row of data and contains one or more fields.
  • Development environment: used for debugging. Developers have full configuration and data management rights, and can add, delete, modify, and query data type configurations and debugging data records. Developers must exercise caution when configuring the development environment in the production environment. Once the development environment is deployed, it cannot be modified.
  • Production environment: Developers can view or add data type configurations, but cannot modify or delete them.

Integration Procedure

The access needs to be configured on both the cloud and device. On the cloud, you need to create a container and configure data types to determine the data storage space and cloud fields of your app in the cloud space. On the device, you need to declare the access fields and connection environment to display the sync switch and debug the sync function on the device.

Prerequisites

Operations on the Cloud

  1. Go to the cloud synchronization page.

    Sign in to AppGallery Connect, click Development and services, and select My projects.

    Find your project and click the app for which you want to create a container.

    Enable the cloud space on the API management or open capability management page.

    Click All Features (below the left navigation tree), go to the cloud space service page under Build, and click the fixed button to display the service in the left navigation tree.

  2. Run the following command to create a container:

    On the cloud synchronization service page, create a container with custom name.

    The container name must be the same as the local ArkData database name. For example, if the ArkData database name is note.db, the container name is note (case-sensitive). You do not need to enter the suffix.

    You can access the data type configuration page only after the container is created.

  3. Configure the data type.

    On the Cloud Synchronization Service page, click the Data Type Configuration tab, and set data type and custom field. You can add, delete, modify, and query data types as required.

    The data type name must be the same as the name of the local ArkData table.

    The name and type of the custom field on the cloud must be the same as those of the field for local data to access the cloud space. The change relationships are as follows.

    Expand
    Cloud Field Type Local Field Type
    Encrypted String/String TEXT
    Integer INTEGER
    Double DOUBLE
    Bytes BLOB
    NOTE
    • When setting the type of a customized field, if the field is of the string type, you can select an encrypted field (with the prefix Encrypted) to protect user data privacy.

    • After a field is added as an encrypted field, the performance and efficiency of device-cloud synchronization may be affected. You are advised to select an encrypted field based on the data security level.

    • By default, all configuration fields on the cloud can be empty. The NOT NULL attribute cannot be set for all fields in the local ArkData table.

    • When setting a field in the ArkData local table to the primary key, you need to perform the following operations on the cloud: Expand the advanced settings, drop-down deduplicate primary key on device, and select the field for which the primary key attribute is set locally.

  4. Commission multi-device synchronization.

    Commissioning scheme 1:

    On the home page of the cloud synchronization service, choose Data record debugging, select the data type and field to be viewed from the Data type and Field drop-down lists, and click Search to view personal data on the cloud.

    NOTE
    • On this page, you can only query and modify the data of your own account. If other accounts are used for device-side commissioning, you cannot query the data on this page. To use this page, log in to the same developer account for client commissioning.

    • The content of encrypted fields cannot be viewed on the data record commissioning page. To view the content of encrypted fields, use commissioning scheme 2.

    • Data occupies cloud storage space. Make sure there is enough space.

    Commissioning scheme 2:

    Log in to the two devices using the same account. Open the app on device A and add data. Then open the app on device B and check whether the data written on device A is synchronized to the local device.

  5. Reset the development environment.

    Developers can perform this operation to quickly delete a large amount of temporary data and configurations generated during commissioning.

    On the Cloud Sync home page, click Reset Development Environment, select I understand that all data will be deleted and cannot be retrieved, and click Reset in the dialog box that is displayed.

    All data type configurations will be reset (if the configurations have been changed to the production environment, the configurations will be the same as those in the production environment). All personal data will be cleared and the operation cannot be undone. Exercise caution when performing this operation.

  6. Deploying the production environment

    After the multi-device synchronization commissioning is complete in the development environment and the configuration meets service requirements, developers can change the development environment configuration to the production environment. If new configurations are added later, repeat this operation.

    On the Cloud Synchronization Service page, select Change to production environment and click Implement in the displayed dialog box.

    Exercise caution when performing this operation. After the operation is performed, the operation cannot be withdrawn, and the configuration cannot be deleted or modified. Only the configuration can be added.

Operations on the Device

  1. App declaration

    You can configure the cloudStructuredDataSyncEnabled field in the app tag of the app.json5 file to determine whether to access the cloud synchronization capability. If the field is set to true, the cloud synchronization capability is accessed. You can view the application switch in Settings > Cloud.

    {
      "app": {
        "cloudStructuredDataSyncEnabled": true
      }
    }
  2. Environment connection

    If the certificate type of the app is debug, the app connects to the development environment. If the certificate type of the app is release, the app connects to the production environment.

  3. For details about the development process, see Developing RDB Store for Device-Cloud Data Synchronization (ArkTS).

  4. Experience design suggestions.

    When the in-app settings synchronization switch is turned on, prompt and guide the user to go to the cloud space page to turn on the switch.

    User data is a valuable data asset of users and one of the important reasons for continuous use of applications. It is recommended that the synchronization status be explicit to make services more transparent and users more comfortable.

    Synchronization is affected by the function enabling status, network conditions, and cloud storage space. For details, see Device-Cloud Synchronization Status Code. Example:

    • Added the notification "Syncing with Cloud" when the synchronization is in progress.

    • If the synchronization is complete and the completion status code is available, add a reminder by referring to the following table.

      Expand
      completion status code Suggestion
      0 Synced with cloud.
      1 Syncing with cloud paused.
      2 Network error. Syncing with cloud paused.
      3 Sync disabled.
      4 Cloud syncing paused. It will automatically resume later.
      5 Data limit exceeded. Syncing with cloud paused.
      6 Insufficient cloud storage. Go to Settings > Cloud to manage.
      7 No Wi-Fi connection. Syncing with cloud paused.
      NOTE

      Go to Settings > Cloud. You can also add a Deeplink text link. You can click the link to go to the cloud space home page. The URI is hicloud://cloudDrive/getInfo?path=MainActivity.

Personal Data Processing Information

This document describes the processing of personal data where Huawei acts as the data processor and the developer acts as the data controller for end-user data. It covers the following:

  • List of personal data processed by Huawei
  • Guidance for you to help end users control personal data

List of Personal Data Processed by Huawei

Expand
Personal Data Processing Purpose Retention Period
User data Data backup and synchronization. The scope of data stored on the cloud is specified by the app and confirmed by the end user (by going to Settings > Cloud to enable or disable the syncing function). This is to prevent permanent data loss caused by app uninstallation, device loss, or device damage, and ensure data consistency between devices logged in to the same HUAWEI ID. Data stored on the cloud will be retained until the end user deletes the data.

Guidance for you to help users control personal data

  • How to clear end users' data stored on the cloud

    End users can delete data stored on the cloud by going to the storage space management page under Settings > Cloud and using the ''stop syncing and delete cloud data'' feature. Data stored on the device will not be deleted.

  • How to export end-user data

    It is recommended that the app provide the in-device export function.

  • How to ensure that users are aware of data management rights

    Describe the purpose and scope of storing data to the cloud in the privacy statement. You can refer to the following information (which can be adjusted by developers): For the purpose of {user experience description}, {data item name} and other data will be synced between devices logged in to HUAWEI ID through HUAWEI Mobile Cloud. You can manage the syncing feature and data stored on Cloud by going to Settings > Cloud.

FAQs

Unable to find the cloud space service in AppGallery Connect

On the Development and services page, expand all features in the lower left corner. Find cloud space servces under Build and pin it to the navigation tree on the left for future use.

Error message in the log: {"schedule":2,"code":1,"details":{}}

The possible solutions are listed below:

  1. The data type in the local table does not comply with the basic data type of Sqlite. Check whether the data type in the table complies with the specifications.
  2. The configuration on the cloud is inconsistent with that on the device. Check the following items:
    • Whether to set a distributed table.
    • Check whether the table name matches the configuration on the cloud.
    • Check whether the field attributes in the table match the configuration on the cloud. For details about the field restrictions, see step 3 in Operations on the Cloud.

If the problem persists, try the following:

  1. Log out of your HUAWEI ID and log in again.
  2. Uninstall the development application and reinstall it.

After the data type configuration is modified on the cloud, the synchronization on the device fails.

Log out of the HUAWEI ID and log in again.

Search in Guides
Enter a keyword.