Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Kiosk mode not working when using Android Management API Policy

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.

like image 244
Horse Avatar asked Oct 16 '22 05:10

Horse


2 Answers

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 :)

like image 198
Florian Avatar answered Oct 20 '22 11:10

Florian


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.

like image 39
S.Thomson Avatar answered Oct 20 '22 11:10

S.Thomson