gpt4 book ai didi

android - 打开文件 Android Marshmallow 时 FileNotFound EACCESS

转载 作者:行者123 更新时间:2023-11-29 14:37:00 31 4
gpt4 key购买 nike

在我的产品的自动化测试期间,我将文件推送到应用程序的私有(private)目录,然后 chmod 文件,以便应用程序可以访问它。在 APIs < Marshmallow 上,这很好,应用程序在访问文件时从未遇到过问题。

现在,在某些文件上,我在尝试打开它时收到以下日志:

W/System.err(7669): Caused by: 
java.io.FileNotFoundException: /data/user/0/foo/foo.txt: open failed: EACCES (Permission denied) 09-28 18:20:56.724:
W/System.err(7669): at libcore.io.IoBridge.open(IoBridge.java:452) 09-28 18:20:56.724:
W/System.err(7669): at java.io.FileInputStream.<init>(FileInputStream.java:76) 09-28 18:20:56.724:
W/System.err(7669): at android.app.ContextImpl.openFileInput(ContextImpl.java:384) 09-28 18:20:56.724:
W/System.err(7669): at android.content.ContextWrapper.openFileInput(ContextWrapper.java:177) 09-28 18:20:56.724:
W/System.err(7669): Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) 09-28 18:20:56.724:
W/System.err(7669): at libcore.io.Posix.open(Native Method) 09-28 18:20:56.724:
W/System.err(7669): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) 09-28 18:20:56.724:
W/System.err(7669): at libcore.io.IoBridge.open(IoBridge.java:438) 09-28 18:20:56.716:
W/pool-5-thread-1(8279): type=1400 audit(0.0:57): avc: denied { search } for name="files" dev="mtdblock1" ino=7314 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0 tclass=dir permissive=0

我该如何解决?

最佳答案

Android Marshmallow 采用了其底层操作系统 SELinux(安全增强型 Linux)的扩展文件属性,因此通过 shell 而不是通过具有财政司司长。

首先,确保您正确chmod 文件。然后,确保该文件也被正确拥有。您可以通过执行 ls -la file 检查普通文件的所有者和组的外观,然后将有问题的文件的组更改为您从 chgrp user 的上一个命令中找到的组。组文件

$ ls -la  
drwxrwxrwx u0_a69 u0_a69 2015-09-28 18:20 existing_file
drwxrwxrwx root root 2015-09-28 18:20 file
$ chown u0_a69.u0_a69 file

如果这些都不起作用,请通过 ls -Z file 检查扩展文件属性并阅读 https://fedoraproject.org/wiki/Security_context?rd=SELinux/SecurityContext了解您正在查看的内容,然后使用 chcon some:extended:security:attributes file 更改您的文件权限。

$ ls -Z 
drwxrwx--x u0_a69 u0_a69 u:object_r:app_data_file:s0:c512,c768 existing_file
drwxrwx--x u0_a69 u0_a69 u: file
$ chcon u:object_r:app_data_file:s0:c512,c768 file

如果仍然不起作用,/system/bin 中有一个名为 setenforce 的二进制文件,它禁用 Marshmallow 底层 SELinux 的扩展文件系统安全性。

从 root shell 调用 setenforce permissive,您的应用程序将能够访问它需要的文件。这可能会掩盖错误,因此请谨慎使用。

$ setenforce permissive

关于android - 打开文件 Android Marshmallow 时 FileNotFound EACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32832836/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com