Merge branch 'kylin-nm-0913' into 'dbus-interface'

bug 122742 wifi安全类型改变

See merge request kylin-desktop/kylin-nm!708
This commit is contained in:
陈学超 2022-09-22 01:36:38 +00:00
commit 28fa451a39
10 changed files with 131 additions and 18 deletions

View File

@ -306,7 +306,12 @@ void KyNetworkResourceManager::addWifiNetwork(NetworkManager::WirelessNetwork::P
//device signals
connect(net.data(), &NetworkManager::WirelessNetwork::signalStrengthChanged, this, &KyNetworkResourceManager::onUpdateWirelessNet);
connect(net.data(), &NetworkManager::WirelessNetwork::referenceAccessPointChanged, this, &KyNetworkResourceManager::onUpdateWirelessNet);
connect(net.data(), &NetworkManager::WirelessNetwork::referenceAccessPointChanged, this, &KyNetworkResourceManager::onReferenceAccessPointChanged);
connect(net.data(), &NetworkManager::WirelessNetwork::disappeared, this, &KyNetworkResourceManager::onUpdateWirelessNet);
connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::wpaFlagsChanged, this, &KyNetworkResourceManager::onWifiNetworkSecuChang,
Qt::UniqueConnection);
connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::rsnFlagsChanged, this, &KyNetworkResourceManager::onWifiNetworkSecuChang,
Qt::UniqueConnection);
}
void KyNetworkResourceManager::insertWifiNetworks()
@ -838,6 +843,31 @@ void KyNetworkResourceManager::onWifiNetworkDisappeared(QString const & ssid)
return;
}
void KyNetworkResourceManager::onReferenceAccessPointChanged()
{
NetworkManager::WirelessNetwork *p_wirelessNet =
qobject_cast<NetworkManager::WirelessNetwork *>(sender());
if (nullptr != p_wirelessNet) {
onAccessPointUpdate(p_wirelessNet);
}
}
void KyNetworkResourceManager::onAccessPointUpdate(NetworkManager::WirelessNetwork * net)
{
if (nullptr == net) {
return;
}
auto index = std::find(m_wifiNets.cbegin(), m_wifiNets.cend(), net);
if (m_wifiNets.cend() != index) {
if (!net->referenceAccessPoint().isNull()) {
connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::wpaFlagsChanged, this, &KyNetworkResourceManager::onWifiNetworkSecuChang,
Qt::UniqueConnection);
connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::rsnFlagsChanged, this, &KyNetworkResourceManager::onWifiNetworkSecuChang,
Qt::UniqueConnection);
}
}
}
void KyNetworkResourceManager::onUpdateWirelessNet()
{
NetworkManager::WirelessNetwork *p_wirelessNet =
@ -849,6 +879,13 @@ void KyNetworkResourceManager::onUpdateWirelessNet()
return;
}
void KyNetworkResourceManager::onWifiNetworkSecuChang()
{
NetworkManager::AccessPoint *p_wirelessNet =
qobject_cast<NetworkManager::AccessPoint *>(sender());
emit wifiNetworkSecuChange(p_wirelessNet);
}
void KyNetworkResourceManager::onDeviceAdded(QString const & uni)
{
qDebug()<< "onDeviceAdded"<<uni;

View File

@ -122,6 +122,7 @@ signals:
void wifiNetworkRemoved(QString, QString);
void wifiNetworkAdded(QString, QString);
void wifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net);
void wifiNetworkSecuChange(NetworkManager::AccessPoint *);
void wifiNetworkDeviceDisappear();
void wifiEnabledChanged(bool);
@ -177,6 +178,7 @@ private slots:
//wifi network
void onUpdateWirelessNet();
void onWifiNetworkSecuChang();
//notifier
void onDeviceAdded(QString const & uni);
@ -193,6 +195,9 @@ private:
void onWifiNetworkUpdate(NetworkManager::WirelessNetwork * net);
void onWifiNetworkRemove(NetworkManager::Device * dev, QString const & ssid);
void onAccessPointUpdate(NetworkManager::WirelessNetwork * net);
void onReferenceAccessPointChanged();
private:
bool m_initFinished = false;

