MTK 5.1 开启SELinux后,添加串口读写权限

1,找到源码编译时使用的device.te 文件。
我的代码对应目录在:device/mediatek/common/sepolicy/device.te
定义一个类型:
type tty_device_file,dev_type;
tty_device_file 为类型名称,名字可以随意取,原则是方便理解。

2,找到源码编译时使用的file_contexts文件。
我的代码对应目录在:device/mediatek/common/sepolicy/file_contexts
绑定 tty_device_file对应的label:
/dev/ttymxc[0-3] u:object_r:tty_device_file:s0

3,申请权限。
系统app:/device/mediatek/common/sepolicy/system_app.te
第三方app:/device/mediatek/common/sepolicy/untrusted_app.te

或者根据log提示对应的地方增加申请权限,连接adb后,
用命令:dmesg | grep avc 获取日志。
如: avc: denied { read } for pid=2478 comm="jw.ComAssistant" >name="ttymxc1" dev="tmpfs" ino=5327 scontext=u:r:untrusted_app:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=0

scontext == 》 对应的就是需要添加权限的app类型。

这里就是第三方app,我们在对应文件增加:
allow untrusted_app tty_device_file:chr_file rw_file_perms;

make installclean -j12;make -j12 重新编译代码。
如果编译出错,就clean重编一次。

至此,问题解决。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容