summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-14 17:25:14 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-16 07:58:20 -0700
commitc19e3bd5ba1fa18d90c14643bf4321029f7b01fe (patch)
tree58d11fe842710f1676f136ebab08fde4ecd2581d /core
parentc81854ca21a4c158a057b7c0d47c704b717fc8ca (diff)
downloadsubsurface-c19e3bd5ba1fa18d90c14643bf4321029f7b01fe.tar.gz
android/usb: remove alternative way of scanning for devices
We now always create a list of usb devices that doesn't list a driver for known devices, and adds multiple entries with each of the drivers for devices that are unknown to us. This removes some debugging output in the ..._open() function as well. This could be combined with Christof's earlier commit. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r--core/serial_usb_android.cpp61
1 files changed, 14 insertions, 47 deletions
diff --git a/core/serial_usb_android.cpp b/core/serial_usb_android.cpp
index a4f060183..8da56b510 100644
--- a/core/serial_usb_android.cpp
+++ b/core/serial_usb_android.cpp
@@ -303,13 +303,9 @@ android_usb_serial_device_descriptor getDescriptor(QAndroidJniObject usbDevice)
return descriptor;
}
-std::vector<android_usb_serial_device_descriptor> serial_usb_android_get_devices(book driverSelection)
+std::vector<android_usb_serial_device_descriptor> serial_usb_android_get_devices()
{
- std::vector<std::string> driverNames;
- if (driverSelection)
- driverNames = { "", "CdcAcmSerialDriver", "Ch34xSerialDriver", "Cp21xxSerialDriver", "FtdiSerialDriver", "ProlificSerialDriver" };
- else
- driverNames = {""};
+ std::vector<std::string> driverNames = { "", "CdcAcmSerialDriver", "Ch34xSerialDriver", "Cp21xxSerialDriver", "FtdiSerialDriver", "ProlificSerialDriver" };
// Get the current main activity of the application.
QAndroidJniObject activity = QtAndroid::androidActivity();
@@ -325,35 +321,27 @@ std::vector<android_usb_serial_device_descriptor> serial_usb_android_get_devices
jint numDevices = deviceListCollection.callMethod<jint>("size");
QAndroidJniObject arrayOfDevices = deviceListCollection.callObjectMethod("toArray", "()[Ljava/lang/Object;");
- // Special case to keep a generic user-facing name if only one device is present.
- if (numDevices == 1 && !driverSelection) {
- // UsbDevice usbDevice = arrayOfDevices[0]
- jobject value = env->GetObjectArrayElement(arrayOfDevices.object<jobjectArray>(), 0);
+ std::vector<android_usb_serial_device_descriptor> retval;
+ for (int i = 0; i < numDevices ; i++) {
+ // UsbDevice usbDevice = arrayOfDevices[i]
+ jobject value = env->GetObjectArrayElement(arrayOfDevices.object<jobjectArray>(), i);
QAndroidJniObject usbDevice(value);
android_usb_serial_device_descriptor descriptor = getDescriptor(usbDevice);
- descriptor.uiRepresentation = "USB Connection";
-
- return {descriptor};
- } else {
- std::vector<android_usb_serial_device_descriptor> retval;
- for (int i = 0; i < numDevices ; i++) {
- // UsbDevice usbDevice = arrayOfDevices[i]
- jobject value = env->GetObjectArrayElement(arrayOfDevices.object<jobjectArray>(), i);
- QAndroidJniObject usbDevice(value);
-
+ if (knownChipset(descriptor.vid, descriptor.pid)) {
+ retval.push_back(descriptor);
+ } else {
+ std::string ui = descriptor.uiRepresentation;
for (std::string driverName : driverNames) {
- android_usb_serial_device_descriptor descriptor = getDescriptor(usbDevice);
-
descriptor.className = driverName;
if (driverName != "")
- descriptor.uiRepresentation += " (" + driverName + ")";
+ descriptor.uiRepresentation = ui + " (" + driverName + ")";
else
- descriptor.uiRepresentation += " (autoselect driver)";
+ descriptor.uiRepresentation = ui + " (autoselect driver)";
retval.push_back(descriptor);
}
}
- return retval;
}
+ return retval;
}
/*
@@ -362,28 +350,7 @@ std::vector<android_usb_serial_device_descriptor> serial_usb_android_get_devices
*/
dc_status_t serial_usb_android_open(dc_iostream_t **iostream, dc_context_t *context)
{
- // Testing of the method only!
- {
- TRACE(device->contxt, "List of devices with specific drivers:");
- std::vector<android_usb_serial_device_descriptor> devices = serial_usb_android_get_devices(true);
- for (auto device : devices) {
- TRACE(device->contxt,
- "USB Device: uiRepresentation=%s, className=%s, manufacturer=%s, product=%s, pid=%i, vid=%i",
- device.uiRepresentation.c_str(), device.className.c_str(), device.manufacturer.c_str(),
- device.product.c_str(), device.pid, device.vid);
- }
-
- TRACE(device->contxt, "List of devices simple:");
- devices = serial_usb_android_get_devices(false);
- for (auto device : devices) {
- TRACE(device->contxt,
- "USB Device: uiRepresentation=%s, className=%s, manufacturer=%s, product=%s, pid=%i, vid=%i",
- device.uiRepresentation.c_str(), device.className.c_str(), device.manufacturer.c_str(),
- device.product.c_str(), device.pid, device.vid);
- }
- }
-
- std::vector<android_usb_serial_device_descriptor> devices = serial_usb_android_get_devices(false);
+ std::vector<android_usb_serial_device_descriptor> devices = serial_usb_android_get_devices();
if(devices.empty())
return DC_STATUS_NODEVICE;