fix(ui-lvgl): no USB drive behind the screen PIN; drop the NVS PIN migration

The SD card (message history) could be lent to a computer from the lock
card before the PIN was entered. While locked with a PIN, usbPoll() no
longer reacts; a cable plugged in meanwhile is offered once unlocked.

The plain-text NVS PIN never shipped, so there's nothing to migrate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-09-29 00:13:33 +02:00
co-authored by Claude Opus 5.5
parent 4bda4f3a76
commit e28b5c5c51
3 changed files with 4 additions and 16 deletions
@@ -680,7 +680,6 @@ static int getU8(const char* ns, const char* key, int def) { return getInt(ns,
static void putU8(const char* ns, const char* key, int v) { putInt(ns, key, v); }
static void getStr(const char* ns, const char* key, char* out, size_t n) { Kv* k = find(ns, key, false); snprintf(out, n, "%s", k ? k->val : ""); }
static void putStr(const char* ns, const char* key, const char* v) { if (Kv* k = find(ns, key, true)) snprintf(k->val, sizeof(k->val), "%s", v); }
static void remove(const char* ns, const char* key) { if (Kv* k = find(ns, key, false)) k->val[0] = '\0'; }
} // namespace nvs
static bool s_swallow = false;
@@ -849,12 +848,6 @@ static bool vectorOn() { return nvs::getBool("mc_ui", "vector", false); }
static void setVectorOn(bool on) { nvs::putBool("mc_ui", "vector", on); }
// Screen-lock PIN (Settings > Display & power > Screen PIN): digits, "" = none.
// The screen PIN as older builds kept it (plain text): read once and removed;
// it lives hashed in NodePrefs now (ui-core/ScreenLock.h).
static void takeOldPin(char* out, size_t n) {
nvs::getStr("mc_lock", "pin", out, n);
if (out[0]) nvs::remove("mc_lock", "pin");
}
// Accent colour (Settings > Display & power): an index into theme::ACCENTS.
static int loadAccent() { return nvs::getU8("mc_ui", "accent", 0); }
@@ -482,6 +482,9 @@ void UITask::usbPoll() {
restartScreen("The computer has given the SD card back.");
return;
}
// Behind a screen PIN the card (message history) isn't offered: a cable
// plugged in while locked is noticed once the PIN is entered.
if (locked() && pinSet()) return;
bool host = lvport::usbHost();
if (host == s_host) return;
s_host = host;
@@ -499,7 +502,7 @@ void UITask::usbPoll() {
void UITask::usbTap(bool drive) {
using namespace usbview;
if (s_overlay) { lv_obj_delete_async(s_overlay); s_overlay = nullptr; }
if (!drive) return;
if (!drive || (locked() && pinSet())) return;
storeview::stopWalk();
if (mapview::s_dl.active()) mapDownloadStop();
if (!lvport::usbDriveStart()) { showToast("No SD card to share", 3000); return; }
@@ -898,14 +898,6 @@ void UITask::begin(DisplayDriver* display_drv, SensorManager* sensors, NodePrefs
buildStatusBar();
applyDisplayPrefs(); // a slider percentage overrides the level main.cpp set
showHome();
// Before the PIN moved into NodePrefs it was kept in NVS in plain text.
char old_pin[9];
lvport::takeOldPin(old_pin, sizeof(old_pin));
if (old_pin[0] && _prefs && !pinSet()) {
screenlock::set(*_prefs, old_pin, the_mesh.getRNG());
the_mesh.savePrefs();
}
memset(old_pin, 0, sizeof(old_pin));
if (pinSet()) lockScreen(); // a reboot doesn't get round the PIN
showSplash(); // over both; fades out by itself
}