300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 判断android已经root android 如何用代码判断手机是否被root

判断android已经root android 如何用代码判断手机是否被root

时间:2023-06-01 18:17:31

相关推荐

判断android已经root android 如何用代码判断手机是否被root

直接上代码:

public class RootUtils {

public static boolean isDeviceRooted() {

return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();

}

private static boolean checkRootMethod1() {

String buildTags = android.os.Build.TAGS;

return buildTags != null && buildTags.contains("test-keys");

}

private static boolean checkRootMethod2() {

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 checkRootMethod3() {

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();

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。