Android为system_app开放sys下节点的读写权限
由于Android源码的SELinux安全访问机制,app是无法直接访问设备节点,systemAPP也不行
开放权限步骤:
节点的实际路径:/sys/devices/platform/5v_en/led
1、在\device\rockchip\common\sepolicy目录下file.te文件中添加
type sysfs_led, fs_type, sysfs_type;
sysfs_led为自定义的名称(如果是dev/下的应该写在device.te文件中,具体照着其他的写就行)
2、在file_context 文件中:
/sys/devices/platform/5v_en/led u:object_r:sysfs_led_state:s0
节点路径,u:object_r:(在file.te中定义的名称):s0
3、为systemAPP 开放权限 ,所以在 system_app.te中添加
allow system_app sysfs_led:chr_file rw_file_perms;
allow system_app sysfs_led:file { open write getattr };
其中 open write getattr 权限查看avc日志补全缺少的权限:
avc: denied { write } for name="system_app " scontext=u:r:system_app:s0:c512,c768 tcontext=u:r:sysfs_led:s0 tclass=file permissive=1
这个大概意思就是system_app缺少对sysfs_led:file的write的权限,写法:
allow system_app sysfs_led:file { write };
这样就为systemAPP开放了对led节点的读写的操作权限,
如果使用这种方法对第三方APP untrusted_app 开放权限,会编译报错。