diff --git a/src/corelib/kernel/qjnihelpers.cpp b/src/corelib/kernel/qjnihelpers.cpp index f5e4aceff3..2324a615d5 100644 --- a/src/corelib/kernel/qjnihelpers.cpp +++ b/src/corelib/kernel/qjnihelpers.cpp @@ -41,6 +41,7 @@ #include "qmutex.h" #include "qlist.h" #include "qsemaphore.h" +#include "qsharedpointer.h" #include "qvector.h" #include @@ -338,6 +339,16 @@ void QtAndroidPrivate::runOnAndroidThread(const QtAndroidPrivate::Runnable &runn env->CallStaticVoidMethod(g_jNativeClass, g_runPendingCppRunnablesMethodID); } +void QtAndroidPrivate::runOnAndroidThreadSync(const QtAndroidPrivate::Runnable &runnable, JNIEnv *env, int timeoutMs) +{ + QSharedPointer sem(new QSemaphore); + runOnAndroidThread([&runnable, sem]{ + runnable(); + sem->release(); + }, env); + sem->tryAcquire(1, timeoutMs); +} + void QtAndroidPrivate::registerGenericMotionEventListener(QtAndroidPrivate::GenericMotionEventListener *listener) { QMutexLocker locker(&g_genericMotionEventListeners()->mutex); diff --git a/src/corelib/kernel/qjnihelpers_p.h b/src/corelib/kernel/qjnihelpers_p.h index 3f24597312..1bffd26e08 100644 --- a/src/corelib/kernel/qjnihelpers_p.h +++ b/src/corelib/kernel/qjnihelpers_p.h @@ -105,6 +105,7 @@ namespace QtAndroidPrivate jobject classLoader(); Q_CORE_EXPORT jint androidSdkVersion(); Q_CORE_EXPORT void runOnAndroidThread(const Runnable &runnable, JNIEnv *env); + Q_CORE_EXPORT void runOnAndroidThreadSync(const Runnable &runnable, JNIEnv *env, int timeoutMs = INT_MAX); Q_CORE_EXPORT void runOnUiThread(QRunnable *runnable, JNIEnv *env); Q_CORE_EXPORT void handleActivityResult(jint requestCode, jint resultCode, jobject data);