【问题标题】:Android Root Check fails on samsung tab while executin /system/bin/which su执行 /system/bin/which su 时,三星选项卡上的 Android Root 检查失败
【发布时间】:2018-08-02 09:00:29
【问题描述】:

我已经点击链接Determining if an Android device is rooted programmatically? 检查应用程序是否在有根的 android 设备上运行。对于某些设备和模拟器,它工作正常,但对于我的新三星平板电脑,它失败了。

    Runtime.getRuntime().exec("/system/bin/which su ");

执行上述行后,它返回true。 谢谢

【问题讨论】:

    标签: java android android-studio


    【解决方案1】:

    试试这个

    公共类 RootUtil {

    private static final String TAG = "RootUtil";
    
    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()));
            return in.readLine() != null;
        } catch (Throwable t) {
            return false;
        } finally {
            if (process != null) process.destroy();
        }
    }
    
    public static boolean isDeviceRootedV2() {
        try {
            Runtime.getRuntime().exec("su");
            return true;
        } catch (IOException e) {
            Log.e(TAG, "isDeviceRootedV2: " + e.getMessage());
            return false;
        }
    }
    

    }

    【讨论】:

    • 调用 isDeviceRootedV2() 进行根检查
    • 如果你请参考我分享这个命令的链接。
    猜你喜欢
    • 2017-01-28
    • 2017-09-01
    • 2021-04-04
    • 2012-01-29
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2017-02-21
    相关资源
    最近更新 更多