Skip to content

Commit

Permalink
Merge pull request #102 from trilitech/palmer@functori@fix-low-cost-s…
Browse files Browse the repository at this point in the history
…creensaver-which-overrides-new-screens

Stop the low-cost screensaver after a new display
  • Loading branch information
ajinkyaraj-23 authored Apr 12, 2024
2 parents fc266a4 + 9a2d209 commit b7b1ac6
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/ui_bagl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand All @@ -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;
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/ui_screensaver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 6 additions & 0 deletions src/ui_screensaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 123 additions & 2 deletions test/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit b7b1ac6

Please sign in to comment.