1. 程式人生 > >android 7.1 服務程序 open串列埠裝置失敗

android 7.1 服務程序 open串列埠裝置失敗

寫了一個簡單的helloworld程式作為一個服務,執行後出現各種avc許可權問題,如open(/dev/tty*)裝置返回-1,log如下:

01-01 11:47:51.200  1714  1714 W helloworld: type=1400 audit(0.0:96): avc: denie
d { read write } for name="ttyVCOM0" dev="tmpfs" ino=3390 scontext=u:r:helloworl
d:s0 tcontext=u:object_r:device:s0 tclass=chr_file permissive=0

解決辦法:

在helloworld.te中新增

allow helloworld device:chr_file rw_file_perms;