fix(wifi): The second choice of wifi did not consider the property "category"

Description: 修复第二次选网时未考虑wifi的category属性的Bug

Log: 修复第二次选网时未考虑wifi的category属性的Bug
Bug: http://172.17.66.192/biz/bug-view-54463.html
This commit is contained in:
zhangjiaping 2021-05-17 11:34:45 +08:00
parent bcd2eb5432
commit c53c84ef1c
2 changed files with 50 additions and 43 deletions

View File

@ -1749,16 +1749,20 @@ void MainWindow::getWifiListDone(QStringList slist)
} }
if (current_wifi_list_state == RECONNECT_WIFI) { if (current_wifi_list_state == RECONNECT_WIFI) {
qDebug()<<"======优选后的列表为======";
foreach (QString line, slist) {
qDebug()<<line;
}
qDebug()<<"========================";
QVector<structWifiProperty> targetWifiStructList = connectableWifiPriorityList(slist); QVector<structWifiProperty> targetWifiStructList = connectableWifiPriorityList(slist);
if (!targetWifiStructList.isEmpty()) { if (!targetWifiStructList.isEmpty()) {
if (!isReconnectingWifi) { if (!isReconnectingWifi) {
isReconnectingWifi = true; //保证对于连续发出的重连信号,只处理第一个 isReconnectingWifi = true; //保证对于连续发出的重连信号,只处理第一个
QtConcurrent::run([=]() { QtConcurrent::run([=]() {
QString wifiSsid = objKyDBus->getWifiSsid(targetWifiStructList.at(0).objectPath); QString wifiSsid = objKyDBus->getWifiSsid(targetWifiStructList.at(0).objectPath);
QString modityCmd = "nmcli connection modify \""+ wifiSsid + "\" " + "802-11-wireless.bssid " + targetWifiStructList.at(0).bssid; QString modifyCmd = "nmcli connection modify \""+ wifiSsid + "\" " + "802-11-wireless.bssid " + targetWifiStructList.at(0).bssid;
qDebug()<<"Will modify configuration for "<<wifiSsid<<"; cmd = "<<modityCmd; int res = system(modifyCmd.toUtf8().data());
int res = system(modityCmd.toUtf8().data()); qDebug()<<"Modification finished, cmd = "<<modifyCmd<<". res = "<<res;
qDebug()<<"Modifination finished, res = "<<res;
// QString reconnectWifiCmd = "nmcli connection up \"" + wifiSsid + "\""; // QString reconnectWifiCmd = "nmcli connection up \"" + wifiSsid + "\"";
// system(reconnectWifiCmd.toUtf8().data()); // system(reconnectWifiCmd.toUtf8().data());
canReconnectWifiTimeInterval = false; canReconnectWifiTimeInterval = false;
@ -2023,7 +2027,7 @@ void MainWindow::wifiListOptimize(QStringList& slist)
if (slist.size() < 2) return ; if (slist.size() < 2) return ;
QString headLine = slist.at(0); QString headLine = slist.at(0);
int indexSignal, indexSecu, indexFreq, indexBSsid, indexName, indexPath; int indexSignal, indexSecu, indexFreq, indexBSsid, indexName, indexPath, indexCate;
headLine = headLine.trimmed(); headLine = headLine.trimmed();
bool isChineseExist = headLine.contains(QRegExp("[\\x4e00-\\x9fa5]+")); bool isChineseExist = headLine.contains(QRegExp("[\\x4e00-\\x9fa5]+"));
if (isChineseExist) { if (isChineseExist) {
@ -2032,6 +2036,7 @@ void MainWindow::wifiListOptimize(QStringList& slist)
indexFreq = headLine.indexOf("频率") + 4; indexFreq = headLine.indexOf("频率") + 4;
indexBSsid = headLine.indexOf("BSSID") + 6; indexBSsid = headLine.indexOf("BSSID") + 6;
indexPath = headLine.indexOf("DBUS-PATH"); indexPath = headLine.indexOf("DBUS-PATH");
indexCate = headLine.indexOf("CATEGORY");
indexName = headLine.lastIndexOf("SSID"); indexName = headLine.lastIndexOf("SSID");
} else { } else {
indexSignal = headLine.indexOf("SIGNAL"); indexSignal = headLine.indexOf("SIGNAL");
@ -2039,69 +2044,71 @@ void MainWindow::wifiListOptimize(QStringList& slist)
indexFreq = headLine.indexOf("FREQ"); indexFreq = headLine.indexOf("FREQ");
indexBSsid = headLine.indexOf("BSSID"); indexBSsid = headLine.indexOf("BSSID");
indexPath = headLine.indexOf("DBUS-PATH"); indexPath = headLine.indexOf("DBUS-PATH");
indexCate = headLine.indexOf("CATEGORY");
indexName = headLine.lastIndexOf("SSID"); indexName = headLine.lastIndexOf("SSID");
} }
QStringList targetList; //slist优化同名同频AP中只留信号最强 QStringList targetList; //slist优化同名同频同类别(category)AP中只留信号最强
targetList<<slist.at(0); //把第一行加进去 targetList<<slist.at(0); //把第一行加进去
hasStarWifiInfo = ""; // hasStarWifiInfo = "";
hasStarWifiName = ""; // hasStarWifiName = "";
for (int ii = 1;ii < slist.size();ii++) { for (int ii = 1;ii < slist.size();ii++) {
if ((ii+1) == slist.size()) { if ((ii+1) == slist.size()) {
break; break;
} }
QString currentWifiInfo = slist.at(ii); QString currentWifiInfo = slist.at(ii);
bool ifContinue = false; bool ifContinue = false;
bool isConnected = false;
QString conName = currentWifiInfo.mid(indexName).trimmed(); QString conName = currentWifiInfo.mid(indexName).trimmed();
int conSignal = currentWifiInfo.mid(indexSignal,3).trimmed().toInt(); // int conSignal = currentWifiInfo.mid(indexSignal,3).trimmed().toInt();
int conFreq = currentWifiInfo.mid(indexFreq,4).trimmed().toInt(); int conFreq = currentWifiInfo.mid(indexFreq,4).trimmed().toInt();
int conCate = currentWifiInfo.mid(indexCate,1).trimmed().toInt();
if ("*" == currentWifiInfo.mid(0,indexSignal).trimmed()) { if ("*" == currentWifiInfo.mid(0,indexSignal).trimmed()) {
hasStarWifiInfo = currentWifiInfo; // hasStarWifiInfo = currentWifiInfo;
hasStarWifiName = conName; // hasStarWifiName = conName;
isConnected = true;
} }
for (int jj=1;jj<slist.size();jj++) { for (int jj=1;jj<ii;jj++) {//仅与排在它前面的wifi比较即可
QString compareWifiInfo = slist.at(jj); QString compareWifiInfo = slist.at(jj);
QString name = compareWifiInfo.mid(indexName).trimmed(); QString name = compareWifiInfo.mid(indexName).trimmed();
int signal = compareWifiInfo.mid(indexSignal,3).trimmed().toInt(); // int signal = compareWifiInfo.mid(indexSignal,3).trimmed().toInt();
int freq = compareWifiInfo.mid(indexFreq,4).trimmed().toInt(); int freq = compareWifiInfo.mid(indexFreq,4).trimmed().toInt();
int category = compareWifiInfo.mid(indexCate,1).trimmed().toInt();
if (conName == name) { if (conName == name) {
if (conFreq < 5000 && freq < 5000) { if (conFreq < 5000 && freq < 5000 && conCate == category) {
if(conSignal < signal){ //若前面有同频同category的同名wifi它的信号一定比此wifi强
ifContinue = true; ifContinue = true;
break; break;
}
} }
if (conFreq >= 5000 && freq >= 5000) { if (conFreq >= 5000 && freq >= 5000 && conCate == category) {
if (conSignal < signal) { ifContinue = true;
ifContinue = true; break;
break;
}
} }
} }
} }
if (ifContinue) continue; if (ifContinue && !isConnected) continue;
targetList << currentWifiInfo; targetList << currentWifiInfo;
} }
//上面的选网方法容易把存在同名wifi的情况下把已经连接的那个wifi给去掉 // //上面的选网方法容易把存在同名wifi的情况下把已经连接的那个wifi给去掉
//在这种情况下把连接的wifi信息加回去 // //在这种情况下把连接的wifi信息加回去
int changePosition = 100000; // int changePosition = 100000;
for (int kk=1;kk<targetList.size();kk++) { // for (int kk=1;kk<targetList.size();kk++) {
QString wifiInfo = slist.at(kk); // QString wifiInfo = slist.at(kk);
QString wifiName = wifiInfo.mid(indexName).trimmed(); // QString wifiName = wifiInfo.mid(indexName).trimmed();
if (hasStarWifiName == wifiName) { // if (hasStarWifiName == wifiName) {
changePosition = kk; // changePosition = kk;
break; // break;
} // }
} // }
if (changePosition < 100000) { // if (changePosition < 100000) {
//证明确实有已经连接的wifi被去掉了 // //证明确实有已经连接的wifi被去掉了
targetList.replace(changePosition, hasStarWifiInfo); // targetList.replace(changePosition, hasStarWifiInfo);
} // }
slist = targetList; slist = targetList;
} }
@ -2206,12 +2213,12 @@ QVector<structWifiProperty> MainWindow::connectableWifiPriorityList(const QStrin
QString wifiname = line.mid(indexName).trimmed(); QString wifiname = line.mid(indexName).trimmed();
QString wifibssid = line.mid(indexBSsid, indexPath-indexBSsid).trimmed(); QString wifibssid = line.mid(indexBSsid, indexPath-indexBSsid).trimmed();
QString wifiObjectPath = line.mid(indexPath,indexCate-indexPath).trimmed(); QString wifiObjectPath = line.mid(indexPath,indexCate-indexPath).trimmed();
QString wifiAutoConnection; QString wifiAutoConnection = "no";
QString wifiPriority; QString wifiPriority;
if (ocf->isWifiConfExist(wifiname) && canReconnectWifiList.contains(wifiname)) { if (ocf->isWifiConfExist(wifiname) && canReconnectWifiList.contains(wifiname)) {
QString tmpPath = "/tmp/kylin-nm-lanprop-" + QDir::home().dirName(); QString tmpPath = "/tmp/kylin-nm-lanprop-" + QDir::home().dirName();
QString getInfoCmd = "nmcli connection show '" + wifiname + "' > " + tmpPath; QString getInfoCmd = "nmcli -f connection.autoconnect,connection.autoconnect-priority connection show '" + wifiname + "' > " + tmpPath;
Utils::m_system(getInfoCmd.toUtf8().data()); Utils::m_system(getInfoCmd.toUtf8().data());
QFile file(tmpPath); QFile file(tmpPath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {

View File

@ -351,8 +351,8 @@ private:
QString actWifiSsid = "--"; //当前连接wifi的ssid QString actWifiSsid = "--"; //当前连接wifi的ssid
QStringList actWifiBssidList; //当前连接wifi的bssid QStringList actWifiBssidList; //当前连接wifi的bssid
QString actWifiUuid = "--"; //当前连接wifi的uuid QString actWifiUuid = "--"; //当前连接wifi的uuid
QString hasStarWifiInfo; //nmcli命令获取的wifi列表中已经连接的wifi in-use熟悉会有一个* // QString hasStarWifiInfo; //nmcli命令获取的wifi列表中已经连接的wifi in-use熟悉会有一个*
QString hasStarWifiName; // QString hasStarWifiName;
bool hasWifiConnected;//当前是否有wifi连接 bool hasWifiConnected;//当前是否有wifi连接
QDBusInterface *mDbusXrandInter; QDBusInterface *mDbusXrandInter;