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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