USB串口转换器ttyUSB0权限问题
我们正在开发一个从串行设备读取数据的应用程序。现有的 C++ 代码被重用为共享库(libProtocol.so 使用 NDK 构建)来读取和解码设备中的数据并将其传递给应用程序。但是当设备连接时,由于权限问题,共享库代码无法访问设备。在 adb shell 命令 ls -l/dev/ttyUSB0 中显示“crw-------- root root”。如果我手动从 adb 使用 chmod 777 ttyUSB0 ,然后运行该应用程序,它就能够打开该端口。 (如果我创建一个C++ exe来访问USB串行端口并在android环境中运行,它可以访问该端口,但从共享库访问失败)
- 是否可以永久更改权限?
- android 是否以 root 或其他用户身份运行?
- 一般来说 ttyUSB0 属于 dialout 组,为什么它显示为 root 和 crw-------- 而不是 crw-rw---- ?
- 为什么从 exe 访问可以,而从共享库访问却失败?
硬件平台:Beagle Board - XM 操作系统:Android Froyo 有人可以帮忙吗?
We are developing an application which reads data from a serial device. Existing C++ code is reused as a shared library (libProtocol.so is built using NDK) to read and decode the data from the device and pass it to the application. But when the device is connected, the shared library code is not able to access the device because of the permission issues. In adb shell command ls -l/dev/ttyUSB0 shows "crw------- root root". If I mannually use chmod 777 ttyUSB0 from adb and after that run the application, it is able to open the port. (If I create a C++ exe to access USB Serial port and run in android environment, it is able access the port but accessing from shared library fails)
- Is it possible to change the permissions permanently?
- Does android run as a root or any other user?
- Generally ttyUSB0 belongs to dialout group, why it is showing as root and crw------- instead of crw-rw---- ?
- Why accessing from exe works and accessing from shared library falils?
Hardware platform : Beagle Board - XM
OS: Android Froyo
Can anyone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要弄清楚设备文件的创建位置,并适当地设置权限。这可能位于 /init.rc 或类似文件中,或者可能位于 USB 设备插入时触发的内容中。对文件系统的部分设备名称(由特权用户)进行递归 grep 可以帮助您找到出现该字符串的所有内容,从而在几分钟内为您提供答案,至少前提是它是本机代码而不是dalvik 类文件(我认为不太可能)
Android 应用程序通常不会以 root 身份运行;让它们这样做是相当复杂的,因为它们通常不是按正常意义上启动的,而是从 zygote 进程中分叉出来的(因此可以共享公共库映射)。但一个选择是,Android 应用程序可以 - 非正式地 - 启动 setuid 二进制文件,并使用它们作为代理来执行操作,即,您可以拥有一些东西,将其 stdin 上收到的任何内容写入到端口,并打印从其端口上接收到的任何内容。标准输出。
You need to figure out where the device file is being created, and set the permissions appropriately. This may be in /init.rc or similar or it may be in something triggered upon USB device insertion. A recursive grep of the filesystem for part of the device name (by a priveleged user) may get you an answer in a couples of minutes by helping you find everything with an occurrence of that string, at least provided it's in native code and not a dalvik classfile (which I would consider unlikely)
Android applications do not normally run as root; it's quite complicated to make them do so, because they are not normally launched in the normal sense, but instead forked off of the zygote process (so common library mappings can be shared). But an option is that android apps can - unofficially - launch setuid binaries, and use them as proxies to do things, ie, you can have something that just writes anything received on its stdin to the port and prints anything received from the port on its stdout.