Android 设备植根检查 [英] Android device rooted check

查看:66
本文介绍了Android 设备植根检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查我的设备是否已植根.当我在真实设备中尝试下面的这段代码时,它没有扎根,没关系.但是非 root 模拟器在这一行中断

I want to check my device is rooted or not. When I try this code below in real device is not rooted, its ok. But Non rooted emulator break in this line

if (new File(path).exists())
    return true;

/system/xbin/su"路径存在.

"/system/xbin/su" path is exists.

private static boolean isRooted() {
    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;
}

Genymotion 或 Android Studio 的模拟器总是在代码块中中断.

Genymotion or Android studio's emulator always break in code block.

所有安卓模拟器都root了吗?

Is all android emulators rooted?

推荐答案

您可以通过以下方法检查设备是否root:

You can check the device is rooted or not by below method:

public static boolean isRootedDevice(Context context) {

    boolean rootedDevice = false;
    String buildTags = android.os.Build.TAGS;
    if (buildTags != null && buildTags.contains("test-keys")) {
        Log.e("Root Detected", "1");
        rootedDevice = true;
    }

    // check if /system/app/Superuser.apk is present
    try {
        File file = new File("/system/app/Superuser.apk");
        if (file.exists()) {
            Log.e("Root Detected", "2");
            rootedDevice = true;
        }
    } catch (Throwable e1) {
        //Ignore
    }

    //check if SU command is executable or not
    try {
        Runtime.getRuntime().exec("su");
        Log.e("Root Detected", "3");
        rootedDevice = true;
    } catch (IOException localIOException) {
        //Ignore
    }

    //check weather busy box application is installed
    String packageName = "stericson.busybox"; //Package for busy box app
    PackageManager pm = context.getPackageManager();
    try {
        Log.e("Root Detected", "4");
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        rootedDevice = true;
    } catch (PackageManager.NameNotFoundException e) {
        //App not installed
    }

    return rootedDevice;
}  

如果设备已root,它将返回true,否则返回false.

It will return true if the device is rooted else false.

这篇关于Android 设备植根检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