Why can't I open/write from a serial port on Android?

拟墨画扇 提交于 2019-12-04 17:28:16

Gabe, Google changed the SELinux mode from Permissive Mode to Enforce Mode in Android 4.4, by default apps do not have the (SELinux) permissions to access the serial ports. Here are a couple of ways to work around the issue: (1). If your device is rooted you can toggle the SELinux mode from Enforce Mode to Permissive Mode: “su setenforce 0”. You will need to run the command every time you restart your device. see http://www.xda-developers.com/easily-change-your-android-selinux-mode/ (2). If you have access to the kernel framework files for the device you can change them and grant serial port access to your apps.

Amit

run setenforce 0 from shell to disable SELinux. It worked for me and I was able to read/write on tty/ACM0.

The issue turned out to be with SELinux, which most of the Samsung line of devices use as a security enforcement policy. That security policy was set to enforcing, such that no apps could access files outside of their designated app space, such as the serial port I was trying to open.

Given that we could change the kernel, we were able to add a policy exception to SELinux that gave my app elevated priviliges, thereby allowing it to open the port correctly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!