From 8bca441b6f65c532915cf3e93ecbe8a5cd2750a9 Mon Sep 17 00:00:00 2001 From: Jarkko Koivikko Date: Sun, 27 Mar 2022 15:50:42 +0300 Subject: 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 --- src/corelib/kernel/qjnihelpers.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/corelib/kernel/qjnihelpers.cpp') 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) -- cgit v1.2.3