1
votes

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)

  1. Is it possible to change the permissions permanently?
  2. Does android run as a root or any other user?
  3. Generally ttyUSB0 belongs to dialout group, why it is showing as root and crw------- instead of crw-rw---- ?
  4. Why accessing from exe works and accessing from shared library falils?

Hardware platform : Beagle Board - XM OS: Android Froyo Can anyone please help?

1
I don't think this is a programming question.unwind
@unwind The solutions may requires some programming, and it's a bit obscure for any of the usage or administration oriented sites. Note also that the poster is writing an application.Chris Stratton

1 Answers

0
votes

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.