From d60d565bf45a02eeaac021219b7d2ea735d076d5 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 28 Oct 2026 15:05:09 -0700
Subject: [PATCH] Improved responsiveness of Android joystick hotplug
---
src/hidapi/SDL_hidapi.c | 5 +++++
src/hidapi/SDL_hidapi_c.h | 3 +++
src/hidapi/android/hid.cpp | 5 +++++
3 files changed, 13 insertions(+)
diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c
index b7ff159720b46..a379a9022f4d1 100644
--- a/src/hidapi/SDL_hidapi.c
+++ b/src/hidapi/SDL_hidapi.c
@@ -131,6 +131,11 @@ static void HIDAPI_DeviceChanged(void)
SDL_AddAtomicU32(&SDL_HIDAPI_discovery.m_unDeviceChangeCounter, 1);
}
+void SDL_HIDAPI_DeviceChanged(void)
+{
+ HIDAPI_DeviceChanged();
+}
+
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK)
#include <initguid.h>
diff --git a/src/hidapi/SDL_hidapi_c.h b/src/hidapi/SDL_hidapi_c.h
index 706d96a30c7a0..2ad9e72b7207e 100644
--- a/src/hidapi/SDL_hidapi_c.h
+++ b/src/hidapi/SDL_hidapi_c.h
@@ -24,3 +24,6 @@
/* Return true if the HIDAPI should ignore a device during enumeration */
extern bool SDL_HIDAPI_ShouldIgnoreDevice(int bus_type, Uint16 vendor_id, Uint16 product_id, Uint16 usage_page, Uint16 usage, bool libusb, bool is_xbox);
+/* Called by platform backends when devices may have changed, this is safe to call from any thread */
+extern void SDL_HIDAPI_DeviceChanged(void);
+
diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp
index f1cb937fa4996..474a771d63dab 100644
--- a/src/hidapi/android/hid.cpp
+++ b/src/hidapi/android/hid.cpp
@@ -954,6 +954,7 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNI
{
g_Devices = pDevice;
}
+ SDL_HIDAPI_DeviceChanged();
}
extern "C"
@@ -976,6 +977,9 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceOpenResult)(JN
{
pDevice->SetOpenResult( bOpened );
}
+
+ // Devices waiting for permission are hidden from enumeration until the open completes
+ SDL_HIDAPI_DeviceChanged();
}
extern "C"
@@ -1007,6 +1011,7 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceDisconnected)(
{
pDevice->Close( false );
}
+ SDL_HIDAPI_DeviceChanged();
}
extern "C"