diff --git a/legacy/firmware/config.c b/legacy/firmware/config.c index 787e3c499..a15ad1cf6 100644 --- a/legacy/firmware/config.c +++ b/legacy/firmware/config.c @@ -937,8 +937,7 @@ uint32_t config_getAutoLockDelayMs() { } void config_setAutoLockDelayMs(uint32_t auto_lock_delay_ms) { - const uint32_t min_delay_ms = 10 * 1000U; // 10 seconds - auto_lock_delay_ms = MAX(auto_lock_delay_ms, min_delay_ms); + auto_lock_delay_ms = MAX(auto_lock_delay_ms, MIN_AUTOLOCK_DELAY_MS); if (sectrue == storage_set(KEY_AUTO_LOCK_DELAY_MS, &auto_lock_delay_ms, sizeof(auto_lock_delay_ms))) { autoLockDelayMs = auto_lock_delay_ms; diff --git a/legacy/firmware/config.h b/legacy/firmware/config.h index ff6daa6da..cbb50bfe0 100644 --- a/legacy/firmware/config.h +++ b/legacy/firmware/config.h @@ -85,6 +85,8 @@ extern Storage configUpdate; #define MAX_MNEMONIC_LEN 240 #define HOMESCREEN_SIZE 1024 #define UUID_SIZE 12 +#define MIN_AUTOLOCK_DELAY_MS (10 * 1000U) // 10 seconds +#define MAX_AUTOLOCK_DELAY_MS 0x20000000U // ~6 days void config_init(void); void session_clear(bool lock); diff --git a/legacy/firmware/fsm_msg_common.h b/legacy/firmware/fsm_msg_common.h index 7a65d59c4..bdc498b09 100644 --- a/legacy/firmware/fsm_msg_common.h +++ b/legacy/firmware/fsm_msg_common.h @@ -413,9 +413,19 @@ void fsm_msgApplySettings(const ApplySettings *msg) { } if (msg->has_auto_lock_delay_ms) { - layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, - _("Do you really want to"), _("change auto-lock"), - _("delay?"), NULL, NULL, NULL); + if (msg->auto_lock_delay_ms < MIN_AUTOLOCK_DELAY_MS) { + fsm_sendFailure(FailureType_Failure_ProcessError, + _("Auto-lock delay too short")); + layoutHome(); + return; + } + if (msg->auto_lock_delay_ms > MAX_AUTOLOCK_DELAY_MS) { + fsm_sendFailure(FailureType_Failure_ProcessError, + _("Auto-lock delay too long")); + layoutHome(); + return; + } + layoutConfirmAutoLockDelay(msg->auto_lock_delay_ms); if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); diff --git a/legacy/firmware/layout2.c b/legacy/firmware/layout2.c index 9bd88ebd9..82288299c 100644 --- a/legacy/firmware/layout2.c +++ b/legacy/firmware/layout2.c @@ -1022,3 +1022,32 @@ void layoutCosiCommitSign(const uint32_t *address_n, size_t address_n_count, layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), desc, str[0], str[1], str[2], str[3], NULL, NULL); } + +void layoutConfirmAutoLockDelay(uint32_t delay_ms) { + char line[sizeof("after 4294967296 minutes?")] = {0}; + + const char *unit = _("second"); + uint32_t num = delay_ms / 1000U; + + if (delay_ms >= 60 * 60 * 1000) { + unit = _("hour"); + num /= 60 * 60U; + } else if (delay_ms >= 60 * 1000) { + unit = _("minute"); + num /= 60U; + } + + strlcpy(line, _("after "), sizeof(line)); + size_t off = strlen(line); + bn_format_uint64(num, NULL, NULL, 0, 0, false, &line[off], + sizeof(line) - off); + strlcat(line, " ", sizeof(line)); + strlcat(line, unit, sizeof(line)); + if (num > 1) { + strlcat(line, "s", sizeof(line)); + } + strlcat(line, "?", sizeof(line)); + layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), NULL, + _("Do you really want to"), _("auto-lock your device"), + line, NULL, NULL, NULL); +} diff --git a/legacy/firmware/layout2.h b/legacy/firmware/layout2.h index b5b2191c7..85530f354 100644 --- a/legacy/firmware/layout2.h +++ b/legacy/firmware/layout2.h @@ -90,6 +90,8 @@ void layoutNEMLevy(const NEMMosaicDefinition *definition, uint8_t network); void layoutCosiCommitSign(const uint32_t *address_n, size_t address_n_count, const uint8_t *data, uint32_t len, bool final_sign); +void layoutConfirmAutoLockDelay(uint32_t delay_ms); + const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen); const char **split_message_hex(const uint8_t *msg, uint32_t len);