1

It seems to work, but I'm not positive, as I'm limited (to an AVD) in my ability to test it. I came up with this algorithm to check if I'm rooted. Think it will always work? I'm not convinced.

private boolean isRooted() {
    try {
        Process process = new ProcessBuilder()
            .command("/system/bin/su")
            .redirectErrorStream(false)
            .start();
    } catch (IOException e) { 
        return false;
    }
    return true;
}
Tom
  • 221
  • 4
  • 15
  • well there might be lot of phones which have root access but without su installed. This is not foolproof – nandeesh Aug 14 '12 at 14:22
  • @nandeesh I see what you are saying. I saw [this](http://stackoverflow.com/questions/3424195/determining-if-an-android-device-is-rooted-programatically) but I wanted something more intuitive. I guess it'll do. – Tom Aug 14 '12 at 14:29
  • How about executing the `id` shell command from your code?. Or you could try writing to the /system directory. Typically only the root user is allowed to do that. – Michael Aug 14 '12 at 14:30
  • @Michael I wasn't aware of the `id` shell command. That would work. It seems that it does. – Tom Aug 14 '12 at 14:36
  • Like this post you cannot detect root. But most of the rooting methods should be detected by what you are pointing to. If you build your own code with non test keys and then make ro.secure = 0 or service.adb.root and ro.debuggable then too will the adb shell provide you root access. And then you have this which can provide root access by running this in <2.3.6 . So its quite unpredictable – nandeesh Aug 14 '12 at 14:42
  • @nandeesh When you say, "Most of the rooting methods should be detected by what you are pointing to," you mean that if I call `id` and it doesn't work, it'll typically detect if I'm rooted or not? – Tom Aug 14 '12 at 15:01

0 Answers0