Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bast practice to solve the permission denied #3

Open
fynxiu opened this issue Sep 15, 2020 · 17 comments
Open

Bast practice to solve the permission denied #3

fynxiu opened this issue Sep 15, 2020 · 17 comments
Labels
help wanted Extra attention is needed

Comments

@fynxiu
Copy link

fynxiu commented Sep 15, 2020

@jpnurmi Thanks for the useful package.
I have a little problem when use it on USB serial device. The device file's permission is default 500, and chmod 755 could only temporarily make it work. Is there any better way to make it work permanently?

@jpnurmi
Copy link
Owner

jpnurmi commented Sep 15, 2020

The serial port device nodes are most likely owned by the dialout group:

$ ls -la /dev/ttyA*
crw-rw---- 1 root dialout 166,  0 Jan  1 00:00 /dev/ttyACM0
crw-rw---- 1 root dialout 204, 64 Sep 13  2020 /dev/ttyAMA0

If you add your user to the dialout group, logout, and re-login, it should be allowed to access the port. For example:

sudo usermod -a -G dialout $USER

P.S. There are also other alternatives, such as specifying the desired owner and/or permissions as UDEV rules.

@fynxiu
Copy link
Author

fynxiu commented Sep 16, 2020

Thanks. The app I'm developing is exclusive to Android, so I write a Plugin, and use Android API related to USB to implement it. Also, we can listen the attached/detached events to realize the hot plug of USB. While, there's another question: How can I substitute the stream in SerialPortReader after re-plug the USB and the stream observers don't have to re-subscript the stream again?

@ayalma
Copy link

ayalma commented Sep 21, 2020

Hi
The app throw Permission denied, errno = 0
When i use it on android device

@jpnurmi
Copy link
Owner

jpnurmi commented Sep 26, 2020

While, there's another question: How can I substitute the stream in SerialPortReader after re-plug the USB and the stream observers don't have to re-subscript the stream again?

Thanks for bringing this up, I've split this to a separate issue: #4

The app throw Permission denied, errno = 0
When i use it on android device

Hi @fynxiu, how did you manage to solve the permission issue on Android? When I wrote the instructions above, I was actually thinking about Linux. Does the same trick work on Android too? According to libserialport they do support Android, but I don't think I have any suitable devices to test with.

@jpnurmi
Copy link
Owner

jpnurmi commented Sep 28, 2020

I have flashed AOSP 10 on a Raspberry Pi 4. I'm having trouble connecting an STM32 development board over USB. Any tips?

With USB cable attached:

130|rpi4:/ # lsusb
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 004: ID 062a:4101
Bus 001 Device 002: ID 2109:3431
Bus 002 Device 001: ID 1d6b:0003
Bus 001 Device 005: ID 0483:5740 # <=== STM32
Bus 001 Device 003: ID 0eef:0005

With USB cable detached:

rpi4:/ # lsusb
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 004: ID 062a:4101
Bus 001 Device 002: ID 2109:3431
Bus 002 Device 001: ID 1d6b:0003
Bus 001 Device 003: ID 0eef:0005

The USB device is clearly recognized, but it doesn't show up in /dev. The output of ls -la /dev/tty* is the same regardless of whether the USB cable is connected or not. There should be something like ttyACM0 or ttyUSB0... what's the trick to make /dev/ttyXXX appear on Android

rpi4:/ # ls -la /dev/tty*
crw-rw-rw- 1 root      root        5,   0 1970-01-01 00:00 /dev/tty
crw-rw---- 1 bluetooth bluetooth 204,  64 1970-01-01 00:00 /dev/ttyAMA0
crw------- 1 root      root        4,  64 1970-01-01 00:00 /dev/ttyS0
crw------- 1 root      root        5,   3 1970-01-01 00:00 /dev/ttyprintk

For reference, the exact same hardware on Linux (Raspberry Pi 4 + Raspberry Pi OS & STM32):

2020-09-28-163940_640x480_scrot

@jpnurmi
Copy link
Owner

jpnurmi commented Sep 28, 2020

It turns out I had to re-compile the kernel with Device drivers => USB support => USB Modem (CDC ACM).

Furthermore, I added the following line to /vendor/ueventd.rc:

/dev/ttyACM0              0666   system     usb

Now, when I connect the USB cable:

[  179.656912] usb 1-1.4: new high-speed USB device number 6 using xhci_hcd
[  179.788579] usb 1-1.4: New USB device found, idVendor=0483, idProduct=5740, bcdDevice= 2.00
[  179.797109] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  179.804539] usb 1-1.4: Product: STM32 Virtual ComPort
[  179.809709] usb 1-1.4: Manufacturer: STMicroelectronics
[  179.815028] usb 1-1.4: SerialNumber: XXXXX0010001
[  179.830525] cdc_acm 1-1.4:1.0: ttyACM0: USB ACM device

