How to prevent kiosk app from launching twice after reboot

0

I've successfully created kiosk app using Android management API with following policy:

{
  "appAutoUpdatePolicy" : "ALWAYS",
  "applications" : [ {
    "defaultPermissionPolicy" : "GRANT",
    "installType" : "KIOSK",
    "managedConfiguration" : {
      "deviceId" : "36edd69cd4c25e4c"
    },
    "packageName" : "com.example.app"
  } ],
  "blockApplicationsEnabled" : true,
  "bluetoothDisabled" : true,
  "dataRoamingDisabled" : true,
  "debuggingFeaturesAllowed" : true,
  "factoryResetDisabled" : true,
  "installAppsDisabled" : true,
  "keyguardDisabled" : true,
  "name" : "enterprises/LC0xxxxxxx/policies/policy_locked36edd69cd4c25e4c",
  "playStoreMode" : "WHITELIST",
  "safeBootDisabled" : true,
  "screenCaptureDisabled" : true,
  "systemUpdate" : {
    "endMinutes" : 240,
    "startMinutes" : 120,
    "type" : "WINDOWED"
  },
  "uninstallAppsDisabled" : true,
  "version" : "3"
}

After reboot my app is automatically launched preventing access to default home screen. However, about 15 seconds after first launch follows another one, so that app that is already in RESUMED state is launched once again, so old activity and all the fragments it contains are destroyed and replaced with a new instance. I've tried hard to detec what causes two separate launches, but the only clue I got were these two logs following one after another with 15-20 seconds gap:

2020-08-25 13:34:44.111 1074-2694/? I/ActivityManager: START u0 {act=android.intent.action.MAIN typ=null flg=0x10000000 cmp=ComponentInfo{com.example.app/com.example.app.presentation.ui.activities.MainActivity}} from uid 10132

2020-08-25 13:35:00.525 1074-2694/? I/ActivityManager: START u0 {act=null typ=null flg=0x10008000 cmp=ComponentInfo{com.example.app/com.example.app.presentation.ui.activities.MainActivity}} from uid 10136

I've found the way to workaround this issue: I've added BroadcastReceiver that receives ACTION_BOOT_COMPLETED event and writes boolean flag in SharedPreferences. So in MainActivity I check this flag and if it's false I show Splash screen instead of main ui. That's because ACTION_BOOT_COMPLETED is received right between these two launches. But my question is - is there any good way to solve this issue without such "dirty" workaround? I'm pretty sure that two launches of kiosk app is not an expected behavior, but I have no idea what I did wrong.

In case it matters here is also part of my AndroidManifest.xml:

        <activity
        android:theme="@style/AppTheme.Launcher"
        android:name=".presentation.ui.activities.MainActivity"
        android:launchMode="singleTask"
        android:lockTaskMode="if_whitelisted"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>

            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.DIAL" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="tel" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.DIAL" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
android
kiosk-mode
android-management-api
asked on Stack Overflow Aug 25, 2020 by anro

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0