目录

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:

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

Constraints

Basic Concepts

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.

[h2]Prerequisites

[h2]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.

    Cloud Field Type Local Field Type
    Encrypted String/String TEXT
    Integer INTEGER
    Double DOUBLE
    Bytes BLOB
    • 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.

    • 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.

[h2]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.

      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.

      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:

[h2]List of Personal Data Processed by Huawei

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.

[h2]Guidance for you to help users control personal data

FAQs

[h2]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.

[h2]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.

[h2]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.