From 218a650de711f1927057ddc63144be80fd75a1bc Mon Sep 17 00:00:00 2001 From: Mike Achtelik Date: Tue, 28 Jun 2022 09:55:25 +0200 Subject: [PATCH] Android A11Y: Fix deadlock in QtAndroidAccessibility::runInObjectContext() On android the event loop is normally blocked, when the application is suspended, e.g. when it enters the background or when the screen is locked (see android.app.background_running). This leads to a problem when we try to process events after this happens, e.g. when android sends us an ACTION_CLEAR_ACCESSIBILITY_FOCUS event after the event loop is suspended. While handling it we eventually call QtAndroidAccessibility::runInObjectContext() which tries to do a blocking call on the object context, however, with the event loop being suspended we run into a deadlock which leads to an ANR. So we need to make sure to never make a blocking call while the event loop is suspended. Task-number: QTBUG-102594 Change-Id: I33f0440a3da84fb4bdae5ab0fc10d514c73f23ad Reviewed-by: Assam Boudjelthia (cherry picked from commit ac984bd8768b3d7e6439e0ffd98fd8b53e16b922) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/android/androidjniaccessibility.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/android/androidjniaccessibility.cpp b/src/plugins/platforms/android/androidjniaccessibility.cpp index 1043d0058d3..3f156cdb7bc 100644 --- a/src/plugins/platforms/android/androidjniaccessibility.cpp +++ b/src/plugins/platforms/android/androidjniaccessibility.cpp @@ -94,7 +94,13 @@ namespace QtAndroidAccessibility template void runInObjectContext(QObject *context, Func &&func, Ret *retVal) { - QMetaObject::invokeMethod(context, func, Qt::BlockingQueuedConnection, retVal); + if (!QtAndroid::blockEventLoopsWhenSuspended() + || QGuiApplication::applicationState() != Qt::ApplicationSuspended) { + QMetaObject::invokeMethod(context, func, Qt::BlockingQueuedConnection, retVal); + } else { + __android_log_print(ANDROID_LOG_WARN, m_qtTag, + "Could not run accessibility call in object context, event loop suspended."); + } } void initialize()