1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-26 15:20:58 +00:00

core: move confirm_signal evaluation into concrete Layout implementations

Apart from making the code more correct for its users in
apps.common.confirm and elsewhere, this fixes a problem where the
confirm_signal would be scheduled before the dialog is rendered.
By making sure that handle_rendering is scheduled (i.e., listed in
create_tasks) before confirm_signal, we can be sure to render at least
once and thus appear in the UI test results.
This commit is contained in:
matejcik 2020-01-22 16:50:20 +01:00
parent 9a884a5dc5
commit a79279115e
6 changed files with 36 additions and 38 deletions

View File

@ -5,7 +5,6 @@ from trezor.messages.ButtonRequest import ButtonRequest
from trezor.ui.confirm import CONFIRMED, INFO, Confirm, HoldToConfirm, InfoConfirm from trezor.ui.confirm import CONFIRMED, INFO, Confirm, HoldToConfirm, InfoConfirm
if __debug__: if __debug__:
from apps.debug import confirm_signal
from trezor.ui.scroll import Paginated from trezor.ui.scroll import Paginated
if False: if False:
@ -47,10 +46,7 @@ async def confirm(
content, confirm, confirm_style, cancel, cancel_style, major_confirm content, confirm, confirm_style, cancel, cancel_style, major_confirm
) )
if __debug__: return await ctx.wait(dialog) is CONFIRMED
return await ctx.wait(dialog, confirm_signal()) is CONFIRMED
else:
return await ctx.wait(dialog) is CONFIRMED
async def info_confirm( async def info_confirm(
@ -72,10 +68,7 @@ async def info_confirm(
) )
while True: while True:
if __debug__: result = await ctx.wait(dialog)
result = await ctx.wait(dialog, confirm_signal())
else:
result = await ctx.wait(dialog)
if result is INFO: if result is INFO:
await info_func(ctx) await info_func(ctx)
@ -106,10 +99,7 @@ async def hold_to_confirm(
else: else:
dialog = HoldToConfirm(content, confirm, confirm_style, loader_style) dialog = HoldToConfirm(content, confirm, confirm_style, loader_style)
if __debug__: return await ctx.wait(dialog) is CONFIRMED
return await ctx.wait(dialog, confirm_signal()) is CONFIRMED
else:
return await ctx.wait(dialog) is CONFIRMED
async def require_confirm(*args: Any, **kwargs: Any) -> None: async def require_confirm(*args: Any, **kwargs: Any) -> None:

View File

@ -56,7 +56,7 @@ if __debug__:
msg = await debuglink_decision_chan.take() msg = await debuglink_decision_chan.take()
if msg.yes_no is not None: if msg.yes_no is not None:
await confirm_chan.put( await confirm_chan.put(
confirm.CONFIRMED if msg.yes_no else confirm.CANCELLED ui.Result(confirm.CONFIRMED if msg.yes_no else confirm.CANCELLED)
) )
if msg.swipe is not None: if msg.swipe is not None:
if msg.swipe == DebugSwipeDirection.UP: if msg.swipe == DebugSwipeDirection.UP:

View File

@ -1,12 +1,9 @@
from trezor import loop, ui, utils from trezor import ui, utils
from trezor.messages import ButtonRequestType from trezor.messages import ButtonRequestType
from trezor.messages.ButtonAck import ButtonAck from trezor.messages.ButtonAck import ButtonAck
from trezor.messages.ButtonRequest import ButtonRequest from trezor.messages.ButtonRequest import ButtonRequest
from trezor.ui.text import Text from trezor.ui.text import Text
if __debug__:
from apps.debug import confirm_signal
async def naive_pagination( async def naive_pagination(
ctx, lines, title, icon=ui.ICON_RESET, icon_color=ui.ORANGE, per_page=5 ctx, lines, title, icon=ui.ICON_RESET, icon_color=ui.ORANGE, per_page=5
@ -29,10 +26,7 @@ async def naive_pagination(
while True: while True:
await ctx.call(ButtonRequest(code=ButtonRequestType.SignTx), ButtonAck) await ctx.call(ButtonRequest(code=ButtonRequestType.SignTx), ButtonAck)
if __debug__: result = await paginated
result = await loop.race(paginated, confirm_signal())
else:
result = await paginated
if result is CONFIRMED: if result is CONFIRMED:
return True return True
if result is CANCELLED: if result is CANCELLED:

View File

@ -20,9 +20,6 @@ from apps.webauthn.resident_credentials import (
store_resident_credential, store_resident_credential,
) )
if __debug__:
from apps.debug import confirm_signal
if False: if False:
from typing import Any, Coroutine, List, Optional, Tuple from typing import Any, Coroutine, List, Optional, Tuple
@ -561,19 +558,11 @@ async def verify_user(keepalive_callback: KeepaliveCallback) -> bool:
async def confirm(*args: Any, **kwargs: Any) -> bool: async def confirm(*args: Any, **kwargs: Any) -> bool:
dialog = Confirm(*args, **kwargs) return await Confirm(*args, **kwargs) is CONFIRMED
if __debug__:
return await loop.race(dialog, confirm_signal()) is CONFIRMED
else:
return await dialog is CONFIRMED
async def confirm_pageable(*args: Any, **kwargs: Any) -> bool: async def confirm_pageable(*args: Any, **kwargs: Any) -> bool:
dialog = ConfirmPageable(*args, **kwargs) return await ConfirmPageable(*args, **kwargs) is CONFIRMED
if __debug__:
return await loop.race(dialog, confirm_signal()) is CONFIRMED
else:
return await dialog is CONFIRMED
class State: class State:

View File

@ -5,7 +5,7 @@ from trezor.ui.button import Button, ButtonCancel, ButtonConfirm, ButtonDefault
from trezor.ui.loader import Loader, LoaderDefault from trezor.ui.loader import Loader, LoaderDefault
if __debug__: if __debug__:
from apps.debug import swipe_signal from apps.debug import swipe_signal, confirm_signal
if False: if False:
from typing import Any, Optional, List, Tuple from typing import Any, Optional, List, Tuple
@ -79,6 +79,9 @@ class Confirm(ui.Layout):
def read_content(self) -> List[str]: def read_content(self) -> List[str]:
return self.content.read_content() return self.content.read_content()
def create_tasks(self) -> Tuple[loop.Task, ...]:
return super().create_tasks() + (confirm_signal(),)
class Pageable: class Pageable:
def __init__(self) -> None: def __init__(self) -> None:
@ -217,6 +220,9 @@ class InfoConfirm(ui.Layout):
def read_content(self) -> List[str]: def read_content(self) -> List[str]:
return self.content.read_content() return self.content.read_content()
def create_tasks(self) -> Tuple[loop.Task, ...]:
return super().create_tasks() + (confirm_signal(),)
class HoldToConfirm(ui.Layout): class HoldToConfirm(ui.Layout):
DEFAULT_CONFIRM = "Hold To Confirm" DEFAULT_CONFIRM = "Hold To Confirm"
@ -271,3 +277,6 @@ class HoldToConfirm(ui.Layout):
def read_content(self) -> List[str]: def read_content(self) -> List[str]:
return self.content.read_content() return self.content.read_content()
def create_tasks(self) -> Tuple[loop.Task, ...]:
return super().create_tasks() + (confirm_signal(),)

View File

@ -6,7 +6,7 @@ from trezor.ui.confirm import CANCELLED, CONFIRMED
from trezor.ui.swipe import SWIPE_DOWN, SWIPE_UP, SWIPE_VERTICAL, Swipe from trezor.ui.swipe import SWIPE_DOWN, SWIPE_UP, SWIPE_VERTICAL, Swipe
if __debug__: if __debug__:
from apps.debug import swipe_signal, notify_layout_change from apps.debug import confirm_signal, swipe_signal, notify_layout_change
if False: if False:
from typing import List, Tuple from typing import List, Tuple
@ -98,7 +98,20 @@ class Paginated(ui.Layout):
self.on_change() self.on_change()
def create_tasks(self) -> Tuple[loop.Task, ...]: def create_tasks(self) -> Tuple[loop.Task, ...]:
return self.handle_input(), self.handle_rendering(), self.handle_paging() tasks = (
self.handle_input(),
self.handle_rendering(),
self.handle_paging(),
) # type: Tuple[loop.Task, ...]
if __debug__:
# XXX This isn't strictly correct, as it allows *any* Paginated layout to be
# shut down by a DebugLink confirm, even if used outside of a confirm() call
# But we don't have any such usages in the codebase, and it doesn't actually
# make much sense to use a Paginated without a way to confirm it.
return tasks + (confirm_signal(),)
else:
return tasks
def on_change(self) -> None: def on_change(self) -> None:
if self.one_by_one: if self.one_by_one:
@ -212,3 +225,6 @@ class PaginatedWithButtons(ui.Layout):
def read_content(self) -> List[str]: def read_content(self) -> List[str]:
return self.pages[self.page].read_content() return self.pages[self.page].read_content()
def create_tasks(self) -> Tuple[loop.Task, ...]:
return super().create_tasks() + (confirm_signal(),)