androidandroid-management-api

Creating enrollment token gives back wrong QR code


I'm trying to provision a device with QR code method according to these documentations.

I'm using this Google collab quickstart guide to do so.

Right now, I'm stuck here:

enrollment_token = androidmanagement.enterprises().enrollmentTokens().create(
    parent=enterprise_name,
    body={
        "policyName": policy_name,
        "qrCode": "{'android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME': 'com.tmp.app.admin/.AdminReceiver','android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM': 'MUQ6NEQ6MDQ6NTY6M0E6ODA6Mzg6NEY6NUM6ODI6Qzk6NUY6MkM6QjA6RTk6RDc6QTM6RjI6NDg6NTA6QTQ6RjY6QTA6RjM6MTA6NUM6MzI6NkY6QkU6NUI6M0E6Qzk%3D','android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION':'https://myurl-stuff.com/link_part/my_app.apk','android.app.extra.PROVISIONING_SKIP_ENCRYPTION': false,'android.app.extra.PROVISIONING_WIFI_SSID': 'MY_WIFI_SSID','android.app.extra.PROVISIONING_WIFI_PASSWORD': 'my_wifi_password','android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE': 'WPA'}"
         }
).execute()


json.dumps(enrollment_token, indent=2)

Whenever I run this code, the output is the following.

{\n  "name": "enterprises/LC00y54m79/enrollmentTokens/UV4yLfxoyWSln7CArwtp7OJQiHH_Gvc76JttPa4-r48",\n  "value": "ZBNWPOWHBQUPNLMBTNRU",\n  "expirationTimestamp": "2023-02-06T12:43:34.634467Z",\n  "policyName": "enterprises/LC00y54m79/policies/policy1",\n  "qrCode": "{\\"android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME\\":\\"com.google.android.apps.work.clouddpc/.receivers.CloudDeviceAdminReceiver\\",\\"android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM\\":\\"I5YvS0O5hXY46mb01BlRjq4oJJGs2kuUcHvVkAPEXlg\\",\\"android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION\\":\\"https://play.google.com/managed/downloadManagingApp?identifier=setup\\",\\"android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE\\":{\\"com.google.android.apps.work.clouddpc.EXTRA_ENROLLMENT_TOKEN\\":\\"ZBNWPOWHBQUPNLMBTNRU\\"}}"\n}

It is the default Google example and it does not contains my application, instead, it contains Google's official example app.

What am I doing here wrong?

EDIT:

I have syntax error with double quotes.

enter image description here

EDIT 2:

Also tried with starting and ending single quotes like:

'{"android.app.extra (...)

Also tried with starting and ending with triple quotes like in Google's previous example like here:

enter image description here

But still no luck.

The api either returns a syntax error or simple doesn't returns with my app/parameters in the qrCode, instead it replaces to their own example project.

EDIT 3:

Tried like this:

enter image description here

But with no success:

enter image description here


Solution

  • There are two ways to manage devices :

    You are trying to mix the two approaches. It is no longer possible :

    Android Enterprise is no longer accepting new registrations for custom device policy controllers (DPC) using the Google Play EMM API. All new EMM solutions should now use Android Management API, which comes with its own DPC provided by Google.

    The Google DPC is the com.google.android.apps.work.clouddpc you are seeing in the generated QR code.

    If you want to use you own DPC, you need to use the json containing the android.app.extra.PROVISIONING* keys directly, without wrapping it in a Google token.

    The content looks fine except the SSID has to be quoted, and the signature hash should not be percent encoded :

    {
        "android.app.extra.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME": "com.tmp.app.admin/.AdminReceiver",
        "android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION": "https://myurl-stuff.com/link_part/my_app.apk",
        "android.app.extra.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM": "MUQ6NEQ6MDQ6NTY6M0E6ODA6Mzg6NEY6NUM6ODI6Qzk6NUY6MkM6QjA6RTk6RDc6QTM6RjI6NDg6NTA6QTQ6RjY6QTA6RjM6MTA6NUM6MzI6NkY6QkU6NUI6M0E6Qzk=",
        "android.app.extra.PROVISIONING_SKIP_ENCRYPTION": false,
        "android.app.extra.PROVISIONING_WIFI_PASSWORD": "my_wifi_password",
        "android.app.extra.PROVISIONING_WIFI_SECURITY_TYPE": "WPA",
        "android.app.extra.PROVISIONING_WIFI_SSID": "\"MY_WIFI_SSID\""
    }
    

    You just have to generate a QR code containing this content (with any generator), and scan it with the device.

    Unfortunately the provisioning process is not forgiving. If something is wrong, the device shows a "Provisionning failed" error message without any clue. You have to triple check everything.