La détection d'enracinement est un jeu de chat et de souris et il est difficile de faire une détection d'enracinement qui fonctionnera sur tous les appareils dans tous les cas.
Si vous avez encore besoin de base détection enracinant vérifier le code ci-dessous:
/**
* 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;
}
Probablement pas toujours correct. Testé sur ~ 10 appareils en 2014.
Vous voulez dire enraciné avec un outil spécifique qui ajoute Superuser.apk? Il n'existe pas de méthode programmatique garantie pour déterminer si un périphérique est root car la plupart des vérifications peuvent être contournées. – dljava
J'ai utilisé cette vérification dans mon produit, mais récemment le Nexus 7.1 signale faux pour tous (aucune commande 'which' installée) et SuperSu n'installe pas dans le dossier/system/app. – Graeme
Peut-être vous devriez également jeter un oeil à http://stackoverflow.com/questions/1101380/determine-if-running-on-a-rooted-device –