ROOT判断
This commit is contained in:
parent
383f8a9a80
commit
670bf385ac
@ -1,5 +1,6 @@
|
||||
package com.dahe.mylibrary.utils;
|
||||
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -14,38 +15,28 @@ import java.io.InputStreamReader;
|
||||
* @Description 判断Android设备是否拥有Root权限
|
||||
*/
|
||||
public class RootCheck {
|
||||
private final static String TAG = "RootUtil";
|
||||
|
||||
private static final String[] rootRelatedDirs = new String[]{
|
||||
"/su", "/su/bin/su", "/sbin/su",
|
||||
"/data/local/xbin/su", "/data/local/bin/su", "/data/local/su",
|
||||
"/system/xbin/su",
|
||||
"/system/bin/su", "/system/sd/xbin/su", "/system/bin/failsafe/su",
|
||||
"/system/bin/cufsdosck", "/system/xbin/cufsdosck", "/system/bin/cufsmgr",
|
||||
"/system/xbin/cufsmgr", "/system/bin/cufaevdd", "/system/xbin/cufaevdd",
|
||||
"/system/bin/conbb", "/system/xbin/conbb"};
|
||||
|
||||
public static boolean isRoot() {
|
||||
String binPath = "/system/bin/su";
|
||||
String xBinPath = "/system/xbin/su";
|
||||
if (new File(binPath).exists() && isExecutable(binPath))
|
||||
return true;
|
||||
if (new File(xBinPath).exists() && isExecutable(xBinPath))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isExecutable(String filePath) {
|
||||
Process p = null;
|
||||
try {
|
||||
p = Runtime.getRuntime().exec("ls -l " + filePath);
|
||||
// 获取返回内容
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
String str = in.readLine();
|
||||
Log.i(TAG, str);
|
||||
if (str != null && str.length() >= 4) {
|
||||
char flag = str.charAt(3);
|
||||
if (flag == 's' || flag == 'x')
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (p != null) {
|
||||
p.destroy();
|
||||
boolean hasRootDir = false;
|
||||
String[] rootDirs;
|
||||
int dirCount = (rootDirs = rootRelatedDirs).length;
|
||||
for (int i = 0; i < dirCount; ++i) {
|
||||
String dir = rootDirs[i];
|
||||
if ((new File(dir)).exists()) {
|
||||
hasRootDir = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return Build.TAGS != null && Build.TAGS.contains("test-keys") || hasRootDir;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user