Help Center/ Cloud Phone Host/ Best Practices/ Installing an Application on Cloud Phones in Batches
Updated on 2023-03-16 GMT+08:00

Installing an Application on Cloud Phones in Batches

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

The cloud phone that has the application installed is regarded as 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. Otherwise, reset it.

Procedure

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

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

    Figure 2 Create Bucket Policy
  2. Connect to the seed cloud phone in ADB mode and install the required application on it.

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

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

    curl command

    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 data exported
    • object_path: OBS path for storing the data exported

    If you want to pack all data of applications on the seed cloud phone, 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}

    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 the file packed and uploaded in 3 is successfully uploaded. If yes, go to the next step.
  5. Differentiate storage 1.0 and storage 2.0 servers in this step.
    • Servers of storage 2.0 (recommended)

      Call an API to push files stored in the OBS bucket to the server.

      Example of the curl command

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

      Parameter descriptions:

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

      For details about this API, see Pushing a Shared Application.

    • Servers of storage 1.0

      Call an API to push files stored in the OBS bucket to the shared storage directory of the server.

      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: IDs of servers that receive the file pushed. If multiple server IDs are specified, the application can be installed on cloud phones on multiple servers.

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

  1. Differentiate storage 1.0 and storage 2.0 servers in this step.
    • Servers of storage 2.0 (recommended)

      Run the appctrl install package_name command on the cloud phone to install the application. package_name corresponds to the value of package_name in 5, for example, com.miniteck.miniworld.

    • Servers of storage 1.0
      Log in to the CPH console, click the name of the server that has received the files pushed. In the Cloud Phones area, select all cloud phones on which the application needs to be installed, and click Reset.

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

Execution Results

For servers that use storage 1.0, the applications have been installed after the cloud phones are reset.

For servers that use storage 2.0, the applications can be directly started by running appctrl start package_name package.activity_name.