Android权限 - avc权限问题

1.一般来说,如何确认是Selinux权限引起的问题?
通过命令adb shell getenforce,查看Selinux状态
adb shell getenforce
Enforcing  //1
Permissive //0
如果为Enforcing,则使用命令adb shell setenforce 0,设置成Permissive mode,如果设置成Permissive mode后没有问题,就是SELinux方面的问题。
adb shell setenforce 0
0代表Permissive
1代表Enforcing

2.在访问文件过程中,报avc权限问题log一般如下(搜索avc: denied):
04-03 14:56:15.919  3877  3877 W droid.launcher3: type=1400 audit(0.0:213): avc: denied { open } for path="/data/system/myapp.config" dev="dm-0" ino=4538462 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0 app=com.android.launcher3
04-03 14:56:15.929  3877  3877 E CheckPresetApp: /data/system/myapp.config: open failed: EACCES (Permission denied)
04-03 14:56:15.929  3877  3877 E CheckPresetApp: java.io.FileNotFoundException: /data/system/myapp.config: open failed: EACCES (Permission denied)

3.如何添加相应的权限

以上面这条avc log为例:
avc: denied { open } for path="/data/system/myapp.config" dev="dm-0" ino=4538462 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0 app=com.android.launcher3

缺少的权限:{ open }

谁缺少权限:scontext=u:r:platform_app:s0:c512

对哪个文件缺少权限:tcontext=u:object_r:system_data_file:s0

什么类型的文件:tclass=file

也就是说:在platform_app进程对system_data_file类型的file缺少read权限

在platform_app.te(device\qcom\sepolicy\generic\vendor\common\platform_app.te,找到自己项目中使用的相应的te文件)文件中添加:
allow platform_app system_data_file:file { open };
因为我需要读myapp.config中的内容,所以还一起添加了read权限:
allow platform_app system_data_file:file { open read };

参考:https://blog.csdn.net/tung214/article/details/72734086

扫描二维码关注公众号,回复: 13613518 查看本文章

猜你喜欢

转载自blog.csdn.net/hanhan1016/article/details/105929535