Merge "Allow multiple device entries in usb-car-handler"
diff --git a/car-usb-handler/src/android/car/usb/handler/UsbSettingsStorage.java b/car-usb-handler/src/android/car/usb/handler/UsbSettingsStorage.java
index 1b251f8..7e8704e 100644
--- a/car-usb-handler/src/android/car/usb/handler/UsbSettingsStorage.java
+++ b/car-usb-handler/src/android/car/usb/handler/UsbSettingsStorage.java
@@ -24,6 +24,7 @@
import android.database.sqlite.SQLiteOpenHelper;
import android.hardware.usb.UsbDevice;
import android.util.Log;
+
import java.util.ArrayList;
import java.util.List;
@@ -51,25 +52,23 @@
private Cursor queryFor(SQLiteDatabase db, UsbDevice device) {
String serial = device.getSerialNumber();
String selection;
- String[] selectionArgs;
+ List<String> selectionArgs = new ArrayList<>();
if (AoapInterface.isDeviceInAoapMode(device)) {
selection = COLUMN_SERIAL + " = ? AND " + COLUMN_AOAP + " = 1";
- selectionArgs = new String[] {serial};
+ selectionArgs.add(serial);
} else if (serial == null) {
- selection = COLUMN_SERIAL + " IS NULL AND "
- + COLUMN_VID + " = ? AND " + COLUMN_PID + " = ?";
- selectionArgs = new String[] {
- Integer.toString(device.getVendorId()),
- Integer.toString(device.getProductId())};
+ selection = COLUMN_SERIAL + " IS NULL";
} else {
- selection =
- COLUMN_SERIAL + " = ? AND " + COLUMN_VID + " = ? AND " + COLUMN_PID + " = ?";
- selectionArgs = new String[] {
- device.getSerialNumber(),
- Integer.toString(device.getVendorId()),
- Integer.toString(device.getProductId())};
+ selection = COLUMN_SERIAL + " = ?";
+ selectionArgs.add(serial);
}
- return db.query(TABLE_USB_SETTINGS, null, selection, selectionArgs, null, null, null);
+
+ selection += " AND " + COLUMN_VID + " = ? AND " + COLUMN_PID + " = ?";
+ selectionArgs.add(String.valueOf(device.getVendorId()));
+ selectionArgs.add(String.valueOf(device.getProductId()));
+
+ return db.query(TABLE_USB_SETTINGS, null, selection,
+ selectionArgs.toArray(new String[0]), null, null, null);
}
/**