La detección de enraizamiento es un juego de gato y ratón y es difícil hacer detección de enraizamiento que funcione en todos los dispositivos para todos los casos.
Si aún necesita algunos básica enraizamiento de detección de comprobar el código de abajo:
/**
* Checks if the device is rooted.
*
* @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
*/
public static boolean isRooted() {
// get from build info
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
// check if /system/app/Superuser.apk is present
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
return true;
}
} catch (Exception e1) {
// ignore
}
// try executing commands
return canExecuteCommand("/system/xbin/which su")
|| canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
}
// executes a command on the system
private static boolean canExecuteCommand(String command) {
boolean executedSuccesfully;
try {
Runtime.getRuntime().exec(command);
executedSuccesfully = true;
} catch (Exception e) {
executedSuccesfully = false;
}
return executedSuccesfully;
}
Probablemente no siempre es correcta. Probado en ~ 10 dispositivos en 2014.
¿Quieres decir rooteado con una herramienta específica que agrega Superuser.apk? No existe una forma programática garantizada para determinar si un dispositivo está rooteado, ya que la mayoría de los controles podrían ser eludidos. – dljava
He estado utilizando esta verificación en mi producto, pero recientemente el Nexus 7.1 informa fallas en todos estos (no hay ningún comando 'which' instalado) y SuperSu no se está instalando en la carpeta/system/app. – Graeme
Puede ser que también debería echar un vistazo a http://stackoverflow.com/questions/1101380/determine-if-running-on-a-rooted-device –