简体   繁体   English

Android 设备植根检查

[英]Android device rooted check

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" path is exists. “/system/xbin/su”路径存在。

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 or Android studio's emulator always break in code block. Genymotion 或 Android Studio 的模拟器总是在代码块中中断。

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

It will return true if the device is rooted else false .如果设备已植根,它将返回true否则返回false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM