Browse Source

android: Fix assorted errors and deprecations

rdb 1 year ago
parent
commit
c31041c8cc

+ 4 - 5
panda/src/android/android_main.cxx

@@ -267,11 +267,10 @@ void android_main(struct android_app* app) {
 
 
     // We still need to keep an event loop going until Android gives us leave
     // We still need to keep an event loop going until Android gives us leave
     // to end the process.
     // to end the process.
-    int looper_id;
-    int events;
-    struct android_poll_source *source;
-    while ((looper_id = ALooper_pollAll(-1, nullptr, &events, (void**)&source)) >= 0) {
-      // Process this event, but intercept application command events.
+    while (!app->destroyRequested) {
+      int looper_id;
+      struct android_poll_source *source;
+      auto result = ALooper_pollOnce(-1, &looper_id, nullptr, (void **)&source);
       if (looper_id == LOOPER_ID_MAIN) {
       if (looper_id == LOOPER_ID_MAIN) {
         int8_t cmd = android_app_read_cmd(app);
         int8_t cmd = android_app_read_cmd(app);
         android_app_pre_exec_cmd(app, cmd);
         android_app_pre_exec_cmd(app, cmd);

+ 1 - 1
panda/src/android/pview_manifest.xml

@@ -8,7 +8,7 @@
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.INTERNET" />
-    <uses-sdk android:minSdkVersion="21" />
+    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="30" />
     <uses-feature android:glEsVersion="0x00020000" android:required="true" />
     <uses-feature android:glEsVersion="0x00020000" android:required="true" />
 
 
     <application android:label="Panda Viewer" android:hasCode="true" android:debuggable="true">
     <application android:label="Panda Viewer" android:hasCode="true" android:debuggable="true">

+ 8 - 10
panda/src/androiddisplay/androidGraphicsWindow.cxx

@@ -181,16 +181,14 @@ process_events() {
   GraphicsWindow::process_events();
   GraphicsWindow::process_events();
 
 
   // Read all pending events.
   // Read all pending events.
-  int looper_id;
-  int events;
-  struct android_poll_source* source;
-
-  // Loop until all events are read.
-  while ((looper_id = ALooper_pollAll(0, nullptr, &events, (void**)&source)) >= 0) {
-    // Process this event.
-    if (source != nullptr) {
-      source->process(_app, source);
-    }
+  struct android_poll_source *source;
+
+  auto result = ALooper_pollOnce(0, nullptr, nullptr, (void **)&source);
+  nassertv(result != ALOOPER_POLL_ERROR);
+
+  // Process this event.
+  if (source != nullptr) {
+    source->process(_app, source);
   }
   }
 }
 }
 
 

+ 4 - 5
pandatool/src/deploy-stub/android_main.cxx

@@ -297,11 +297,10 @@ void android_main(struct android_app *app) {
 
 
     // We still need to keep an event loop going until Android gives us leave
     // We still need to keep an event loop going until Android gives us leave
     // to end the process.
     // to end the process.
-    int looper_id;
-    int events;
-    struct android_poll_source *source;
-    while ((looper_id = ALooper_pollAll(-1, nullptr, &events, (void**)&source)) >= 0) {
-      // Process this event, but intercept application command events.
+    while (!app->destroyRequested) {
+      int looper_id;
+      struct android_poll_source *source;
+      auto result = ALooper_pollOnce(-1, &looper_id, nullptr, (void **)&source);
       if (looper_id == LOOPER_ID_MAIN) {
       if (looper_id == LOOPER_ID_MAIN) {
         int8_t cmd = android_app_read_cmd(app);
         int8_t cmd = android_app_read_cmd(app);
         android_app_pre_exec_cmd(app, cmd);
         android_app_pre_exec_cmd(app, cmd);