Help Center> Cloud Phone Host> Best Practices> Installing an App on Cloud Phones in Batches

Installing an App on Cloud Phones in Batches

After you install an app on a cloud phone, you can share and install the app on multiple cloud phones by calling an API.

Assume that the cloud phone has the app installed is a seed cloud phone.

Restrictions and Limitations

  • This solution applies only to cloud phones whose specifications name does not contain qemu.
    Figure 1 Specifications
  • The seed cloud phone must be a cloud phone that has not been operated on. If there is any operation on the cloud phone, reset it.

Procedure

  1. Log in to the management console and choose Storage > Object Storage Service. Create an OBS bucket and configure permissions for accessing the bucket. For details, see Managing Cloud Phones in Batches.

    Note: To successfully upload files to the bucket, select Directory read and write when configuring the bucket policy.

    Figure 2 Configuring the bucket policy
  2. Connect to the seed cloud phone in ADB mode and install required app on it.

    For details, see How Do I Install Apps on a Cloud Phone?

  3. Call the API to export the seed cloud phone data, pack the data, and upload the data package to the OBS bucket created in 1.

    The curl command is as follows:

    curl -i -k -X POST "https://${CPH Endpoint}/v1/${projectId}/cloud-phone/phones/batch-storage" -H "Content-Type: application/json" -H "X-Auth-Token: $token" -d '
    {
        "storage_infos": [
            {
                "phone_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                "include_files": [
                    "/data/app/${package-name}-1",
                    "/data/data/${package-name}",
                    "/data/media/0/Android/data/${package-name}"
                ],
                "bucket_name": "${bucket_name}",
                "object_path": "${your_dir}/${package-name}.tar"
            }
        ]
    }'

    Parameter descriptions:

    • phone_id: ID of the seed cloud phone
    • bucket_name: name of the OBS bucket for storing the exported data
    • object_path: OBS path for storing the exported data

    If you want to pack all data of the seed cloud phone app, the following three paths must be included:

    • /data/app/${package-name}-1

      ${package-name} may not be followed by -1. Configure this parameter as required.

    • /data/data/${package-name}
    • /data/media/0/Android/data/${package-name}

    The following is an example.

    curl -i -k -X POST "https://${CPH Endpoint}/v1/${projectId}/cloud-phone/phones/batch-storage" -H "Content-Type: application/json" -H "X-Auth-Token: $token" -d '
    {
        "storage_infos": [
            {
                "phone_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                "include_files": [
                    "/data/app/com.taptap-1",
                    "/data/data/com.taptap",
                    "/data/media/0/Android/data/com.taptap"
                ],
                "bucket_name": "your-bucket-name",
                "object_path": "your/dir/taptap.tar"
            }
        ]
    }'
  4. View the OBS bucket created in 1 and check whether all files packed and uploaded in 3 are successfully uploaded. If yes, go to the next step.
  5. Call an API to push files stored in the OBS bucket to the shared storage directories of the servers.

    The following is an example of the curl command:

    curl -i -k -X POST "https://${CPH Endpoint}/v1/${projectId}/cloud-phone/phones/share-files" -H "Content-Type: application/json" -H "X-Auth-Token: $token" -d '
    {
        "bucket_name": "your-bucket-name", 
        "object_path": "your/dir/taptap.tar",
        "server_ids": ["1678567b8bab40f93711234cb8","1234567b8bab40ffb711234cb"]
    }'

    Parameter descriptions:

    • bucket_name and object_path are the same as those in 3.
    • server_ids: ID list of servers that receive the file push If multiple server IDs are specified, the app can be installed on cloud phones on multiple servers.

    For details about this API, see Pushing Shared Storage Files.

  6. Log in to the Cloud Phone console, click the name of the server that has received the files pushed. In the Instances area, select all cloud phones on which the preceding app needs to be installed, and click Reset.

    This step is a reset operation, not a restart operation.

Execution Result

The app on the seed cloud phone has been installed on all other cloud phones.