Skip to content

Commit

Permalink
cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
pazos committed Sep 30, 2024
1 parent a2a6f2c commit 3b4a833
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
2 changes: 1 addition & 1 deletion jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ include $(CLEAR_VARS)
LOCAL_PATH := $(BASE_PATH)
LOCAL_MODULE := luajit-launcher
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := jni_helper.c main.c
LOCAL_SRC_FILES := jni_helper.cpp main.c
LOCAL_STATIC_LIBRARIES := android_native_app_glue
# NOTE: By default, we link against the shared LuaJIT library directly.
LOCAL_SHARED_LIBRARIES := luajit
Expand Down
33 changes: 0 additions & 33 deletions jni/jni_helper.c

This file was deleted.

41 changes: 41 additions & 0 deletions jni/jni_helper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifdef __cplusplus
extern "C" {
#endif

#include <jni.h>
#include "jni_helper.h"

bool has_permission(struct android_app* app) {
JNIEnv* env;
JavaVM* vm = app->activity->vm;
int status = vm->GetEnv((void**)&env, JNI_VERSION_1_6);
if ((status == JNI_OK) || ((status == JNI_EDETACHED)
&& (vm->AttachCurrentThread(&env, NULL) == 0)))
{
jclass clazz = env->GetObjectClass(app->activity->clazz);
jmethodID method = env->GetMethodID(clazz, "hasRequiredPermissions", "()Z");
bool ok = env->CallBooleanMethod(app->activity->clazz, method) == JNI_TRUE;
vm->DetachCurrentThread();
return ok;
} else {
return false;
}
}

void crash_report(struct android_app* app) {
JNIEnv* env;
JavaVM* vm = app->activity->vm;
int status = vm->GetEnv((void**)&env, JNI_VERSION_1_6);
if ((status == JNI_OK) || ((status == JNI_EDETACHED)
&& (vm->AttachCurrentThread(&env, NULL) == 0)))
{
jclass clazz = env->GetObjectClass(app->activity->clazz);
jmethodID method = env->GetMethodID(clazz, "onNativeCrash", "()V");
env->CallVoidMethod(app->activity->clazz, method);
vm->DetachCurrentThread();
}
}

#ifdef __cplusplus
}
#endif
1 change: 0 additions & 1 deletion jni/jni_helper.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <stdbool.h>
#include "android_native_app_glue.h"

bool has_permission(struct android_app* app);
Expand Down

0 comments on commit 3b4a833

Please sign in to comment.