diff --git a/src/ui_bagl.c b/src/ui_bagl.c index 5f67bbbd..e84f6ec5 100644 --- a/src/ui_bagl.c +++ b/src/ui_bagl.c @@ -48,7 +48,7 @@ void ux_set_low_cost_display_mode(bool enable) { if (G_display.low_cost_display_mode) { ux_screensaver_start_clock(); } else { - ux_screensaver_stop_clock(); + ux_screensaver_stop(); } } } @@ -69,6 +69,7 @@ uint8_t io_event(uint8_t channel) { switch (G_io_seproxyhal_spi_buffer[0]) { case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: + // Pressing any button will stop the low-cost display mode. ux_set_low_cost_display_mode(false); UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer); break; @@ -80,6 +81,8 @@ uint8_t io_event(uint8_t channel) { } __attribute__((fallthrough)); case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT: + // As soon as something is newly displayed, the low-cost display mode stops. + ux_set_low_cost_display_mode(false); #ifdef HAVE_BAGL UX_DISPLAYED_EVENT({}); #endif // HAVE_BAGL diff --git a/src/ui_screensaver.c b/src/ui_screensaver.c index 211f27ee..b15a3359 100644 --- a/src/ui_screensaver.c +++ b/src/ui_screensaver.c @@ -69,12 +69,17 @@ static void ux_layout_blank_init(unsigned int stack_slot) { ux_stack_display(stack_slot); } +void ux_screensaver_stop(void) { + G_screensaver_state.on = false; + ux_screensaver_stop_clock(); +} + /** * @brief Exits the blank screen to home screen * */ static void return_to_idle(void) { - G_screensaver_state.on = false; + ux_screensaver_stop(); ui_initial_screen(); } diff --git a/src/ui_screensaver.h b/src/ui_screensaver.h index 48c10f4b..9e24a753 100644 --- a/src/ui_screensaver.h +++ b/src/ui_screensaver.h @@ -47,6 +47,12 @@ typedef struct { */ void ui_start_screensaver(void); +/** + * @brief Stop using the screensaver + * + */ +void ux_screensaver_stop(void); + /** * @brief Start a timeout before saving screen * diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_cancelled_by_display/first_authorize_screen.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_cancelled_by_display/first_authorize_screen.png new file mode 100644 index 00000000..4d1d8b6b Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_cancelled_by_display/first_authorize_screen.png differ diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_cancelled_by_display/home_screen.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_cancelled_by_display/home_screen.png new file mode 100644 index 00000000..ce795f34 Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_cancelled_by_display/home_screen.png differ diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00000.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00000.png new file mode 100644 index 00000000..4d1d8b6b Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00000.png differ diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00001.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00001.png new file mode 100644 index 00000000..12f70a27 Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00001.png differ diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00002.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00002.png new file mode 100644 index 00000000..50537f75 Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00002.png differ diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00003.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00003.png new file mode 100644 index 00000000..a30fbd95 Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00003.png differ diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00004.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00004.png new file mode 100644 index 00000000..660f665e Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00004.png differ diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00005.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00005.png new file mode 100644 index 00000000..2f90a3a5 Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00005.png differ diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00006.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00006.png new file mode 100644 index 00000000..ce795f34 Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/authorize/00006.png differ diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/black.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/black.png new file mode 100644 index 00000000..34037194 Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/black.png differ diff --git a/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/home_screen.png b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/home_screen.png new file mode 100644 index 00000000..ce795f34 Binary files /dev/null and b/test/snapshots/nanos/test_automatic_low_cost_screensaver_exited_by_display/home_screen.png differ diff --git a/test/test_instructions.py b/test/test_instructions.py index 385d3dee..40f707d9 100644 --- a/test/test_instructions.py +++ b/test/test_instructions.py @@ -222,7 +222,12 @@ def test_automatic_low_cost_screensaver(firmware: Firmware, account = DEFAULT_ACCOUNT - tezos_navigator.authorize_baking(account) + tezos_navigator.setup_app_context( + account, + DEFAULT_CHAIN_ID, + Hwm(0, 0), + Hwm(0, 0) + ) tezos_navigator.assert_screen("home_screen") @@ -256,9 +261,125 @@ def test_automatic_low_cost_screensaver(firmware: Firmware, time.sleep(30) - # Low-cost screensaver desactivate after button push + # Low-cost screensaver deactivate after button push + tezos_navigator.assert_screen("home_screen") + +def test_automatic_low_cost_screensaver_cancelled_by_display( + firmware: Firmware, + backend: BackendInterface, + client: TezosClient, + tezos_navigator: TezosNavigator) -> None: + """Test that low-cost screensaver is cancelled by display""" + + if firmware.name != "nanos": + pytest.skip("Only on nanos devices") + + account = DEFAULT_ACCOUNT + + tezos_navigator.setup_app_context( + account, + DEFAULT_CHAIN_ID, + Hwm(0, 0), + Hwm(0, 0) + ) + + attestation = build_attestation( + op_level=1, + op_round=0, + chain_id=DEFAULT_CHAIN_ID + ) + + client.sign_message(account, attestation) + + time.sleep(5) + + # Low-cost screensaver activate after 20s after signing + tezos_navigator.assert_screen("home_screen") + + def delayed_authorize_navigate(**kwargs): + time.sleep(30) + + # Low-cost screensaver deactivate after something is displayed. + backend.wait_for_screen_change() + tezos_navigator.assert_screen("first_authorize_screen") + + tezos_navigator.accept_key_navigate( + screen_change_before_first_instruction=False, + **kwargs + ) + + tezos_navigator.authorize_baking( + account, + navigate=delayed_authorize_navigate + ) + +def test_automatic_low_cost_screensaver_exited_by_display( + firmware: Firmware, + backend: BackendInterface, + client: TezosClient, + tezos_navigator: TezosNavigator) -> None: + """Test that low-cost screensaver is exited by display""" + + if firmware.name != "nanos": + pytest.skip("Only on nanos devices") + + account = DEFAULT_ACCOUNT + + tezos_navigator.setup_app_context( + account, + DEFAULT_CHAIN_ID, + Hwm(0, 0), + Hwm(0, 0) + ) + + attestation = build_attestation( + op_level=1, + op_round=0, + chain_id=DEFAULT_CHAIN_ID + ) + + client.sign_message(account, attestation) + + time.sleep(5) + + # Low-cost screensaver activate after 20s after signing + tezos_navigator.assert_screen("home_screen") + + time.sleep(30) + + # Low-cost screensaver has been activated + backend.wait_for_screen_change() + tezos_navigator.assert_screen("black") + + # Exit the low-cost screensaver by display + tezos_navigator.authorize_baking(account, snap_path=Path("authorize")) + + tezos_navigator.assert_screen("home_screen") + + time.sleep(30) + + # Low-cost screensaver deactivate after display tezos_navigator.assert_screen("home_screen") + attestation = build_attestation( + op_level=2, + op_round=0, + chain_id=DEFAULT_CHAIN_ID + ) + + client.sign_message(account, attestation) + + time.sleep(5) + + # Low-cost screensaver activate after 20s after signing + tezos_navigator.assert_screen("home_screen") + + time.sleep(30) + + # Low-cost screensaver has been activated + backend.wait_for_screen_change() + tezos_navigator.assert_screen("black") + def test_version(client: TezosClient) -> None: """Test the VERSION instruction."""