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:
@@ -381,6 +381,12 @@ static int BuildAAudioStream(SDL_AudioDevice *device)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// !!! 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 int AAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
#if ALLOW_MULTIPLE_ANDROID_AUDIO_DEVICES
|
||||
@@ -390,7 +396,18 @@ static int AAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
LOGI(__func__);
|
||||
|
||||
if (device->iscapture) {
|
||||
if (!Android_JNI_RequestPermission("android.permission.RECORD_AUDIO")) {
|
||||
// !!! FIXME: make this non-blocking!
|
||||
SDL_AtomicInt permission_response;
|
||||
SDL_AtomicSet(&permission_response, 0);
|
||||
if (SDL_AndroidRequestPermission("android.permission.RECORD_AUDIO", AndroidRequestPermissionBlockingCallback, &permission_response) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (SDL_AtomicGet(&permission_response) == 0) {
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
if (SDL_AtomicGet(&permission_response) < 0) {
|
||||
LOGI("This app doesn't have RECORD_AUDIO permission");
|
||||
return SDL_SetError("This app doesn't have RECORD_AUDIO permission");
|
||||
}
|
||||
|
||||
@@ -228,6 +228,12 @@ static void OPENSLES_DestroyPCMRecorder(SDL_AudioDevice *device)
|
||||
}
|
||||
}
|
||||
|
||||
// !!! 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 int OPENSLES_CreatePCMRecorder(SDL_AudioDevice *device)
|
||||
{
|
||||
struct SDL_PrivateAudioData *audiodata = device->hidden;
|
||||
@@ -241,9 +247,22 @@ static int OPENSLES_CreatePCMRecorder(SDL_AudioDevice *device)
|
||||
SLresult result;
|
||||
int i;
|
||||
|
||||
if (!Android_JNI_RequestPermission("android.permission.RECORD_AUDIO")) {
|
||||
LOGE("This app doesn't have RECORD_AUDIO permission");
|
||||
return SDL_SetError("This app doesn't have RECORD_AUDIO permission");
|
||||
// !!! FIXME: make this non-blocking!
|
||||
{
|
||||
SDL_AtomicInt permission_response;
|
||||
SDL_AtomicSet(&permission_response, 0);
|
||||
if (SDL_AndroidRequestPermission("android.permission.RECORD_AUDIO", AndroidRequestPermissionBlockingCallback, &permission_response) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (SDL_AtomicGet(&permission_response) == 0) {
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
if (SDL_AtomicGet(&permission_response) < 0) {
|
||||
LOGE("This app doesn't have RECORD_AUDIO permission");
|
||||
return SDL_SetError("This app doesn't have RECORD_AUDIO permission");
|
||||
}
|
||||
}
|
||||
|
||||
// Just go with signed 16-bit audio as it's the most compatible
|
||||
|
||||
@@ -161,17 +161,9 @@ void *SDL_AndroidGetJNIEnv()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DECLSPEC SDL_bool SDLCALL SDL_AndroidRequestPermission(const char *permission);
|
||||
SDL_bool SDL_AndroidRequestPermission(const char *permission)
|
||||
{
|
||||
(void)permission;
|
||||
SDL_Unsupported();
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
typedef void (SDLCALL *SDL_AndroidRequestPermissionCallback)(void *userdata, const char *permission, SDL_bool granted);
|
||||
DECLSPEC int SDLCALL SDL_AndroidRequestPermissionAsync(const char *permission, SDL_AndroidRequestPermissionCallback cb, void *userdata);
|
||||
int SDL_AndroidRequestPermissionAsync(const char *permission, SDL_AndroidRequestPermissionCallback cb, void *userdata)
|
||||
DECLSPEC int SDLCALL SDL_AndroidRequestPermission(const char *permission, SDL_AndroidRequestPermissionCallback cb, void *userdata);
|
||||
int SDL_AndroidRequestPermission(const char *permission, SDL_AndroidRequestPermissionCallback cb, void *userdata)
|
||||
{
|
||||
(void)permission;
|
||||
(void)cb;
|
||||
|
||||
@@ -2557,11 +2557,6 @@ const char *SDL_AndroidGetExternalStoragePath(void)
|
||||
return s_AndroidExternalFilesPath;
|
||||
}
|
||||
|
||||
SDL_bool SDL_AndroidRequestPermission(const char *permission)
|
||||
{
|
||||
return Android_JNI_RequestPermission(permission);
|
||||
}
|
||||
|
||||
int SDL_AndroidShowToast(const char *message, int duration, int gravity, int xOffset, int yOffset)
|
||||
{
|
||||
return Android_JNI_ShowToast(message, duration, gravity, xOffset, yOffset);
|
||||
@@ -2662,7 +2657,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePermissionResult)(
|
||||
SDL_assert(!"Shouldn't have hit this code"); // we had a permission response for a request we never made...?
|
||||
}
|
||||
|
||||
int SDL_AndroidRequestPermissionAsync(const char *permission, SDL_AndroidRequestPermissionCallback cb, void *userdata)
|
||||
int SDL_AndroidRequestPermission(const char *permission, SDL_AndroidRequestPermissionCallback cb, void *userdata)
|
||||
{
|
||||
if (!permission) {
|
||||
return SDL_InvalidParamError("permission");
|
||||
@@ -2700,29 +2695,6 @@ int SDL_AndroidRequestPermissionAsync(const char *permission, SDL_AndroidRequest
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void SDLCALL AndroidRequestPermissionBlockingCallback(void *userdata, const char *permission, SDL_bool granted)
|
||||
{
|
||||
SDL_AtomicSet((SDL_AtomicInt *) userdata, granted ? 1 : -1);
|
||||
}
|
||||
|
||||
SDL_bool Android_JNI_RequestPermission(const char *permission)
|
||||
{
|
||||
SDL_AtomicInt response;
|
||||
SDL_AtomicSet(&response, 0);
|
||||
|
||||
if (SDL_AndroidRequestPermissionAsync(permission, AndroidRequestPermissionBlockingCallback, &response) == -1) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
/* Wait for the request to complete */
|
||||
while (SDL_AtomicGet(&response) == 0) {
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
return (SDL_AtomicGet(&response) < 0) ? SDL_FALSE : SDL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* Show toast notification */
|
||||
int Android_JNI_ShowToast(const char *message, int duration, int gravity, int xOffset, int yOffset)
|
||||
{
|
||||
|
||||
@@ -125,9 +125,6 @@ SDL_bool Android_JNI_SetSystemCursor(int cursorID);
|
||||
SDL_bool Android_JNI_SupportsRelativeMouse(void);
|
||||
SDL_bool Android_JNI_SetRelativeMouseEnabled(SDL_bool enabled);
|
||||
|
||||
/* Request permission */
|
||||
SDL_bool Android_JNI_RequestPermission(const char *permission);
|
||||
|
||||
/* Show toast notification */
|
||||
int Android_JNI_ShowToast(const char *message, int duration, int gravity, int xOffset, int yOffset);
|
||||
|
||||
|
||||
@@ -972,7 +972,6 @@ SDL3_0.0.0 {
|
||||
SDL_RenderGeometryRawFloat;
|
||||
SDL_SetWindowShape;
|
||||
SDL_RenderViewportSet;
|
||||
SDL_AndroidRequestPermissionAsync;
|
||||
# extra symbols go here (don't modify this line)
|
||||
local: *;
|
||||
};
|
||||
|
||||
@@ -997,4 +997,3 @@
|
||||
#define SDL_RenderGeometryRawFloat SDL_RenderGeometryRawFloat_REAL
|
||||
#define SDL_SetWindowShape SDL_SetWindowShape_REAL
|
||||
#define SDL_RenderViewportSet SDL_RenderViewportSet_REAL
|
||||
#define SDL_AndroidRequestPermissionAsync SDL_AndroidRequestPermissionAsync_REAL
|
||||
|
||||
@@ -93,7 +93,7 @@ SDL_DYNAPI_PROC(const char*,SDL_AndroidGetExternalStoragePath,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_AndroidGetExternalStorageState,(Uint32 *a),(a),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_AndroidGetInternalStoragePath,(void),(),return)
|
||||
SDL_DYNAPI_PROC(void*,SDL_AndroidGetJNIEnv,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_AndroidRequestPermission,(const char *a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_AndroidRequestPermission,(const char *a, SDL_AndroidRequestPermissionCallback b, void *c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_AndroidSendMessage,(Uint32 a, int b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_AndroidShowToast,(const char *a, int b, int c, int d, int e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetAndroidSDKVersion,(void),(),return)
|
||||
@@ -1022,4 +1022,3 @@ SDL_DYNAPI_PROC(int,SDL_GetRenderColorScale,(SDL_Renderer *a, float *b),(a,b),re
|
||||
SDL_DYNAPI_PROC(int,SDL_RenderGeometryRawFloat,(SDL_Renderer *a, SDL_Texture *b, const float *c, int d, const SDL_FColor *e, int f, const float *g, int h, int i, const void *j, int k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_SetWindowShape,(SDL_Window *a, SDL_Surface *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_RenderViewportSet,(SDL_Renderer *a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_AndroidRequestPermissionAsync,(const char *a, SDL_AndroidRequestPermissionCallback b, void *c),(a,b,c),return)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,12 +68,12 @@ static void
|
||||
create_cameraMgr(void)
|
||||
{
|
||||
if (cameraMgr == NULL) {
|
||||
|
||||
#if 0 // !!! FIXME: this is getting replaced in a different branch.
|
||||
if (!Android_JNI_RequestPermission("android.permission.CAMERA")) {
|
||||
SDL_SetError("This app doesn't have CAMERA permission");
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
cameraMgr = ACameraManager_create();
|
||||
if (cameraMgr == NULL) {
|
||||
SDL_Log("Error creating ACameraManager");
|
||||
|
||||
Reference in New Issue
Block a user