android/usb: pass in the UsbDevice when downloading

This finally allows us to download from not just the first device, but specifically
the device that the user picks.

Passing the object through a void pointer is not nice - but since this traverses
C code other solutions (like passing an index into the list) seemed even worse.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-03-14 18:11:46 -07:00
parent 1495aa2dbf
commit ec3a968df9
8 changed files with 38 additions and 11 deletions

View file

@ -348,13 +348,12 @@ std::vector<android_usb_serial_device_descriptor> serial_usb_android_get_devices
* For testing and compatibility only, can be removed after the UI changes. Behaves exactly like the "old"
* implementation if only one device is attached.
*/
dc_status_t serial_usb_android_open(dc_iostream_t **iostream, dc_context_t *context)
dc_status_t serial_usb_android_open(dc_iostream_t **iostream, dc_context_t *context, void *androidUsbDevice)
{
std::vector<android_usb_serial_device_descriptor> devices = serial_usb_android_get_devices();
if(devices.empty())
if (!androidUsbDevice)
return DC_STATUS_NODEVICE;
android_usb_serial_device_descriptor *usbDeviceDescriptor = (android_usb_serial_device_descriptor *)androidUsbDevice;
return serial_usb_android_open(iostream, context, devices[0].usbDevice, devices[0].className);
// danger, danger, we need to pick the correct device here - passing the index around assumes that the table didn't change
return serial_usb_android_open(iostream, context, usbDeviceDescriptor->usbDevice, usbDeviceDescriptor->className);
}