summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinWX/MainAndroid.cpp
diff options
context:
space:
mode:
authorRyan Houdek <Sonicadvance1@gmail.com>2015-06-07 23:14:34 -0400
committerRyan Houdek <Sonicadvance1@gmail.com>2015-06-07 23:14:34 -0400
commit9521bc1fc62b3e92ebd7ba855608fa86a15529ba (patch)
tree91f9ccdb51a101725c7e572f1fd8935b4c3f0422 /Source/Core/DolphinWX/MainAndroid.cpp
parentc79dd40e721650c2951aad9aab890a0c3385c9e9 (diff)
parentd752ee73c0f1957a36db6171130377754a30915e (diff)
Merge pull request #2558 from sigmabeta/android-panic-alerts
Android: Display Panic Alerts on-screen as a Toast message.
Diffstat (limited to 'Source/Core/DolphinWX/MainAndroid.cpp')
-rw-r--r--Source/Core/DolphinWX/MainAndroid.cpp60
1 files changed, 37 insertions, 23 deletions
diff --git a/Source/Core/DolphinWX/MainAndroid.cpp b/Source/Core/DolphinWX/MainAndroid.cpp
index 07532be838..f1a789b7f3 100644
--- a/Source/Core/DolphinWX/MainAndroid.cpp
+++ b/Source/Core/DolphinWX/MainAndroid.cpp
@@ -37,13 +37,22 @@ ANativeWindow* surf;
std::string g_filename;
std::string g_set_userpath = "";
-// PanicAlert
-static bool g_alert_available = false;
-static std::string g_alert_message = "";
-static Common::Event g_alert_event;
+JavaVM* g_java_vm;
+jclass g_jni_class;
+jmethodID g_jni_method_alert;
#define DOLPHIN_TAG "DolphinEmuNative"
+/*
+ * Cache the JavaVM so that we can call into it later.
+ */
+jint JNI_OnLoad(JavaVM* vm, void* reserved)
+{
+ g_java_vm = vm;
+
+ return JNI_VERSION_1_6;
+}
+
void Host_NotifyMapLoaded() {}
void Host_RefreshDSPDebuggerWindow() {}
@@ -99,11 +108,18 @@ void Host_ShowVideoConfig(void*, const std::string&, const std::string&) {}
static bool MsgAlert(const char* caption, const char* text, bool yes_no, int /*Style*/)
{
- g_alert_message = std::string(text);
- g_alert_available = true;
- // XXX: Uncomment next line when the Android UI actually handles messages
- // g_alert_event.Wait()
- g_alert_available = false;
+ __android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "%s:%s", caption, text);
+
+ // Associate the current Thread with the Java VM.
+ JNIEnv* env;
+ g_java_vm->AttachCurrentThread(&env, NULL);
+
+ // Execute the Java method.
+ env->CallStaticVoidMethod(g_jni_class, g_jni_method_alert, env->NewStringUTF(text));
+
+ // Must be called before the current thread exits; might as well do it here.
+ g_java_vm->DetachCurrentThread();
+
return false;
}
@@ -363,12 +379,9 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirec
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv *env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv *env, jobject obj, jboolean enable);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv *env, jobject obj);
+JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv *env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj, jobject _surf);
-// MsgAlert
-JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_HasAlertMsg(JNIEnv *env, jobject obj);
-JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetAlertMsg(JNIEnv *env, jobject obj);
-JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ClearAlertMsg(JNIEnv *env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv *env, jobject obj)
{
@@ -564,19 +577,20 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfile
JitInterface::WriteProfileResults(filename);
}
-JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_HasAlertMsg(JNIEnv *env, jobject obj)
+JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv *env, jobject obj)
{
- return g_alert_available;
-}
+ // This class reference is only valid for the lifetime of this method.
+ jclass localClass = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary");
-JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetAlertMsg(JNIEnv *env, jobject obj)
-{
- return env->NewStringUTF(g_alert_message.c_str());
-}
+ // This reference, however, is valid until we delete it.
+ g_jni_class = reinterpret_cast<jclass>(env->NewGlobalRef(localClass));
-JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ClearAlertMsg(JNIEnv *env, jobject obj)
-{
- g_alert_event.Set(); // Kick the alert
+ // TODO Find a place for this.
+ // So we don't leak a reference to NativeLibrary.class.
+ // env->DeleteGlobalRef(g_jni_class);
+
+ // Method signature taken from javap -s Source/Android/app/build/intermediates/classes/arm/debug/org/dolphinemu/dolphinemu/NativeLibrary.class
+ g_jni_method_alert = env->GetStaticMethodID(g_jni_class, "displayAlertMsg", "(Ljava/lang/String;)V");
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *env, jobject obj, jobject _surf)