diff --git a/MessengerProj/jni/mrwrapper.c b/MessengerProj/jni/mrwrapper.c index 6e89e7dd1..b619656bd 100644 --- a/MessengerProj/jni/mrwrapper.c +++ b/MessengerProj/jni/mrwrapper.c @@ -66,32 +66,37 @@ static jstring jstring_new__(JNIEnv* env, const char* a) } -/* our log handler */ - -static void s_log_callback_(int type, const char* msg) -{ - int prio; - - switch( type ) { - case 'd': prio = ANDROID_LOG_DEBUG; break; - case 'i': prio = ANDROID_LOG_INFO; break; - case 'w': prio = ANDROID_LOG_WARN; break; - default: prio = ANDROID_LOG_ERROR; break; - } - __android_log_print(prio, "DeltaChat", "%s\n", msg); /* on problems, add `-llog` to `Android.mk` */ -} - - /* global stuff */ static JavaVM* s_jvm = NULL; static jclass s_MrMailbox_class = NULL; static jmethodID s_MrCallback_methodID = NULL; +static int s_global_init_done = 0; + + +static void s_log_callback_(int type, const char* msg) +{ + int prio; + + switch( type ) { + case 'd': prio = ANDROID_LOG_DEBUG; break; + case 'i': prio = ANDROID_LOG_INFO; break; + case 'w': prio = ANDROID_LOG_WARN; break; + default: prio = ANDROID_LOG_ERROR; break; /* 'e'rror or 'p'opup */ + } + __android_log_print(prio, "DeltaChat", "%s\n", msg); /* on problems, add `-llog` to `Android.mk` */ + + if( type == 'p' && s_global_init_done && s_jvm && s_MrMailbox_class && s_MrCallback_methodID ) { + JNIEnv* env; + (*s_jvm)->GetEnv(s_jvm, &env, JNI_VERSION_1_6); /* as this function may be called from _any_ thread, we cannot use a static pointer to JNIEnv */ + (*env)->CallStaticLongMethod(env, s_MrMailbox_class, s_MrCallback_methodID, MR_EVENT_REPORT, MR_REPORT_POPUP_ERR, (jlong)msg); + } +} + static void s_init_globals(JNIEnv *env, jclass MrMailbox_class) { /* make sure, the intialisation is done only once */ - static bool s_global_init_done = 0; if( s_global_init_done ) { return; } s_global_init_done = 1; diff --git a/MessengerProj/src/main/java/com/b44t/messenger/MrMailbox.java b/MessengerProj/src/main/java/com/b44t/messenger/MrMailbox.java index 9321c77b5..b8d65dee2 100644 --- a/MessengerProj/src/main/java/com/b44t/messenger/MrMailbox.java +++ b/MessengerProj/src/main/java/com/b44t/messenger/MrMailbox.java @@ -197,6 +197,7 @@ public class MrMailbox { public final static int MR_EVENT_GET_QUANTITIY_STRING = 2092; public final static int MR_REPORT_ERR_SELF_NOT_IN_GROUP = 1; + public final static int MR_REPORT_POPUP_ERR = 2; public static long MrCallback(final int event, final long data1, final long data2) // this function is called from within the C-wrapper { @@ -261,14 +262,22 @@ public class MrMailbox { return 0; case MR_EVENT_REPORT: - AndroidUtilities.runOnUIThread(new Runnable() { - @Override - public void run() { - if(data1==MR_REPORT_ERR_SELF_NOT_IN_GROUP) { - NotificationCenter.getInstance().postNotificationName(NotificationCenter.errSelfNotInGroup); + { + final String errorText = CPtr2String(data2); + AndroidUtilities.runOnUIThread(new Runnable() { + @Override + public void run() { + if (data1 == MR_REPORT_ERR_SELF_NOT_IN_GROUP) { + NotificationCenter.getInstance().postNotificationName(NotificationCenter.errSelfNotInGroup); + } else if (data1 == MR_REPORT_POPUP_ERR) { + if( ConnectionsManager.isNetworkOnline() ) { + // report the errors only if we're online - otherwise, it is quite usual that we get lots of connection errors ... + AndroidUtilities.showHint(ApplicationLoader.applicationContext, errorText); + } + } } - } - }); + }); + } return 0; case MR_EVENT_GET_STRING: