美文网首页
Android判断手机是否Root

Android判断手机是否Root

作者: 愤怒的折袖丶 | 来源:发表于2018-07-12 10:13 被阅读44次

    本文非原创,方法来自Stack Overflow的大神。

    原文链接

    代码如下

    public class 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()));

     if (in.readLine() != null) return true;

     return false; 

     } 

    catch (Throwable t) {

     return false; 

     } finally { 

     if (process != null) process.destroy();

     } 

     }

    }

    相关文章

      网友评论

          本文标题:Android判断手机是否Root

          本文链接:https://www.haomeiwen.com/subject/ocelpftx.html