QNetworkInfo[NetworkManager]: Mark invalid if unconnected

On some configs (e.g. using Snap) the NetworkManager service is not
available without some manifest or similar. In this case, the
_interface_ we have is still valid but we can't connect to the
service. So we need to mark the interface as invalid in this case, so
that we can avoid trying to use this plugin.

Fixes: QTBUG-117490
Change-Id: I3c5ebb492f9ca4dfdf4353d77705ba993279eb69
Reviewed-by: Ilya Fedin <fedin-ilja2010@ya.ru>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit fe653b70ae271da9a110d627da4ad2609a1fb8db)
(cherry picked from commit 9f49af182f3be4a6f6c87266db0c14409de08ba0)
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Mårten Nordheim 2023-10-16 12:31:55 +02:00 committed by Volker Hilsheimer
parent c30dabc370
commit 9e6de9e8ef
3 changed files with 13 additions and 6 deletions

View File

@ -167,6 +167,8 @@ private:
QNetworkManagerNetworkInformationBackend::QNetworkManagerNetworkInformationBackend()
{
if (!iface.isValid())
return;
auto updateReachability = [this](QNetworkManagerInterface::NMState newState) {
setReachability(reachabilityFromNMState(newState));
};

View File

@ -41,7 +41,7 @@ bool QNetworkManagerInterfaceBase::networkManagerAvailable()
QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent)
: QNetworkManagerInterfaceBase(parent)
{
if (!isValid())
if (!QDBusAbstractInterface::isValid())
return;
PropertiesDBusInterface managerPropertiesInterface(
@ -51,13 +51,15 @@ QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent)
argumentList << NM_DBUS_INTERFACE ""_L1;
QDBusPendingReply<QVariantMap> propsReply = managerPropertiesInterface.callWithArgumentList(
QDBus::Block, "GetAll"_L1, argumentList);
if (!propsReply.isError()) {
propertyMap = propsReply.value();
} else {
qWarning() << "propsReply" << propsReply.error().message();
if (propsReply.isError()) {
validDBusConnection = false;
if (auto error = propsReply.error(); error.type() != QDBusError::AccessDenied)
qWarning() << "Failed to query NetworkManager properties:" << error.message();
return;
}
propertyMap = propsReply.value();
QDBusConnection::systemBus().connect(NM_DBUS_SERVICE ""_L1, NM_DBUS_PATH ""_L1,
validDBusConnection = QDBusConnection::systemBus().connect(NM_DBUS_SERVICE ""_L1, NM_DBUS_PATH ""_L1,
DBUS_PROPERTIES_INTERFACE""_L1, "PropertiesChanged"_L1, this,
SLOT(setProperties(QString, QMap<QString, QVariant>, QList<QString>)));
}

View File

@ -136,6 +136,8 @@ public:
NMDeviceType deviceType() const;
NMMetered meteredState() const;
bool isValid() const { return QDBusAbstractInterface::isValid() && validDBusConnection; }
Q_SIGNALS:
void stateChanged(NMState);
void connectivityChanged(NMConnectivityState);
@ -155,6 +157,7 @@ private:
std::optional<QDBusObjectPath> primaryConnectionDevicePath() const;
QVariantMap propertyMap;
bool validDBusConnection = true;
};
class PropertiesDBusInterface : public QDBusAbstractInterface