解决Android5.1之后 tcsetattr出错,错误信息I/O error

       用c写串口调试程序,相关功能都已经调试完成,正准备做成jni给java层调用,发现在调用tcsetattr接口的时候一直返回-1,错误码5,错误信息I/O error,找原因找了一段时间,还把android推荐的那个串口库也移植了,问题依然存在,后面仔细看了下log,发现是全新问题如下:

01-18 08:58:26.990  2692  2692 I jnidemo: type=1400 audit(0.0:53): avc: denied { read write } for name="ttyS1" dev="tmpfs" ino=8867 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:serial_device:s0 tclass=chr_file permissive=1
01-18 08:58:26.990  2692  2692 I jnidemo: type=1400 audit(0.0:54): avc: denied { open } for path="/dev/ttyS1" dev="tmpfs" ino=8867 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:serial_device:s0 tclass=chr_file permissive=1
01-18 08:58:26.993  2692  2692 I jnidemo: type=1400 audit(0.0:55): avc: denied { ioctl } for path="/dev/ttyS1" dev="tmpfs" ino=8867 ioctlcmd=5401 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:serial_device:s0 tclass=chr_file permissive=1

 发现原来是权限搞得鬼(并非网上所说的NDK版本不对,所以还是要仔细查log)

根据sepolicy权限添加原则(system\sepolicy):

scontext=u:r:untrusted_app:对应的权限文件untrusted_app.te

 tcontext=u:object_r:serial_device:操作的相应设备 serial_device

tclass=chr_file:操作的对应类chr_file

最终在untrusted_app.te 增加如下:

allow untrusted_app serial_device:chr_file { read write open ioctl };

编译kernel,烧写,重新运行就ok

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值