ardera / flutter_packages

My collected packages for pub.dev
MIT License
28 stars 7 forks source link

Permission denied, errno = 13 #16

Open schigabiga opened 1 year ago

schigabiga commented 1 year ago

Hello! I started to use https://pub.dev/packages/linux_serial this package, but after I run on Android 11 mobile and called the below function I got an error. final ports = SerialPorts.ports; print(ports);

Error: Directory listing failed, path = '/sys/dev/char/' (OS Error: Permission denied, errno = 13)

Stack:

#0      _Directory._fillWithDirectoryListing (dart:io-patch/directory_patch.dart:42:24)
#1      _Directory.listSync (dart:io/directory_impl.dart:243:5)
#2      SerialPorts.ports (package:linux_serial/src/linux_serial.dart:581:7)
#3      _MyHomePageState._incrementCounter (package:usb_serial_test/main.dart:37:31)
#4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:1005:21)
#5      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:198:24)
#6      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:613:11)
#7      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:298:5)

I got the same error, when I used these packages: https://pub.dev/packages/libserialport , https://pub.dev/packages/flutter_libserialport

What kind of permission should I grant? Thank you in advance!

Flutter version:

Flutter 3.0.0
Framework • revision ee4e09cce0 (8 months ago) • 2022-05-09 16:45:18 -0700
Engine • revision d1b9a6938a
Tools • Dart 2.17.0 • DevTools 2.12.2
ardera commented 1 year ago

For listing the serial ports, read access to /sys/dev/char is required. You can try running chmod ugo+r /sys/dev/char as the root user to grant everyone access to that folder. Though that may be a security problem. There's probably a reason why android doesn't grant the permission by default.

If you know the path of the serial port device, you can also try creating the serial port directly:

final port = SerialPort('/dev/ttyUSB0', 0, 0, '');

To read & write the serial port, you also need read&write access to the device node, so (in the example above) read & write permissions to /dev/ttyUSB0