Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android application must not run on rooted devices

I'm writing an application that must not run on rooted devices. I want to store some secure data and which is possible only on non-rooted devices as nobody can access files in /data/data/package-name.

Does anyone know:

1) Is it possible to prevent the installation of an application on rooted devices? I read something about the "copy-protection mechanism" of Android Market. This feature seems to be outdated and replaced by the licensing feature. However, licensing is only possible for paid application and mine is free...

2) Is it possible to check programmatically whether a device is rooted or not? If it would be possible to do so I could simply stop the application if the device is rooted.

Any help regarding this topic is appreciated!

like image 752
Peter Avatar asked Jan 22 '11 16:01

Peter


2 Answers

Use those methods which will help you check for root

public static boolean findBinary(String binaryName) {
        boolean found = false;
        if (!found) {
            String[] places = { "/sbin/", "/system/bin/", "/system/xbin/",
                    "/data/local/xbin/", "/data/local/bin/",
                    "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/" };
            for (String where : places) {
                if (new File(where + binaryName).exists()) {
                    found = true;

                    break;
                }
            }
        }
        return found;
    }

    private static boolean isRooted() {
        return findBinary("su");
    }

Now try to check whether the device is rooted.

if (isRooted() == true){
//Do something to prevent run this app on the device

}
else{
//Do nothing and run app normally
}

For example you can force stop the app if the device is rooted

like image 163
noobProgrammer Avatar answered Sep 23 '22 03:09

noobProgrammer


Execute

Runtime.getRuntime().exec("su");

and check the result code.

In other words, if you can exec su, then you have root access. it doesn't matter if the user allows or denies it, you have your answer.

like image 29
Jeffrey Blattman Avatar answered Sep 21 '22 03:09

Jeffrey Blattman