View File

@ -89,13 +89,14 @@ void KyWirelessNetItem::init(NetworkManager::WirelessNetwork::Ptr net)
NetworkManager::AccessPoint::WpaFlags wpaFlag = net->referenceAccessPoint()->wpaFlags();
NetworkManager::AccessPoint::WpaFlags rsnFlag = net->referenceAccessPoint()->rsnFlags();
m_secuType = enumToQstring(cap, wpaFlag, rsnFlag);
if (m_secuType.indexOf(ENTERPRICE_TYPE) >= 0) {
m_kySecuType = WPA_AND_WPA2_ENTERPRISE;
} else if (m_secuType.indexOf(WPA3) >= 0) {
m_kySecuType = WPA3_PERSONAL;
} else if ( m_secuType.indexOf(WPA1_AND_WPA2) >= 0) {
m_kySecuType = WPA_AND_WPA2_PERSONAL;
}
// if (m_secuType.indexOf(ENTERPRICE_TYPE) >= 0) {
// m_kySecuType = WPA_AND_WPA2_ENTERPRISE;
// } else if (m_secuType.indexOf(WPA3) >= 0) {
// m_kySecuType = WPA3_PERSONAL;
// } else if ( m_secuType.indexOf(WPA1_AND_WPA2) >= 0) {
// m_kySecuType = WPA_AND_WPA2_PERSONAL;
// }
setKySecuType(m_secuType);
m_bssid = net->referenceAccessPoint()->hardwareAddress();
m_device = net->device();
m_uni = net->referenceAccessPoint()->uni();
@ -151,3 +152,16 @@ int KyWirelessNetItem::getCategory(QString uni)
}
}
void KyWirelessNetItem::setKySecuType(QString strSecuType)
{
if (strSecuType.indexOf(ENTERPRICE_TYPE) >= 0) {
m_kySecuType = WPA_AND_WPA2_ENTERPRISE;
} else if (strSecuType.indexOf(WPA3) >= 0) {
m_kySecuType = WPA3_PERSONAL;
} else if ( strSecuType.indexOf(WPA1_AND_WPA2) >= 0) {
m_kySecuType = WPA_AND_WPA2_PERSONAL;
} else {
m_kySecuType = NONE;
}
}

View File

@ -55,6 +55,7 @@ public:
uint m_channel;
int getCategory(QString uni);
void setKySecuType(QString strSecuType);
private:
KyNetworkResourceManager *m_networkResourceInstance = nullptr;

View File

