ketan dhopeshwarkar
ketan dhopeshwarkar

Reputation: 309

How to run an Android App in Kiosk Mode, keep Safe Mode disabled and prevent the device from Hard Reset?

How to run Android App in Kiosk Mode, keep Safe Mode disabled and prevent the device from Hard Reset?

I have following 3 requirements for my app:

  1. Show only specific apps to school students in the normal mode of the device. This can be possible by disabling default launcher and enabling kiosk launcher.

  2. Disable or set the password to safe mode to avoid usage of system apps or built-in apps (youtube, video player, music app, etc.).

  3. Restrict hard reset of a device by disabling long press of hard keys (power button, volume buttons) of a device.

I have interpreted these requirements and came up with below detailed understanding.

  1. We can redesign the school students app to make itself a launcher app which will run in kiosk mode. That implies we will not require any other (trial version) launcher apps.

  2. We can disable safe mode access to the system or third-party apps via the AppLock app or similar other apps. It will work only up to Android Marshmallow 6.0. But there is an Android imposed limitation – it won’t work on Nougat / Oreo devices. Alternatively, we tried to handle the power button key press for preventing the device from going into safe mode. But Android doesn't allow the access or listen to power key press from our app as per this link and various other.

IMPORTANT NOTE FOR ANDROID 7.0 (NOUGAT) AND 8.0 (OREO) - link here

As per MMGuardian App, at this time, Safe Mode Lock cannot be enabled for phones running on Android 7.0 or 8.0. If an older phone for which Safe Mode Lock was previously enabled is updated to these versions of Android, the Safe Mode Lock function will become disabled.

  1. We cannot prevent any device from hard reset as it is mostly done after the phone is switched off leaving the apps with no control. But there is an expensive alternative. We can use a COSU device and design a custom firmware. More details about COSU are available on below links. https://developer.android.com/work/cosu.html https://developers.google.com/android/work/requirements/cosu

Can someone help me to add more thoughts to it for me to understand this situation in more details?

Am I going in the right direction? or Have I detailed it correctly?

Upvotes: 11

Views: 6567

Answers (3)

Anu Martin
Anu Martin

Reputation: 731

100% Kiosk Mode impossible.

Restrict hard reset : The hard reset option is a part of bootloader, so it's hard to prevent device getting factory reset,

I had solution, but only works if the device rooted

Restrict hard reset : copy your apk file to system/app, when device got restored Android will automatically reinstall all apps from system/app folder

Disable System APP : to disable system apps or any apps run a shell command

pm disable <package name>


Interpret Volume Keys : To run this you don't need root access, Use this code in your Activity Class

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    // TODO Auto-generated method stub
    if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN))
    {
        // Do what ever you want
    }
    if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP))
    {
        // Do what ever you want
    }
    return true;
}

Bonus disable navigation bar and status bar
To Hide

 private void hideNavigationBar(){
    try {
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes("pm disable com.android.systemui\n");
        os.flush();
        try {
        Process process = null;
        process = Runtime.getRuntime().exec("su");
        DataOutputStream osReboot = new DataOutputStream(process.getOutputStream());
        osReboot.writeBytes("reboot\n");
        osReboot.flush();
        process.waitFor();
            } 
            catch (IOException e) {
                e.printStackTrace();
            } 
            catch (InterruptedException e) {
                e.printStackTrace();
            }

    }catch (IOException e) {
        e.printStackTrace();
    }
}

Restore back to normal

private void showNavigationBar(){
    try {
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes("pm enable com.android.systemui\n");
        os.flush();
        os.writeBytes("reboot\n");
        os.flush();
        process.waitFor();

    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Note : Device will reboot after running shell commands

Your playing with root, so you and your own, If any doubt please command before start coding

Upvotes: 5

JBA
JBA

Reputation: 2909

Can you design and then deploy your app as DeviceOwner? This gives you the greatest possibilities on the device, but deployment can be painful depending on the context: not suitable for a public release, but doable if you can manage the devices fleet.

Upvotes: 2

Andrii Omelchenko
Andrii Omelchenko

Reputation: 13353

Take a look at Android Management API, seems more can't be done without custom device firmware.

Upvotes: 4

Related Questions