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=0scontext == 》 对应的就是需要添加权限的app类型。
这里就是第三方app,我们在对应文件增加:
allow untrusted_app tty_device_file:chr_file rw_file_perms;make installclean -j12;make -j12 重新编译代码。
如果编译出错,就clean重编一次。
至此,问题解决。