From 72d14c281ce863cd3578fa59deef42fe554c9ed8 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Sat, 6 Jun 2026 11:13:46 +0200
Subject: [PATCH] Fixed bug #13850: SDLControllerManager, we can use
isVirtual() since API > 16
---
.../src/main/java/org/libsdl/app/SDLActivity.java | 4 ++--
.../java/org/libsdl/app/SDLControllerManager.java | 12 +++++++-----
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index 4edeecc33cf28..62abfa7aa4cf2 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -1495,9 +1495,9 @@ public static boolean isTextInputEvent(KeyEvent event) {
public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputConnection ic) {
int deviceId = event.getDeviceId();
int source = event.getSource();
+ InputDevice device = InputDevice.getDevice(deviceId);
if (source == InputDevice.SOURCE_UNKNOWN) {
- InputDevice device = InputDevice.getDevice(deviceId);
if (device != null) {
source = device.getSources();
}
@@ -1516,7 +1516,7 @@ public static boolean handleKeyEvent(View v, int keyCode, KeyEvent event, InputC
// Furthermore, it's possible a game controller has SOURCE_KEYBOARD and
// SOURCE_JOYSTICK, while its key events arrive from the keyboard source
// So, retrieve the device itself and check all of its sources
- if (SDLControllerManager.isDeviceSDLJoystick(deviceId)) {
+ if (SDLControllerManager.isDeviceSDLJoystick(device)) {
// Note that we process events with specific key codes here
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (SDLControllerManager.onNativePadDown(deviceId, keyCode, event.getScanCode())) {
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
index 1335933b836c6..f61bab1d54db7 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
@@ -144,11 +144,9 @@ static void hapticStop(int device_id)
}
// Check if a given device is considered a possible SDL joystick
- static public boolean isDeviceSDLJoystick(int deviceId) {
- InputDevice device = InputDevice.getDevice(deviceId);
- // We cannot use InputDevice.isVirtual before API 16, so let's accept
- // only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
- if ((device == null) || (deviceId < 0)) {
+ static public boolean isDeviceSDLJoystick(InputDevice device) {
+ // No virtual device (eg nonnegative deviceId. VIRTUAL_KEYBOARD equals -1)
+ if (device == null || device.isVirtual()) {
return false;
}
int sources = device.getSources();
@@ -171,6 +169,10 @@ static public boolean isDeviceSDLJoystick(int deviceId) {
((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
);
}
+
+ static public boolean isDeviceSDLJoystick(int deviceId) {
+ return isDeviceSDLJoystick(InputDevice.getDevice(deviceId));
+ }
}