Merge pull request #82 from mammonsama666/0309-dev
fix(wifi): Wifi is not reconnected after setting ipv4.address
This commit is contained in:
commit
4d531586a2
|
@ -344,6 +344,14 @@ void BackThread::execConnWifi(QString connName)
|
|||
cmdConnWifi->write(cmdStr.toUtf8().data());
|
||||
}
|
||||
|
||||
void BackThread::execReconnWIfi(QString uuid)
|
||||
{
|
||||
QString cmd = "nmcli connection down " + uuid;
|
||||
Utils::m_system(cmd.toUtf8().data());
|
||||
cmd = "nmcli connection up " + uuid;
|
||||
Utils::m_system(cmd.toUtf8().data());
|
||||
}
|
||||
|
||||
void BackThread::onReadOutputWifi()
|
||||
{
|
||||
QString str = cmdConnWifi->readAllStandardOutput();
|
||||
|
|
|
@ -60,6 +60,7 @@ public slots:
|
|||
void execDisWifi();
|
||||
void execConnLan(QString connName, QString ifname, QString connectType);
|
||||
void execConnWifi(QString connName);
|
||||
void execReconnWIfi(QString uuid);
|
||||
void execConnWifiPWD(QString connName, QString password, QString connType);
|
||||
void execConnWifiPsk(QString cmd);
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ KylinDBus::KylinDBus(MainWindow *mainWindow, QObject *parent) :QObject(parent)
|
|||
if (mw) {
|
||||
QObject::connect(this, SIGNAL(updateWiredList(int)), mw, SLOT(onBtnNetListClicked(int)));
|
||||
QObject::connect(this, SIGNAL(newConnAdded(int)), mw, SLOT(onNewConnAdded(int)));
|
||||
QObject::connect(this, SIGNAL(updateWirelessList()), mw, SLOT(on_btnWifiList_clicked()));
|
||||
}
|
||||
|
||||
mUtils = new Utils();
|
||||
|
@ -386,6 +387,61 @@ void KylinDBus::getLanIpDNS(QString uuidName, bool isActNet)
|
|||
} //end foreach (QDBusObjectPath objNet, m_objNets)
|
||||
}
|
||||
|
||||
void KylinDBus::getWifiIp(QString uuid)
|
||||
{
|
||||
QDBusInterface m_interface("org.freedesktop.NetworkManager",
|
||||
"/org/freedesktop/NetworkManager/Settings",
|
||||
"org.freedesktop.NetworkManager.Settings",
|
||||
QDBusConnection::systemBus() );
|
||||
QDBusReply<QList<QDBusObjectPath>> m_reply = m_interface.call("ListConnections");
|
||||
|
||||
QList<QDBusObjectPath> m_objNets = m_reply.value();
|
||||
foreach (QDBusObjectPath objNet, m_objNets) {
|
||||
QDBusInterface m_interface("org.freedesktop.NetworkManager",
|
||||
objNet.path(),
|
||||
"org.freedesktop.NetworkManager.Settings.Connection",
|
||||
QDBusConnection::systemBus());
|
||||
QDBusMessage result = m_interface.call("GetSettings");
|
||||
|
||||
const QDBusArgument &dbusArg1st = result.arguments().at( 0 ).value<QDBusArgument>();
|
||||
QMap<QString,QMap<QString,QVariant>> map;
|
||||
dbusArg1st >> map;
|
||||
|
||||
for (QString outside_key : map.keys() ) {
|
||||
QMap<QString,QVariant> outsideMap = map.value(outside_key);
|
||||
if (outside_key == "connection") {
|
||||
for (QString search_key : outsideMap.keys()) {
|
||||
if (search_key == "uuid") {
|
||||
if (uuid == outsideMap.value(search_key).toString()) {
|
||||
for (QString key : map.keys() ) {
|
||||
QMap<QString,QVariant> innerMap = map.value(key);
|
||||
if (key == "ipv4") {
|
||||
for (QString inner_key : innerMap.keys()) {
|
||||
if (inner_key == "address-data") {
|
||||
const QDBusArgument &dbusArg2nd = innerMap.value(inner_key).value<QDBusArgument>();
|
||||
QMap<QString,QVariant> m_map;
|
||||
dbusArg2nd.beginArray();
|
||||
while (!dbusArg2nd.atEnd()) {
|
||||
dbusArg2nd >> m_map;
|
||||
}
|
||||
dbusArg2nd.endArray();
|
||||
dbusWifiIpv4 = m_map.value("address").toString();
|
||||
} else if (inner_key == "method") {
|
||||
dbusWifiIpv4Method = innerMap.value(inner_key).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取有线网络的MAC
|
||||
QString KylinDBus::getLanMAC(QString ifname)
|
||||
{
|
||||
|
@ -433,6 +489,9 @@ QString KylinDBus::getLanMAC(QString ifname)
|
|||
//获取已经连接的有线网ip
|
||||
void KylinDBus::getConnectNetIp(QString netUuid)
|
||||
{
|
||||
dbusWifiIpv4 = "";
|
||||
dbusActiveWifiIpv4 = "";
|
||||
dbusWifiIpv4Method = "";
|
||||
QDBusInterface interface( "org.freedesktop.NetworkManager",
|
||||
"/org/freedesktop/NetworkManager",
|
||||
"org.freedesktop.DBus.Properties",
|
||||
|
@ -458,7 +517,7 @@ void KylinDBus::getConnectNetIp(QString netUuid)
|
|||
|
||||
QDBusReply<QVariant> replyType = interfacePro.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Type");
|
||||
QDBusReply<QVariant> replyUuid = interfacePro.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Uuid");
|
||||
if (replyType.value().toString() == "ethernet" || replyType.value().toString() == "802-3-ethernet") {
|
||||
if (replyType.value().toString() == "ethernet" || replyType.value().toString() == "802-3-ethernet") { //有线网
|
||||
if (replyUuid.value().toString() == netUuid) {
|
||||
//ipv4的路径信息和ip信息
|
||||
QDBusInterface interfaceIp4( "org.freedesktop.NetworkManager",
|
||||
|
@ -523,6 +582,39 @@ void KylinDBus::getConnectNetIp(QString netUuid)
|
|||
}
|
||||
}
|
||||
|
||||
} else { //无线网
|
||||
if (replyUuid.value().toString() == netUuid) {
|
||||
//ipv4的路径信息和ip信息
|
||||
QDBusInterface interfaceIp4( "org.freedesktop.NetworkManager",
|
||||
objPath.path(),
|
||||
"org.freedesktop.DBus.Properties",
|
||||
QDBusConnection::systemBus() );
|
||||
QDBusMessage replyIp4 = interfaceIp4.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Ip4Config");
|
||||
QList<QVariant> outArgsIp4 = replyIp4.arguments();
|
||||
QVariant firstIp4 = outArgsIp4.at(0);
|
||||
QDBusVariant dbvFirstIp4 = firstIp4.value<QDBusVariant>();
|
||||
QVariant vFirstIp4 = dbvFirstIp4.variant();
|
||||
QDBusObjectPath dbusPathIp4 = vFirstIp4.value<QDBusObjectPath>();
|
||||
|
||||
QDBusInterface interfaceIpv4( "org.freedesktop.NetworkManager",
|
||||
dbusPathIp4.path(),
|
||||
"org.freedesktop.DBus.Properties",
|
||||
QDBusConnection::systemBus() );
|
||||
QDBusMessage replyIpv4 = interfaceIpv4.call("Get", "org.freedesktop.NetworkManager.IP4Config", "AddressData");
|
||||
|
||||
QList<QVariant> outArgsIpv4 = replyIpv4.arguments();
|
||||
QVariant firstIpv4 = outArgsIpv4.at(0);
|
||||
QDBusVariant dbvFirstIpv4 = firstIpv4.value<QDBusVariant>();
|
||||
QVariant vFirstIpv4 = dbvFirstIpv4.variant();
|
||||
|
||||
const QDBusArgument &dbusArgIpv4 = vFirstIpv4.value<QDBusArgument>();
|
||||
QList<QVariantMap> mDatasIpv4;
|
||||
dbusArgIpv4 >> mDatasIpv4;
|
||||
|
||||
foreach (QVariantMap mDataIpv4, mDatasIpv4) {
|
||||
dbusActiveWifiIpv4 = mDataIpv4.value("address").toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dbusArgs.endArray();
|
||||
|
@ -555,7 +647,12 @@ void KylinDBus::getLanIpChanged()
|
|||
QDBusConnection::systemBus().connect(QString("org.freedesktop.NetworkManager"),
|
||||
objNet.path(),
|
||||
QString("org.freedesktop.NetworkManager.Settings.Connection"),
|
||||
QString("Updated"), this, SLOT(onIpPropertiesChanged() ) );
|
||||
QString("Updated"), this, SLOT(onLanIpPropertiesChanged() ) );
|
||||
} else if (key == "802-11-wireless") {
|
||||
QDBusConnection::systemBus().connect(QString("org.freedesktop.NetworkManager"),
|
||||
objNet.path(),
|
||||
QString("org.freedesktop.NetworkManager.Settings.Connection"),
|
||||
QString("Updated"), this, SLOT(onWifiIpPropertiesChanged() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -890,7 +987,7 @@ void KylinDBus::onWiredSettingNumChanged()
|
|||
QDBusConnection::systemBus().disconnect(QString("org.freedesktop.NetworkManager"),
|
||||
objSettingPath.path(),
|
||||
QString("org.freedesktop.NetworkManager.Settings.Connection"),
|
||||
QString("Updated"), this, SLOT(onIpPropertiesChanged() ) );
|
||||
QString("Updated"), this, SLOT(onLanIpPropertiesChanged() ) );
|
||||
}
|
||||
|
||||
//再建立新的信号槽连接
|
||||
|
@ -986,6 +1083,48 @@ QList<QString> KylinDBus::getAtiveLanSsidUuidState()
|
|||
return strSsidUuidState;
|
||||
}
|
||||
|
||||
//获取已连接wifi的uuid
|
||||
QString KylinDBus::getActiveWifiUuid()
|
||||
{
|
||||
QString ssid;
|
||||
|
||||
QDBusInterface interface( "org.freedesktop.NetworkManager",
|
||||
"/org/freedesktop/NetworkManager",
|
||||
"org.freedesktop.DBus.Properties",
|
||||
QDBusConnection::systemBus() );
|
||||
//获取已经连接了那些网络,及这些网络对应的网络类型(ethernet or wifi)
|
||||
QDBusMessage result = interface.call("Get", "org.freedesktop.NetworkManager", "ActiveConnections");
|
||||
QList<QVariant> outArgs = result.arguments();
|
||||
QVariant first = outArgs.at(0);
|
||||
QDBusVariant dbvFirst = first.value<QDBusVariant>();
|
||||
QVariant vFirst = dbvFirst.variant();
|
||||
QDBusArgument dbusArgs = vFirst.value<QDBusArgument>();
|
||||
|
||||
QDBusObjectPath objPath;
|
||||
dbusArgs.beginArray();
|
||||
while (!dbusArgs.atEnd()) {
|
||||
dbusArgs >> objPath;
|
||||
|
||||
QDBusInterface interfaceType( "org.freedesktop.NetworkManager",
|
||||
objPath.path(),
|
||||
"org.freedesktop.DBus.Properties",
|
||||
QDBusConnection::systemBus() );
|
||||
QDBusReply<QVariant> reply = interfaceType.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Type");
|
||||
|
||||
if (reply.value().toString() == "wifi" || reply.value().toString() == "802-11-wireless") {
|
||||
QDBusInterface interfaceInfo( "org.freedesktop.NetworkManager",
|
||||
objPath.path(),
|
||||
"org.freedesktop.DBus.Properties",
|
||||
QDBusConnection::systemBus() );
|
||||
QDBusReply<QVariant> replyUuid = interfaceInfo.call("Get", "org.freedesktop.NetworkManager.Connection.Active", "Uuid");
|
||||
ssid = replyUuid.value().toString();
|
||||
}
|
||||
}
|
||||
dbusArgs.endArray();
|
||||
|
||||
return ssid;
|
||||
}
|
||||
|
||||
//检查wifi连接状态
|
||||
int KylinDBus::checkWifiConnectivity()
|
||||
{
|
||||
|
@ -1379,11 +1518,15 @@ void KylinDBus::slot_timeout()
|
|||
}
|
||||
|
||||
//有线网的Ip属性变化时的响应函数
|
||||
void KylinDBus::onIpPropertiesChanged()
|
||||
void KylinDBus::onLanIpPropertiesChanged()
|
||||
{
|
||||
emit this->updateWiredList(0);
|
||||
}
|
||||
|
||||
//无线网的Ip属性变化时的响应函数
|
||||
void KylinDBus::onWifiIpPropertiesChanged() {
|
||||
emit this->updateWirelessList();
|
||||
}
|
||||
//利用dbus的方法对已经连接的有线网进行再次连接
|
||||
void KylinDBus::reConnectWiredNet(QString netUuid)
|
||||
{
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
void showDesktopNotify(QString message);
|
||||
void initConnectionInfo();
|
||||
QList<QString> getAtiveLanSsidUuidState();
|
||||
QString getActiveWifiUuid();
|
||||
QList<QString> getAtiveWifiBSsidUuid(QStringList wifilist);
|
||||
void reConnectWiredNet(QString netUuid);
|
||||
bool toConnectWiredNet(QString netUuid, QString netIfName);
|
||||
|
@ -89,8 +90,11 @@ public:
|
|||
QString dbusLanIpv4 = "";
|
||||
QString dbusLanIpv6 = "";
|
||||
QString dbusLanIpv6Method = "";
|
||||
QString dbusWifiIpv4Method = "";
|
||||
QString dbusActiveLanIpv4 = "";
|
||||
QString dbusActiveLanIpv6 = "";
|
||||
QString dbusActiveWifiIpv4 = "";
|
||||
QString dbusWifiIpv4 = "";
|
||||
QString dbusLanGateway = "";
|
||||
QString dbusWiFiCardName = "";
|
||||
QString dbusWifiMac = "";
|
||||
|
@ -106,12 +110,14 @@ public slots:
|
|||
QString getConnLanNameByIfname(QString ifname);
|
||||
void onPropertiesChanged(QVariantMap qvm);
|
||||
void onLanPropertyChanged(QVariantMap qvm);
|
||||
void onIpPropertiesChanged();
|
||||
void onLanIpPropertiesChanged();
|
||||
void onWifiIpPropertiesChanged();
|
||||
void getPhysicalCarrierState(int n);
|
||||
void getLanHwAddressState();
|
||||
void getWiredCardName();
|
||||
void getWirelessCardName();
|
||||
void getLanIpDNS(QString uuidName, bool isActNet);
|
||||
void getWifiIp(QString uuid);
|
||||
QString getLanMAC(QString ifname);
|
||||
void getWifiMac(QString netName);
|
||||
void slot_timeout();
|
||||
|
@ -135,6 +141,7 @@ private:
|
|||
|
||||
signals:
|
||||
void updateWiredList(int n);
|
||||
void updateWirelessList();
|
||||
void requestSendDesktopNotify(QString message);
|
||||
void newConnAdded(int type);
|
||||
void toGetWifiListFinished(QStringList slist);
|
||||
|
|
|
@ -364,7 +364,7 @@ void kylin_network_set_automethod(char *con_name)
|
|||
{
|
||||
char str[256];
|
||||
char *automethod="auto";
|
||||
sprintf(str,"nmcli connection modify '%s' ipv4.method %s",con_name,automethod);
|
||||
sprintf(str,"nmcli connection modify '%s' ipv4.method %s ipv4.address '' ipv4.gateway ''",con_name,automethod);
|
||||
int status = system(str);
|
||||
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection modify' in function 'kylin_network_set_automethod' failed");}
|
||||
}
|
||||
|
|
|
@ -1641,6 +1641,22 @@ void MainWindow::getWifiListDone(QStringList slist)
|
|||
return;
|
||||
}
|
||||
|
||||
QString actWifiUuid = objKyDBus->getActiveWifiUuid();
|
||||
objKyDBus->getConnectNetIp(actWifiUuid);
|
||||
objKyDBus->getWifiIp(actWifiUuid);
|
||||
if (oldWifiIpv4Method == "") {
|
||||
oldWifiIpv4Method = objKyDBus-> dbusWifiIpv4Method;
|
||||
}
|
||||
if (objKyDBus->dbusWifiIpv4 != "" && objKyDBus->dbusActiveWifiIpv4 != "" && objKyDBus->dbusWifiIpv4 != objKyDBus->dbusActiveWifiIpv4 &&objKyDBus-> dbusWifiIpv4Method == "manual") {
|
||||
//在第三方nm-connection-editor进行新的IP配置后,重新连接网络
|
||||
oldWifiIpv4Method = "manual";
|
||||
qDebug()<<"Ipv4.address of current activated wifi is:"<<objKyDBus->dbusActiveWifiIpv4 << ". Real ipv4.address is:" << objKyDBus->dbusWifiIpv4;
|
||||
emit this->reConnectWifi(actWifiUuid);
|
||||
} else if (objKyDBus-> dbusWifiIpv4Method == "auto" && oldWifiIpv4Method == "manual") {
|
||||
oldWifiIpv4Method = "auto";
|
||||
qDebug()<<"Ipv4.method is set to auto.";
|
||||
emit this->reConnectWifi(actWifiUuid);
|
||||
}
|
||||
//qDebug()<<"debug: oldWifiSlist.size()="<<oldWifiSlist.size()<<" slist.size()="<<slist.size();
|
||||
|
||||
//qDebug()<<"------------";
|
||||
|
@ -2899,7 +2915,10 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp)
|
|||
qDebug()<<"debug: connect wifi failed just now, no need to refresh wifi interface";
|
||||
is_connect_net_failed = 0;
|
||||
is_stop_check_net_state = 0;
|
||||
} else {
|
||||
} else if (is_wifi_reconnected) {
|
||||
qDebug()<<"debug: wifi reconnected just now, no need to refresh wifi interface";
|
||||
is_wifi_reconnected = 0;
|
||||
}else {
|
||||
isToSetWifiValue = false;
|
||||
QTimer::singleShot(4*1000, this, SLOT(onExternalWifiChange() ));
|
||||
}
|
||||
|
|
|
@ -166,12 +166,14 @@ public:
|
|||
int is_keep_wifi_turn_on_state = 1; //是否要执行wifi开关变为打开样式
|
||||
int is_stop_check_net_state = 0; //是否要在进行其他操作时停止检查网络状态
|
||||
int is_connect_net_failed = 0; //刚才是否连接网络失败
|
||||
int is_wifi_reconnected = 0;//刚才是否主动重连wifi导致wifi断开
|
||||
int is_fly_mode_on = 0; //是否已经打开飞行模式
|
||||
int is_hot_sopt_on = 0; //是否已经打开热点
|
||||
int is_connect_hide_wifi = 0; //是否正在连接隐藏wifi
|
||||
|
||||
QString currSelNetName = ""; //当前ScrollArea中选中的网络名称
|
||||
QString currConnIfname = ""; //当前连接的有线网对应网卡名称,只有一个有线网连接的情况
|
||||
QString oldWifiIpv4Method = ""; //原来的wifi的ipv4地址获取方式,自动还是手动
|
||||
int currSelNetNum = 0; //当前选中的item序号
|
||||
bool isLanBeConnUp = false; //lan是否连接上
|
||||
bool isWifiBeConnUp = false; //wifi是否是连接上
|
||||
|
@ -369,6 +371,7 @@ signals:
|
|||
|
||||
void waitWifiStop();
|
||||
void waitLanStop();
|
||||
void reConnectWifi(const QString& uuid);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -142,6 +142,19 @@ OneConnForm::OneConnForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf
|
|||
connect(waitTimer, SIGNAL(timeout()), this, SLOT(waitAnimStep()));
|
||||
|
||||
connect(mw, SIGNAL(waitWifiStop()), this, SLOT(stopWaiting()));
|
||||
connect(mw, &MainWindow::reConnectWifi, this, [ = ](const QString& uuid) {
|
||||
if (isActive) {
|
||||
QThread *t = new QThread();
|
||||
BackThread *bt = new BackThread();
|
||||
bt->moveToThread(t);
|
||||
connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
|
||||
connect(t, &QThread::started, bt, [ = ]() {
|
||||
mw->is_wifi_reconnected = 1;
|
||||
bt->execReconnWIfi(uuid);
|
||||
});
|
||||
t->start();
|
||||
}
|
||||
});
|
||||
|
||||
connType = "";
|
||||
lbNameLyt = new QHBoxLayout(ui->lbName);
|
||||
|
|
Loading…
Reference in New Issue