1

I'm trying to create a single-use devices (kiosk app) and follow tutorial below: https://codelabs.developers.google.com/codelabs/cosu/index.html?index=..%2F..%2Findex#0

The code works very normal, except that "reboot" case. Every after reboot, it fails to lock the app, keep fall into "LOCK_TASK_EXITING" every after rebooting.

07-05 15:45:14.583   785   802 V ActivityManager: Broadcast: Intent { act=android.app.action.LOCK_TASK_ENTERING flg=0x10 cmp=com.google.codelabs.cosu/.DeviceAdminReceiver (has extras) } ordered=false userid=0 callerApp=ProcessRecord{6438256 785:system/1000}
07-05 15:45:14.584   785   802 V ActivityManager: Broadcast: Intent { act=android.app.action.LOCK_TASK_EXITING flg=0x10 cmp=com.google.codelabs.cosu/.DeviceAdminReceiver } ordered=false userid=0 callerApp=ProcessRecord{6438256 785:system/1000}
paugoo
  • 138
  • 1
  • 2
  • 11

2 Answers2

0

see GitHub ...one can work around the issue alike:

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (mSharedPreferences.getBoolean(KEY_PREF_RECREATED, false)) {

        mSharedPreferences.edit().putBoolean(KEY_PREF_RECREATED, false).apply();

        // start LOCK TASK here

    } else {

        mSharedPreferences.edit().putBoolean(KEY_PREF_RECREATED, true).apply();

        finish(); // close the app
        startActivity(new Intent(this, MainActivity.class)); // reopen the app
    }

    setContentView(R.layout.activity_main);
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Yes of course I did, because without setting it as device owner, we even can't lock it in normal case (without rebooting), and it works to lock the app, until we reboot the devices. – paugoo Jul 13 '18 at 05:19
  • 1
    but in this link tutorial, it said no need to do rooting. https://codelabs.developers.google.com/codelabs/cosu/index.html#0 – paugoo Jul 13 '18 at 05:28
  • https://developer.android.com/reference/android/app/admin/DeviceAdminReceiver hints for, that the `Manifest.xml` and/or receiver might not function as expected... try logging to console. it is entering/leaving lock task mode - therefore the question is, why it doesn't stay. – Martin Zeitler Jul 13 '18 at 05:32
  • I realize this only happen for some devices ex: lenovo tab3. I tried the same code for samsung galaxy, and it works for all, after rebooting, it still lock the app. – paugoo Jul 13 '18 at 05:34
  • see the updated answer, this appear to be a known issue. – Martin Zeitler Jul 13 '18 at 05:43
  • I've tried this one, and still not working for some devices. – paugoo Jul 13 '18 at 06:26
  • Figure out some interesting clue, this problem only happen when we set the app as the default launcher (Home). – paugoo Jul 13 '18 at 08:25
0

From: https://developer.android.com/work/dpc/dedicated-devices/lock-task-mode#kotlin

To call the Activity.startLockTask() method, the activity must be running in the foreground, it is suggested calling it inside the onResume() method of an Activity or Fragment.

Example:

// In our Fragment subclass.
override fun onResume() {
    super.onResume()
    // First, confirm that this package is allowlisted to run in lock task mode.
    if (dpm.isLockTaskPermitted(context.packageName)) {
        activity.startLockTask()
    } else {
        // Because the package isn't allowlisted, calling startLockTask() here
        // would put the activity into screen pinning mode.
    }
}
Rodrigo Quelhas
  • 101
  • 1
  • 1