mirror of https://github.com/encounter/SDL.git
HIDAPI is only reliable on Android 4.3 and newer
Fixes https://github.com/libsdl-org/SDL/issues/4955
This commit is contained in:
parent
d713a68071
commit
30f04d63e6
|
@ -1047,29 +1047,32 @@ int hid_init(void)
|
||||||
{
|
{
|
||||||
if ( !g_initialized )
|
if ( !g_initialized )
|
||||||
{
|
{
|
||||||
// Make sure thread is attached to JVM/env
|
// HIDAPI doesn't work well with Android < 4.3
|
||||||
JNIEnv *env;
|
if (SDL_GetAndroidSDKVersion() >= 18) {
|
||||||
g_JVM->AttachCurrentThread( &env, NULL );
|
// Make sure thread is attached to JVM/env
|
||||||
pthread_setspecific( g_ThreadKey, (void*)env );
|
JNIEnv *env;
|
||||||
|
g_JVM->AttachCurrentThread( &env, NULL );
|
||||||
|
pthread_setspecific( g_ThreadKey, (void*)env );
|
||||||
|
|
||||||
if ( !g_HIDDeviceManagerCallbackHandler )
|
if ( !g_HIDDeviceManagerCallbackHandler )
|
||||||
{
|
{
|
||||||
LOGV( "hid_init() without callback handler" );
|
LOGV( "hid_init() without callback handler" );
|
||||||
return -1;
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
env->CallBooleanMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerInitialize, init_usb, init_bluetooth );
|
// Bluetooth is currently only used for Steam Controllers, so check that hint
|
||||||
ExceptionCheck( env, NULL, "hid_init" );
|
// 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" );
|
||||||
|
}
|
||||||
g_initialized = true; // Regardless of result, so it's only called once
|
g_initialized = true; // Regardless of result, so it's only called once
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue