summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qjnihelpers.cpp
diff options
context:
space:
mode:
authorJarkko Koivikko <jarkko.koivikko@code-q.fi>2022-03-27 15:50:42 +0300
committerJarkko Koivikko <jarkko.koivikko@code-q.fi>2022-04-05 12:06:23 +0300
commit8bca441b6f65c532915cf3e93ecbe8a5cd2750a9 (patch)
treee134e6c57cce7fb5149391fbfada50428af256f0 /src/corelib/kernel/qjnihelpers.cpp
parente6c80fc01179a0752357bad35d3e9e9068c4be84 (diff)
Android: Fix deadlock caused by a race between permissions query and IM
Android permissions query blocks Qt main thread. If the input method was activated before the permissions query started, android would try to invoke input method before returning back to permissions query. This will cause a deadlock. Fix the issue by moving the deadlock counter to Qt core and incrementing the value before the permissions query. This will prevent the input method queries to enter Qt main thread. Fixes: QTBUG-99484 Pick-to: 6.2 6.3 6.3.0 Change-Id: I54ea59578880cde4095c26fa2a6a264c4dc1b7ff Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/corelib/kernel/qjnihelpers.cpp')
-rw-r--r--src/corelib/kernel/qjnihelpers.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/kernel/qjnihelpers.cpp b/src/corelib/kernel/qjnihelpers.cpp
index b2a5dc7441..73b15ce46a 100644
--- a/src/corelib/kernel/qjnihelpers.cpp
+++ b/src/corelib/kernel/qjnihelpers.cpp
@@ -376,6 +376,18 @@ jobject QtAndroidPrivate::callOnBindListener(jobject intent)
return nullptr;
}
+Q_GLOBAL_STATIC(QAtomicInt, g_androidDeadlockProtector);
+
+bool QtAndroidPrivate::acquireAndroidDeadlockProtector()
+{
+ return g_androidDeadlockProtector->testAndSetAcquire(0, 1);
+}
+
+void QtAndroidPrivate::releaseAndroidDeadlockProtector()
+{
+ g_androidDeadlockProtector->storeRelease(0);
+}
+
QT_END_NAMESPACE
Q_CORE_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)