summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android/androidjnimain.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-04-06 19:10:10 +0200
committerLiang Qi <liang.qi@theqtcompany.com>2015-04-06 19:10:25 +0200
commit20cac3d9c9c22153e9e316daff32b6050ff6be6b (patch)
treeb563a89475df9afb4f40841ec371be9488d5b1ed /src/plugins/platforms/android/androidjnimain.cpp
parent8ce85d74b692392a4ea0785360156f37418cff13 (diff)
parent9eb0b09abce28b11e4915fc9c3b3e996eb19cef2 (diff)
Merge remote-tracking branch 'origin/5.5' into dev
Diffstat (limited to 'src/plugins/platforms/android/androidjnimain.cpp')
-rw-r--r--src/plugins/platforms/android/androidjnimain.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp
index 47018bfece..19ab051162 100644
--- a/src/plugins/platforms/android/androidjnimain.cpp
+++ b/src/plugins/platforms/android/androidjnimain.cpp
@@ -42,6 +42,7 @@
#include "androidjniinput.h"
#include "androidjniclipboard.h"
#include "androidjnimenu.h"
+#include "androiddeadlockprotector.h"
#include "qandroidplatformdialoghelpers.h"
#include "qandroidplatformintegration.h"
#include "qandroidassetsfileenginehandler.h"
@@ -600,11 +601,22 @@ static void updateApplicationState(JNIEnv */*env*/, jobject /*thiz*/, jint state
QtAndroidPrivate::handlePause();
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();
QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationState(state));
- QWindowSystemInterface::flushWindowSystemEvents();
+ {
+ AndroidDeadlockProtector protector;
+ if (protector.acquire())
+ QWindowSystemInterface::flushWindowSystemEvents();
+ }
if (state == Qt::ApplicationSuspended)
QAndroidEventDispatcherStopper::instance()->stopAll();
} else {