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. Pick-to: 6.6 6.5 Fixes: QTBUG-117490 Change-Id: I3c5ebb492f9ca4dfdf4353d77705ba993279eb69 Reviewed-by: Ilya Fedin <fedin-ilja2010@ya.ru> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>bb10
parent
8170e9e85a
commit
fe653b70ae
|
|
@ -167,6 +167,8 @@ private:
|
|||
|
||||
QNetworkManagerNetworkInformationBackend::QNetworkManagerNetworkInformationBackend()
|
||||
{
|
||||
if (!iface.isValid())
|
||||
return;
|
||||
auto updateReachability = [this](QNetworkManagerInterface::NMState newState) {
|
||||
setReachability(reachabilityFromNMState(newState));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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_SERVICE;
|
||||
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, NM_DBUS_PATH,
|
||||
validDBusConnection = QDBusConnection::systemBus().connect(NM_DBUS_SERVICE, NM_DBUS_PATH,
|
||||
DBUS_PROPERTIES_INTERFACE, "PropertiesChanged"_L1, this,
|
||||
SLOT(setProperties(QString,QMap<QString,QVariant>,QList<QString>)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue