-
Notifications
You must be signed in to change notification settings - Fork 583
Description
Problem description
When using the termux-usb functionality, the USB device is successfully enumerated and authorized, however, attempts to use it with termux-usb -e produces an empty result with no execution of the callback.
Steps to reproduce
Compile the latest termux-api and deployed using adb. In termux, compile the sample program at https://wiki.termux.com/wiki/Termux-usb. Authorize a device connected with USB OTG and run the example command, ie termux-usb -e ./usbtest /dev/bus/usb/001/002
I confirmed the same issue occurs from termux-api-package from master, so it's on the termux-api side.
Expected behavior
We expect to see a printout of the device information. Instead, we get an empty response and a prompt. Something as simple as termux-usb -e echo /dev/bus/usb/001/002
doesn't even show the fd print.
Additional information
- termux-api application version: Latest from master (b732327)
- Android OS version: 13
- Device model: Galaxy S20+
Investigations
I compiled my own termux-api-broadcast and confirmed that the fd returned is -1. I also inspected the recvmsg response and got len=0, thus no callback is issued.
When I looked in app/src/main/java/com/termux/api/TermuxApiReceiver.java, I noticed that when commenting out the following block the API functions properly:
if(pfds[0] != null) {
pfds[0].close();
}
I suspect the issue is that the pfds is getting closed before the output is properly written for the message to dup the fd.
Indeed, when I flush the writer and the outputSocket before closing, it also appears to work.
I suspect the problem was introduced in 3c1a6be which rearranged the socket close logic.