【问题标题】:Changing system file permission更改系统文件权限
【发布时间】:2012-08-03 01:59:18
【问题描述】:

我真的什么都试过了:

现在,假设我以 root 身份重新挂载,因此对文件系统具有 RW 权限(Android 版本 2.3.7):

Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes("chmod -c 0777 /system/etc/customization/settings/com/android/browser/custom_settings.xml\n");
        os.writeBytes("exit\n");
        os.flush();
        process.waitFor();

或:

Process process = Runtime.getRuntime().exec("su -c \"/system/etc/customization/settings/com/android/browser/custom_settings.xml\"");

或:

Class<?> fileUtils = Class.forName("android.os.FileUtils");
            Method setPermissions =
                fileUtils.getMethod("setPermissions", String.class, int.class, int.class, int.class);
            int a = (Integer) setPermissions.invoke(null, "/system/etc/customization/settings/com/android/browser/custom_settings.xml", 0777, -1, -1);

行为是相同的:没有任何反应。而如果我来自 adb shell 的chmod 工作正常。如何在我的代码中更改该文件的权限?

【问题讨论】:

    标签: android permissions


    【解决方案1】:

    这是我的解决方案:

            Process sh = Runtime.getRuntime().exec("su", null, new File("/system/bin/"));
            OutputStream os = sh.getOutputStream();
    
            os.write(("chmod 777 <filepath>").getBytes("ASCII"));
            os.flush();
            os.close();
            sh.waitFor();
    
    猜你喜欢
    • 2015-09-06
    • 2015-04-02
    • 1970-01-01
    • 2014-08-28
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    相关资源
    最近更新 更多