From 9091a058bc61e297abea03edca322edcd658cc1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Tue, 28 Mar 2017 15:53:42 +0200 Subject: Android: Fix application state tracking - Make sure we don't process state changes before the platform plugin is completely created and registered. - Protect shared data with mutexes. - Don't update the application state from different threads. This was causing issues when testing run-time permission checks, when the application quickly switches state due to permission dialog being shown. In this case the states would be incorrectly delivered when the application was made active again. Change-Id: I3446eab9414ee5437cd788c27d65f808d1314aa5 Reviewed-by: BogDan Vatra --- .../platforms/android/qandroidplatformintegration.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms/android/qandroidplatformintegration.cpp') diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index de9e27e595..44b4668585 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -80,8 +80,6 @@ int QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight = 71; Qt::ScreenOrientation QAndroidPlatformIntegration::m_orientation = Qt::PrimaryOrientation; Qt::ScreenOrientation QAndroidPlatformIntegration::m_nativeOrientation = Qt::PrimaryOrientation; -Qt::ApplicationState QAndroidPlatformIntegration::m_defaultApplicationState = Qt::ApplicationActive; - bool QAndroidPlatformIntegration::m_showPasswordEnabled = false; void *QAndroidPlatformNativeInterface::nativeResourceForIntegration(const QByteArray &resource) @@ -120,6 +118,12 @@ void *QAndroidPlatformNativeInterface::nativeResourceForIntegration(const QByteA return 0; } +void QAndroidPlatformNativeInterface::customEvent(QEvent *event) +{ + if (event->type() == QEvent::User) + QtAndroid::setAndroidPlatformIntegration(static_cast(QGuiApplicationPrivate::platformIntegration())); +} + QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶mList) : m_touchDevice(nullptr) #ifndef QT_NO_ACCESSIBILITY @@ -147,7 +151,6 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶ m_primaryScreen->setAvailableGeometry(QRect(0, 0, m_defaultGeometryWidth, m_defaultGeometryHeight)); m_mainThread = QThread::currentThread(); - QtAndroid::setAndroidPlatformIntegration(this); m_androidFDB = new QAndroidPlatformFontDatabase(); m_androidPlatformServices = new QAndroidPlatformServices(); @@ -210,7 +213,9 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶ } } - QGuiApplicationPrivate::instance()->setApplicationState(m_defaultApplicationState); + // We can't safely notify the jni bridge that we're up and running just yet, so let's postpone + // it for now. + QCoreApplication::postEvent(m_androidPlatformNativeInterface, new QEvent(QEvent::User)); } static bool needsBasicRenderloopWorkaround() -- cgit v1.2.3