From 527640b9379ded115459a6565d3feda1db11c8aa Mon Sep 17 00:00:00 2001 From: renpeijia Date: Wed, 1 Dec 2021 15:34:02 +0800 Subject: [PATCH 1/2] fix:the wired connection will connect, when the device is not carrierd. bug link:https://172.17.50.104/biz/bug-view-93798.html --- .../dbus-interface/kylinconnectoperation.cpp | 6 ++++++ .../kylinwiredconnectoperation.cpp | 17 +++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/backend/dbus-interface/kylinconnectoperation.cpp b/src/backend/dbus-interface/kylinconnectoperation.cpp index 7c4b1eeb..daf8234f 100644 --- a/src/backend/dbus-interface/kylinconnectoperation.cpp +++ b/src/backend/dbus-interface/kylinconnectoperation.cpp @@ -87,7 +87,13 @@ void KyConnectOperation::connectSettingSet( void KyConnectOperation::setAutoConnect(NetworkManager::ConnectionSettings::Ptr &connectSetting, bool bAutoConnect) { + if (connectSetting.isNull()) { + return; + } + connectSetting->setAutoconnect(bAutoConnect); + + return; } void KyConnectOperation::createConnect(KyConnectSetting &connectSettingsInfo) diff --git a/src/backend/dbus-interface/kylinwiredconnectoperation.cpp b/src/backend/dbus-interface/kylinwiredconnectoperation.cpp index c211c4bf..4e0e7070 100644 --- a/src/backend/dbus-interface/kylinwiredconnectoperation.cpp +++ b/src/backend/dbus-interface/kylinwiredconnectoperation.cpp @@ -241,12 +241,17 @@ int KyWiredConnectOperation::openWiredNetworkWithDevice(QString deviceName) return -EINVAL; } - QString connectUuid; - getActiveConnection(deviceName, connectUuid); - if (!connectUuid.isEmpty()) { - qDebug()<<"[KyWiredConnectOperation]" << "open wired network active connection" - << connectUuid <<"device name" << deviceName; - activateConnection(connectUuid, deviceName); + NetworkManager::WiredDevice *p_wiredDevice = + qobject_cast(wiredDevicePtr.data()); + + if (p_wiredDevice->carrier()) { + QString connectUuid; + getActiveConnection(deviceName, connectUuid); + if (!connectUuid.isEmpty()) { + qDebug()<<"[KyWiredConnectOperation]" << "open wired network active connection" + << connectUuid <<"device name" << deviceName; + activateConnection(connectUuid, deviceName); + } } wiredDevicePtr->setAutoconnect(true); From 7c1b6cdf9be5870426dd174d0b8b7cd1cb146595 Mon Sep 17 00:00:00 2001 From: renpeijia Date: Thu, 9 Dec 2021 10:48:52 +0800 Subject: [PATCH 2/2] fix:the lan is open, when close lan switch and reboot bug link:https://172.17.50.104/biz/bug-view-93825.html fix: the wired connection will be activeted, when close wired network. bug link:http://172.17.50.104/biz/bug-view-92578.html (reopen) --- .../kylinnetworkdeviceresource.cpp | 11 ++-- .../kylinnetworkdeviceresource.h | 5 +- .../kylinnetworkresourcemanager.cpp | 64 +++++++++++++++---- .../kylinnetworkresourcemanager.h | 10 ++- .../kylinwiredconnectoperation.cpp | 1 + src/frontend/tab-pages/lanpage.cpp | 26 ++++++-- src/frontend/tab-pages/lanpage.h | 1 + 7 files changed, 89 insertions(+), 29 deletions(-) diff --git a/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp b/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp index 4724ea56..d6d3ebdc 100644 --- a/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp +++ b/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp @@ -24,8 +24,10 @@ KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(pare this, &KyNetworkDeviceResourse::carrierChanage); connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceBitRateChanage, this, &KyNetworkDeviceResourse::deviceBitRateChanage); - connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceMacAddressChanaged, - this, &KyNetworkDeviceResourse::deviceMacAddressChanaged); + connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceMacAddressChanage, + this, &KyNetworkDeviceResourse::deviceMacAddressChanage); + connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceActiveChanage, + this, &KyNetworkDeviceResourse::deviceActiveChanage); } @@ -269,11 +271,8 @@ void KyNetworkDeviceResourse::onDeviceRemove(QString deviceName, QString uni) return; } -void KyNetworkDeviceResourse::onDeviceUpdate(NetworkManager::Device * dev) +void KyNetworkDeviceResourse::onDeviceUpdate(QString interface, QString dbusPath) { - QString dbusPath = dev->uni(); - QString interface = dev->interfaceName(); - if (m_deviceMap.contains(dbusPath)) { if (m_deviceMap[dbusPath] != interface) { QString oldName = m_deviceMap[dbusPath]; diff --git a/src/backend/dbus-interface/kylinnetworkdeviceresource.h b/src/backend/dbus-interface/kylinnetworkdeviceresource.h index 58841c98..e3283c6c 100644 --- a/src/backend/dbus-interface/kylinnetworkdeviceresource.h +++ b/src/backend/dbus-interface/kylinnetworkdeviceresource.h @@ -23,12 +23,13 @@ signals: void carrierChanage(QString deviceName, bool pluged); void deviceBitRateChanage(QString deviceName, int bitRate); - void deviceMacAddressChanaged(QString deviceName, const QString &hwAddress); + void deviceMacAddressChanage(QString deviceName, const QString &hwAddress); + void deviceActiveChanage(QString deviceName, bool deivceActive); public slots: void onDeviceAdd(QString deviceName, QString uni, NetworkManager::Device::Type deviceType); void onDeviceRemove(QString deviceName, QString uni); - void onDeviceUpdate(NetworkManager::Device * dev); + void onDeviceUpdate(QString interface, QString dbusPath); public: void getNetworkDeviceList(NetworkManager::Device::Type deviceType, QStringList &networkDeviceList); diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp index 3b6ba68d..85810bfc 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp @@ -210,9 +210,8 @@ void KyNetworkResourceManager::addDevice(NetworkManager::Device::Ptr device) connect(device.data(), &NetworkManager::Device::firmwareMissingChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::firmwareVersionChanged, this, &KyNetworkResourceManager::onDeviceUpdated); #endif - + connect(device.data(), &NetworkManager::Device::activeConnectionChanged, this, &KyNetworkResourceManager::onDeviceActiveChanage); connect(device.data(), &NetworkManager::Device::interfaceNameChanged, this, &KyNetworkResourceManager::onDeviceUpdated); - #if 0 connect(device.data(), &NetworkManager::Device::ipV4AddressChanged, this, &KyNetworkResourceManager::onDeviceUpdated); connect(device.data(), &NetworkManager::Device::ipV4ConfigChanged, this, &KyNetworkResourceManager::onDeviceUpdated); @@ -234,7 +233,7 @@ void KyNetworkResourceManager::addDevice(NetworkManager::Device::Ptr device) case NetworkManager::Device::Ethernet: connect(qobject_cast(device.data()), &NetworkManager::WiredDevice::bitRateChanged, this, &KyNetworkResourceManager::onDeviceBitRateChanage); connect(qobject_cast(device.data()), &NetworkManager::WiredDevice::carrierChanged, this, &KyNetworkResourceManager::onDeviceCarrierChanage); - connect(qobject_cast(device.data()), &NetworkManager::WiredDevice::hardwareAddressChanged, this, &KyNetworkResourceManager::onDeviceMacAddressChanaged); + connect(qobject_cast(device.data()), &NetworkManager::WiredDevice::hardwareAddressChanged, this, &KyNetworkResourceManager::onDeviceMacAddressChanage); // connect(qobject_cast(device.data()), &NetworkManager::WiredDevice::permanentHardwareAddressChanged, this, &KyNetworkResourceManager::onDeviceUpdated); break; @@ -598,9 +597,38 @@ void KyNetworkResourceManager::onVpnActiveConnectChanagedReason(NetworkManager:: return; } +void KyNetworkResourceManager::onDeviceActiveChanage() +{ + NetworkManager::Device *p_device = qobject_cast(sender()); + if (nullptr == p_device) { + return; + } + + QString deviceName = p_device->interfaceName(); + //此处需要取反,因为激活连接的网卡状态是false,断开连接的网卡状态是true + bool isActive = !p_device->isActive(); + + qDebug()<< LOG_FLAG << "device active change, device name " << deviceName + << "active state" << isActive; + + emit deviceActiveChanage(deviceName, isActive); + + return; +} + void KyNetworkResourceManager::onDeviceUpdated() { - emit deviceUpdate(qobject_cast(sender())); + NetworkManager::Device *p_device = qobject_cast(sender()); + if (nullptr == p_device) { + return; + } + + QString deviceName = p_device->interfaceName(); + QString deviceUni = p_device->uni(); + + emit deviceUpdate(deviceName, deviceUni); + + return; } void KyNetworkResourceManager::onDeviceCarrierChanage(bool pluged) @@ -633,13 +661,13 @@ void KyNetworkResourceManager::onDeviceBitRateChanage(int bitRate) return; } -void KyNetworkResourceManager::onDeviceMacAddressChanaged(const QString &hwAddress) +void KyNetworkResourceManager::onDeviceMacAddressChanage(const QString &hwAddress) { NetworkManager::WiredDevice * networkDevice = qobject_cast(sender()); if (nullptr !=networkDevice && networkDevice->isValid()) { - emit deviceMacAddressChanaged(networkDevice->interfaceName(), hwAddress); + emit deviceMacAddressChanage(networkDevice->interfaceName(), hwAddress); } else { qWarning()<< LOG_FLAG <<"the device is not invalid with mac" << hwAddress; } @@ -743,10 +771,14 @@ void KyNetworkResourceManager::onWifiNetworkRemove(NetworkManager::Device * dev, void KyNetworkResourceManager::onWifiNetworkAppeared(QString const & ssid) { - NetworkManager::Device * dev = qobject_cast(sender()); - if (nullptr != dev) { - onWifiNetworkAdd(dev, ssid); - emit deviceUpdate(dev); + NetworkManager::Device * p_device = qobject_cast(sender()); + if (nullptr != p_device) { + onWifiNetworkAdd(p_device, ssid); + + QString deviceName = p_device->interfaceName(); + QString deviceUni = p_device->uni(); + + emit deviceUpdate(deviceName, deviceUni); } else { qWarning()<< LOG_FLAG << "onWifiNetworkAppeared failed."; } @@ -756,10 +788,14 @@ void KyNetworkResourceManager::onWifiNetworkAppeared(QString const & ssid) void KyNetworkResourceManager::onWifiNetworkDisappeared(QString const & ssid) { - NetworkManager::Device * dev = qobject_cast(sender()); - if (nullptr != dev) { - onWifiNetworkRemove(dev, ssid); - emit deviceUpdate(dev); + NetworkManager::Device *p_device = qobject_cast(sender()); + if (nullptr != p_device) { + onWifiNetworkRemove(p_device, ssid); + + QString deviceName = p_device->interfaceName(); + QString deviceUni = p_device->uni(); + + emit deviceUpdate(deviceName, deviceUni); } else { qWarning()<< LOG_FLAG << "onWifiNetworkDisappeared failed."; } diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.h b/src/backend/dbus-interface/kylinnetworkresourcemanager.h index efb0c12a..36bcb48c 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.h +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.h @@ -109,12 +109,13 @@ signals: void connectionRemove(QString path); void deviceAdd(QString deviceName, QString uni, NetworkManager::Device::Type deviceType); - void deviceUpdate(NetworkManager::Device * dev); + void deviceUpdate(QString deviceName, QString deviceUni); void deviceRemove(QString deviceName, QString uni); + void deviceActiveChanage(QString deviceName, bool deviceActive); void deviceCarrierChanage(QString deviceName, bool pluged); void deviceBitRateChanage(QString deviceName, int bitRate); - void deviceMacAddressChanaged(QString deviceName, const QString &hwAddress); + void deviceMacAddressChanage(QString deviceName, const QString &hwAddress); //to KyWirelessNetResource void wifiNetworkRemoved(QString, QString); @@ -155,10 +156,13 @@ private slots: NetworkManager::VpnConnection::StateChangeReason reason); //device + + void onDeviceActiveChanage(); + void onDeviceUpdated(); void onDeviceCarrierChanage(bool pluged); void onDeviceBitRateChanage(int bitRate); - void onDeviceMacAddressChanaged(const QString &hwAddress); + void onDeviceMacAddressChanage(const QString &hwAddress); void onDeviceStateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason); diff --git a/src/backend/dbus-interface/kylinwiredconnectoperation.cpp b/src/backend/dbus-interface/kylinwiredconnectoperation.cpp index 4e0e7070..f224cc95 100644 --- a/src/backend/dbus-interface/kylinwiredconnectoperation.cpp +++ b/src/backend/dbus-interface/kylinwiredconnectoperation.cpp @@ -220,6 +220,7 @@ int KyWiredConnectOperation::closeWiredNetworkWithDevice(QString deviceName) } } + //wiredDevicePtr->setAutoconnect(false); wiredDevicePtr->disconnectInterface(); return 0; diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 0a64c5d0..d759daa3 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -44,6 +44,7 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) connect(m_deviceResource, &KyNetworkDeviceResourse::deviceNameUpdate, this, &LanPage::onDeviceNameUpdate); connect(m_deviceResource, &KyNetworkDeviceResourse::carrierChanage, this, &LanPage::onDeviceCarriered); + connect(m_deviceResource, &KyNetworkDeviceResourse::deviceActiveChanage, this, &LanPage::onDeviceActiveChanage); connect(m_wiredConnectOperation, &KyWiredConnectOperation::activateConnectionError, this, &LanPage::activateFailed); connect(m_wiredConnectOperation, &KyWiredConnectOperation::deactivateConnectionError, this, &LanPage::deactivateFailed); @@ -179,10 +180,10 @@ void LanPage::onLanSwitchClicked() this->showDesktopNotify(tr("No ethernet device avaliable")); } else { if (m_netSwitch->getSwitchStatus()) { - qDebug() << "[wiredSwitch]set true after clicked"; + //qDebug() << "[wiredSwitch]set true after clicked"; m_switchGsettings->set(WIRED_SWITCH, true); } else { - qDebug() << "[wiredSwitch]set false after clicked"; + //qDebug() << "[wiredSwitch]set false after clicked"; m_switchGsettings->set(WIRED_SWITCH,false); } } @@ -681,13 +682,30 @@ void LanPage::onDeviceCarriered(QString deviceName, bool pluged) return; } - if (!m_wiredSwitch || !m_enableDeviceList.contains(deviceName)) { - m_wiredConnectOperation->closeWiredNetworkWithDevice(deviceName); + if (m_enableDeviceList.contains(deviceName)) { + m_wiredConnectOperation->openWiredNetworkWithDevice(deviceName); } return; } +void LanPage::onDeviceActiveChanage(QString deviceName, bool deviceActive) +{ + if (!m_devList.contains(deviceName)) { + return; + } + + if (deviceActive) { + if (!m_wiredSwitch || !m_enableDeviceList.contains(deviceName)) { + qDebug()<< LOG_FLAG << "close disabled device"; + m_wiredConnectOperation->closeWiredNetworkWithDevice(deviceName); + } + } + + return; +} + + void LanPage::onDeviceComboxIndexChanged(int currentIndex) { //TODO 设备变更时更新设备和列表 diff --git a/src/frontend/tab-pages/lanpage.h b/src/frontend/tab-pages/lanpage.h index ac6e770c..7610db81 100644 --- a/src/frontend/tab-pages/lanpage.h +++ b/src/frontend/tab-pages/lanpage.h @@ -103,6 +103,7 @@ private slots: void onDeviceNameUpdate(QString oldName, QString newName); void onDeviceCarriered(QString deviceName, bool pluged); + void onDeviceActiveChanage(QString deviceName, bool deviceActive); void onDeviceComboxIndexChanged(int currentIndex);