From cdd397118f07eba0f664535c14f6b4f1ab499744 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 15 Dec 2020 14:57:49 -0800 Subject: [PATCH] Fixed the Xbox Series X controller showing up twice on Android --- .../src/main/java/org/libsdl/app/HIDDeviceManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index 56f677e66..5899817f6 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -353,9 +353,18 @@ public class HIDDeviceManager { private void connectHIDDeviceUSB(UsbDevice usbDevice) { synchronized (this) { + int interface_mask = 0; for (int interface_index = 0; interface_index < usbDevice.getInterfaceCount(); interface_index++) { UsbInterface usbInterface = usbDevice.getInterface(interface_index); if (isHIDDeviceInterface(usbDevice, usbInterface)) { + // Check to see if we've already added this interface + // This happens with the Xbox Series X controller which has a duplicate interface 0, which is inactive + int interface_id = usbInterface.getId(); + if ((interface_mask & (1 << interface_id)) != 0) { + continue; + } + interface_mask |= (1 << interface_id); + HIDDeviceUSB device = new HIDDeviceUSB(this, usbDevice, interface_index); int id = device.getId(); mDevicesById.put(id, device);