From 1c806bb5721bcfb5e3c3188d847698d616869c5a Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 31 Jan 2021 19:42:41 -0600 Subject: [PATCH] Only use the virtual device as a gamepad if at least one gamepad is present --- .../binding/input/ControllerHandler.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/limelight/binding/input/ControllerHandler.java b/app/src/main/java/com/limelight/binding/input/ControllerHandler.java index 6088f537..dd497092 100644 --- a/app/src/main/java/com/limelight/binding/input/ControllerHandler.java +++ b/app/src/main/java/com/limelight/binding/input/ControllerHandler.java @@ -199,7 +199,22 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD // HACK for https://issuetracker.google.com/issues/163120692 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) { if (device.getId() == -1) { - return true; + // This "virtual" device could be input from any of the attached devices. + // Look to see if any gamepads are connected. + int[] ids = InputDevice.getDeviceIds(); + for (int id : ids) { + InputDevice dev = InputDevice.getDevice(id); + if (dev == null) { + // This device was removed during enumeration + continue; + } + + // If there are any gamepad devices connected, we'll + // report that this virtual device is a gamepad. + if (hasJoystickAxes(dev) || hasGamepadButtons(dev)) { + return true; + } + } } }