HIDAPI is only reliable on Android 4.3 and newer Fixes https://github.com/libsdl-org/SDL/issues/4955
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp
index 0984f47..faed885 100644
--- a/src/hidapi/android/hid.cpp
+++ b/src/hidapi/android/hid.cpp
@@ -1047,29 +1047,32 @@ int hid_init(void)
{
if ( !g_initialized )
{
- // Make sure thread is attached to JVM/env
- JNIEnv *env;
- g_JVM->AttachCurrentThread( &env, NULL );
- pthread_setspecific( g_ThreadKey, (void*)env );
-
- if ( !g_HIDDeviceManagerCallbackHandler )
- {
- LOGV( "hid_init() without callback handler" );
- return -1;
- }
+ // HIDAPI doesn't work well with Android < 4.3
+ if (SDL_GetAndroidSDKVersion() >= 18) {
+ // Make sure thread is attached to JVM/env
+ JNIEnv *env;
+ g_JVM->AttachCurrentThread( &env, NULL );
+ pthread_setspecific( g_ThreadKey, (void*)env );
+
+ if ( !g_HIDDeviceManagerCallbackHandler )
+ {
+ LOGV( "hid_init() without callback handler" );
+ return -1;
+ }
- // Bluetooth is currently only used for Steam Controllers, so check that hint
- // before initializing Bluetooth, which will prompt the user for permission.
- bool init_usb = true;
- bool init_bluetooth = false;
- if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STEAM, SDL_FALSE)) {
- if (SDL_GetAndroidSDKVersion() < 31 ||
- Android_JNI_RequestPermission("android.permission.BLUETOOTH_CONNECT")) {
- init_bluetooth = true;
+ // Bluetooth is currently only used for Steam Controllers, so check that hint
+ // before initializing Bluetooth, which will prompt the user for permission.
+ bool init_usb = true;
+ bool init_bluetooth = false;
+ if (SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STEAM, SDL_FALSE)) {
+ if (SDL_GetAndroidSDKVersion() < 31 ||
+ Android_JNI_RequestPermission("android.permission.BLUETOOTH_CONNECT")) {
+ init_bluetooth = true;
+ }
}
- }
- env->CallBooleanMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerInitialize, init_usb, init_bluetooth );
- ExceptionCheck( env, NULL, "hid_init" );
+ env->CallBooleanMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerInitialize, init_usb, init_bluetooth );
+ ExceptionCheck( env, NULL, "hid_init" );
+ }
g_initialized = true; // Regardless of result, so it's only called once
}
return 0;