Skip to content

Commit

Permalink
This is a lighter-weight version of commaai#30500 that provides only …
Browse files Browse the repository at this point in the history
…two options, instead of three.

▸ "low upload" mode (works the same as pull request commaai#30500)
▸ "default upload" mode (works the same as pull request commaai#30500)
▸ "full upload" mode: not implemented here

Without a "full upload" option, we can skip checking to see whether we are using a Comma SIM (i.e. whether the user is subscribed to full prime?)
  • Loading branch information
yuzisee committed Dec 1, 2023
1 parent 07e75c7 commit 49b895e
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 1 deletion.
1 change: 1 addition & 0 deletions common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class FileLock {

std::unordered_map<std::string, uint32_t> keys = {
{"AccessToken", CLEAR_ON_MANAGER_START | DONT_LOG},
{"AllowMeteredUploads", PERSISTENT},
{"ApiCache_Device", PERSISTENT},
{"ApiCache_NavDestinations", PERSISTENT},
{"AssistNowToken", PERSISTENT},
Expand Down
20 changes: 19 additions & 1 deletion selfdrive/athena/athenad.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ class UploadFile:
headers: Dict[str, str]
allow_cellular: bool

def upload_on_cellular_allowed_by_params(self) -> bool:
# see uploadPolicyToggle in selfdrive/ui/qt/network/networking.cc#AdvancedNetworking::AdvancedNetworking

if Params().get_bool("AllowMeteredUploads", True):
# ^^^ This is the `default upload` policy. It's believed to use an *average* of 6 GiB/mo or so...
# https://discord.com/channels/469524606043160576/819046761287909446/1161369395382202438
# https://discord.com/channels/469524606043160576/819046761287909446/1161366312686198905
# At the moment this means we fall back to the UploadFile's initial `allow_cellular` value which
# * will upload the qlogs & qcameras while the connection is metered
# * will upload everything if the connection is not metered
return self.allow_cellular
else:
# 'low upload' policy is to upload nothing until we're connected to a full connection (e.g. home Wi-Fi)
# see also https://discord.com/channels/469524606043160576/819046761287909446/1161366616920051914
return False

@classmethod
def from_dict(cls, d: dict) -> UploadFile:
return cls(d.get("fn", ""), d.get("url", ""), d.get("headers", {}), d.get("allow_cellular", False))
Expand Down Expand Up @@ -223,6 +239,8 @@ def cb(sm, item, tid, sz: int, cur: int) -> None:


def upload_handler(end_event: threading.Event) -> None:
# `log_handler` and `stats_handler` add to the queues, but don't actually upload anything themselves
# all the upload activity happens here in `upload_handler`
sm = messaging.SubMaster(['deviceState'])
tid = threading.get_ident()

Expand Down Expand Up @@ -419,7 +437,7 @@ def uploadFilesToUrls(files_data: List[UploadFileDict]) -> UploadFilesToUrlRespo
headers=file.headers,
created_at=int(time.time() * 1000),
id=None,
allow_cellular=file.allow_cellular,
allow_cellular=file.upload_on_cellular_allowed_by_params(),
)
upload_id = hashlib.sha1(str(item).encode()).hexdigest()
item = replace(item, id=upload_id)
Expand Down
1 change: 1 addition & 0 deletions selfdrive/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def manager_init() -> None:
("CompletedTrainingVersion", "0"),
("DisengageOnAccelerator", "0"),
("GsmMetered", "1"),
("AllowMeteredUploads", "1"),
("HasAcceptedTerms", "0"),
("LanguageSetting", "main_en"),
("OpenpilotEnabledToggle", "1"),
Expand Down
20 changes: 20 additions & 0 deletions selfdrive/ui/qt/network/networking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,34 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
});
list->addItem(meteredToggle);

// Upload Policy toggle
const bool upload_policy = params.getBool("AllowMeteredUploads");
uploadPolicyToggle = new ToggleControl(tr("Upload when Metered"),
tr("Allow uploads when on a metered connection "
"(such as if the cellular SIM is on a limited data plan, or "
"if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)"),
"", upload_policy);
QObject::connect(uploadPolicyToggle, &SshToggle::toggleFlipped, [=](bool state) {
params.putBool("AllowMeteredUploads", state);
});
list->addItem(uploadPolicyToggle);

// Set initial config
wifi->updateGsmSettings(roamingEnabled, QString::fromStdString(params.get("GsmApn")), metered);

connect(uiState(), &UIState::primeTypeChanged, this, [=](PrimeType prime_type) {
bool gsmVisible = prime_type == PrimeType::NONE || prime_type == PrimeType::LITE;
// gsmVisible: `true` means "Bring your own SIM", so allow whatever uploads they want
roamingToggle->setVisible(gsmVisible);
editApnButton->setVisible(gsmVisible);
meteredToggle->setVisible(gsmVisible);
// TODO(from yuzisee): It seems like there's an exploit here...
// * if I sign up for PrimeType::LITE (with my own SIM) couldn't I set roamingToggle and meteredToggle?
// ...and then, immediately after that...
// * if I upgrade to regular Comma Prime and put the Comma SIM back in wouldn't it read back the values of GsmRoaming and GsmMetered
// ...even though these toggles are disabled
//
// As far as I can tell, it doesn't look like selfdrive/athena/athenad.py checks whether the user is a Lite or Regular Prime customer.
});

main_layout->addWidget(new ScrollView(list, this));
Expand Down
1 change: 1 addition & 0 deletions selfdrive/ui/qt/network/networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class AdvancedNetworking : public QWidget {
ToggleControl* roamingToggle;
ButtonControl* editApnButton;
ToggleControl* meteredToggle;
ToggleControl* uploadPolicyToggle;
WifiManager* wifi = nullptr;
Params params;

Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<source>Prevent large data uploads when on a metered connection</source>
<translation>منع تحميل البيانات الكبيرة عندما يكون الاتصال محدوداً</translation>
</message>
<message>
<source>Upload when Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow uploads when on a metered connection (such as if the cellular SIM is on a limited data plan, or if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AnnotatedCameraWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<source>Prevent large data uploads when on a metered connection</source>
<translation>Hochladen großer Dateien über getaktete Verbindungen unterbinden</translation>
</message>
<message>
<source>Upload when Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow uploads when on a metered connection (such as if the cellular SIM is on a limited data plan, or if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AnnotatedCameraWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<source>Prevent large data uploads when on a metered connection</source>
<translation>Éviter les transferts de données importants sur une connexion limitée</translation>
</message>
<message>
<source>Upload when Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow uploads when on a metered connection (such as if the cellular SIM is on a limited data plan, or if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AnnotatedCameraWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<source>Prevent large data uploads when on a metered connection</source>
<translation>大量のデータのアップロードを防止します。</translation>
</message>
<message>
<source>Upload when Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow uploads when on a metered connection (such as if the cellular SIM is on a limited data plan, or if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AnnotatedCameraWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<source>Prevent large data uploads when on a metered connection</source>
<translation>데이터 요금제 연결 시 대용량 데이터 업로드를 방지합니다</translation>
</message>
<message>
<source>Upload when Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow uploads when on a metered connection (such as if the cellular SIM is on a limited data plan, or if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AnnotatedCameraWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<source>Prevent large data uploads when on a metered connection</source>
<translation>Evite grandes uploads de dados quando estiver em uma conexão limitada</translation>
</message>
<message>
<source>Upload when Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow uploads when on a metered connection (such as if the cellular SIM is on a limited data plan, or if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AnnotatedCameraWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_th.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<source>Prevent large data uploads when on a metered connection</source>
<translation>ปิดการอัพโหลดข้อมูลขนาดใหญ่เมื่อเชื่อมต่อผ่านเซลลูล่าร์</translation>
</message>
<message>
<source>Upload when Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow uploads when on a metered connection (such as if the cellular SIM is on a limited data plan, or if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AnnotatedCameraWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<source>Prevent large data uploads when on a metered connection</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Upload when Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow uploads when on a metered connection (such as if the cellular SIM is on a limited data plan, or if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AnnotatedCameraWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_zh-CHS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<source>Prevent large data uploads when on a metered connection</source>
<translation>当使用按流量计费的连接时,避免上传大流量数据</translation>
</message>
<message>
<source>Upload when Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow uploads when on a metered connection (such as if the cellular SIM is on a limited data plan, or if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AnnotatedCameraWidget</name>
Expand Down
8 changes: 8 additions & 0 deletions selfdrive/ui/translations/main_zh-CHT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<source>Prevent large data uploads when on a metered connection</source>
<translation>防止使用行動網路上傳大量的數據</translation>
</message>
<message>
<source>Upload when Metered</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Allow uploads when on a metered connection (such as if the cellular SIM is on a limited data plan, or if connected to a Wi-Fi hotspot that is reporting as a metered connection of its own)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>AnnotatedCameraWidget</name>
Expand Down

0 comments on commit 49b895e

Please sign in to comment.