From 4f7507c52390cd19d76e0f36744f21fbc3e14674 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Tue, 8 Nov 2016 17:12:05 +0200 Subject: Forward Service.onBind notification to Qt It is needed to implement Android Binder in Qt. Change-Id: I8f6f8ef778f97a444a1b16d6f62e211e188b65cc Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/android/androidjnimain.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/android') diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 06bca0354d..4a24f3fb47 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -542,7 +542,14 @@ static jboolean startQtApplication(JNIEnv *env, jobject /*object*/, jstring para if (sem_init(&m_terminateSemaphore, 0, 0) == -1) return false; - return pthread_create(&m_qtAppThread, nullptr, startMainMethod, nullptr) == 0; + jboolean res = pthread_create(&m_qtAppThread, nullptr, startMainMethod, nullptr) == 0; + + // The service must wait until the QCoreApplication starts otherwise onBind will be + // called too early + if (m_serviceObject) + QtAndroidPrivate::waitForServiceSetup(); + + return res; } static void quitQtCoreApplication(JNIEnv *env, jclass /*clazz*/) @@ -742,6 +749,11 @@ static void onNewIntent(JNIEnv *env, jclass /*cls*/, jobject data) QtAndroidPrivate::handleNewIntent(env, data); } +static jobject onBind(JNIEnv */*env*/, jclass /*cls*/, jobject intent) +{ + return QtAndroidPrivate::callOnBindListener(intent); +} + static JNINativeMethod methods[] = { {"startQtAndroidPlugin", "()Z", (void *)startQtAndroidPlugin}, {"startQtApplication", "(Ljava/lang/String;Ljava/lang/String;)V", (void *)startQtApplication}, @@ -754,7 +766,8 @@ static JNINativeMethod methods[] = { {"updateApplicationState", "(I)V", (void *)updateApplicationState}, {"handleOrientationChanged", "(II)V", (void *)handleOrientationChanged}, {"onActivityResult", "(IILandroid/content/Intent;)V", (void *)onActivityResult}, - {"onNewIntent", "(Landroid/content/Intent;)V", (void *)onNewIntent} + {"onNewIntent", "(Landroid/content/Intent;)V", (void *)onNewIntent}, + {"onBind", "(Landroid/content/Intent;)Landroid/os/IBinder;", (void *)onBind} }; #define FIND_AND_CHECK_CLASS(CLASS_NAME) \ -- cgit v1.2.3