Fix bug can not trigger wifi scan after turn on wifi switch

This commit is contained in:
chenlelin 2021-06-02 11:36:53 +08:00
parent 08d5f26ac1
commit c66e13275b
6 changed files with 65 additions and 43 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
kylin-nm (3.0.1-1kylin47) v101; urgency=medium kylin-nm (3.0.1-1kylin47hw1) v101.hw; urgency=medium
* BUG号#57475 #56581 * BUG号#57475 #56581
* 需求号:无 * 需求号:无

View File

@ -83,7 +83,6 @@ void KSimpleNM::execGetWifiList(const QString& wname, const bool &isHuaweiPc)
return; return;
} }
isExecutingGetWifiList = true; isExecutingGetWifiList = true;
qDebug()<< __FUNCTION__<<__LINE__;
shellOutputWifi = ""; shellOutputWifi = "";
QString cmd; QString cmd;
//将ssid放置在最后一列以防ssid存在中文或特殊字符导致其后面的列不对齐 //将ssid放置在最后一列以防ssid存在中文或特殊字符导致其后面的列不对齐
@ -137,7 +136,6 @@ void KSimpleNM::finishedProcessWifi(int msg)
QStringList slist = shellOutputWifi.split("\n"); QStringList slist = shellOutputWifi.split("\n");
emit getWifiListFinished(slist); emit getWifiListFinished(slist);
isExecutingGetWifiList = false; isExecutingGetWifiList = false;
qDebug()<< __FUNCTION__<<__LINE__;
} }
void KSimpleNM::finishedProcessConn(int msg) void KSimpleNM::finishedProcessConn(int msg)
{ {

View File

@ -1720,7 +1720,11 @@ void KylinDBus::onAutoConnect()
{ {
//syslog(LOG_DEBUG, "Receive a auto-connect signal to reconnect wifi"); //syslog(LOG_DEBUG, "Receive a auto-connect signal to reconnect wifi");
qDebug() << Q_FUNC_INFO << "Receive a auto-connect signal to reconnect wifi"; qDebug() << Q_FUNC_INFO << "Receive a auto-connect signal to reconnect wifi";
if (!mw->isRadioWifiTurningOn) {
mw->toReconnectWifi(); mw->toReconnectWifi();
} else {
qDebug() << Q_FUNC_INFO << "but need waiting turn on wifi switch, will not reconnect wifi";
}
} }
//有线网属性变化时,执行该函数。由于可能在短时间收到几条相同属性变化信息,所以在短时间内,执行一次 //有线网属性变化时,执行该函数。由于可能在短时间收到几条相同属性变化信息,所以在短时间内,执行一次
@ -1960,7 +1964,7 @@ void KylinDBus::requestScanWifi()
QDBusConnection::systemBus() ); QDBusConnection::systemBus() );
QMap<QString, QVariant> my_map; QMap<QString, QVariant> my_map;
my_map = {}; my_map = {};
interface.call("RequestScan", my_map); //get accesspoint for each wifi interface.call("RequestScan", my_map);
} }
//显示桌面通知 //显示桌面通知

View File

@ -82,7 +82,7 @@ int main(int argc, char *argv[])
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication a(argc, argv); QApplication a(argc, argv);
qInstallMessageHandler(messageOutput); //qInstallMessageHandler(messageOutput);
openlog(LOG_IDENT, LOG_NDELAY | LOG_NOWAIT | LOG_PID, LOG_USER); openlog(LOG_IDENT, LOG_NDELAY | LOG_NOWAIT | LOG_PID, LOG_USER);
qDebug()<<"Kylin Network Manager Is Already Launched"; qDebug()<<"Kylin Network Manager Is Already Launched";

View File