@ -21,6 +21,9 @@
#include "kylinutil.h"
#define LOG_FLAG "[KyWirelessNetResource]"
const QString ENTERPRICE_TYPE = "802.1X";
const QString WPA1_AND_WPA2 = "WPA";
const QString WPA3 = "WPA3";
static bool subWifiListSort(const KyWirelessNetItem info1, const KyWirelessNetItem info2)
{
@ -63,6 +66,8 @@ KyWirelessNetResource::KyWirelessNetResource(QObject *parent)
this, &KyWirelessNetResource::onWifiNetworkRemoved, Qt::ConnectionType::DirectConnection);
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkPropertyChange,
this, &KyWirelessNetResource::onWifiNetworkPropertyChange, Qt::ConnectionType::DirectConnection);
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkSecuChange,
this, &KyWirelessNetResource::onWifiNetworkSecuChange, Qt::ConnectionType::DirectConnection);
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkDeviceDisappear,
this, &KyWirelessNetResource::onWifiNetworkDeviceDisappear, Qt::ConnectionType::DirectConnection);
@ -426,12 +431,39 @@ void KyWirelessNetResource::onWifiNetworkRemoved(QString devIfaceName, QString s
}
}
void KyWirelessNetResource::onWifiNetworkSecuChange(NetworkManager::AccessPoint *accessPointPtr)
{
QString secuType = enumToQstring(accessPointPtr->capabilities(),
accessPointPtr->wpaFlags(),
accessPointPtr->rsnFlags());
QMap<QString, QList<KyWirelessNetItem> >::iterator iter = m_WifiNetworkList.begin();
while (iter != m_WifiNetworkList.end()) {
QList<KyWirelessNetItem>::iterator itemIter = iter.value().begin();
while (itemIter != iter.value().end()) {
if (itemIter->m_NetSsid == accessPointPtr->ssid()) {
QString devName = iter.key();
itemIter->m_secuType = secuType;
itemIter->setKySecuType(secuType);
//qDebug() << "!!!!" << itemIter->m_NetSsid << itemIter->m_secuType << itemIter->m_kySecuType;
emit secuTypeChange(devName, accessPointPtr->ssid(), secuType);
break;
}
itemIter++;
}
iter++;
}
}
void KyWirelessNetResource::onWifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net)
{
if (nullptr == net) {
return;
}
qDebug() << "onWifiNetworkPropertyChange" << net->ssid();
NetworkManager::AccessPoint::Ptr accessPointPtr = net->referenceAccessPoint();
QByteArray rawSsid = accessPointPtr->rawSsid();
QString wifiSsid = getSsidFromByteArray(rawSsid);
@ -460,7 +492,10 @@ void KyWirelessNetResource::onWifiNetworkPropertyChange(NetworkManager::Wireless
accessPointPtr->wpaFlags(),
accessPointPtr->rsnFlags());
if (iter->m_secuType != secuType) {
//qDebug() << "!!!!secuTypeChange" << wifiSsid << iter->m_secuType << "change to " << secuType;
iter->m_secuType = secuType;
iter->setKySecuType(secuType);
emit secuTypeChange(devIface, wifiSsid, secuType);
}
@ -693,7 +728,7 @@ void KyWirelessNetResource::onConnectionRemove(QString path)
for(auto var = map.cbegin(); var != map.cend(); var++) {
QString devIfaceName = var.key();
QString ssid = var.value();
emit connectionRemove(devIfaceName, ssid);
emit connectionRemove(devIfaceName, ssid, path);
}
}

View File

@ -64,6 +64,7 @@ public slots:
void onWifiNetworkAdded(QString, QString);
void onWifiNetworkRemoved(QString, QString);
void onWifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net);
void onWifiNetworkSecuChange(NetworkManager::AccessPoint *accessPointPtr);
void onWifiNetworkDeviceDisappear();
void onConnectionAdd(QString uuid);
@ -78,7 +79,7 @@ signals:
void signalStrengthChange(QString, QString, int);
void bssidChange(QString, QString, QString);
void secuTypeChange(QString, QString, QString);
void connectionRemove(QString, QString);
void connectionRemove(QString, QString, QString);
void connectionAdd(QString, QString);
void wifiNetworkUpdate();
void wifiNetworkAdd(QString, KyWirelessNetItem&);

View File

@ -28,6 +28,10 @@
#define ENABLE_BUTTON_COLOR qApp->palette().highlight().color()
#define UNABLE_BUTTON_COLOR qApp->palette().button().color()
const QString ENTERPRICE_TYPE = "802.1X";
const QString WPA1_AND_WPA2 = "WPA";
const QString WPA3 = "WPA3";
WlanListItem::WlanListItem(KyWirelessNetItem &wirelessNetItem, QString device, bool isApMode, QWidget *parent)
: WlanListItem(wirelessNetItem, device, parent)
{
@ -84,6 +88,11 @@ QString WlanListItem::getUuid()
return m_wirelessNetItem.m_connectUuid;
}
QString WlanListItem::getPath()
{
return m_wirelessNetItem.m_connDbusPath;
}
void WlanListItem::setSignalStrength(const int &signal)
{
m_wirelessNetItem.m_signalStrength = signal;
@ -467,7 +476,7 @@ void WlanListItem::onNetButtonClicked()
} else {
qDebug() << "KeyMgmt not support now " << type;
}
//qDebug() << "!!!!" << m_wirelessNetItem.m_kySecuType << kySecuType;
//有配置或者无密码的wifi直接连接
if (m_wirelessNetItem.m_isConfigured) {
if (m_wirelessNetItem.m_kySecuType == kySecuType) {
@ -512,7 +521,7 @@ void WlanListItem::updateWirelessNetSecurity(QString ssid, QString securityType)
}
qDebug() << LOG_FLAG << "Security changed! ssid = " << m_wirelessNetItem.m_NetSsid
<< "; security = " << m_wirelessNetItem.m_secuType << "." <<Q_FUNC_INFO << __LINE__;
<< "; security = " << m_wirelessNetItem.m_secuType << "change to "<< securityType <<Q_FUNC_INFO << __LINE__;
m_wirelessNetItem.m_secuType = securityType;
bool newSecu = (m_wirelessNetItem.m_secuType.isEmpty() || m_wirelessNetItem.m_secuType == "") ? false : true;
@ -521,6 +530,8 @@ void WlanListItem::updateWirelessNetSecurity(QString ssid, QString securityType)
refreshIcon(false);
}
m_wirelessNetItem.setKySecuType(securityType);
return;
}

