licheedev / Android-SerialPort-API

Fork自Google开源的Android串口通信Demo,修改成Android Studio项目
https://code.google.com/archive/p/android-serialport-api/
Apache License 2.0
1.3k stars 374 forks source link

android 10以上的串口访问权限问题 #49

Closed Domlaa closed 1 year ago

Domlaa commented 1 year ago

在android 10以上的设备运行,扫描端口驱动的时候,无法访问 /proc/tty/drivers

提示信息: 17:07:39.340 System.err W java.io.FileNotFoundException: /proc/tty/drivers: open failed: EACCES (Permission denied) 17:07:39.340 System.err W at libcore.io.IoBridge.open(IoBridge.java:575) 17:07:39.340 System.err W at java.io.FileInputStream.(FileInputStream.java:160) 17:07:39.336 rialport.sample W type=1400 audit(0.0:100530): avc: denied { read } for name="drivers" dev="proc" ino=4026531852 scontext=u:r:untrusted_app_29:s0:c191,c258,c512,c768 tcontext=u:object_r:proc_tty_drivers:s0 tclass=file permissive=0 app=android.serialport.sample 17:07:39.340 System.err W at java.io.FileReader.(FileReader.java:58) 17:07:39.340 System.err W at android.serialport.SerialPortFinder.getDrivers(SerialPortFinder.java:71) 17:07:39.340 System.err W at android.serialport.SerialPortFinder.getAllDevices(SerialPortFinder.java:93) 17:07:39.340 System.err W at android.serialport.sample.SerialPortPreferences.onCreate(SerialPortPreferences.java:42)

可否有解决方法

Mr-Jiang commented 1 year ago

avc: denied { read } for name="drivers" dev="proc" ino=4026531852 scontext=u:r:untrusted_app_29:s0:c191,c258,c512,c768 tcontext=u:object_r:proc_tty_drivers:s0 tclass=file permissive=0 SE-Linux权限问题,如果是自己的方案或平台的话可以修改对应的.te文件,具体看什么平台,每个平台对应的文件都不一样因为都是被产商修改Google原生源码而来的,只能给你提供这些思路

Domlaa commented 1 year ago

avc: denied { read } for name="drivers" dev="proc" ino=4026531852 scontext=u:r:untrusted_app_29:s0:c191,c258,c512,c768 tcontext=u:object_r:proc_tty_drivers:s0 tclass=file permissive=0 SE-Linux权限问题,如果是自己的方案或平台的话可以修改对应的.te文件,具体看什么平台,每个平台对应的文件都不一样因为都是被产商修改Google原生源码而来的,只能给你提供这些思路

感谢,不过已经换方案实现了,采用了usbdevice的方式检测连接