Tethering: Edit password while enabled (#21457)

* restart tethering if password is edited

* fixes

* connect straight to WifiManager

* revert
pull/21484/head
sshane 4 years ago committed by GitHub
parent 32d5239912
commit f96b3cc597
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      selfdrive/ui/qt/offroad/networking.cc
  2. 5
      selfdrive/ui/qt/offroad/networking.h
  3. 18
      selfdrive/ui/qt/offroad/wifiManager.cc
  4. 8
      selfdrive/ui/qt/offroad/wifiManager.h

@ -117,13 +117,13 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
main_layout->addWidget(back, 0, Qt::AlignLeft); main_layout->addWidget(back, 0, Qt::AlignLeft);
// Enable tethering layout // Enable tethering layout
ToggleControl *tetheringToggle = new ToggleControl("Enable Tethering", "", "", wifi->tetheringEnabled()); ToggleControl *tetheringToggle = new ToggleControl("Enable Tethering", "", "", wifi->isTetheringEnabled());
main_layout->addWidget(tetheringToggle); main_layout->addWidget(tetheringToggle);
QObject::connect(tetheringToggle, &ToggleControl::toggleFlipped, this, &AdvancedNetworking::toggleTethering); QObject::connect(tetheringToggle, &ToggleControl::toggleFlipped, this, &AdvancedNetworking::toggleTethering);
main_layout->addWidget(horizontal_line(), 0); main_layout->addWidget(horizontal_line(), 0);
// Change tethering password // Change tethering password
editPasswordButton = new ButtonControl("Tethering Password", "EDIT"); ButtonControl *editPasswordButton = new ButtonControl("Tethering Password", "EDIT");
connect(editPasswordButton, &ButtonControl::released, [=]() { connect(editPasswordButton, &ButtonControl::released, [=]() {
QString pass = InputDialog::getText("Enter new tethering password", 8, wifi->getTetheringPassword()); QString pass = InputDialog::getText("Enter new tethering password", 8, wifi->getTetheringPassword());
if (!pass.isEmpty()) { if (!pass.isEmpty()) {
@ -151,13 +151,8 @@ void AdvancedNetworking::refresh() {
update(); update();
} }
void AdvancedNetworking::toggleTethering(bool enable) { void AdvancedNetworking::toggleTethering(bool enabled) {
if (enable) { wifi->setTetheringEnabled(enabled);
wifi->enableTethering();
} else {
wifi->disableTethering();
}
editPasswordButton->setEnabled(!enable);
} }
// WifiUI functions // WifiUI functions
@ -183,7 +178,7 @@ void WifiUI::refresh() {
ssid_label->setStyleSheet("font-size: 55px;"); ssid_label->setStyleSheet("font-size: 55px;");
hlayout->addWidget(ssid_label, 1, Qt::AlignLeft); hlayout->addWidget(ssid_label, 1, Qt::AlignLeft);
if (wifi->isKnownConnection(network.ssid) && !wifi->tetheringEnabled()) { if (wifi->isKnownConnection(network.ssid) && !wifi->isTetheringEnabled()) {
QPushButton *forgetBtn = new QPushButton(); QPushButton *forgetBtn = new QPushButton();
QPixmap pix("../assets/offroad/icon_close.svg"); QPixmap pix("../assets/offroad/icon_close.svg");

@ -30,8 +30,6 @@ private:
WifiManager *wifi = nullptr; WifiManager *wifi = nullptr;
QVBoxLayout* main_layout; QVBoxLayout* main_layout;
bool tetheringEnabled;
signals: signals:
void connectToNetwork(const Network &n); void connectToNetwork(const Network &n);
@ -46,14 +44,13 @@ public:
private: private:
LabelControl* ipLabel; LabelControl* ipLabel;
ButtonControl* editPasswordButton;
WifiManager* wifi = nullptr; WifiManager* wifi = nullptr;
signals: signals:
void backPress(); void backPress();
public slots: public slots:
void toggleTethering(bool enable); void toggleTethering(bool enabled);
void refresh(); void refresh();
}; };

@ -438,18 +438,18 @@ void WifiManager::addTetheringConnection() {
nm_settings.call("AddConnection", QVariant::fromValue(connection)); nm_settings.call("AddConnection", QVariant::fromValue(connection));
} }
void WifiManager::enableTethering() { void WifiManager::setTetheringEnabled(bool enabled) {
if (enabled) {
if (!isKnownConnection(tethering_ssid)) { if (!isKnownConnection(tethering_ssid)) {
addTetheringConnection(); addTetheringConnection();
} }
activateWifiConnection(tethering_ssid.toUtf8()); activateWifiConnection(tethering_ssid);
} } else {
deactivateConnection(tethering_ssid);
void WifiManager::disableTethering() { }
deactivateConnection(tethering_ssid.toUtf8());
} }
bool WifiManager::tetheringEnabled() { bool WifiManager::isTetheringEnabled() {
if (activeAp != "" && activeAp != "/") { if (activeAp != "" && activeAp != "/") {
return get_property(activeAp, "Ssid") == tethering_ssid; return get_property(activeAp, "Ssid") == tethering_ssid;
} }
@ -480,5 +480,9 @@ void WifiManager::changeTetheringPassword(const QString &newPassword) {
Connection settings = QDBusReply<Connection>(nm.call("GetSettings")).value(); Connection settings = QDBusReply<Connection>(nm.call("GetSettings")).value();
settings["802-11-wireless-security"]["psk"] = newPassword; settings["802-11-wireless-security"]["psk"] = newPassword;
nm.call("Update", QVariant::fromValue(settings)); nm.call("Update", QVariant::fromValue(settings));
if (isTetheringEnabled()) {
activateWifiConnection(tethering_ssid);
}
} }
} }

@ -40,6 +40,7 @@ public:
void refreshNetworks(); void refreshNetworks();
void forgetConnection(const QString &ssid); void forgetConnection(const QString &ssid);
bool isKnownConnection(const QString &ssid); bool isKnownConnection(const QString &ssid);
void activateWifiConnection(const QString &ssid);
void connect(const Network &ssid); void connect(const Network &ssid);
void connect(const Network &ssid, const QString &password); void connect(const Network &ssid, const QString &password);
@ -47,12 +48,9 @@ public:
void disconnect(); void disconnect();
// Tethering functions // Tethering functions
void enableTethering(); void setTetheringEnabled(bool enabled);
void disableTethering(); bool isTetheringEnabled();
bool tetheringEnabled();
void addTetheringConnection(); void addTetheringConnection();
void activateWifiConnection(const QString &ssid);
void changeTetheringPassword(const QString &newPassword); void changeTetheringPassword(const QString &newPassword);
QString getTetheringPassword(); QString getTetheringPassword();

Loading…
Cancel
Save