检查su是否存在,即设备是否已植根

时间:2016-04-12 11:16:19

标签: android superuser

这个问题可能是重复的,但我已经完成了所有的答案,并注意到他们不再工作了。

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

方法1失败

 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" };
    for (String path : paths) {
        if (new File(path).exists()) return true;
    }
    return false;
}

方法2也失败了因为" SuperSu"它不再是系统应用程序,它可以卸载,su文件现在出现在单独的文件夹SU / bin / su

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

方法3也失败了,因为没有"哪个"现在在Android设备上的文件

RootTools.isavailable();

也失败了

我的问题是我可以通过检查su文件是否在Su / bin / su文件夹中来检测设备吗?这是检测root设备的正确方法吗?

1 个答案:

答案 0 :(得分:1)

  1. 将“/ su / bin / su”添加到checkRootMethod2()
  2. 的路径变量中
  3. 对于方法3,您还应该使用“/ system / bin / which”
  4. 调用“which”