Mr_Yuki_Lee 2014-01-07 03:38 采纳率: 0%
浏览 2593

求指教如何用代码判断手机是否ROOT过

自己的手机是LG的NEXUS4,用过了网上各种代码判断的方法。 运行后都显示是ROOT过。但手机本身实际上并没有ROOT过。 但是使用其他一款软件的时候可以正确判断出我的手机有没ROOT过。 不知道问题到底出在哪里。 希望有高人可以指点下。。非常感谢。。

  • 写回答

1条回答 默认 最新

  • _Carl 2014-01-13 11:18
    关注

    public static boolean isRoot() {
    boolean isRoot = false;
    String sys = System.getenv("PATH");
    ArrayList commands = new ArrayList();
    String[] path = sys.split(":");
    for (int i = 0; i < path.length; i++) {
    String commod = "ls -l " + path[i] + "/su";
    commands.add(commod);
    System.out.println("commod : "+commod);
    }
    ArrayList res = run("/system/bin/sh", commands);
    String response = "";
    for (int i = 0; i < res.size(); i++) {
    response += res.get(i);
    }
    String root = "-rwsr-sr-x root root";
    if (response.contains(root)) {
    isRoot = true;
    }
    return isRoot;
    }
    public static ArrayList run(String shell, ArrayList commands){
    ArrayList output = new ArrayList();
    Process process =null;
    try {
    process = Runtime.getRuntime().exec(shell);

            BufferedOutputStream shellInput = new BufferedOutputStream(
                    process.getOutputStream());
            BufferedReader shellOutput = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));
    
            for (String command : commands) {
                shellInput.write((command + " 2>&1\n").getBytes());
            }
    
            shellInput.write("exit\n".getBytes());
            shellInput.flush();
    
            String line;
            while ((line = shellOutput.readLine()) != null) {
                output.add(line);
            }
    
            process.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally{
            process.destroy();
        }
    
        return output;
    }
    

    这代码看你用过没

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题