The open source OpenXR runtime
at prediction-2 50 lines 1.6 kB view raw
1// Copyright 2021, Qualcomm Innovation Center, Inc. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Implementation of android looper functions. 6 * @author Jarvis Huang 7 * @ingroup aux_android 8 */ 9 10#include "android_looper.h" 11 12#include "util/u_logging.h" 13#include "wrap/android.app.h" 14 15#include <android_native_app_glue.h> 16#include <android/looper.h> 17 18void 19android_looper_poll_until_activity_resumed(struct _JavaVM *vm, void *activity) 20{ 21 jni::init(vm); 22 wrap::android::app::Activity activityObject{(jobject)activity}; 23 if (!jni::env()->IsInstanceOf(activityObject.object().getHandle(), 24 jni::Class("android/app/NativeActivity").getHandle())) { 25 // skip if given activity is not android.app.NativeActivity 26 U_LOG_I("Activity is not NativeActivity, skip"); 27 return; 28 } 29 30 // Activity is in resumed state if window is active. Check Activity#onPostResume for detail. 31 if (!activityObject.getWindow().isNull() && activityObject.getWindow().call<bool>("isActive()Z")) { 32 // Already in resume state, skip 33 U_LOG_I("Activity is NativeActivity and already in resume state with window available, skip"); 34 return; 35 } 36 37 struct android_poll_source *source; 38 while (ALooper_pollOnce(1000, NULL, NULL, (void **)&source) >= 0) { 39 if (source) { 40 // Let callback owner handle the event 41 source->process(source->app, source); 42 if (source->app->destroyRequested != 0) 43 break; 44 if (source->app->activityState == APP_CMD_RESUME && source->app->window) { 45 U_LOG_I("Activity is in resume state with window available now"); 46 break; 47 } 48 } 49 } 50}