可能的重复:
确定是否在已取得 root 权限的设备上运行
如何(以编程方式)确定 Android 设备是否: 已 root 运行软件或 ROM 的破解副本。
我的数据库中有一些敏感信息,我想在手机 root 后(即用户可以访问数据库)对其进行加密。我如何检测到这一点?
Root 检测是一场猫捉老鼠的游戏,很难使 Root 检测适用于所有情况下的所有设备。
See Android 根汁汽水 https://github.com/scottyab/rootbeer用于高级根检测,它还使用编译到 .so 本机库中的 JNI 和本机 CPP 代码。
如果你需要一些简单和基本root检测检查下面的代码:
/**
* 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;
}
可能并不总是正确的。 2014 年在约 10 台设备上进行了测试。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)