sdl2-compat: android: Updated for SDL3's revised SDL_AndroidRequestPermission().

From fc211d5babd769cce7e3a10026c4edbf0d7fe74f Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 13 Feb 2024 13:43:28 -0500
Subject: [PATCH] android: Updated for SDL3's revised
 SDL_AndroidRequestPermission().

---
 src/sdl2_compat.c | 23 +++++++++++++++++++++++
 src/sdl3_syms.h   |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index e7a7464..5e38933 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -7835,6 +7835,29 @@ SDL_AndroidGetExternalStorageState(void)
     }
     return state;
 }
+
+static void SDLCALL AndroidRequestPermissionBlockingCallback(void *userdata, const char *permission, SDL_bool granted)
+{
+    SDL3_AtomicSet((SDL_AtomicInt *) userdata, granted ? 1 : -1);
+}
+
+DECLSPEC SDL_bool SDLCALL
+SDL_AndroidRequestPermission(const char *permission)
+{
+    SDL_AtomicInt response;
+    SDL3_AtomicSet(&response, 0);
+
+    if (SDL_AndroidRequestPermissionAsync(permission, AndroidRequestPermissionBlockingCallback, &response) == -1) {
+        return SDL_FALSE;
+    }
+
+    /* Wait for the request to complete */
+    while (SDL3_AtomicGet(&response) == 0) {
+        SDL3_Delay(10);
+    }
+
+    return (SDL3_AtomicGet(&response) < 0) ? SDL_FALSE : SDL_TRUE;
+}
 #endif
 
 #ifdef __cplusplus
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index ccba0e7..e69bd22 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -101,7 +101,7 @@ SDL3_SYM_PASSTHROUGH(SDL_bool,IsAndroidTV,(void),(),return)
 SDL3_SYM_PASSTHROUGH(SDL_bool,IsChromebook,(void),(),return)
 SDL3_SYM_PASSTHROUGH(SDL_bool,IsDeXMode,(void),(),return)
 SDL3_SYM_PASSTHROUGH(void,AndroidBackButton,(void),(),)
-SDL3_SYM_PASSTHROUGH(SDL_bool,AndroidRequestPermission,(const char *a),(a),return)
+SDL3_SYM(int,AndroidRequestPermission,(const char *a, SDL_AndroidRequestPermissionCallback b, void *c),(a,b,c),return)
 SDL3_SYM_PASSTHROUGH(int,AndroidShowToast,(const char *a, int b, int c, int d, int e),(a,b,c,d,e),return)
 SDL3_SYM_PASSTHROUGH(int,GetAndroidSDKVersion,(void),(),return)
 #endif