From a4cc41c33baa1e6f14d12dbfe3c7ab3939feb864 Mon Sep 17 00:00:00 2001 From: Juha Vuolle Date: Mon, 7 Apr 2025 15:00:31 +0300 Subject: [PATCH] Make Qt for Android configurable without 'desktopservices' support Put all URL open handling behind desktopservices-feature flag. Move the few remaining function (desktopEnvironment()) a bit to keep #ifdeffery simple. Fixes: QTBUG-135722 Pick-to: 6.8 Change-Id: Id210f99f905719b8c5dc0a5fa5ac3cf10181ae84 Reviewed-by: Assam Boudjelthia (cherry picked from commit bed78605e7611252a784e7501806518edba32f0e) Reviewed-by: Qt Cherry-pick Bot --- src/gui/configure.cmake | 4 ++-- .../android/qandroidplatformservices.cpp | 18 +++++++++++++----- .../android/qandroidplatformservices.h | 12 ++++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/gui/configure.cmake b/src/gui/configure.cmake index 95985bd0fa0..97b39d4cd62 100644 --- a/src/gui/configure.cmake +++ b/src/gui/configure.cmake @@ -1482,6 +1482,6 @@ qt_configure_add_report_entry( ) qt_configure_add_report_entry( TYPE ERROR - MESSAGE "The desktopservices feature is required on macOS, iOS, and Android and cannot be disabled." - CONDITION (APPLE OR ANDROID) AND NOT QT_FEATURE_desktopservices + MESSAGE "The desktopservices feature is required on macOS and iOS, and cannot be disabled." + CONDITION APPLE AND NOT QT_FEATURE_desktopservices ) diff --git a/src/plugins/platforms/android/qandroidplatformservices.cpp b/src/plugins/platforms/android/qandroidplatformservices.cpp index 5cc5eca35bc..dea73d800ea 100644 --- a/src/plugins/platforms/android/qandroidplatformservices.cpp +++ b/src/plugins/platforms/android/qandroidplatformservices.cpp @@ -4,6 +4,7 @@ #include "qandroidplatformservices.h" +#if QT_CONFIG(desktopservices) #include #include #include @@ -11,17 +12,21 @@ #include #include #include +#endif QT_BEGIN_NAMESPACE using namespace QtJniTypes; using namespace Qt::StringLiterals; +#if QT_CONFIG(desktopservices) static constexpr auto s_defaultScheme = "file"_L1; static constexpr auto s_defaultProvider = "qtprovider"_L1; +#endif QAndroidPlatformServices::QAndroidPlatformServices() { +#if QT_CONFIG(desktopservices) m_actionView = QJniObject::getStaticObjectField("android/content/Intent", "ACTION_VIEW", "Ljava/lang/String;") .toString(); @@ -40,6 +45,12 @@ QAndroidPlatformServices::QAndroidPlatformServices() }, Qt::QueuedConnection); } +#endif // QT_CONFIG(desktopservices) +} + +QByteArray QAndroidPlatformServices::desktopEnvironment() const +{ + return QByteArray("Android"); } Q_DECLARE_JNI_CLASS(FileProvider, "androidx/core/content/FileProvider"); @@ -47,6 +58,7 @@ Q_DECLARE_JNI_CLASS(PackageManager, "android/content/pm/PackageManager"); Q_DECLARE_JNI_CLASS(PackageInfo, "android/content/pm/PackageInfo"); Q_DECLARE_JNI_CLASS(ProviderInfo, "android/content/pm/ProviderInfo"); +#if QT_CONFIG(desktopservices) bool QAndroidPlatformServices::openUrl(const QUrl &theUrl) { QUrl url(theUrl); @@ -159,11 +171,6 @@ bool QAndroidPlatformServices::openDocument(const QUrl &url) return openUrl(url); } -QByteArray QAndroidPlatformServices::desktopEnvironment() const -{ - return QByteArray("Android"); -} - bool QAndroidPlatformServices::handleNewIntent(JNIEnv *env, jobject intent) { Q_UNUSED(env); @@ -178,5 +185,6 @@ bool QAndroidPlatformServices::handleNewIntent(JNIEnv *env, jobject intent) QScopedValueRollback rollback(m_handlingUrl, url); return QDesktopServices::openUrl(url); } +#endif // QT_CONFIG(desktopservices) QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformservices.h b/src/plugins/platforms/android/qandroidplatformservices.h index 9988cab0a4c..d76c5a9dfc5 100644 --- a/src/plugins/platforms/android/qandroidplatformservices.h +++ b/src/plugins/platforms/android/qandroidplatformservices.h @@ -13,16 +13,19 @@ QT_BEGIN_NAMESPACE class QAndroidPlatformServices : public QObject, - public QPlatformServices, - public QtAndroidPrivate::NewIntentListener + public QPlatformServices +#if QT_CONFIG(desktopservices) + , public QtAndroidPrivate::NewIntentListener +#endif { public: QAndroidPlatformServices(); - bool openUrl(const QUrl &url) override; - bool openDocument(const QUrl &url) override; QByteArray desktopEnvironment() const override; +#if QT_CONFIG(desktopservices) + bool openUrl(const QUrl &url) override; + bool openDocument(const QUrl &url) override; bool handleNewIntent(JNIEnv *env, jobject intent) override; private: @@ -38,6 +41,7 @@ private: private: QUrl m_handlingUrl; QString m_actionView; +#endif }; QT_END_NAMESPACE