1

Possible Duplicate:
Determine if running on a rooted device

I'm creating an Android application and I want to know if my application is running on a rooted device.
I did the digging on Google, but could not come up with even one solid solution.

Similar questions have been asked before on stackoverflow, but without any solution. The solutions provided in these links do not work on my device. Even Runtime.exec("su") does not work.

Determining if an Android device is rooted programatically?

Determine if running on a rooted device

Testing if a phone is rooted

Is there a way to find out the device is rooted? If we cannot do it, how is that Google can find if the device is rooted?

When I do Runtime.exec("su") I am getting exception 10-15 18:36:36.445: W/System.err(668): java.io.IOException: Error running exec(). Commands: [su] Working Directory: null Environment: null

public static boolean isDeviceRooted_BySu() {
    try {
        Log.d("BySu", "BySu");
        Process p = Runtime.getRuntime().exec("su");
        return true;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

I have checked from ADB shell, and It gives me a "#" prompt, So I can be sure that the device is at least Shell rooted. Given that it is shell rooted, then the solutions provided on the Determine if running on a rooted device should at least work, but that does not work either.

Community
  • 1
  • 1
  • could you provide some related log output about how does `Runtime.exec("su")` not work? Any exceptions? – dumbfingers Oct 15 '12 at 10:35
  • There are some apps on google play that can help you determine your phone is rooted or not. Let's take a look at here: https://play.google.com/store/search?q=root+checker&c=apps – Nguyen Minh Binh Oct 15 '12 at 10:36
  • @ss1271: I have updated the post. I am getting an exception 10-15 18:36:36.445: W/System.err(668): java.io.IOException: Error running exec(). Commands: [ su ] Working Directory: null Environment: null – user1746693 Oct 15 '12 at 13:16
  • @user1746693 Yeah, thx for the update, would you please post some of your code as well? Seemed you didn't pass the correct parameters or something else was wrong. – dumbfingers Oct 15 '12 at 14:09

1 Answers1

1

There is no definitive way. You can check system properties ('ro.secure', etc.), search for a SUID su binary, try to run it, search for a number of 'superuser' apps etc. However, there might be a foobar binary that is actually su, or any other program that gives you root privileges. There might be a 'regular' binary that exploits some Android vulnerability to get root, etc. If you check every single file for SUID you might get close. Google is probably using a combination of some/all of those.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84