在Android 6.0中,我尝试在/ data分区的sample
文件夹中创建一个空文件:/data/sample/emptyfile
。
代码从/external
File file = new File(/data/sample/emptyfile);
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
我已在sample
source
/system/core/libcutils/fs_config.c
文件夹分配了相应的权限
我尝试添加以下代码变体:
/* Rules for directories.
** These rules are applied based on "first match", so they
** should start with the most specific path and work their
** way up to the root.
*/
static const struct fs_path_config android_dirs[] = {
{ 00777, AID_ROOT, AID_ROOT, 0, "data/sample" },
{ 00770, AID_SYSTEM, AID_CACHE, 0, "cache" },
... etc.
和at:
/* Rules for files.
** These rules are applied based on "first match", so they
** should start with the most specific path and work their
** way up to the root. Prefixes ending in * denotes wildcard
** and will allow partial matches.
*/
static const char conf_dir[] = "/system/etc/fs_config_dirs";
static const char conf_file[] = "/system/etc/fs_config_files";
static const struct fs_path_config android_files[] = {
{ 00777, AID_ROOT, AID_ROOT, 0, "data/sample/*" },
{ 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" },
... etc.
我尝试使用AID_ROOT, AID_ROOT
和AID_SYSTEM, AID_SYSTEM
文件夹sample
在编译时成功创建,权限为:drw-rw-rw-
根据文件资源管理器(即使我已分配777,也没有执行权限。)
但是,当尝试创建文件时,logcat打印:
02-27 17:33:30.097: W/System.err(1939): java.io.IOException: open failed: EACCES (Permission denied)
02-27 17:33:30.097: W/System.err(1939): at java.io.File.createNewFile(File.java:939)
02-27 17:33:30.097: W/System.err(1939): at com.android.incallui.InCallPresenter (...)
02-27 17:33:30.097: W/System.err(1939): at com.android.incallui.CallList.notifyGenericListeners(CallList.java:541)
02-27 17:33:30.097: W/System.err(1939): at com.android.incallui.CallList.onUpdate(CallList.java:188)
02-27 17:33:30.098: W/System.err(1939): at com.android.incallui.Call.update(Call.java:311)
02-27 17:33:30.098: W/System.err(1939): at com.android.incallui.Call.-wrap0(Call.java)
02-27 17:33:30.098: W/System.err(1939): at com.android.incallui.Call$1.onDetailsChanged(Call.java:208)
02-27 17:33:30.098: W/System.err(1939): at android.telecom.Call$4.run(Call.java:1156)
02-27 17:33:30.098: W/System.err(1939): at android.os.Handler.handleCallback(Handler.java:739)
02-27 17:33:30.098: W/System.err(1939): at android.os.Handler.dispatchMessage(Handler.java:95)
02-27 17:33:30.098: W/System.err(1939): at android.os.Looper.loop(Looper.java:148)
02-27 17:33:30.098: W/System.err(1939): at android.app.ActivityThread.main(ActivityThread.java:5417)
02-27 17:33:30.098: W/System.err(1939): at java.lang.reflect.Method.invoke(Native Method)
02-27 17:33:30.098: W/System.err(1939): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-27 17:33:30.098: W/System.err(1939): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-27 17:33:30.098: W/System.err(1939): Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
02-27 17:33:30.098: W/System.err(1939): at libcore.io.Posix.open(Native Method)
02-27 17:33:30.098: W/System.err(1939): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
02-27 17:33:30.098: W/System.err(1939): at java.io.File.createNewFile(File.java:932)
02-27 17:33:30.098: W/System.err(1939): ... 16 more
答案 0 :(得分:1)
仅仅因为您在Android中拥有DAC(rwx)权限,并不意味着您拥有相应的SELinux权限。由于您获得了EACCES,并且如果您的文件确实是777,我的猜测是您在尝试访问它时获得SELinux拒绝。如果你被拒绝,Logcat或dmesg应该有一个avc否认。
可能在AOSP的某处有防护装置,以防止世界可写或世界可读的目录或文件。尝试将权限下放到合理的内容,例如dir的00771和文件的00644。
无论如何,使文件成为世界可读或世界可写的是一个可怕的,通常是不必要的想法。