修改系统文件权限 [英] Changing system file permission

查看:262
本文介绍了修改系统文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的什么都试过了:

  • <一个href="https://nethack-android.google$c$c.com/svn-history/r430/trunk/slashem-0.0.7E7F3/sys/android/NetHackApp/src/com/slashemff/NetHackFileHelpers.java"相对=nofollow> NetHackFileHelpers
  • <一个href="http://stackoverflow.com/questions/11408154/how-to-get-file-permission-mode-programmatically-in-java">How获取文件权限模式编程在Java中
  • 更改文件权限
  • <一个href="http://stackoverflow.com/questions/7129144/mount-r-w-system-in-android-application-to-edit-read-only-files">Mount在Android应用程序来编辑R / W系统只读文件
  • NetHackFileHelpers
  • How to get File Permission Mode programmatically in Java
  • Change file permission in application
  • Mount R/W system in android application to edit Read Only files

现在,假设我已经重新安装的根,因此 RW​​ 文件系统(Android版本2.3.7)的权限:

Now, suppose I've remounted as root, and therefore RW permission on file system (Android version 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);

的行为是一样的:没有任何反应。而如果我搭配chmod 亚行的shell工作正常。我怎样才能从我的code更改该文件的权限?

The behaviour is the same: nothing happens. Whereas if I chmod from adb shell works fine. How can I change the permissions of that file from within my code?

推荐答案

下面是我的解决办法:

        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();

这篇关于修改系统文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