SDL: Fixed bug #9792 - Android: build failure with ndk 27-beta1 due to use of deprecated ALooper_pollAll

From ee16d2f7052b4e7cdcb9fb0d05d7d76bb7e62fc9 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Thu, 16 May 2024 10:10:17 +0200
Subject: [PATCH] Fixed bug #9792 - Android: build failure with ndk 27-beta1
 due to use of deprecated ALooper_pollAll replace ALooper_pollAll by
 ALooper_pollOnce

---
 src/sensor/android/SDL_androidsensor.c | 32 +++++++++++++++++---------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/sensor/android/SDL_androidsensor.c b/src/sensor/android/SDL_androidsensor.c
index eb46dd5e046a3..fea4fe815e3a9 100644
--- a/src/sensor/android/SDL_androidsensor.c
+++ b/src/sensor/android/SDL_androidsensor.c
@@ -69,20 +69,30 @@ static int SDLCALL SDL_ANDROID_SensorThread(void *data)
 
     while (SDL_AtomicGet(&ctx->running)) {
         Uint64 timestamp = SDL_GetTicksNS();
-
-        if (ALooper_pollAll(-1, NULL, &events, (void **)&source) == LOOPER_ID_USER) {
-            SDL_LockSensors();
-            for (i = 0; i < SDL_sensors_count; ++i) {
-                if (!SDL_sensors[i].event_queue) {
-                    continue;
+        SDL_bool done = SDL_FALSE;
+
+        while (!done) {
+            int result;
+
+            result = ALooper_pollOnce(-1, NULL, &events, (void **)&source);
+            if (result == LOOPER_ID_USER) {
+                SDL_LockSensors();
+                for (i = 0; i < SDL_sensors_count; ++i) {
+                    if (!SDL_sensors[i].event_queue) {
+                        continue;
+                    }
+
+                    SDL_zero(event);
+                    while (ASensorEventQueue_getEvents(SDL_sensors[i].event_queue, &event, 1) > 0) {
+                        SDL_SendSensorUpdate(timestamp, SDL_sensors[i].sensor, timestamp, event.data, SDL_arraysize(event.data));
+                    }
                 }
+                SDL_UnlockSensors();
+            }
 
-                SDL_zero(event);
-                while (ASensorEventQueue_getEvents(SDL_sensors[i].event_queue, &event, 1) > 0) {
-                    SDL_SendSensorUpdate(timestamp, SDL_sensors[i].sensor, timestamp, event.data, SDL_arraysize(event.data));
-                }
+            if (result < 0) {
+                done = SDL_TRUE;
             }
-            SDL_UnlockSensors();
         }
     }