summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-14 18:11:46 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-16 07:58:20 -0700
commitec3a968df9d8fc706fedb788959631e2ed84e04b (patch)
treeaaa56de98ae2a861aef1d9bc2ab78fe05f06f745 /core
parent1495aa2dbf5366cc135c1ceb959c6a12abbb3e0b (diff)
downloadsubsurface-ec3a968df9d8fc706fedb788959631e2ed84e04b.tar.gz
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>
Diffstat (limited to 'core')
-rw-r--r--core/downloadfromdcthread.cpp10
-rw-r--r--core/downloadfromdcthread.h5
-rw-r--r--core/libdivecomputer.c4
-rw-r--r--core/libdivecomputer.h3
-rw-r--r--core/serial_usb_android.cpp11
-rw-r--r--core/serial_usb_android.h3
6 files changed, 25 insertions, 11 deletions
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp
index c71a96fd9..2517b7fb6 100644
--- a/core/downloadfromdcthread.cpp
+++ b/core/downloadfromdcthread.cpp
@@ -220,6 +220,9 @@ DCDeviceData::DCDeviceData()
#else
data.libdc_log = false;
#endif
+#if defined(Q_OS_ANDROID)
+ data.androidUsbDeviceDescriptor = nullptr;
+#endif
}
DCDeviceData *DCDeviceData::instance()
@@ -320,6 +323,13 @@ void DCDeviceData::setDevName(const QString &devName)
data.devname = copy_qstring(devName);
}
+#if defined(Q_OS_ANDROID)
+void DCDeviceData::setUsbDevice(void *device)
+{
+ data.androidUsbDeviceDescriptor = device;
+}
+#endif
+
void DCDeviceData::setDevBluetoothName(const QString &name)
{
m_devBluetoothName = name;
diff --git a/core/downloadfromdcthread.h b/core/downloadfromdcthread.h
index 4284c2cc6..f142a4243 100644
--- a/core/downloadfromdcthread.h
+++ b/core/downloadfromdcthread.h
@@ -31,7 +31,7 @@ public:
int diveId() const;
/* this needs to be a pointer to make the C-API happy */
- device_data_t* internalData();
+ device_data_t *internalData();
QStringList getProductListFromVendor(const QString& vendor);
int getMatchingAddress(const QString &vendor, const QString &product);
@@ -49,6 +49,9 @@ public:
void setForceDownload(bool force);
void setSaveDump(bool dumpMode);
void setSaveLog(bool saveLog);
+#if defined(Q_OS_ANDROID)
+ void setUsbDevice(void *device);
+#endif
private:
device_data_t data;
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index 475a78ef0..bc0836c3c 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -1336,8 +1336,8 @@ dc_status_t divecomputer_device_open(device_data_t *data)
return ftdi_open(&data->iostream, context);
#endif
#ifdef __ANDROID__
- if (!strcasecmp(data->devname, "usb-serial"))
- return serial_usb_android_open(&data->iostream, context);
+ if (data->androidUsbDeviceDescriptor)
+ return serial_usb_android_open(&data->iostream, context, data->androidUsbDeviceDescriptor);
#endif
rc = dc_serial_open(&data->iostream, context, data->devname);
if (rc == DC_STATUS_SUCCESS)
diff --git a/core/libdivecomputer.h b/core/libdivecomputer.h
index e24143a7b..f8a919bbe 100644
--- a/core/libdivecomputer.h
+++ b/core/libdivecomputer.h
@@ -48,6 +48,7 @@ typedef struct dc_user_device_t
FILE *libdc_logfile;
struct dive_table *download_table;
struct dive_site_table *sites;
+ void *androidUsbDeviceDescriptor;
} device_data_t;
const char *errmsg (dc_status_t rc);
@@ -67,7 +68,7 @@ extern char *dumpfile_name;
dc_status_t ble_packet_open(dc_iostream_t **iostream, dc_context_t *context, const char* devaddr, void *userdata);
dc_status_t rfcomm_stream_open(dc_iostream_t **iostream, dc_context_t *context, const char* devaddr);
dc_status_t ftdi_open(dc_iostream_t **iostream, dc_context_t *context);
-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);
dc_status_t divecomputer_device_open(device_data_t *data);
diff --git a/core/serial_usb_android.cpp b/core/serial_usb_android.cpp
index 8da56b510..7583f5011 100644
--- a/core/serial_usb_android.cpp
+++ b/core/serial_usb_android.cpp
@@ -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);
}
diff --git a/core/serial_usb_android.h b/core/serial_usb_android.h
index 37083c7cf..578fb1a9e 100644
--- a/core/serial_usb_android.h
+++ b/core/serial_usb_android.h
@@ -19,6 +19,7 @@ struct android_usb_serial_device_descriptor {
uint16_t vid;
};
-std::vector<android_usb_serial_device_descriptor> serial_usb_android_get_devices(bool driverSelection);
+std::vector<android_usb_serial_device_descriptor> serial_usb_android_get_devices();
+android_usb_serial_device_descriptor getDescriptor(QAndroidJniObject usbDevice);
#endif