5

我正在尝试使用 NFC 在设备上设置设备所有者包。此处的棒棒糖概述中提到了:

要部署和激活设备所有者,您必须在设备处于未配置状态时执行从编程应用程序到设备的 NFC 数据传输。此数据传输发送的信息与托管供应中描述的供应意图中的信息相同。

原因是一旦设置好,您就可以使用屏幕固定功能将设备锁定在信息亭模式。我已经能够通过将 device_owner.xml 文件放置到根设备上的 data/system/ 来手动设置设备所有者来测试此信息亭模式。

我以前从未使用过 NFC,所以我可能会走得很远,但我根据这里的信息想出了以下 NdefMessage :

Properties properties = new Properties();
properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, "com.my.package");
properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID, "MyWiFiSSID");
properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PASSWORD, "WifiPassword");
properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM, "C9AD9E082457819B54CF76255A400375E4127112");
properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION, "https://dl.dropboxusercontent.com/u/xxx/app-release.apk");


ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(properties);
byte[] yourBytes = bos.toByteArray();
NdefRecord ndefRecord = NdefRecord.createMime(DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, yourBytes);
NdefMessage msg = new NdefMessage(ndefRecord);

将此发送到我刚刚使用 Lollipop 预览恢复的设备会导致它显示:

哎呀!无法设置您的设备。请联系您的 IT 部门。

它似乎认识到它正在接收供应请求的事实,但我不认为它正在读取我设置的属性,它不会尝试连接 wifi。

4

3 回答 3

4

看来您需要使用Properties.store为 NdefRecord 正确创建字节。

Properties properties = new Properties();
properties.setProperty(...);

ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStream out = new ObjectOutputStream(bos);
properties.store(out, "");
byte[] bytes = bos.toByteArray();

NdefMessage msg = new NdefMessage(NdefRecord.createMime(DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, bytes));

目前,我在下载我的 APK 并且校验和失败时遇到问题。完全不知道为什么。

于 2014-10-22T13:54:12.627 回答
1

我也一直试图让它通过 NFC 工作。我在我的 Nexus 4 (KitKat) 上安装了一个简单的应用程序,其中包含一个活动:

@Override
protected void onResume() {
    super.onResume();
    try {
        Properties properties = new Properties();
        properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, "com.deviceowner.app");
        properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION, "https://docs.google.com/uc?export=download&id=........");
        properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_CHECKSUM, "6ee735dfb8090ab1862fecce430864e21a0e37");
        properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SSID, "wlan");
        properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_PASSWORD, "XXXXXX");
        properties.setProperty(DevicePolicyManager.EXTRA_PROVISIONING_WIFI_SECURITY_TYPE, "WPA2");

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(bos);
        out.writeObject(properties);
        byte[] yourBytes = bos.toByteArray();
        NdefRecord ndefRecord = NdefRecord.createMime(DevicePolicyManager.MIME_TYPE_PROVISIONING_NFC, yourBytes);
        NdefMessage msg = new NdefMessage(ndefRecord);
        nfcAdapter.setNdefPushMessage(msg, this);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

我用 Lollipop 预览图像 (razor-lpx13d-preview-ae4f461f.tgz) 刷新了我的 Nexus 7,并在 Nexus 7 未配置时(没有设置 - 刷新后新鲜)给它与 Nexus 4 的 NFC 碰撞并得到同样的错误信息:

哎呀!无法设置您的设备。请联系您的 IT 部门。

然后我尝试了同样的事情,但这次是在 Nexus 7 上运行了初始设备设置之后(直到我可以看到主屏幕)。这次我收到了消息

哎呀!此设备已设置

但是这一次,我能够看到一些日志记录,因为我能够在 Nexus 7 上设置 USB 调试:

