Android Kiosk mode not working when using Android Management API Policy

蹲街弑〆低调 提交于 2020-02-28 05:40:30

问题


So I'm trying to get a single use, dedicated app + device to work in kiosk mode + auto launch. The app itself is built in Nativescript (with Angular), so not native Java, however this is still handled via an admin receiver etc as normal.

When we use adb to set the device owner, kiosk mode works as expected.

adb shell dpm set-device-owner com.domain.app/.DeviceAdminReceiver

When we use an Android Management policy to enrol the device and auto install, the kiosk mode is never initiated correctly.

{
  "name": "enterprises/LC00mpaqaj/policies/policy1",
  "version": "12",
  "applications": [
    {
      "packageName": "com.domain.app",
      "installType": "FORCE_INSTALLED",
      "lockTaskAllowed": true,
      "defaultPermissionPolicy": "GRANT"
    }
  ],
  "persistentPreferredActivities": [
    {
      "receiverActivity": "com.domain.app/.DeviceAdminReceiver",
      "actions": [
        "android.intent.action.MAIN"
      ],
      "categories": [
        "android.intent.category.HOME",
        "android.intent.category.DEFAULT"
      ]
    }
  ],
  "dataRoamingDisabled": true,
  "kioskCustomLauncherEnabled": true
}

AndroidManifest.xml - the part relevant to the admin receiver

<receiver
    android:name=".DeviceAdminReceiver"
    android:lockTaskMode="if_whitelisted"
    android:description="@string/admin_description"
    android:label="@string/app_name"
    android:permission="android.permission.BIND_DEVICE_ADMIN">
    <meta-data
        android:name="android.app.device_admin"
        android:resource="@xml/admin_permissions" />
    <intent-filter>
        <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.HOME" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

When I do a GET on the individual device via the AMAPI it shows..

{
  "name": "enterprises/LC00mpaqaj/devices/3e26eac6be79d049",
  "managementMode": "DEVICE_OWNER",
  "state": "ACTIVE",
  "appliedState": "ACTIVE",
  "policyCompliant": true,
  "nonComplianceDetails": [
    {
      "settingName": "persistentPreferredActivities",
      "nonComplianceReason": "INVALID_VALUE",
      "packageName": "com.domain.app"
    }
  ],...

So it seems to not be liking the persistentPreferredActivities, however I have been playing around trying examples I have found both on this medium kiosk article, as well as the actual google kiosk policy examples.

Based on those examples I have tried using various receiverActivity alternative formats, and still no joy:

"receiverActivity": "com.domain.app/.DeviceAdminReceiver",
"receiverActivity": "com.domain.app",
"receiverActivity": "com.domain.app/.com.domain.app.DeviceAdminReceiver",

So my question: Why can I not get android kiosk mode to work with my policy, but it works fine with ADB?

Semi related, I can't use google play test tracks in testing my possible resolutions, so I am having to push changes to prod track, which makes my development cycle fairly long / arduous.


回答1:


I'm not an Android Management API expert, but did you try without the kioskCustomLauncherEnabled parameter? In the test I've run with it, it launches Google's own Kiosk app, maybe preventing your activity to launch.

My two cents :)




回答2:


I'd just like to add that you no longer need persistentPreferredActivities or lockType if you set "installType": "KIOSK".

This seems to be a new feature that's been introduced this year and I've just found out about it (nothing in the changelog). It should simplify your config somewhat.



来源:https://stackoverflow.com/questions/55181021/android-kiosk-mode-not-working-when-using-android-management-api-policy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!