1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QCOREAPPLICATION_PLATFORM_H
5#define QCOREAPPLICATION_PLATFORM_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is part of the native interface APIs. Usage of
12// this API may make your code source and binary incompatible
13// with future versions of Qt.
14//
15
16#include <QtCore/qglobal.h>
17#include <QtCore/qnativeinterface.h>
18#include <QtCore/qcoreapplication.h>
19
20#if defined(Q_OS_ANDROID) || defined(Q_QDOC)
21#include <QtCore/qjnitypes.h>
22#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
23#include <QtCore/qfuture.h>
24#include <QtCore/qvariant.h>
25#endif
26#endif // #if defined(Q_OS_ANDROID) || defined(Q_QDOC)
27
28#if defined(Q_OS_ANDROID)
29class _jobject;
30typedef _jobject* jobject;
31#endif
32
33QT_BEGIN_NAMESPACE
34
35#if defined(Q_OS_ANDROID)
36Q_DECLARE_JNI_TYPE(Context, "Landroid/content/Context;")
37#endif
38
39namespace QNativeInterface
40{
41#if defined(Q_OS_ANDROID) || defined(Q_QDOC)
42struct Q_CORE_EXPORT QAndroidApplication
43{
44 QT_DECLARE_NATIVE_INTERFACE(QAndroidApplication, 1, QCoreApplication)
45#ifdef Q_QDOC
46 static jobject context();
47#else
48 static QtJniTypes::Context context();
49#endif
50 static bool isActivityContext();
51 static int sdkVersion();
52 static void hideSplashScreen(int duration = 0);
53
54#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
55 static QFuture<QVariant> runOnAndroidMainThread(const std::function<QVariant()> &runnable,
56 const QDeadlineTimer timeout = QDeadlineTimer::Forever);
57
58 template <class T>
59 std::enable_if_t<std::is_invocable_v<T> && std::is_same_v<std::invoke_result_t<T>, void>,
60 QFuture<void>> static runOnAndroidMainThread(const T &runnable,
61 const QDeadlineTimer timeout = QDeadlineTimer::Forever)
62 {
63 std::function<QVariant()> func = [runnable](){ runnable(); return QVariant(); };
64 return static_cast<QFuture<void>>(runOnAndroidMainThread(func, timeout));
65 }
66#endif
67};
68#endif
69}
70
71QT_END_NAMESPACE
72
73#endif // QCOREAPPLICATION_PLATFORM_H
74

source code of qtbase/src/corelib/kernel/qcoreapplication_platform.h