summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-15 15:12:30 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-16 07:58:20 -0700
commit2265a27912dca82cd7bbf51dadadf25be5084174 (patch)
tree662cc7f5a56f189326960d1db0012f5212a2b505
parent0b72495413e8b060b58b96aa6d6a0ce96baa168c (diff)
downloadsubsurface-2265a27912dca82cd7bbf51dadadf25be5084174.tar.gz
android/usb: better memory management
Instead of relying on the std::vector staying unchanged and not freeing its members, instead keep a copy of the object in our DCDeviceData class. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--core/downloadfromdcthread.cpp5
-rw-r--r--core/downloadfromdcthread.h9
-rw-r--r--mobile-widgets/qmlmanager.cpp2
3 files changed, 12 insertions, 4 deletions
diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp
index 2517b7fb6..8a3365842 100644
--- a/core/downloadfromdcthread.cpp
+++ b/core/downloadfromdcthread.cpp
@@ -324,9 +324,10 @@ void DCDeviceData::setDevName(const QString &devName)
}
#if defined(Q_OS_ANDROID)
-void DCDeviceData::setUsbDevice(void *device)
+void DCDeviceData::setUsbDevice(const android_usb_serial_device_descriptor &usbDescriptor)
{
- data.androidUsbDeviceDescriptor = device;
+ androidUsbDescriptor = usbDescriptor;
+ data.androidUsbDeviceDescriptor = &androidUsbDescriptor;
}
#endif
diff --git a/core/downloadfromdcthread.h b/core/downloadfromdcthread.h
index f142a4243..239811749 100644
--- a/core/downloadfromdcthread.h
+++ b/core/downloadfromdcthread.h
@@ -12,6 +12,10 @@
#if BT_SUPPORT
#include "core/btdiscovery.h"
#endif
+#if defined(Q_OS_ANDROID)
+#include "core/serial_usb_android.h"
+#endif
+
/* Helper object for access of Device Data in QML */
class DCDeviceData {
public:
@@ -50,9 +54,12 @@ public:
void setSaveDump(bool dumpMode);
void setSaveLog(bool saveLog);
#if defined(Q_OS_ANDROID)
- void setUsbDevice(void *device);
+ void setUsbDevice(const android_usb_serial_device_descriptor &usbDescriptor);
#endif
private:
+#if defined(Q_OS_ANDROID)
+ struct android_usb_serial_device_descriptor androidUsbDescriptor;
+#endif
device_data_t data;
// Bluetooth name is managed outside of libdivecomputer
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 184ce023f..08b674a2a 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -2024,7 +2024,7 @@ void QMLManager::DC_setDevName(const QString& devName)
for (unsigned int i = 0; i < androidSerialDevices.size(); i++) {
if (androidSerialDevices[i].uiRepresentation == connection) {
appendTextToLog(QString("setDevName matches USB device %1").arg(i));
- DCDeviceData::instance()->setUsbDevice((void *)&androidSerialDevices[i]);
+ DCDeviceData::instance()->setUsbDevice(androidSerialDevices[i]);
}
}
#endif