andriod JNI 访问权限 open总是失败

现象:JNI中open 总是失败,打印信息如下

[  622.188592] type=1400 audit(1718.939:13): avc: denied { read write } for pid=6144 comm="ter.com.control" name="sc20_gpio" dev="tmpfs" ino=9251 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:sc20_gpio_device:s0 tclass=chr_file permissive=0

执行 setenforce 0 ,chmod 777 /dev/sc20_gpio 后打开成功,说明是selinux原因

修改如下:
1.device\qcom\sepolicy\common\untrusted_app.te下添加
type sc20_gpio_device, dev_type,mlstrustedobject;

2.device\qcom\sepolicy\common\untrusted_app.te 下添加
allow untrusted_app sc20_gpio_device:chr_file rw_file_perms;

3.device\qcom\sepolicy\common\file_contexts 下添加
/dev/sc20_gpio u:object_r:sc20_gpio_device:s0

4.device\qcom\common\rootdir\etc\init.qcom.rc 下添加
chmod 0777 /dev/sc20_gpio

你可能感兴趣的:(andriod JNI 访问权限 open总是失败)