Android "permanent"应用程序的 super 用户权限?

标签 android process runtime exec root

澄清一下,我使用此代码为我的应用程序获取 super 用户权限,以便我可以访问 root 等等:

    public String runProcess(String[] functs) {

    DataOutputStream dos;
    DataInputStream dis;
    StringBuffer contents = new StringBuffer("");
    String tempInput;
    Process process;

    try {
        process = Runtime.getRuntime().exec(functs);
        dos = new DataOutputStream(process.getOutputStream());
        dis = new DataInputStream(process.getInputStream());

        for (String command : functs) {
            dos.writeBytes(command + "\n");
            dos.flush();

            while ((tempInput = dis.readLine()) != null)
                contents.append(tempInput + "\n");

        }

        dos.writeBytes("exit\n");
        dos.flush();
        process.waitFor();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return contents.toString();

}

虽然它工作得很好,但每当我调用 runProcess(new String[] { "su", "-c", "some other command"}); 它总是要求 super 用户权限.我在市场上看到很多 root 应用程序每次启动时只需要获得一次 super 用户权限,但我认为我不需要在每次应用程序调用函数时都向用户询问 super 用户权限这需要苏。所以我的问题是,我如何在应用程序启动时提示用户给我一次 SU 权限,而不必为每个与 SU 相关的操作不断请求?

编辑:我知道我可以运行我的方法/Runtime.getRuntime().exec() 方法而无需每次都在其中键入“su”,但这只适用于非 su 相关操作(即 exec("ps") 或 exec("ls")。有什么想法吗?

最佳答案

您可以使用我的库来执行此操作。

https://code.google.com/p/roottools/

此外,如果您不想使用该库,可以使用源代码,这样您就可以撕掉我的代码并在您的应用程序中使用它。

这是源代码的链接:

https://code.google.com/p/roottools/source/browse/#svn%2Ftrunk%2FStable%2FRootTools-sdk3-generic%2Fsrc%2Fcom%2Fstericson%2FRootTools

关于Android "permanent"应用程序的 super 用户权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12430717/

相关文章:

android - Firebase limitToLast(查询)不解析响应

c# - Android(c2dm)推送通知错误

c - 进程子创建新 session

c++ - C++ 中的高效运行时类型检查

c - R6034 应用程序尝试错误地加载 C 运行时库

runtime - 在标准 TCL 基础上添加数学运算

android - 恢复列表中的 Activity 实例?

android - Xposed : how to block a method call

java - 运行时进程 BufferedReader 未输出所有行 (Psexec)

python - 进程组中的所有 child 并不总是看到信号