「Android入門」root化されているかどうかを確認する方法」

Javaコード
public class RootUtil {
public static boolean isDeviceRooted() {
return chkRootMethod1() || chkRootMethod2() || chkRootMethod3();
}

private static boolean chkRootMethod1() {
String buildTags = android.os.Build.TAGS;
return buildTags != null && buildTags.contains(“test-keys");
}

private static boolean chkRootMethod2() {
String[] paths = { “/system/app/Superuser.apk", “/sbin/su", “/system/bin/su", “/system/xbin/su", “/data/local/xbin/su", “/data/local/bin/su", “/system/sd/xbin/su",
“/system/bin/failsafe/su", “/data/local/su", “/su/bin/su"};
for (String path : paths) {
if (new File(path).exists()) return true;
}
return false;
}

private static boolean chkRootMethod3() {
Process process = null;
try {
process = Runtime.getRuntime().exec(new String[] { “/system/xbin/which", “su" });
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
if (in.readLine() != null) return true;
return false;
} catch (Throwable t) {
return false;
} finally {
if (process != null) process.destroy();
}
}
}

Android

Posted by arkgame