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 <assam.boudjelthia@qt.io>
(cherry picked from commit bed78605e7611252a784e7501806518edba32f0e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Juha Vuolle 2025-04-07 15:00:31 +03:00 committed by Qt Cherry-pick Bot
parent 00b28640a2
commit a4cc41c33b
3 changed files with 23 additions and 11 deletions

View File

@ -1482,6 +1482,6 @@ qt_configure_add_report_entry(
) )
qt_configure_add_report_entry( qt_configure_add_report_entry(
TYPE ERROR TYPE ERROR
MESSAGE "The desktopservices feature is required on macOS, iOS, and Android and cannot be disabled." MESSAGE "The desktopservices feature is required on macOS and iOS, and cannot be disabled."
CONDITION (APPLE OR ANDROID) AND NOT QT_FEATURE_desktopservices CONDITION APPLE AND NOT QT_FEATURE_desktopservices
) )

View File

@ -4,6 +4,7 @@
#include "qandroidplatformservices.h" #include "qandroidplatformservices.h"
#if QT_CONFIG(desktopservices)
#include <QDebug> #include <QDebug>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFile> #include <QFile>
@ -11,17 +12,21 @@
#include <QtCore/QJniObject> #include <QtCore/QJniObject>
#include <QtCore/qcoreapplication.h> #include <QtCore/qcoreapplication.h>
#include <QtCore/qscopedvaluerollback.h> #include <QtCore/qscopedvaluerollback.h>
#endif
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using namespace QtJniTypes; using namespace QtJniTypes;
using namespace Qt::StringLiterals; using namespace Qt::StringLiterals;
#if QT_CONFIG(desktopservices)
static constexpr auto s_defaultScheme = "file"_L1; static constexpr auto s_defaultScheme = "file"_L1;
static constexpr auto s_defaultProvider = "qtprovider"_L1; static constexpr auto s_defaultProvider = "qtprovider"_L1;
#endif
QAndroidPlatformServices::QAndroidPlatformServices() QAndroidPlatformServices::QAndroidPlatformServices()
{ {
#if QT_CONFIG(desktopservices)
m_actionView = QJniObject::getStaticObjectField("android/content/Intent", "ACTION_VIEW", m_actionView = QJniObject::getStaticObjectField("android/content/Intent", "ACTION_VIEW",
"Ljava/lang/String;") "Ljava/lang/String;")
.toString(); .toString();
@ -40,6 +45,12 @@ QAndroidPlatformServices::QAndroidPlatformServices()
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
} }
#endif // QT_CONFIG(desktopservices)
}
QByteArray QAndroidPlatformServices::desktopEnvironment() const
{
return QByteArray("Android");
} }
Q_DECLARE_JNI_CLASS(FileProvider, "androidx/core/content/FileProvider"); 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(PackageInfo, "android/content/pm/PackageInfo");
Q_DECLARE_JNI_CLASS(ProviderInfo, "android/content/pm/ProviderInfo"); Q_DECLARE_JNI_CLASS(ProviderInfo, "android/content/pm/ProviderInfo");
#if QT_CONFIG(desktopservices)
bool QAndroidPlatformServices::openUrl(const QUrl &theUrl) bool QAndroidPlatformServices::openUrl(const QUrl &theUrl)
{ {
QUrl url(theUrl); QUrl url(theUrl);
@ -159,11 +171,6 @@ bool QAndroidPlatformServices::openDocument(const QUrl &url)
return openUrl(url); return openUrl(url);
} }
QByteArray QAndroidPlatformServices::desktopEnvironment() const
{
return QByteArray("Android");
}
bool QAndroidPlatformServices::handleNewIntent(JNIEnv *env, jobject intent) bool QAndroidPlatformServices::handleNewIntent(JNIEnv *env, jobject intent)
{ {
Q_UNUSED(env); Q_UNUSED(env);
@ -178,5 +185,6 @@ bool QAndroidPlatformServices::handleNewIntent(JNIEnv *env, jobject intent)
QScopedValueRollback<QUrl> rollback(m_handlingUrl, url); QScopedValueRollback<QUrl> rollback(m_handlingUrl, url);
return QDesktopServices::openUrl(url); return QDesktopServices::openUrl(url);
} }
#endif // QT_CONFIG(desktopservices)
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -13,16 +13,19 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QAndroidPlatformServices : public QObject, class QAndroidPlatformServices : public QObject,
public QPlatformServices, public QPlatformServices
public QtAndroidPrivate::NewIntentListener #if QT_CONFIG(desktopservices)
, public QtAndroidPrivate::NewIntentListener
#endif
{ {
public: public:
QAndroidPlatformServices(); QAndroidPlatformServices();
bool openUrl(const QUrl &url) override;
bool openDocument(const QUrl &url) override;
QByteArray desktopEnvironment() const 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; bool handleNewIntent(JNIEnv *env, jobject intent) override;
private: private:
@ -38,6 +41,7 @@ private:
private: private:
QUrl m_handlingUrl; QUrl m_handlingUrl;
QString m_actionView; QString m_actionView;
#endif
}; };
QT_END_NAMESPACE QT_END_NAMESPACE