From 7ad1ce86f2a9918adff60350d3dcbf7269d8daf4 Mon Sep 17 00:00:00 2001 From: Mis012 Date: Tue, 8 Nov 2022 21:12:41 +0100 Subject: [PATCH] call onStart when starting an activity; uncomment handler for onWindowFocusChanged in NativeActivity --- src/api-impl-jni/android_app_NativeActivity.c | 33 +++++++++---------- src/api-impl-jni/util.c | 1 + src/api-impl-jni/util.h | 1 + src/main-executable/main.c | 4 +++ 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/api-impl-jni/android_app_NativeActivity.c b/src/api-impl-jni/android_app_NativeActivity.c index a5b32002..14a27c44 100644 --- a/src/api-impl-jni/android_app_NativeActivity.c +++ b/src/api-impl-jni/android_app_NativeActivity.c @@ -355,7 +355,7 @@ Java_android_app_NativeActivity_unloadNativeCode(JNIEnv* env, jobject clazz, jlo { printf("STUB - unloadNativeCode_native\n"); /*if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; NativeCode_destroy(code); }*/ } @@ -363,7 +363,6 @@ Java_android_app_NativeActivity_unloadNativeCode(JNIEnv* env, jobject clazz, jlo void Java_android_app_NativeActivity_onStartNative(JNIEnv* env, jobject clazz, jlong handle) { - printf("STUB - onStart_native\n"); if (handle != 0) { struct NativeCode* code = (struct NativeCode*)handle; if (code->callbacks.onStart != NULL) { @@ -392,7 +391,7 @@ Java_android_app_NativeActivity_onSaveInstanceStateNative(JNIEnv* env, jobject c jbyteArray array = NULL; if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; if (code->callbacks.onSaveInstanceState != NULL) { size_t len = 0; jbyte* state = (jbyte*)code->callbacks.onSaveInstanceState(code, &len); @@ -416,7 +415,7 @@ Java_android_app_NativeActivity_onPauseNative(JNIEnv* env, jobject clazz, jlong { printf("STUB - onPause_native\n"); /* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; if (code->callbacks.onPause != NULL) { code->callbacks.onPause(code); } @@ -428,7 +427,7 @@ Java_android_app_NativeActivity_onStopNative(JNIEnv* env, jobject clazz, jlong h { printf("STUB - onStop_native\n"); /* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; if (code->callbacks.onStop != NULL) { code->callbacks.onStop(code); } @@ -440,7 +439,7 @@ Java_android_app_NativeActivity_onConfigurationChangedNative(JNIEnv* env, jobjec { printf("STUB - onConfigurationChanged_native\n"); /* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; if (code->callbacks.onConfigurationChanged != NULL) { code->callbacks.onConfigurationChanged(code); } @@ -452,7 +451,7 @@ Java_android_app_NativeActivity_onLowMemoryNative(JNIEnv* env, jobject clazz, jl { printf("STUB - onLowMemory_native\n"); /* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; if (code->callbacks.onLowMemory != NULL) { code->callbacks.onLowMemory(code); } @@ -462,13 +461,12 @@ Java_android_app_NativeActivity_onLowMemoryNative(JNIEnv* env, jobject clazz, jl void Java_android_app_NativeActivity_onWindowFocusChangedNative(JNIEnv* env, jobject clazz, jlong handle, jboolean focused) { - printf("STUB - onWindowFocusChanged_native\n"); -/* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + if (handle != 0) { + struct NativeCode* code = (struct NativeCode*)handle; if (code->callbacks.onWindowFocusChanged != NULL) { code->callbacks.onWindowFocusChanged(code, focused ? 1 : 0); } - }*/ + } } void @@ -476,7 +474,7 @@ Java_android_app_NativeActivity_onSurfaceCreatedNative(JNIEnv* env, jobject claz { printf("STUB - onSurfaceCreated_native\n"); /* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; code->setSurface(surface); if (code->nativeWindow != NULL && code->callbacks.onNativeWindowCreated != NULL) { code->callbacks.onNativeWindowCreated(code, @@ -489,7 +487,6 @@ void Java_android_app_NativeActivity_onSurfaceChangedNative(JNIEnv* env, jobject clazz, jlong handle, jobject surface, jint format, jint width, jint height) { - printf("STUB - onSurfaceChanged_native\n"); if (handle != 0) { struct NativeCode *code = (struct NativeCode *)handle; ANativeWindow *oldNativeWindow = code->nativeWindow; @@ -525,7 +522,7 @@ Java_android_app_NativeActivity_onSurfaceRedrawNeededNative(JNIEnv* env, jobject { printf("STUB - onSurfaceRedrawNeeded_native\n"); /* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; if (code->nativeWindow != NULL && code->callbacks.onNativeWindowRedrawNeeded != NULL) { code->callbacks.onNativeWindowRedrawNeeded(code, code->nativeWindow.get()); } @@ -537,7 +534,7 @@ Java_android_app_NativeActivity_onSurfaceDestroyedNative(JNIEnv* env, jobject cl { printf("STUB - onSurfaceDestroyed_native\n"); /* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; if (code->nativeWindow != NULL && code->callbacks.onNativeWindowDestroyed != NULL) { code->callbacks.onNativeWindowDestroyed(code, code->nativeWindow.get()); @@ -551,7 +548,7 @@ Java_android_app_NativeActivity_onInputQueueCreatedNative(JNIEnv* env, jobject c { printf("STUB - onInputChannelCreated_native\n"); /* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; if (code->callbacks.onInputQueueCreated != NULL) { AInputQueue* queue = reinterpret_cast(queuePtr); code->callbacks.onInputQueueCreated(code, queue); @@ -564,7 +561,7 @@ Java_android_app_NativeActivity_onInputQueueDestroyedNative(JNIEnv* env, jobject { printf("STUB - onInputChannelDestroyed_native\n"); /* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; if (code->callbacks.onInputQueueDestroyed != NULL) { AInputQueue* queue = reinterpret_cast(queuePtr); code->callbacks.onInputQueueDestroyed(code, queue); @@ -578,7 +575,7 @@ Java_android_app_NativeActivity_onContentRectChangedNative(JNIEnv* env, jobject { printf("STUB - onContentRectChanged_native\n"); /* if (handle != 0) { - NativeCode* code = (NativeCode*)handle; + struct NativeCode* code = (struct NativeCode*)handle; if (code->callbacks.onContentRectChanged != NULL) { ARect rect; rect.left = x; diff --git a/src/api-impl-jni/util.c b/src/api-impl-jni/util.c index f700c9c0..7f6446a7 100644 --- a/src/api-impl-jni/util.c +++ b/src/api-impl-jni/util.c @@ -27,6 +27,7 @@ void set_up_handle_cache(JNIEnv *env, char *apk_main_activity_class) if((*env)->ExceptionCheck(env)) (*env)->ExceptionDescribe(env); handle_cache.apk_main_activity.onCreate = _METHOD(handle_cache.apk_main_activity.class, "onCreate", "(Landroid/os/Bundle;)V"); + handle_cache.apk_main_activity.onStart = _METHOD(handle_cache.apk_main_activity.class, "onStart", "()V"); handle_cache.apk_main_activity.onWindowFocusChanged = _METHOD(handle_cache.apk_main_activity.class, "onWindowFocusChanged", "(Z)V"); handle_cache.apk_main_activity.onResume = _METHOD(handle_cache.apk_main_activity.class, "onResume", "()V"); handle_cache.apk_main_activity.onDestroy = _METHOD(handle_cache.apk_main_activity.class, "onDestroy", "()V"); diff --git a/src/api-impl-jni/util.h b/src/api-impl-jni/util.h index f992470e..936c9eb8 100644 --- a/src/api-impl-jni/util.h +++ b/src/api-impl-jni/util.h @@ -10,6 +10,7 @@ struct handle_cache { jclass class; jobject object; jmethodID onCreate; + jmethodID onStart; jmethodID onResume; jmethodID onWindowFocusChanged; jmethodID onDestroy; diff --git a/src/main-executable/main.c b/src/main-executable/main.c index bae82e6a..089791e8 100644 --- a/src/main-executable/main.c +++ b/src/main-executable/main.c @@ -298,6 +298,10 @@ static void open(GtkApplication *app, GFile** files, gint nfiles, const gchar* h (*env)->ExceptionDescribe(env); // TODO: some apps wait for this to actually do stuff + (*env)->CallVoidMethod(env, handle_cache.apk_main_activity.object, handle_cache.apk_main_activity.onStart); + if((*env)->ExceptionCheck(env)) + (*env)->ExceptionDescribe(env); + (*env)->CallVoidMethod(env, handle_cache.apk_main_activity.object, handle_cache.apk_main_activity.onResume); if((*env)->ExceptionCheck(env)) (*env)->ExceptionDescribe(env);