简体   繁体   中英

How to pass enrolment token when using NFC enrolment

I am trying to provision my device using NFC and been following the guide where all the steps are mentioned along with the default parameters, the link is as follows:

https://developers.google.com/android/work/play/emm-api/prov-devices#nfc_method

I am able to send WiFi configuration, settings, and provisioning details required, which my device (un-provisioned device) can successfully recognise but I failed to send the enrolment token as it's not mentioned in the doc how to send it.

Using the provided configurations the device first tries to connect to WiFi and the download the Policy app from google play but failed to read enrolment token and prompt to provide it manually.

Please let me know what I am doing wrong. thanks :)

Code:

    private void gatherAdminExtras(HashMap<String, String> values) {
        Properties props = new Properties();
        Set<String> keys = new HashSet<>(values.keySet());
        for (String key : keys) {
            if (key.startsWith("android.app.extra")) {
                continue;
            }
            props.put(key, values.get(key));
            values.remove(key);
        }
        StringWriter sw = new StringWriter();
        try{
            props.store(sw, "{\"com.google.android.apps.work.clouddpc.EXTRA_ENROLLMENT_TOKEN\": \"{Enrolment_Token}\"}");
            values.put(DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE,
                    sw.toString());
            Log.d(TAG, "Admin extras bundle=" + values.get(
                    DevicePolicyManager.EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE));
        } catch (IOException e) {
            Log.e(TAG, "Unable to build admin extras bundle");
        }
    }

GitHub issue link: https://github.com/android/enterprise-samples/issues/32

The admin extras should be properly formatted as a java property to accomplish this.

The data written to the NFC tag should be similar to this one:

android.app.extra.PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME=com.google.android.apps.work.clouddpc

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\=XXXXXXXXXXXXXXXXXXXX\n

android.app.extra.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED=true

If the JSON in extras contains multiple keys, all the information should be string encoded as well.

{
 "android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE" : {
   "key1": "value1",
   "key2": "value2"
  }
}

The above JSON should be written as:

android.app.extra.PROVISIONING_ADMIN_EXTRAS_BUNDLE=key1\=value1\nkey2\=value2\n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM