fred-ye / summary

my blog
43 stars 9 forks source link

[Android]如何判断某款Android设备是否被Root过 #15

Open fred-ye opened 10 years ago

fred-ye commented 10 years ago

Root过的Android设备,可以让用户拥有最高的权限。判断设备是否被Root过也是根据这一点来做的。通过检测系统中的SU命令。 代码如下:

private static boolean isRooted() {
    return findBinary("su");
}

public static boolean findBinary(String binaryName) {
    boolean found = false;
    if (!found) {
        String[] places = {"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/",
                "/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"};
        for (String where : places) {
            if ( new File( where + binaryName ).exists() ) {
                found = true;
                break;
            }
        }
    }
    return found;
}

代码摘自http://stackoverflow.com/questions/19288463/how-to-check-if-android-phone-is-rooted