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

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

@ -438,18 +438,18 @@ void WifiManager::addTetheringConnection() {
nm_settings.call("AddConnection", QVariant::fromValue(connection));
}
void WifiManager::enableTethering() {
if (!isKnownConnection(tethering_ssid)) {
addTetheringConnection();
void WifiManager::setTetheringEnabled(bool enabled) {
if (enabled) {
if (!isKnownConnection(tethering_ssid)) {
addTetheringConnection();
}
activateWifiConnection(tethering_ssid);
} else {
deactivateConnection(tethering_ssid);
}
activateWifiConnection(tethering_ssid.toUtf8());
}
void WifiManager::disableTethering() {
deactivateConnection(tethering_ssid.toUtf8());
}
bool WifiManager::tetheringEnabled() {
bool WifiManager::isTetheringEnabled() {
if (activeAp != "" && activeAp != "/") {
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();
settings["802-11-wireless-security"]["psk"] = newPassword;
nm.call("Update", QVariant::fromValue(settings));
if (isTetheringEnabled()) {
activateWifiConnection(tethering_ssid);
}
}
}

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

Loading…
Cancel
Save