首页 > 学院 > 开发设计 > 正文

检测安卓手机是否已经Root

2019-11-09 16:35:34
字体:
来源:转载
供稿:网友

检测安卓手机是否已经Root

/** * 反编译支付宝SDK得到的判断root的方法,并增加了对‘/su/bin/’目录的判断 * Created by cyb on 2016/12/15 0015. */public class SystemInfo { public static boolean isRooted(){ // nexus 5x "/su/bin/" String[] paths = { "/system/xbin/", "/system/bin/", "/system/sbin/", "/sbin/", "/vendor/bin/", "/su/bin/" }; try{ for(int i = 0; i < paths.length; i++){ String path = paths[i] + "su"; if(new File(path).exists()){ String execResult = exec(new String[] { "ls", "-l", path }); Log.d("cyb", "isRooted=" + execResult); if(TextUtils.isEmpty(execResult) || execResult.indexOf("root") == execResult.lastIndexOf("root")){ return false; } return true; } } }catch (Exception e){ e.PRintStackTrace(); } return false; } private static String exec(String[] exec){ String ret = ""; ProcessBuilder processBuilder = new ProcessBuilder(exec); try { Process process = processBuilder.start(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while( (line = bufferedReader.readLine()) != null){ ret += line; } process.getInputStream().close(); process.destroy(); } catch (Exception e) { e.printStackTrace(); } return ret; }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表