android 8.1中在SystemUI里面添加了通过jni对驱动节点的ioctl操作,编译user版本的时候受selinux限制,在device目录下的sepolicy下的platform_app.te中添加了ioctl 允许语句,但是还是提示没有权限。打印如下log:
ndroid.systemui: type=1400 audit(0.0:17): avc: denied { ioctl } for path="/dev/mmled" dev="tmpfs" ino=1174 ioctlcmd=44 scontext=u:r:platform_app:s0:c512,c768 tcontext=u:object_r:mmled_device:s0 tclass=chr_file permissive=0
后面查找资料(参见https://www.jianshu.com/p/66062e509d13),是由于Mutil-Level Security(MLS)机制导致的操作被denied了。
需要在platform_app.te中添加type platform_app, domain, mlstrustedsubject; 即可解决
注意需要在system/sepolicy/public/platform_app.te下添加,device下的platform_app.te为扩展文件,添加了编译会报Duplicate declaration of type重复添加错误。