Android permission for usb device

504 views
Skip to first unread message

Jean-Marc Delaplace

unread,
Feb 5, 2021, 6:52:16 AM2/5/21
to Kivy users support
I am working on the library usbserial4a and there is an unpractical behaviour regarding the usb permission granting process.

I am using Pydroid3. Here is an excerpt of the code of the example usbserial4a_ui_example.py:

    def on_btn_device_release(self, btn):
        device_name = btn.text
        
        if platform == 'android':
            device = usb.get_usb_device(device_name)
            if not device:
                raise SerialException(
                    "Device {} not present!".format(device_name)
                )
            if not usb.has_usb_permission(device):
                usb.request_usb_permission(device)
                return
            self.serial_port = serial4a.get_serial_port(
                device_name,
                9600,
                8,
                'N',
                1,
                timeout=1
            )
        else:
            self.serial_port = Serial(
                device_name,
                9600,
                8,
                'N',
                1,
                timeout=1
            )
        
        if self.serial_port.is_open and not self.read_thread:
            self.read_thread = threading.Thread(target = self.read_msg_thread)
            self.read_thread.start()
        
        self.uiDict['sm'].current = 'screen_test'

I have highlighted two lines relative to the permission granting.
The first time the application finds the serial port, it pops a box requesting the permission to access the usb. I click OK, and the box closes, but the return statement stops the operation.
I tried to remove the return, but then the application does not display the incoming serial traffic as it should do.
I must stop the application using the back arrow, then press the RUN arrow again, the app starts, does not ask for the permission, and correctly display the incoming traffic.
So my question is: why, once the permission is granted, is not the usb serial device ready for operation?



planckp...@gmail.com

unread,
Feb 5, 2021, 12:16:02 PM2/5/21
to Kivy users support
Not the place to ask about what I assume is a Pydroid api ,
Python-for-Android has a different permissions api:
Reply all
Reply to author
Forward
0 new messages