10-22 10:31:29.947    2610-2610/? D/NfcService﹕ LLCP Activation message
10-22 10:31:29.947    2610-2610/? I/NfcP2pLinkManager﹕ LLCP activated
10-22 10:31:29.947    2610-2610/? D/NfcP2pLinkManager﹕ onP2pInRange()
10-22 10:31:29.954    2610-2610/? W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
10-22 10:31:29.962      184-547/? D/audio_hw_primary﹕ select_devices: out_snd_device(2: speaker) in_snd_device(0: none)
10-22 10:31:29.962      184-547/? D/ACDB-LOADER﹕ ACDB -> send_afe_cal
10-22 10:31:29.962      184-547/? D/audio_hw_primary﹕ enable_snd_device: snd_device(2: speaker)
10-22 10:31:29.974      184-547/? D/audio_hw_primary﹕ enable_audio_route: apply and update mixer path: low-latency-playback
10-22 10:31:29.981    2610-2610/? D/NfcP2pLinkManager﹕ Last registered callback is not running in the foreground.
10-22 10:31:29.987    2610-2610/? D/NfcP2pLinkManager﹕ Disabling default Beam behavior
10-22 10:31:29.987    2610-2610/? D/NfcP2pLinkManager﹕ mMessageToSend = null
10-22 10:31:29.987    2610-2610/? D/NfcP2pLinkManager﹕ mUrisToSend = null
10-22 10:31:29.996    2610-2610/? D/NfcP2pLinkManager﹕ Took 48 to get first LLCP PDU
10-22 10:31:30.599    3224-3224/? I/wpa_supplicant﹕ wlan0: CTRL-EVENT-SCAN-STARTED
10-22 10:31:31.741    2610-2610/? D/NfcP2pLinkManager﹕ onP2pReceiveComplete()
10-22 10:31:31.751    2610-2610/? D/NfcService﹕ mock NDEF tag, starting corresponding activity
10-22 10:31:31.751    2610-2610/? D/NfcService﹕ TAG: Tech [android.nfc.tech.Ndef]
10-22 10:31:31.757    2610-3275/? W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
10-22 10:31:31.770     549-2765/? I/ActivityManager﹕ START u0 {flg=0x10008000 cmp=com.android.nfc/.NfcRootActivity (has extras)} from uid 1027 on display 0
10-22 10:31:31.795    7237-7237/? D/ManagedProvisioning﹕ Device owner provisioning activity ONDESTROY
10-22 10:31:31.827    2610-3275/? W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client
10-22 10:31:31.848     549-2335/? I/ActivityManager﹕ START u0 {act=android.nfc.action.NDEF_DISCOVERED typ=application/com.android.managedprovisioning cmp=com.android.managedprovisioning/.DeviceOwnerProvisioningActivity (has extras)} from uid 1027 on display 0
10-22 10:31:31.886    7237-7237/? D/ManagedProvisioning﹕ Device owner provisioning activity ONCREATE
10-22 10:31:31.887    7237-7237/? E/ManagedProvisioning﹕ Device already provisioned.
10-22 10:31:31.903    7237-7237/? D/ManagedProvisioning﹕ Device owner provisioning activity ONRESUME
10-22 10:31:32.011      549-621/? I/ActivityManager﹕ Displayed com.android.managedprovisioning/.DeviceOwnerProvisioningActivity: +149ms (total +200ms)
10-22 10:31:32.955    2610-2610/? D/NfcService﹕ LLCP Link Deactivated message. Restart polling loop.
10-22 10:31:32.955    2610-2610/? I/NfcP2pLinkManager﹕ LLCP deactivated.
10-22 10:31:32.955    2610-2610/? D/NfcP2pLinkManager﹕ Debounce timeout
10-22 10:31:32.955    2610-2610/? D/NfcP2pLinkManager﹕ onP2pOutOfRange()

因此,设备所有者 NFC 碰撞似乎只能在未配置的设备上发生。我很欣赏这不能回答您的问题,但日志输出可能会有所帮助。掌握 DeviceOwnerProvisioningActivity 的源代码肯定会有所帮助。

于 2014-10-22T09:50:16.367 回答
1

您应该手动输入 WiFi 参数。Android 5.1 中已更正了一个错误。

于 2015-06-16T15:25:46.270 回答