summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/CMakeLists.txt2
-rw-r--r--src/corelib/io/qstandardpaths_android.cpp32
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp5
-rw-r--r--src/corelib/kernel/qcoreapplication.h4
-rw-r--r--src/corelib/kernel/qcoreapplication_platform.h66
-rw-r--r--src/corelib/platform/android/qandroidnativeinterface.cpp85
6 files changed, 166 insertions, 28 deletions
diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt
index 1106aaae71..ebbe5851bb 100644
--- a/src/corelib/CMakeLists.txt
+++ b/src/corelib/CMakeLists.txt
@@ -94,6 +94,7 @@ qt_internal_add_module(Core
kernel/qassociativeiterable.cpp kernel/qassociativeiterable.h
kernel/qbasictimer.cpp kernel/qbasictimer.h
kernel/qcoreapplication.cpp kernel/qcoreapplication.h kernel/qcoreapplication_p.h
+ kernel/qcoreapplication_platform.h
kernel/qcorecmdlineargs_p.h
kernel/qcoreevent.cpp kernel/qcoreevent.h
kernel/qcoreglobaldata.cpp kernel/qcoreglobaldata_p.h
@@ -996,6 +997,7 @@ qt_internal_extend_target(Core CONDITION ANDROID AND NOT ANDROID_EMBEDDED
kernel/qjniobject.cpp kernel/qjniobject.h
kernel/qjnihelpers.cpp kernel/qjnihelpers_p.h
kernel/qjnionload.cpp
+ platform/android/qandroidnativeinterface.cpp
)
qt_internal_extend_target(Core CONDITION HAIKU AND (ANDROID_EMBEDDED OR NOT ANDROID)
diff --git a/src/corelib/io/qstandardpaths_android.cpp b/src/corelib/io/qstandardpaths_android.cpp
index 46f96e4037..129ae03158 100644
--- a/src/corelib/io/qstandardpaths_android.cpp
+++ b/src/corelib/io/qstandardpaths_android.cpp
@@ -41,11 +41,13 @@
#ifndef QT_NO_STANDARDPATHS
-#include <QJniObject>
-#include <QtCore/private/qjnihelpers_p.h>
+#include <QtCore/qjniobject.h>
#include <QtCore/qmap.h>
+#include <QtCore/qcoreapplication.h>
#include <QDir>
+using namespace QNativeInterface;
+
QT_BEGIN_NAMESPACE
typedef QMap<QString, QString> AndroidDirCache;
@@ -57,24 +59,6 @@ static QString testDir()
: QLatin1String("");
}
-static QJniObject applicationContext()
-{
- static QJniObject appCtx;
- if (appCtx.isValid())
- return appCtx;
-
- QJniObject context(QtAndroidPrivate::activity());
- if (!context.isValid()) {
- context = QtAndroidPrivate::service();
- if (!context.isValid())
- return appCtx;
- }
-
- appCtx = context.callObjectMethod("getApplicationContext",
- "()Landroid/content/Context;");
- return appCtx;
-}
-
static inline QString getAbsolutePath(const QJniObject &file)
{
QJniObject path = file.callObjectMethod("getAbsolutePath",
@@ -95,7 +79,7 @@ static QString getExternalFilesDir(const char *directoryField = nullptr)
if (!path.isEmpty())
return path;
- QJniObject appCtx = applicationContext();
+ QJniObject appCtx = QAndroidApplication::context();
if (!appCtx.isValid())
return QString();
@@ -128,7 +112,7 @@ static QString getExternalCacheDir()
if (!path.isEmpty())
return path;
- QJniObject appCtx = applicationContext();
+ QJniObject appCtx = QAndroidApplication::context();
if (!appCtx.isValid())
return QString();
@@ -150,7 +134,7 @@ static QString getCacheDir()
if (!path.isEmpty())
return path;
- QJniObject appCtx = applicationContext();
+ QJniObject appCtx = QAndroidApplication::context();
if (!appCtx.isValid())
return QString();
@@ -172,7 +156,7 @@ static QString getFilesDir()
if (!path.isEmpty())
return path;
- QJniObject appCtx = applicationContext();
+ QJniObject appCtx = QAndroidApplication::context();
if (!appCtx.isValid())
return QString();
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 781791c971..ccdece6357 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -91,8 +91,7 @@
#endif // QT_NO_QOBJECT
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
-#include <QJniObject>
-#include <private/qjnihelpers_p.h>
+#include <QtCore/qjniobject.h>
#endif
#ifdef Q_OS_MAC
@@ -170,7 +169,7 @@ QString QCoreApplicationPrivate::appVersion() const
# ifdef Q_OS_DARWIN
applicationVersion = infoDictionaryStringProperty(QStringLiteral("CFBundleVersion"));
# elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
- QJniObject context(QtAndroidPrivate::context());
+ QJniObject context(QNativeInterface::QAndroidApplication::context());
if (context.isValid()) {
QJniObject pm = context.callObjectMethod(
"getPackageManager", "()Landroid/content/pm/PackageManager;");
diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h
index dabc518ad2..6539441180 100644
--- a/src/corelib/kernel/qcoreapplication.h
+++ b/src/corelib/kernel/qcoreapplication.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -246,4 +246,6 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
QT_END_NAMESPACE
+#include <QtCore/qcoreapplication_platform.h>
+
#endif // QCOREAPPLICATION_H
diff --git a/src/corelib/kernel/qcoreapplication_platform.h b/src/corelib/kernel/qcoreapplication_platform.h
new file mode 100644
index 0000000000..8dc1199135
--- /dev/null
+++ b/src/corelib/kernel/qcoreapplication_platform.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtCore module 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$
+**
+****************************************************************************/
+
+#ifndef QCOREAPPLICATION_PLATFORM_H
+#define QCOREAPPLICATION_PLATFORM_H
+
+#include <QtCore/qglobal.h>
+
+#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
+class _jobject;
+typedef _jobject* jobject;
+#endif
+
+QT_BEGIN_NAMESPACE
+
+namespace QNativeInterface
+{
+#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) || defined(Q_CLANG_QDOC)
+struct Q_CORE_EXPORT QAndroidApplication
+{
+ QT_DECLARE_NATIVE_INTERFACE(QAndroidApplication)
+ static jobject context();
+ static bool isActivityContext();
+};
+#endif
+}
+
+QT_END_NAMESPACE
+
+#endif // QCOREAPPLICATION_PLATFORM_H
diff --git a/src/corelib/platform/android/qandroidnativeinterface.cpp b/src/corelib/platform/android/qandroidnativeinterface.cpp
new file mode 100644
index 0000000000..74d21c5d4c
--- /dev/null
+++ b/src/corelib/platform/android/qandroidnativeinterface.cpp
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtCore module 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 <QtCore/qcoreapplication.h>
+#include <QtCore/private/qjnihelpers_p.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QNativeInterface::QAndroidApplication
+ \since 6.2
+ \brief Native interface to a core application on Android.
+
+ Accessed through QCoreApplication::nativeInterface().
+
+ \inmodule QtCore
+ \inheaderfile QCoreApplication
+ \ingroup native-interfaces
+ \ingroup native-interfaces-qcoreapplication
+*/
+QT_DEFINE_NATIVE_INTERFACE(QAndroidApplication);
+
+/*!
+ \fn jobject QNativeInterface::QAndroidApplication::context()
+
+ Returns the Android context as a \c jobject. The context is an \c Activity
+ if the main activity object is valid. Otherwise, the context is a \c Service.
+
+ \since 6.2
+*/
+jobject QNativeInterface::QAndroidApplication::context()
+{
+ return QtAndroidPrivate::context();
+}
+
+/*!
+ \fn bool QNativeInterface::QAndroidApplication::isActivityContext()
+
+ Returns \c true if QAndroidApplication::context() provides an \c Activity
+ context.
+
+ \since 6.2
+*/
+bool QNativeInterface::QAndroidApplication::isActivityContext()
+{
+ return QtAndroidPrivate::activity();
+}
+
+QT_END_NAMESPACE