diff options
-rw-r--r-- | src/corelib/kernel/qjnihelpers.cpp | 12 | ||||
-rw-r--r-- | src/corelib/kernel/qjnihelpers_p.h | 3 | ||||
-rw-r--r-- | src/corelib/platform/android/qandroidextras.cpp | 3 | ||||
-rw-r--r-- | src/plugins/platforms/android/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/plugins/platforms/android/androiddeadlockprotector.cpp | 43 | ||||
-rw-r--r-- | src/plugins/platforms/android/androiddeadlockprotector.h | 14 |
6 files changed, 22 insertions, 55 deletions
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) diff --git a/src/corelib/kernel/qjnihelpers_p.h b/src/corelib/kernel/qjnihelpers_p.h index 2860cef4c3..c89c33b51e 100644 --- a/src/corelib/kernel/qjnihelpers_p.h +++ b/src/corelib/kernel/qjnihelpers_p.h @@ -137,6 +137,9 @@ namespace QtAndroidPrivate Q_CORE_EXPORT int acuqireServiceSetup(int flags); Q_CORE_EXPORT void setOnBindListener(OnBindListener *listener); Q_CORE_EXPORT jobject callOnBindListener(jobject intent); + + Q_CORE_EXPORT bool acquireAndroidDeadlockProtector(); + Q_CORE_EXPORT void releaseAndroidDeadlockProtector(); } #define Q_JNI_FIND_AND_CHECK_CLASS(CLASS_NAME) \ diff --git a/src/corelib/platform/android/qandroidextras.cpp b/src/corelib/platform/android/qandroidextras.cpp index d9bcc76a1a..155f88b921 100644 --- a/src/corelib/platform/android/qandroidextras.cpp +++ b/src/corelib/platform/android/qandroidextras.cpp @@ -1230,7 +1230,7 @@ QtAndroidPrivate::requestPermission(QtAndroidPrivate::PermissionType permission) promise->start(); const auto nativePermissions = nativeStringsFromPermission(permission); - if (nativePermissions.size() > 0) { + if (nativePermissions.size() > 0 && QtAndroidPrivate::acquireAndroidDeadlockProtector()) { requestPermissionsInternal(nativePermissions).then( [promise, permission](QFuture<QtAndroidPrivate::PermissionResult> future) { auto AuthorizedCount = future.results().count(QtAndroidPrivate::Authorized); @@ -1242,6 +1242,7 @@ QtAndroidPrivate::requestPermission(QtAndroidPrivate::PermissionType permission) } else { promise->addResult(QtAndroidPrivate::Denied, 0); } + QtAndroidPrivate::releaseAndroidDeadlockProtector(); promise->finish(); }); diff --git a/src/plugins/platforms/android/CMakeLists.txt b/src/plugins/platforms/android/CMakeLists.txt index 416e25c28a..7db5556d7e 100644 --- a/src/plugins/platforms/android/CMakeLists.txt +++ b/src/plugins/platforms/android/CMakeLists.txt @@ -11,7 +11,7 @@ qt_internal_add_plugin(QAndroidIntegrationPlugin DEFAULT_IF ${QT_QPA_DEFAULT_PLATFORM} MATCHES android # special case SOURCES androidcontentfileengine.cpp androidcontentfileengine.h - androiddeadlockprotector.cpp androiddeadlockprotector.h + androiddeadlockprotector.h androidjniaccessibility.cpp androidjniaccessibility.h androidjniclipboard.cpp androidjniclipboard.h androidjniinput.cpp androidjniinput.h diff --git a/src/plugins/platforms/android/androiddeadlockprotector.cpp b/src/plugins/platforms/android/androiddeadlockprotector.cpp deleted file mode 100644 index 2bac55f160..0000000000 --- a/src/plugins/platforms/android/androiddeadlockprotector.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "androiddeadlockprotector.h" - -QAtomicInt AndroidDeadlockProtector::s_blocked(0); - diff --git a/src/plugins/platforms/android/androiddeadlockprotector.h b/src/plugins/platforms/android/androiddeadlockprotector.h index 7fa5bcfcb9..9092eda78b 100644 --- a/src/plugins/platforms/android/androiddeadlockprotector.h +++ b/src/plugins/platforms/android/androiddeadlockprotector.h @@ -40,31 +40,25 @@ #ifndef ANDROID_DEADLOCKPROTECTOR_H #define ANDROID_DEADLOCKPROTECTOR_H -#include <QAtomicInt> +#include <QtCore/private/qjnihelpers_p.h> QT_BEGIN_NAMESPACE class AndroidDeadlockProtector { public: - AndroidDeadlockProtector() - : m_acquired(0) - { - } - ~AndroidDeadlockProtector() { if (m_acquired) - s_blocked.storeRelease(0); + QtAndroidPrivate::releaseAndroidDeadlockProtector(); } bool acquire() { - m_acquired = s_blocked.testAndSetAcquire(0, 1); + m_acquired = QtAndroidPrivate::acquireAndroidDeadlockProtector(); return m_acquired; } private: - static QAtomicInt s_blocked; - int m_acquired; + bool m_acquired = false; }; QT_END_NAMESPACE |