访问根级系统文件夹 Android

Accesing root level system folder Android

我有 root 权限,我正在测试我的应用程序的一项新功能,该功能涉及访问和编辑 Android 的系统文件夹。

但是我的代码似乎没有任何改变。我在 Marshmallow CM 13.

Process p;
    try {
        // Preform su to get root privileges
        p = Runtime.getRuntime().exec("su");

        // Attempt to write a file to a root-only
        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        os.writeBytes("echo \"Do I have root?\" >/system/etc/temporary.txt\n");

        // Close the terminal
        os.writeBytes("exit\n");
        os.flush();
        try {
            p.waitFor();
            if (p.exitValue() != 255) {
                // TODO Code to run on success
                toastMessage("root");
            }
            else {
                // TODO Code to run on unsuccessful
                toastMessage("not root");
            }
        } catch (InterruptedException e) {
            // TODO Code to run in interrupted exception
            toastMessage("not root");
        }
    } catch (IOException e) {
        // TODO Code to run in input/output exception
        toastMessage("not root");
    }

/system挂载点默认挂载在RO。即使有 root 级别的权限,写入它的唯一方法是将它重新挂载为 RW。此外,您可能仍然 运行 遇到 SE Android(Android 的 SE Linux)的一些问题,自 Lollipop 以来它就存在并处于完全执行模式。平台中可能内置了 SE Android 安全策略,这将限制对文件系统某些部分的访问,即使是 root。