usb: restore the previous activity before running a usbstorage action
What changed, and why it matters
This commit fixes a small user-interface bug in Blockstream Jade's USB storage mode. When a user plugs in a USB drive and the device mounts it, the code now restores the previous on-screen activity before running the requested action. It also swaps a generic message screen for a proper error screen when USB storage fails, and removes an unnecessary short delay after an earlier error. There is no clear security vulnerability being patched here; it reads as a UI polish and robustness improvement.
Treat as a routine bug-fix / UI-hardening commit. Review in normal development workflow; no urgent security response is indicated by the diff alone. If the project maintains a security changelog, this likely does not warrant an entry unless further context shows the UI state confusion could mislead a user during a security-critical operation.
Security signals we found
UI state restoration before sensitive action execution
Error-handling path changed from generic message to error activity
Removal of arbitrary delay in error path
Evidence from the diff
In main/usbhmsc/usbmode.c, handle_usbstorage_action() is updated so that, once USB storage reaches USBSTORAGE_STATE_MOUNTED, the GUI reverts to the prior activity (gui_set_current_activity(prior_activity)) before invoking the usbstorage action callback. The patch also changes await_message_activity() to await_error_activity() for the USBSTORAGE_STATE_ERROR path and removes a 100 ms vTaskDelay() after the initial USB-storage-start failure. The diff is small and does not introduce or remove cryptographic, authentication, or memory-unsafe operations.
Changed components
main/usbhmsc/usbmode.chandle_usbstorage_action()USB mass-storage user interface flowInspect captured patch +5 / −2
diff --git a/main/usbhmsc/usbmode.c b/main/usbhmsc/usbmode.c
index 511e7c2..d6a1e83 100644
--- a/main/usbhmsc/usbmode.c
+++ b/main/usbhmsc/usbmode.c
@@ -326,7 +326,6 @@ static bool handle_usbstorage_action(const char* title, usbstorage_action_fn_t u
JADE_LOGE("Failed to start USB storage!");
const char* message[] = { "Failed to start", "usb storage!" };
await_error_activity(message, 2);
- vTaskDelay(100 / portTICK_PERIOD_MS); // sleep a little bit to redraw screen
// Jade may require restart to use usb storage or serial at this point ...
return false;
}
@@ -334,6 +333,7 @@ static bool handle_usbstorage_action(const char* title, usbstorage_action_fn_t u
// We should only do this if within 0.4 seconds or so we don't detect a usb device already plugged
// Now wait for either the state to change or for back button on the activity
+ gui_activity_t* const prior_activity = gui_current_activity();
gui_activity_t* act_prompt = NULL;
int counter = 0;
bool action_initiated = false;
@@ -346,12 +346,15 @@ static bool handle_usbstorage_action(const char* title, usbstorage_action_fn_t u
if (state == USBSTORAGE_STATE_MOUNTED) {
// USB storage is mounted: run the action
+ if (act_prompt) {
+ gui_set_current_activity(prior_activity);
+ }
action_initiated = usbstorage_action(ctx);
break;
} else if (state == USBSTORAGE_STATE_ERROR) {
// Error accessing USB storage: Show error and exit
const char* message[] = { "Error accessing usb", "storage. Note: only", "FAT32 is supported." };
- await_message_activity(message, 3);
+ await_error_activity(message, 3);
break;
}
// At this point, USB storage is not yet mounted
Why this scored 29/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.