networking: add unmetered cellular toggle (#25902)

* add metered toggle to UI

* add GsmMetered param

* add NMMetered constants

* change LTE connection settings: connection.metered

* change to GsmUnmetered override

* update translations

* debug ui

* remove comment

* Revert "debug ui"

This reverts commit 2ad9e65ea229b814782be9f30cc7664125d7e908.

* 'Force Unmetered Cellular' toggle

* update translations

* remove description

* update translations

* change unmetered to metered
old-commit-hash: f6119603912efa4fe28f5da21f3d57f6903a0c77
This commit is contained in:
Cameron Clough
2022-10-01 14:47:06 -07:00
committed by GitHub
parent f7a315e995
commit 597b949813
12 changed files with 72 additions and 8 deletions
+1
View File
@@ -118,6 +118,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"GithubUsername", PERSISTENT},
{"GitRemote", PERSISTENT},
{"GsmApn", PERSISTENT},
{"GsmMetered", PERSISTENT},
{"GsmRoaming", PERSISTENT},
{"HardwareSerial", PERSISTENT},
{"HasAcceptedTerms", PERSISTENT},
+1 -1
View File
@@ -53,8 +53,8 @@ class MockParams():
default_params = {
"DongleId": b"0000000000000000",
"GithubSshKeys": b"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC307aE+nuHzTAgaJhzSf5v7ZZQW9gaperjhCmyPyl4PzY7T1mDGenTlVTN7yoVFZ9UfO9oMQqo0n1OwDIiqbIFxqnhrHU0cYfj88rI85m5BEKlNu5RdaVTj1tcbaPpQc5kZEolaI1nDDjzV0lwS7jo5VYDHseiJHlik3HH1SgtdtsuamGR2T80q1SyW+5rHoMOJG73IH2553NnWuikKiuikGHUYBd00K1ilVAK2xSiMWJp55tQfZ0ecr9QjEsJ+J/efL4HqGNXhffxvypCXvbUYAFSddOwXUPo5BTKevpxMtH+2YrkpSjocWA04VnTYFiPG6U4ItKmbLOTFZtPzoez private", # noqa: E501
"GsmMetered": True,
"AthenadUploadQueue": '[]',
"CellularUnmetered": False,
}
params = default_params.copy()
+1
View File
@@ -39,6 +39,7 @@ def manager_init() -> None:
default_params: List[Tuple[str, Union[str, bytes]]] = [
("CompletedTrainingVersion", "0"),
("DisengageOnAccelerator", "1"),
("GsmMetered", "1"),
("HasAcceptedTerms", "0"),
("LanguageSetting", "main_en"),
("OpenpilotEnabledToggle", "1"),
+13 -5
View File
@@ -151,16 +151,15 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
// Roaming toggle
const bool roamingEnabled = params.getBool("GsmRoaming");
ToggleControl *roamingToggle = new ToggleControl(tr("Enable Roaming"), "", "", roamingEnabled);
QObject::connect(roamingToggle, &SshToggle::toggleFlipped, [=](bool state) {
QObject::connect(roamingToggle, &ToggleControl::toggleFlipped, [=](bool state) {
params.putBool("GsmRoaming", state);
wifi->updateGsmSettings(state, QString::fromStdString(params.get("GsmApn")));
wifi->updateGsmSettings(state, QString::fromStdString(params.get("GsmApn")), params.getBool("GsmMetered"));
});
list->addItem(roamingToggle);
// APN settings
ButtonControl *editApnButton = new ButtonControl(tr("APN Setting"), tr("EDIT"));
connect(editApnButton, &ButtonControl::clicked, [=]() {
const bool roamingEnabled = params.getBool("GsmRoaming");
const QString cur_apn = QString::fromStdString(params.get("GsmApn"));
QString apn = InputDialog::getText(tr("Enter APN"), this, tr("leave blank for automatic configuration"), false, -1, cur_apn).trimmed();
@@ -169,12 +168,21 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
} else {
params.put("GsmApn", apn.toStdString());
}
wifi->updateGsmSettings(roamingEnabled, apn);
wifi->updateGsmSettings(params.getBool("GsmRoaming"), apn, params.getBool("GsmMetered"));
});
list->addItem(editApnButton);
// Metered toggle
const bool metered = params.getBool("GsmMetered");
ToggleControl *meteredToggle = new ToggleControl(tr("Cellular Metered"), tr("Prevent large data uploads when on a metered connection"), "", metered);
QObject::connect(meteredToggle, &SshToggle::toggleFlipped, [=](bool state) {
params.putBool("GsmMetered", state);
wifi->updateGsmSettings(params.getBool("GsmRoaming"), QString::fromStdString(params.get("GsmApn")), state);
});
list->addItem(meteredToggle);
// Set initial config
wifi->updateGsmSettings(roamingEnabled, QString::fromStdString(params.get("GsmApn")));
wifi->updateGsmSettings(roamingEnabled, QString::fromStdString(params.get("GsmApn")), metered);
main_layout->addWidget(new ScrollView(list, this));
main_layout->addStretch(1);
+7
View File
@@ -36,3 +36,10 @@ const int NM_DEVICE_TYPE_WIFI = 2;
const int NM_DEVICE_TYPE_MODEM = 8;
const int NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT = 8;
const int DBUS_TIMEOUT = 100;
// https://developer-old.gnome.org/NetworkManager/1.26/nm-dbus-types.html#NMMetered
const int NM_METERED_UNKNOWN = 0;
const int NM_METERED_YES = 1;
const int NM_METERED_NO = 2;
const int NM_METERED_GUESS_YES = 3;
const int NM_METERED_GUESS_NO = 4;
+8 -1
View File
@@ -345,7 +345,7 @@ NetworkType WifiManager::currentNetworkType() {
return NetworkType::NONE;
}
void WifiManager::updateGsmSettings(bool roaming, QString apn) {
void WifiManager::updateGsmSettings(bool roaming, QString apn, bool metered) {
if (!lteConnectionPath.path().isEmpty()) {
bool changes = false;
bool auto_config = apn.isEmpty();
@@ -368,6 +368,13 @@ void WifiManager::updateGsmSettings(bool roaming, QString apn) {
changes = true;
}
int meteredInt = metered ? NM_METERED_NO : NM_METERED_UNKNOWN;
if (settings.value("connection").value("metered").toInt() != meteredInt) {
qWarning() << "Changing connection.metered to" << meteredInt;
settings["connection"]["metered"] = meteredInt;
changes = true;
}
if (changes) {
call(lteConnectionPath.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, "UpdateUnsaved", QVariant::fromValue(settings)); // update is temporary
deactivateConnection(lteConnectionPath);
+1 -1
View File
@@ -50,7 +50,7 @@ public:
bool isKnownConnection(const QString &ssid);
std::optional<QDBusPendingCall> activateWifiConnection(const QString &ssid);
NetworkType currentNetworkType();
void updateGsmSettings(bool roaming, QString apn);
void updateGsmSettings(bool roaming, QString apn, bool metered);
void connect(const Network &ssid, const QString &password = {}, const QString &username = {});
// Tethering functions
+8
View File
@@ -58,6 +58,14 @@
<source>leave blank for automatic configuration</source>
<translation></translation>
</message>
<message>
<source>Cellular Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Prevent large data uploads when on a metered connection</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ConfirmationDialog</name>
+8
View File
@@ -58,6 +58,14 @@
<source>leave blank for automatic configuration</source>
<translation> </translation>
</message>
<message>
<source>Cellular Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Prevent large data uploads when on a metered connection</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ConfirmationDialog</name>
+8
View File
@@ -58,6 +58,14 @@
<source>leave blank for automatic configuration</source>
<translation>deixe em branco para configuração automática</translation>
</message>
<message>
<source>Cellular Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Prevent large data uploads when on a metered connection</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ConfirmationDialog</name>
+8
View File
@@ -58,6 +58,14 @@
<source>leave blank for automatic configuration</source>
<translation></translation>
</message>
<message>
<source>Cellular Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Prevent large data uploads when on a metered connection</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ConfirmationDialog</name>
+8
View File
@@ -58,6 +58,14 @@
<source>leave blank for automatic configuration</source>
<translation></translation>
</message>
<message>
<source>Cellular Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Prevent large data uploads when on a metered connection</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ConfirmationDialog</name>