0

QUESTION

Is there any way to instruct (programmatically or otherwise) an Android tablet not to allow any user interactions until my app is automatically launched?

BACKGROUND

I have my Android device running in Kiosk mode. My app is the "device owner". The end-goal is to have a kiosk-type interface at a public setting (using an Android tablet). Everything works fine, in the sense that:

(a) When the device is re-booted, my app (which is the "device owner") will launch automatically

(b) Once my app is launched, it is full screen and navigation etc. is disabled, so no back button. The user can't quit the app

THE ISSUE

When the tablet re-boots, it takes 73 seconds before my app is automatically launched. Presumably my app does not get the BOOT_COMPLETED signal until this time.

During this time, any unauthorized person can access the device apps and settings - which is not good!

The only way I can think of preventing this is to set the Screen Lock Mode to PIN, or similar, so that a code is required to unlock the tablet. But if I do this, the app does NOT launch automatically - the screen will stay locked forever. When I eventually enter the code, then it takes about 73 seconds before my app is launched.

So, if I install my tablet in a public kiosk type setup, I have a security issue if the tablet is reset, or caused to reset in some way.

Any suggestions appreciated, thanks.

IMPLEMENTATION

My implementation is based on a lot of other posts: (and described in a previous post by me: here)

I have defined the receiver:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class StartOnBootupReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            Intent activityIntent = new Intent(context, MainActivity.class);
            context.startActivity(activityIntent);
        }
    }
}

And in the AndroidManifest.xml file:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

and

<receiver android:name=".StartOnBootupReceiver"
    android:exported="false"
    >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    </intent-filter>
</receiver>

I then factory reset the tablet and used adb to set my app as the "device owner"

And I have set my app up as the launcher, in the manifest file:

<intent-filter>
    <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>

UPDATE

In trying to get this working, I have been making code changes, and factory resetting the tablet quite a few times a day. This morning, the "kiosk" worked a lot better - it only took about 10 seconds to launch the app, and I couldn't get access to the other apps on the device during those 10 seconds.

This was with NO code changes by me... so TIME might have been a factor.

So, of course I did another factory reset and set everything up, to see if there had been some magic 'fix'. Now it's back to about 73 seconds, and allows me access to the apps during this time. I left it for an hour - same result. So I will leave it over night and see if that "fixes" the issue. Not really sure what else to say / do!

garrettb
  • 139
  • 11
  • In a [prior question](https://stackoverflow.com/q/72972225/295004) you may have mentioned the device/OS version that you are testing on. If you are using the same Samsung device, it may be that Samsung Knox and/or Google Play Services DPC hooks are delaying your third-party DPC from running. If you are using an EMM provider, It may help to mention which one (or reach out to them for assistance). – Morrison Chang Sep 14 '22 at 06:11
  • Thanks for your comment Morrison. I am not using an EMM provider (although I might have to go that way if I can't achieve my goals programmatically). I added an update to my question above. – garrettb Sep 14 '22 at 19:48

1 Answers1

0

When the tablet re-boots, it takes 73 seconds before my app is automatically launched. Presumably my app does not get the BOOT_COMPLETED signal until this time.

Don't use BOOT_COMPLETED. Have your app be the launcher.

During this time, any unauthorized person can access the device apps and settings - which is not good!

Not if your app is the launcher, because the person only has access to your app.

Also note that your code probably does not work on modern versions of Android anyway, as you cannot start an activity from the background the way that you are.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I already have my app as the launcher (I edited my post to include that extra code in the manifest file) – garrettb Sep 14 '22 at 01:36
  • Also, @CommnsWare: I looked at your link to "Restrictions on starting activities from the background", there are exceptions, including: - "The app is a device policy controller running in device owner mode. Example use cases include fully managed enterprise devices, as well as dedicated devices like digital signage and kiosks." So it looks like I am allowed to start it, and indeed it IS starting, but it takes 73 seconds, and I have been able to open Settings and Google Maps and other things on the tablet during those 73 seconds. So I have missed something in the implementation. – garrettb Sep 14 '22 at 01:46
  • @garrettb: "I already have my app as the launcher" -- then, why are you worrying about `BOOT_COMPLETED`, let alone trying to start an activity there? "I have been able to open Settings and Google Maps and other things on the tablet during those 73 seconds" -- how? If your app is the launcher, they would be opening those apps through your own app. – CommonsWare Sep 14 '22 at 11:24
  • Thank you @CommnsWare for your comments. I got rid of the BOOT_COMPLETED flag wait, but that hasn't changed things. I think there is something I am missing / something I don't understand. I updated my question above with my latest discovery. Thanks again. – garrettb Sep 14 '22 at 19:49
  • @garrettb: You still have not explained the mechanics behind "I have been able to open Settings and Google Maps and other things on the tablet during those 73 seconds". What exactly are you doing that is giving you access to these things? If your app is the launcher, then is your app giving your users access to Maps? – CommonsWare Sep 14 '22 at 19:54
  • I will detail it out in a few days when I can get back to it. Essentially there is a time, while Android is starting up and doing some stuff (?) before my "launcher" app starts, that I can use my tablet like I would at any time. So it is probably safe to say that I have not implemented my launcher app correctly. I will post here in a few days. Thanks – garrettb Sep 14 '22 at 21:27
  • @garrettb: "So it is probably safe to say that I have not implemented my launcher app correctly" -- yeah, it sounds like the device's normal launcher is what's getting used. You might want to play around with a third-party launcher for some other device (e.g., a phone) to get a feel for the experience. After you install the third-party launcher, the next time you tap the HOME button (or use the gesture), you should get a chooser, and there you can pick your launcher (and later be able to set it as the default). Device owner apps might have programmatic options for this. – CommonsWare Sep 14 '22 at 22:16
  • I managed to get the launch time down from 73 seconds to 25 seconds, by adding the following in intent actions to the receiver intent filter: ACTION_BOOT_COMPLETED, REBOOT, ACTION_SHUTDOWN. I don't know which made the difference. However, in that 25 seconds, I am still able to access apps etc. For example, I was able to get in to the settings and turn Wi-Fi off, before the app launched. I will probably have to park this for now - I am running out of time. And I will most likely have to look into 3rd party launchers etc. – garrettb Sep 19 '22 at 22:37