mirror of https://github.com/commaai/openpilot.git
ui: configure tethering based on prime type (#23733)
* Store prime type in param
* set tethering metric based on prime type
* update existing connections
* returning zero is fine
* always set
* add callback on activate
* call systemctl
* match server enum
* add delay
* assume field is there
* snake case
old-commit-hash: 4e4cb07297
This commit is contained in:
parent
149925398e
commit
30a0b40b5d
|
@ -115,7 +115,6 @@ std::unordered_map<std::string, uint32_t> keys = {
|
|||
{"GsmRoaming", PERSISTENT},
|
||||
{"HardwareSerial", PERSISTENT},
|
||||
{"HasAcceptedTerms", PERSISTENT},
|
||||
{"HasPrime", PERSISTENT},
|
||||
{"IMEI", PERSISTENT},
|
||||
{"InstallDate", PERSISTENT},
|
||||
{"IsDriverViewEnabled", CLEAR_ON_MANAGER_START},
|
||||
|
@ -145,6 +144,7 @@ std::unordered_map<std::string, uint32_t> keys = {
|
|||
{"PandaSignatures", CLEAR_ON_MANAGER_START},
|
||||
{"Passive", PERSISTENT},
|
||||
{"PrimeRedirected", PERSISTENT},
|
||||
{"PrimeType", PERSISTENT},
|
||||
{"RecordFront", PERSISTENT},
|
||||
{"RecordFrontLock", PERSISTENT}, // for the internal fleet
|
||||
{"ReleaseNotes", PERSISTENT},
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#include "selfdrive/ui/qt/offroad/wifiManager.h"
|
||||
|
||||
#include "selfdrive/ui/ui.h"
|
||||
#include "selfdrive/ui/qt/widgets/prime.h"
|
||||
|
||||
#include "selfdrive/common/params.h"
|
||||
#include "selfdrive/common/swaglog.h"
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
@ -306,12 +309,13 @@ void WifiManager::initConnections() {
|
|||
}
|
||||
}
|
||||
|
||||
void WifiManager::activateWifiConnection(const QString &ssid) {
|
||||
std::optional<QDBusPendingCall> WifiManager::activateWifiConnection(const QString &ssid) {
|
||||
const QDBusObjectPath &path = getConnectionPath(ssid);
|
||||
if (!path.path().isEmpty()) {
|
||||
connecting_to_network = ssid;
|
||||
asyncCall(NM_DBUS_PATH, NM_DBUS_INTERFACE, "ActivateConnection", QVariant::fromValue(path), QVariant::fromValue(QDBusObjectPath(adapter)), QVariant::fromValue(QDBusObjectPath("/")));
|
||||
return asyncCall(NM_DBUS_PATH, NM_DBUS_INTERFACE, "ActivateConnection", QVariant::fromValue(path), QVariant::fromValue(QDBusObjectPath(adapter)), QVariant::fromValue(QDBusObjectPath("/")));
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void WifiManager::activateModemConnection(const QDBusObjectPath &path) {
|
||||
|
@ -403,12 +407,32 @@ void WifiManager::addTetheringConnection() {
|
|||
call(NM_DBUS_PATH_SETTINGS, NM_DBUS_INTERFACE_SETTINGS, "AddConnection", QVariant::fromValue(connection));
|
||||
}
|
||||
|
||||
void WifiManager::tetheringActivated(QDBusPendingCallWatcher *call) {
|
||||
int prime_type = uiState()->prime_type;
|
||||
int ipv4_forward = (prime_type == PrimeType::NONE || prime_type == PrimeType::LITE);
|
||||
|
||||
if (!ipv4_forward) {
|
||||
QTimer::singleShot(5000, this, [=] {
|
||||
qWarning() << "net.ipv4.ip_forward = 0";
|
||||
std::system("sudo sysctl net.ipv4.ip_forward=0");
|
||||
});
|
||||
}
|
||||
call->deleteLater();
|
||||
}
|
||||
|
||||
void WifiManager::setTetheringEnabled(bool enabled) {
|
||||
if (enabled) {
|
||||
if (!isKnownConnection(tethering_ssid)) {
|
||||
addTetheringConnection();
|
||||
}
|
||||
activateWifiConnection(tethering_ssid);
|
||||
|
||||
auto pending_call = activateWifiConnection(tethering_ssid);
|
||||
|
||||
if (pending_call) {
|
||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(*pending_call);
|
||||
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &WifiManager::tetheringActivated);
|
||||
}
|
||||
|
||||
} else {
|
||||
deactivateConnectionBySsid(tethering_ssid);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
void requestScan();
|
||||
void forgetConnection(const QString &ssid);
|
||||
bool isKnownConnection(const QString &ssid);
|
||||
void activateWifiConnection(const QString &ssid);
|
||||
std::optional<QDBusPendingCall> activateWifiConnection(const QString &ssid);
|
||||
NetworkType currentNetworkType();
|
||||
void updateGsmSettings(bool roaming, QString apn);
|
||||
void connect(const Network &ssid, const QString &password = {}, const QString &username = {});
|
||||
|
@ -97,4 +97,5 @@ private slots:
|
|||
void connectionRemoved(const QDBusObjectPath &path);
|
||||
void newConnection(const QDBusObjectPath &path);
|
||||
void refreshFinished(QDBusPendingCallWatcher *call);
|
||||
void tetheringActivated(QDBusPendingCallWatcher *call);
|
||||
};
|
||||
|
|
|
@ -78,7 +78,7 @@ void OnroadWindow::mousePressEvent(QMouseEvent* e) {
|
|||
void OnroadWindow::offroadTransition(bool offroad) {
|
||||
#ifdef ENABLE_MAPS
|
||||
if (!offroad) {
|
||||
if (map == nullptr && (uiState()->has_prime || !MAPBOX_TOKEN.isEmpty())) {
|
||||
if (map == nullptr && (uiState()->prime_type || !MAPBOX_TOKEN.isEmpty())) {
|
||||
MapWindow * m = new MapWindow(get_mapbox_settings());
|
||||
m->setFixedWidth(topWidget(this)->width() / 2);
|
||||
m->offroadTransition(offroad);
|
||||
|
|
|
@ -307,19 +307,19 @@ void SetupWidget::replyFinished(const QString &response, bool success) {
|
|||
}
|
||||
|
||||
QJsonObject json = doc.object();
|
||||
int prime_type = json["prime_type"].toInt();
|
||||
|
||||
if (uiState()->prime_type != prime_type) {
|
||||
uiState()->prime_type = prime_type;
|
||||
Params().put("PrimeType", std::to_string(prime_type));
|
||||
}
|
||||
|
||||
if (!json["is_paired"].toBool()) {
|
||||
mainLayout->setCurrentIndex(0);
|
||||
} else {
|
||||
popup->reject();
|
||||
|
||||
bool prime = json["prime"].toBool();
|
||||
|
||||
if (uiState()->has_prime != prime) {
|
||||
uiState()->has_prime = prime;
|
||||
Params().putBool("HasPrime", prime);
|
||||
}
|
||||
|
||||
if (prime) {
|
||||
if (prime_type) {
|
||||
mainLayout->setCurrentWidget(primeUser);
|
||||
} else {
|
||||
mainLayout->setCurrentWidget(primeAd);
|
||||
|
|
|
@ -7,6 +7,12 @@
|
|||
|
||||
#include "selfdrive/ui/qt/widgets/input.h"
|
||||
|
||||
enum PrimeType {
|
||||
NONE = 0,
|
||||
MAGENTA,
|
||||
LITE,
|
||||
};
|
||||
|
||||
// pairing QR code
|
||||
class PairingQRWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -231,7 +231,7 @@ UIState::UIState(QObject *parent) : QObject(parent) {
|
|||
|
||||
Params params;
|
||||
wide_camera = Hardware::TICI() ? params.getBool("EnableWideCamera") : false;
|
||||
has_prime = params.getBool("HasPrime");
|
||||
prime_type = std::atoi(params.get("PrimeType").c_str());
|
||||
|
||||
// update timer
|
||||
timer = new QTimer(this);
|
||||
|
|
|
@ -127,7 +127,7 @@ public:
|
|||
UIScene scene = {};
|
||||
|
||||
bool awake;
|
||||
bool has_prime = false;
|
||||
int prime_type = 0;
|
||||
|
||||
QTransform car_space_transform;
|
||||
bool wide_camera;
|
||||
|
|
Loading…
Reference in New Issue