The device node:

rpi4:/ # ls -la /dev/ttyACM*                                                                                                                                                                                      
crw-rw-rw- 1 system usb 166,   0 2020-09-28 16:39 /dev/ttyACM0

And it shows up in the flutter_serial_port example too:

image

foo_2

@jpnurmi
Copy link
Owner

jpnurmi commented Sep 28, 2020

Interestingly, with sufficient permissions defined in uevend.rc, I do still see some SELinux-related warnings, but reading and writing works regardless. Here just polling some sort of status message that my dev board answers to.

Launching lib/main.dart on Raspberry Pi 4 in debug mode...
Running Gradle task 'assembleDebug'...
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...
Waiting for Raspberry Pi 4 to report its views...
Debug service listening on ws://127.0.0.1:36327/KKdyoMiqINM=/ws
Syncing files to device Raspberry Pi 4...
I/1.ui    ( 1328): type=1400 audit(0.0:54): avc: denied { getattr } for path="/dev/ttyACM0" dev="tmpfs" ino=8465 scontext=u:r:untrusted_app:s0:c29,c256,c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1 app=org.sigrok.flutter_serial_port_example
I/1.ui    ( 1328): type=1400 audit(0.0:55): avc: denied { read } for name="busnum" dev="sysfs" ino=17196 scontext=u:r:untrusted_app:s0:c29,c256,c512,c768 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1 app=org.sigrok.flutter_serial_port_example
I/1.ui    ( 1328): type=1400 audit(0.0:58): avc: denied { read write } for name="ttyACM0" dev="tmpfs" ino=8465 scontext=u:r:untrusted_app:s0:c29,c256,c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1 app=org.sigrok.flutter_serial_port_example
I/flutter ( 1328): w: [83, ..., 166]
I/flutter ( 1328): r: [83, ..., 164]
I/flutter ( 1328): w: [83, ..., 166]
I/flutter ( 1328): r: [83, ..., 164]
[...]

@jpnurmi
Copy link
Owner

jpnurmi commented Sep 28, 2020

I think it's a matter of Writing SELinux Policy for your Android device.

@fynxiu
Copy link
Author

fynxiu commented Sep 30, 2020

While, there's another question: How can I substitute the stream in SerialPortReader after re-plug the USB and the stream observers don't have to re-subscript the stream again?

Thanks for bringing this up, I've split this to a separate issue: #4

The app throw Permission denied, errno = 0
When i use it on android device

Hi @fynxiu, how did you manage to solve the permission issue on Android? When I wrote the instructions above, I was actually thinking about Linux. Does the same trick work on Android too? According to libserialport they do support Android, but I don't think I have any suitable devices to test with.

@jpnurmi sorry, I just saw this message.
The android device I use is rooted, so I just programmatically give the device file descriptor read/write permission.

@workoutand
Copy link

@fynxiu Can you make a step by step how to make this lib work on android? I don't know much

@fynxiu
Copy link
Author

fynxiu commented Apr 17, 2022

@fynxiu Can you make a step by step how to make this lib work on android? I don't know much

I'm really sorry that I just saw your message now.

I haven't been in contact with this project for a long time.

@trapeye
Copy link

trapeye commented Nov 17, 2022

is this fix yet?

@asrafilll
Copy link

Still have the same problem guys, is it fixed yet? Thanks

@rohit-arctano
Copy link

any one find a solution how to access serial port in android

@winzawhein
Copy link

anyone fixed???

@NaifAlluhaidan
Copy link

Permission denied, errno = 13
is still showing even if i run the example in flutter_libserialport package in flutter.
can anyone show its AndroidManifest.xml?

@NaifAlluhaidan
Copy link

While, there's another question: How can I substitute the stream in SerialPortReader after re-plug the USB and the stream observers don't have to re-subscript the stream again?

Thanks for bringing this up, I've split this to a separate issue: #4

The app throw Permission denied, errno = 0
When i use it on android device

Hi @fynxiu, how did you manage to solve the permission issue on Android? When I wrote the instructions above, I was actually thinking about Linux. Does the same trick work on Android too? According to libserialport they do support Android, but I don't think I have any suitable devices to test with.

@jpnurmi sorry, I just saw this message. The android device I use is rooted, so I just programmatically give the device file descriptor read/write permission.

how did you do that?
o tried to solve the problem but i couldn't );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

9 participants