View File

@ -61,6 +61,8 @@ public:
QString getSsid();
QString getUuid();
QString getPath();
void setSignalStrength(const int &signal);
int getSignalStrength();

View File

@ -606,12 +606,12 @@ void WlanPage::onConnectionAdd(QString deviceName, QString ssid)
return;
}
void WlanPage::onConnectionRemove(QString deviceName, QString ssid)
void WlanPage::onConnectionRemove(QString deviceName, QString ssid, QString path)
{
qDebug() << LOG_FLAG << "one connection is removed, it's ssid " << ssid << "device name"<< deviceName;
if (deviceName == m_currentDevice) {
if (m_activateConnectionItemMap.contains(ssid)) {
updateWirelessNetArea(nullptr, ssid, deviceName);
updateWirelessNetArea(nullptr, ssid, deviceName, path);
}
updateWlanListItem(ssid);
}
@ -872,7 +872,7 @@ void WlanPage::updateActivatedArea(QString uuid, QString ssid, QString devName)
return;
}
void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName)
void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName, QString path)
{
if(m_wirelessNetItemMap.contains(ssid)) {
return;
@ -889,7 +889,12 @@ void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName
qWarning() << LOG_FLAG << "p_wlanItem is null";
return;
}
if (p_wlanItem->getUuid() == uuid) {
if (p_wlanItem->getUuid() == uuid || uuid.isEmpty()) {
if (uuid.isEmpty() && p_wlanItem->getPath() != path) {
return;
}
deleteWirelessItemFormMap(m_activateConnectionItemMap, m_activatedNetListWidget, ssid);
QListWidgetItem *p_activeListWidgetItem = addEmptyItem(m_activatedNetListWidget);
m_activateConnectionItemMap.insert(EMPTY_SSID, p_activeListWidgetItem);
@ -1005,7 +1010,9 @@ void WlanPage::onConnectionStateChanged(QString uuid,
if (devName.isEmpty()) {
devName = m_currentDevice;
}
updateWirelessNetArea(uuid, ssid, devName);
updateWirelessNetArea(uuid, ssid, devName,"");
if (m_wirelessNetItemMap.contains(ssid)) {
QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid);
updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated);

View File

@ -108,7 +108,7 @@ private slots:
void onWlanRemoved(QString interface, QString ssid);
void onConnectionAdd(QString deviceName, QString ssid);
void onConnectionRemove(QString deviceName, QString ssid);
void onConnectionRemove(QString deviceName, QString ssid, QString path);
void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType);
void onDeviceRemove(QString deviceName);
@ -167,7 +167,7 @@ private:
void constructActivateConnectionArea();
void updateActivatedArea(QString uuid, QString ssid, QString devName);
void updateWirelessNetArea(QString uuid, QString ssid, QString devName);
void updateWirelessNetArea(QString uuid, QString ssid, QString devName, QString path);
void addDeviceToCombox(QString deviceName);
void deleteDeviceFromCombox(QString deviceName);