android: Remove blocking permission request code. Async only in SDL3!

(this actually still blocks at our internal points of usage, though, for
replacement at a later time.)
This commit is contained in:
Ryan C. Gordon 2024-02-12 19:46:03 -05:00
parent af61cfd5e0
commit bc984f78bf
12 changed files with 73 additions and 77 deletions

View file

@ -1029,6 +1029,29 @@ JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReportResponse
extern "C"
{
// !!! FIXME: make this non-blocking!
static void SDLCALL AndroidRequestPermissionBlockingCallback(void *userdata, const char *permission, SDL_bool granted)
{
SDL_AtomicSet((SDL_AtomicInt *) userdata, granted ? 1 : -1);
}
static SDL_bool RequestBluetoothPermissions(const char *permission)
{
// !!! FIXME: make this non-blocking!
SDL_AtomicInt permission_response;
SDL_AtomicSet(&permission_response, 0);
if (SDL_AndroidRequestPermission(permission, AndroidRequestPermissionBlockingCallback, &permission_response) == -1) {
return SDL_FALSE;
}
while (SDL_AtomicGet(&permission_response) == 0) {
SDL_Delay(10);
}
return SDL_AtomicGet(&permission_response) > 0;
}
int hid_init(void)
{
if ( !g_initialized && g_HIDDeviceManagerCallbackHandler )
@ -1046,7 +1069,7 @@ int hid_init(void)
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")) {
RequestBluetoothPermissions("android.permission.BLUETOOTH_CONNECT")) {
init_bluetooth = true;
}
}