Skip to content

Instantly share code, notes, and snippets.

@KravaDanil
Created December 5, 2016 10:22
Show Gist options
  • Select an option

  • Save KravaDanil/f001919de2f1d2c6e59721afa3908ae0 to your computer and use it in GitHub Desktop.

Select an option

Save KravaDanil/f001919de2f1d2c6e59721afa3908ae0 to your computer and use it in GitHub Desktop.
private static boolean isRooted() {
return findBinary("su");
}
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;
}
@jaredrummler
Copy link

Many devices have the su binary in /su/bin now. It would be better to just loop over PATH

public static boolean suExists() {
  for (String path : System.getenv("PATH").split(":")) {
    if (new File(path, "su").exists()) {
      return true;
    }
  }
  return false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment