core/debug: reading layouts, inserting synthetic events

pull/632/head
matejcik 5 years ago
parent 8c3d93619e
commit 3664a5f06f

@ -4,12 +4,13 @@ if not __debug__:
halt("debug mode inactive")
if __debug__:
from trezor import config, log, loop, utils
from trezor import config, io, log, loop, ui, utils
from trezor.messages import MessageType, DebugSwipeDirection
from trezor.messages.DebugLinkLayout import DebugLinkLayout
from trezor.wire import register
if False:
from typing import Optional
from typing import List, Optional
from trezor import wire
from trezor.messages.DebugLinkDecision import DebugLinkDecision
from trezor.messages.DebugLinkGetState import DebugLinkGetState
@ -28,6 +29,15 @@ if __debug__:
debuglink_decision_chan = loop.chan()
layout_change_chan = loop.chan()
current_content = [] # type: List[str]
def notify_layout_change(layout: ui.Layout) -> None:
global current_content
current_content = layout.read_content()
if layout_change_chan.takers:
layout_change_chan.publish(current_content)
async def debuglink_decision_dispatcher() -> None:
from trezor.ui import confirm, swipe
@ -53,12 +63,21 @@ if __debug__:
async def dispatch_DebugLinkDecision(
ctx: wire.Context, msg: DebugLinkDecision
) -> None:
) -> Optional[DebugLinkLayout]:
if debuglink_decision_chan.putters:
log.warning(__name__, "DebugLinkDecision queue is not empty")
debuglink_decision_chan.publish(msg)
if msg.x is not None:
evt_down = io.TOUCH_START, msg.x, msg.y
evt_up = io.TOUCH_END, msg.x, msg.y
loop.synthetic_events.append((io.TOUCH, evt_down))
loop.synthetic_events.append((io.TOUCH, evt_up))
else:
debuglink_decision_chan.publish(msg)
if msg.wait:
content = await layout_change_chan.take()
return DebugLinkLayout(lines=content)
async def dispatch_DebugLinkGetState(
ctx: wire.Context, msg: DebugLinkGetState
@ -72,6 +91,7 @@ if __debug__:
m.mnemonic_type = mnemonic.get_type()
m.passphrase_protection = has_passphrase()
m.reset_entropy = reset_internal_entropy
m.layout_lines = current_content
if msg.wait_word_pos:
m.reset_word_pos = await reset_word_index.take()

@ -310,6 +310,11 @@ class RecoveryHomescreen(ui.Component):
self.repaint = False
if __debug__:
def read_content(self):
return [self.__class__.__name__, self.text, self.subtext or ""]
async def homescreen_dialog(
ctx: wire.GenericContext,

@ -643,6 +643,11 @@ class MnemonicWordSelect(ui.Layout):
return fn
if __debug__:
def read_content(self):
return self.text.read_content() + [b.text for b in self.buttons]
async def show_reset_device_warning(ctx, backup_type: BackupType = BackupType.Bip39):
text = Text("Create new wallet", ui.ICON_RESET, new_lines=False)

@ -5,6 +5,9 @@ from trezorui import Display
from trezor import io, loop, res, utils
if __debug__:
from apps.debug import notify_layout_change
if False:
from typing import Any, Awaitable, Generator, Tuple, TypeVar
@ -226,6 +229,11 @@ class Component:
def on_touch_end(self, x: int, y: int) -> None:
pass
if __debug__:
def read_content(self) -> List[str]:
return [self.__class__.__name__]
class Result(Exception):
"""
@ -279,6 +287,8 @@ class Layout(Component):
# layout channel. This allows other layouts to cancel us, and the
# layout tasks to trigger restart by exiting (new tasks are created
# and we continue, because we are in a loop).
if __debug__:
notify_layout_change(self)
while True:
await loop.race(layout_chan.take(), *self.create_tasks())
except Result as result:

@ -4,7 +4,7 @@ from trezor import ui
from trezor.ui import display, in_area
if False:
from typing import Type, Union, Optional
from typing import List, Type, Union
class ButtonDefault:
@ -239,3 +239,8 @@ class Button(ui.Component):
def on_click(self) -> None:
pass
if __debug__:
def read_content(self) -> List[str]:
return ["<Button: {}>".format(self.text)]

@ -8,7 +8,7 @@ if __debug__:
from apps.debug import swipe_signal
if False:
from typing import Any, Optional, Tuple
from typing import Any, Optional, List, Tuple
from trezor.ui.button import ButtonContent, ButtonStyleType
from trezor.ui.loader import LoaderStyleType
@ -74,6 +74,11 @@ class Confirm(ui.Layout):
def on_cancel(self) -> None:
raise ui.Result(CANCELLED)
if __debug__:
def read_content(self) -> List[str]:
return self.content.read_content()
class Pageable:
def __init__(self) -> None:
@ -201,6 +206,11 @@ class InfoConfirm(ui.Layout):
def on_info(self) -> None:
raise ui.Result(INFO)
if __debug__:
def read_content(self) -> List[str]:
return self.content.read_content()
class HoldToConfirm(ui.Layout):
DEFAULT_CONFIRM = "Hold To Confirm"
@ -250,3 +260,8 @@ class HoldToConfirm(ui.Layout):
def on_confirm(self) -> None:
raise ui.Result(CONFIRMED)
if __debug__:
def read_content(self) -> List[str]:
return self.content.read_content()

@ -1,5 +1,8 @@
from trezor import ui
if False:
from typing import List
class Container(ui.Component):
def __init__(self, *children: ui.Component):
@ -8,3 +11,8 @@ class Container(ui.Component):
def dispatch(self, event: int, x: int, y: int) -> None:
for child in self.children:
child.dispatch(event, x, y)
if __debug__:
def read_content(self) -> List[str]:
return sum((c.read_content() for c in self.children), [])

@ -6,10 +6,10 @@ from trezor.ui.confirm import CANCELLED, CONFIRMED
from trezor.ui.swipe import SWIPE_DOWN, SWIPE_UP, SWIPE_VERTICAL, Swipe
if __debug__:
from apps.debug import swipe_signal
from apps.debug import swipe_signal, notify_layout_change
if False:
from typing import Tuple, List
from typing import List, Tuple
def render_scrollbar(pages: int, page: int) -> None:
@ -89,6 +89,9 @@ class Paginated(ui.Layout):
self.pages[self.page].dispatch(ui.REPAINT, 0, 0)
self.repaint = True
if __debug__:
notify_layout_change(self)
self.on_change()
def create_tasks(self) -> Tuple[loop.Task, ...]:
@ -98,6 +101,11 @@ class Paginated(ui.Layout):
if self.one_by_one:
raise ui.Result(self.page)
if __debug__:
def read_content(self) -> List[str]:
return self.pages[self.page].read_content()
class PageWithButtons(ui.Component):
def __init__(
@ -154,6 +162,11 @@ class PageWithButtons(ui.Component):
else:
self.paginated.on_down()
if __debug__:
def read_content(self) -> List[str]:
return self.content.read_content()
class PaginatedWithButtons(ui.Layout):
def __init__(
@ -191,3 +204,8 @@ class PaginatedWithButtons(ui.Layout):
def on_change(self) -> None:
if self.one_by_one:
raise ui.Result(self.page)
if __debug__:
def read_content(self) -> List[str]:
return self.pages[self.page].read_content()

@ -171,6 +171,12 @@ class Text(ui.Component):
render_text(self.content, self.new_lines, self.max_lines)
self.repaint = False
if __debug__:
def read_content(self) -> List[str]:
lines = [w for w in self.content if isinstance(w, str)]
return [self.header_text] + lines[: self.max_lines]
LABEL_LEFT = const(0)
LABEL_CENTER = const(1)
@ -209,6 +215,11 @@ class Label(ui.Component):
)
self.repaint = False
if __debug__:
def read_content(self) -> List[str]:
return [self.content]
def text_center_trim_left(
x: int, y: int, text: str, font: int = ui.NORMAL, width: int = ui.WIDTH - 16

Loading…
Cancel
Save