@ -561,6 +561,7 @@ void MainWindow::initTimer()
numberForWifiScan = 0; numberForWifiScan = 0;
QObject::connect(this, SIGNAL(loadWifiListAfterScan()), this, SLOT(onLoadWifiListAfterScan())); QObject::connect(this, SIGNAL(loadWifiListAfterScan()), this, SLOT(onLoadWifiListAfterScan()));
QObject::connect(this, SIGNAL(refreshWifiListAfterScan()), this, SLOT(onRefreshWifiListAfterScan())); QObject::connect(this, SIGNAL(refreshWifiListAfterScan()), this, SLOT(onRefreshWifiListAfterScan()));
QObject::connect(this, SIGNAL(requestReconnecWifi()), this, SLOT(onRequestReconnecWifi()));
checkWifiListChanged = new QTimer(this); checkWifiListChanged = new QTimer(this);
checkWifiListChanged->setTimerType(Qt::PreciseTimer); checkWifiListChanged->setTimerType(Qt::PreciseTimer);
QObject::connect(checkWifiListChanged, SIGNAL(timeout()), this, SLOT(onRequestScanAccesspoint())); QObject::connect(checkWifiListChanged, SIGNAL(timeout()), this, SLOT(onRequestScanAccesspoint()));
@ -1206,6 +1207,7 @@ void MainWindow::onBtnWifiClicked(int flag)
if (is_fly_mode_on == 0) { if (is_fly_mode_on == 0) {
//on_btnWifiList_clicked(); //on_btnWifiList_clicked();
is_stop_check_net_state = 1; is_stop_check_net_state = 1;
isRadioWifiTurningOn = true;
objKyDBus->setWifiCardState(true); objKyDBus->setWifiCardState(true);
objKyDBus->setWifiSwitchState(true); objKyDBus->setWifiSwitchState(true);
@ -1225,6 +1227,7 @@ void MainWindow::onBtnWifiClicked(int flag)
if (is_fly_mode_on == 0) { if (is_fly_mode_on == 0) {
//on_btnWifiList_clicked(); //on_btnWifiList_clicked();
is_stop_check_net_state = 1; is_stop_check_net_state = 1;
isRadioWifiTurningOn = true;
lbTopWifiList->show(); lbTopWifiList->show();
btnAddNet->show(); btnAddNet->show();
@ -1336,7 +1339,6 @@ void MainWindow::on_btnWifiList_clicked()
{ {
is_stop_check_net_state = 1; is_stop_check_net_state = 1;
current_wifi_list_state = LOAD_WIFI_LIST; current_wifi_list_state = LOAD_WIFI_LIST;
qDebug()<<__FUNCTION__<< __LINE__<<current_wifi_list_state;
this->is_btnWifiList_clicked = 1; this->is_btnWifiList_clicked = 1;
this->is_btnLanList_clicked = 0; this->is_btnLanList_clicked = 0;
end_rcv_rates = 0; end_rcv_rates = 0;
@ -1372,12 +1374,14 @@ void MainWindow::on_btnWifiList_clicked()
btnWireless->setSwitchStatus(true); btnWireless->setSwitchStatus(true);
lbTopWifiList->show(); lbTopWifiList->show();
btnAddNet->show(); btnAddNet->show();
this->startLoading(); this->startLoading();
if (isHuaWeiPC) { if (isHuaWeiPC) {
QtConcurrent::run([=](){ QtConcurrent::run([=]() {
isScaningWifi = true;
objKyDBus->requestScanWifi(); //要求后台扫描AP objKyDBus->requestScanWifi(); //要求后台扫描AP
sleep(2); sleep(2);
isScaningWifi = false;
qDebug() << "scan finished, will load wifi list";
emit loadWifiListAfterScan(); emit loadWifiListAfterScan();
}); });
} else { } else {
@ -1442,8 +1446,8 @@ void MainWindow::on_btnWifiList_clicked()
void MainWindow::onLoadWifiListAfterScan() void MainWindow::onLoadWifiListAfterScan()
{ {
current_wifi_list_state = LOAD_WIFI_LIST; current_wifi_list_state = LOAD_WIFI_LIST;
qDebug()<<__FUNCTION__<< __LINE__<<current_wifi_list_state;
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); //加载wifi列表 this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); //加载wifi列表
objKyDBus->getWirelessCardName();
} }
void MainWindow::on_wifi_changed() void MainWindow::on_wifi_changed()
@ -1746,7 +1750,6 @@ void MainWindow::onRequestRevalueUpdateWifi()
{ {
is_stop_check_net_state = 1; is_stop_check_net_state = 1;
current_wifi_list_state = LOAD_WIFI_LIST; current_wifi_list_state = LOAD_WIFI_LIST;
qDebug()<<__FUNCTION__<< __LINE__<<current_wifi_list_state;
} }
// 获取wifi列表回调 // 获取wifi列表回调
@ -1776,7 +1779,6 @@ void MainWindow::getWifiListDone(QStringList slist)
//getFinalWifiList(slist); //getFinalWifiList(slist);
} }
} }
qDebug()<<__FUNCTION__<< __LINE__<<current_wifi_list_state;
if (current_wifi_list_state == RECONNECT_WIFI) { if (current_wifi_list_state == RECONNECT_WIFI) {
//qDebug()<<"======优选后的列表为======"; //qDebug()<<"======优选后的列表为======";
//foreach (QString line, slist) { //foreach (QString line, slist) {
@ -1785,12 +1787,11 @@ void MainWindow::getWifiListDone(QStringList slist)
//qDebug()<<"========================"; //qDebug()<<"========================";
QVector<structWifiProperty> targetWifiStructList = connectableWifiPriorityList(slist); QVector<structWifiProperty> targetWifiStructList = connectableWifiPriorityList(slist);
if (!targetWifiStructList.isEmpty()) { if (!targetWifiStructList.isEmpty()) {
qDebug()<< __FUNCTION__<<__LINE__<<"current_wifi_list_state="<<current_wifi_list_state<<"isReconnectingWifi="<<isReconnectingWifi;
if (!isReconnectingWifi) { if (!isReconnectingWifi) {
isReconnectingWifi = true; //保证对于连续发出的重连信号,只处理第一个 isReconnectingWifi = true; //保证对于连续发出的重连信号,只处理第一个
QtConcurrent::run([=]() { QtConcurrent::run([=]() {
int current_try_time = 0; int current_try_time = 0;
canReconnectWifiTimeInterval = false; ifCanReconnectWifiNow = false;
//若使用配置文件连接失败且还有可以回连的wifi继续尝试回连下一个 //若使用配置文件连接失败且还有可以回连的wifi继续尝试回连下一个
QStringList tried_list; QStringList tried_list;
for (current_try_time; current_try_time < targetWifiStructList.length(); current_try_time++) { for (current_try_time; current_try_time < targetWifiStructList.length(); current_try_time++) {
@ -1823,7 +1824,7 @@ void MainWindow::getWifiListDone(QStringList slist)
tried_list.append(wifiSsid); tried_list.append(wifiSsid);
} }
isReconnectingWifi = false; isReconnectingWifi = false;
timeIntervalToConnectWifi(); ifCanReconnectWifiNow = true;
current_wifi_list_state = LOAD_WIFI_LIST; current_wifi_list_state = LOAD_WIFI_LIST;
}); });
} }
@ -3484,16 +3485,31 @@ void MainWindow::disNetDone()
void MainWindow::enWifiDone() void MainWindow::enWifiDone()
{ {
if (isHuaWeiPC) {
// QtConcurrent::run([=]() {
// if (is_btnWifiList_clicked) {
// sleep(4);
// objKyDBus->requestScanWifi(); //要求后台扫描AP
// emit loadWifiListAfterScan();
// }
// });
QtConcurrent::run([=]() {
sleep(1);
isRadioWifiTurningOn = false;
qDebug()<<"debug: already turn on the switch of wifi network";
//syslog(LOG_DEBUG, "Already turn on the switch of wifi network");
});
} else {
//on_btnWifiList_clicked();
current_wifi_list_state = LOAD_WIFI_LIST; current_wifi_list_state = LOAD_WIFI_LIST;
if (is_btnWifiList_clicked) { if (is_btnWifiList_clicked) {
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC);
} else {
//on_btnWifiList_clicked();
} }
objKyDBus->getWirelessCardName(); objKyDBus->getWirelessCardName();
qDebug()<<"debug: already turn on the switch of wifi network"; qDebug()<<"debug: already turn on the switch of wifi network";
//syslog(LOG_DEBUG, "Already turn on the switch of wifi network"); //syslog(LOG_DEBUG, "Already turn on the switch of wifi network");
}
} }
void MainWindow::disWifiDone() void MainWindow::disWifiDone()
{ {
@ -3567,24 +3583,14 @@ void MainWindow::on_btnHotspotState()
//执行wifi的重新连接 //执行wifi的重新连接
void MainWindow::toReconnectWifi() void MainWindow::toReconnectWifi()
{ {
qDebug()<<__FUNCTION__<<__LINE__<<"canReconnectWifiTimeInterval="<<canReconnectWifiTimeInterval; if (ifCanReconnectWifiNow) {
if (canReconnectWifiTimeInterval) {
// canReconnectWifiTimeInterval = false;
// QTimer::singleShot(2*1000, this, SLOT(timeIntervalToConnectWifi() ));
if (isHuaWeiPC) { if (isHuaWeiPC) {
current_wifi_list_state = RECONNECT_WIFI; current_wifi_list_state = RECONNECT_WIFI;
qDebug()<<__FUNCTION__<<__LINE__<<"current_wifi_list_state="<<current_wifi_list_state;
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC);
} }
} }
} }
void MainWindow::timeIntervalToConnectWifi()
{
canReconnectWifiTimeInterval = true;
}
//处理外界对网络的连接与断开 //处理外界对网络的连接与断开
void MainWindow::onExternalConnectionChange(QString type, bool isConnUp) void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
{ {
@ -3804,7 +3810,6 @@ void MainWindow::onRequestScanAccesspoint()
if (loop_iface->wstate != 2) { if (loop_iface->wstate != 2) {
current_wifi_list_state = UPDATE_WIFI_LIST; current_wifi_list_state = UPDATE_WIFI_LIST;
qDebug()<<__FUNCTION__<< __LINE__<<current_wifi_list_state;
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); //更新wifi列表 this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); //更新wifi列表
} }
@ -3846,10 +3851,14 @@ void MainWindow::toScanWifi(bool isShow)
void MainWindow::onRefreshWifiListAfterScan() void MainWindow::onRefreshWifiListAfterScan()
{ {
current_wifi_list_state = UPDATE_WIFI_LIST; current_wifi_list_state = UPDATE_WIFI_LIST;
qDebug()<<__FUNCTION__<< __LINE__<<current_wifi_list_state;
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); //更新wifi列表 this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); //更新wifi列表
} }
void MainWindow::onRequestReconnecWifi()
{
toReconnectWifi();
}
void MainWindow::on_setNetSpeed() void MainWindow::on_setNetSpeed()
{ {
if (this->isVisible() && is_stop_check_net_state==0) { if (this->isVisible() && is_stop_check_net_state==0) {
@ -4247,9 +4256,17 @@ int MainWindow::getScreenGeometry(QString methodName)
void MainWindow::requestRefreshWifiList() void MainWindow::requestRefreshWifiList()
{ {
if (isHuaWeiPC) {
QtConcurrent::run([=](){
objKyDBus->requestScanWifi(); //要求后台扫描AP
sleep(2);
emit refreshWifiListAfterScan();
});
} else {
current_wifi_list_state = REFRESH_WIFI; current_wifi_list_state = REFRESH_WIFI;
syslog(LOG_DEBUG, "[%s++%d] state[%d]", __FUNCTION__, __LINE__, current_wifi_list_state); syslog(LOG_DEBUG, "[%s++%d] state[%d]", __FUNCTION__, __LINE__, current_wifi_list_state);
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC);
}
} }
/* get primary screen changed */ /* get primary screen changed */
@ -4331,10 +4348,10 @@ void MainWindow::rfkillEnableWifiDone()
if (is_btnWifiList_clicked) { if (is_btnWifiList_clicked) {
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC);
} else { } else {
// on_btnWifiList_clicked(); //on_btnWifiList_clicked();
} }
objKyDBus->getWirelessCardName(); objKyDBus->getWirelessCardName();
qDebug()<<"debug: already turn on the switch of wifi network"; qDebug()<<"debug: already turn on the switch of wifi network by keyboard button";
//syslog(LOG_DEBUG, "Already turn on the switch of wifi network"); //syslog(LOG_DEBUG, "Already turn on the switch of wifi network by keyboard button");
} }

View File

@ -183,10 +183,12 @@ public:
bool isToSetWifiValue = true; //本次执行是否进行赋值 bool isToSetWifiValue = true; //本次执行是否进行赋值
bool isReconnectingWifi = false; //是否正在执行wifi的回连 bool isReconnectingWifi = false; //是否正在执行wifi的回连
bool isReconnectingLan = false; //是否正在执行lan的回连 bool isReconnectingLan = false; //是否正在执行lan的回连
bool isScaningWifi = false; //是否正在进行扫描
int addNumberForWifi = 0; //短时间内收到关于wifi连接信号的次数 int addNumberForWifi = 0; //短时间内收到关于wifi连接信号的次数
bool isHuaWeiPC; bool isHuaWeiPC;
bool isHandlingWiredCableOn = false; bool isHandlingWiredCableOn = false;
bool canReconnectWifiTimeInterval = true; bool ifCanReconnectWifiNow = true;
bool isRadioWifiTurningOn = false; //是否正在打开wifi开关
QVector<QStringList> dbus_wifiList; //其他组件通过dbus接口获取到的wifi列表,第一个元素一定为已连接wifi若没有已连接wifi则显示为-- QVector<QStringList> dbus_wifiList; //其他组件通过dbus接口获取到的wifi列表,第一个元素一定为已连接wifi若没有已连接wifi则显示为--
void requestRefreshWifiList(); //申请刷新wifi列表 void requestRefreshWifiList(); //申请刷新wifi列表
@ -233,6 +235,7 @@ public slots:
void onRequestRefreshWifiList(); void onRequestRefreshWifiList();
void onRefreshWifiListAfterScan(); void onRefreshWifiListAfterScan();
void onLoadWifiListAfterScan(); void onLoadWifiListAfterScan();
void onRequestReconnecWifi();
//flag =0或1为普通点击、2为收到打开信息、3为收到关闭信息、4为无线网卡插入、5为无线网卡拔出 //flag =0或1为普通点击、2为收到打开信息、3为收到关闭信息、4为无线网卡插入、5为无线网卡拔出
void onBtnWifiClicked(int flag = 0); void onBtnWifiClicked(int flag = 0);
@ -242,7 +245,6 @@ public slots:
void checkIfConnectedWifiExist(); void checkIfConnectedWifiExist();
void toReconnectWifi(); void toReconnectWifi();
void timeIntervalToConnectWifi();
void rfkillDisableWifiDone(); void rfkillDisableWifiDone();
void rfkillEnableWifiDone(); void rfkillEnableWifiDone();
@ -424,6 +426,7 @@ signals:
void wiredConnectionAdded(); void wiredConnectionAdded();
void wiredConnectionRemoved(); void wiredConnectionRemoved();
void actWiredConnectionChanged(); void actWiredConnectionChanged();
void requestReconnecWifi();
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H