From 8c0ef140b3a7202c03f223b692b31206aaf9d8b8 Mon Sep 17 00:00:00 2001 From: Liang Jian Date: Tue, 3 Mar 2015 17:16:16 +0800 Subject: [PATCH] Avoid deadlock with two consecutive suspended notification According to our Android app test, sometimes we will receive two consecutive app suspended notifications. In the second app suspended notification QWindowSystemInterface::flushWindowSystemEvents() will deadlock due to the fact that the event dispatcher has been stopped in the first app suspended notification. This patch will simply return if we found the event dispatcher has been stopped in the beginning of app suspended notification. Change-Id: I15fa4a6a118510b866ff16061862f4bb8360cc9b Reviewed-by: BogDan Vatra --- src/plugins/platforms/android/androidjnimain.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 1c157c79c32..00ef8f670a0 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -593,6 +593,13 @@ static void updateApplicationState(JNIEnv */*env*/, jobject /*thiz*/, jint state return; if (state <= Qt::ApplicationInactive) { + // NOTE: sometimes we will receive two consecutive suspended notifications, + // In the second suspended notification, QWindowSystemInterface::flushWindowSystemEvents() + // will deadlock since the dispatcher has been stopped in the first suspended notification. + // To avoid the deadlock we simply return if we found the event dispatcher has been stopped. + if (QAndroidEventDispatcherStopper::instance()->stopped()) + return; + // Don't send timers and sockets events anymore if we are going to hide all windows QAndroidEventDispatcherStopper::instance()->goingToStop(true); QCoreApplication::processEvents();