2021-04-06 12:31:03 +00:00
|
|
|
import storage.cache
|
2021-01-18 20:18:56 +00:00
|
|
|
from trezor import loop, res, ui, wire
|
2020-04-14 10:21:32 +00:00
|
|
|
|
|
|
|
from . import HomescreenBase
|
|
|
|
|
|
|
|
|
2020-04-22 08:58:24 +00:00
|
|
|
async def lockscreen() -> None:
|
|
|
|
from apps.common.request_pin import can_lock_device
|
|
|
|
from apps.base import unlock_device
|
|
|
|
|
2020-05-28 09:57:04 +00:00
|
|
|
# Only show the lockscreen UI if the device can in fact be locked.
|
2020-04-22 08:58:24 +00:00
|
|
|
if can_lock_device():
|
|
|
|
await Lockscreen()
|
2020-05-28 09:57:04 +00:00
|
|
|
# Otherwise proceed directly to unlock() call. If the device is already unlocked,
|
|
|
|
# it should be a no-op storage-wise, but it resets the internal configuration
|
|
|
|
# to an unlocked state.
|
2020-05-21 10:53:11 +00:00
|
|
|
try:
|
|
|
|
await unlock_device()
|
|
|
|
except wire.PinCancelled:
|
|
|
|
pass
|
2020-04-22 08:58:24 +00:00
|
|
|
|
|
|
|
|
2020-04-14 10:21:32 +00:00
|
|
|
class Lockscreen(HomescreenBase):
|
2020-06-01 10:07:57 +00:00
|
|
|
BACKLIGHT_LEVEL = ui.BACKLIGHT_LOW
|
2021-01-18 20:18:56 +00:00
|
|
|
RENDER_SLEEP = loop.SLEEP_FOREVER
|
2021-04-06 12:31:03 +00:00
|
|
|
RENDER_INDICATOR = storage.cache.LOCKSCREEN_ON
|
2020-06-01 10:07:57 +00:00
|
|
|
|
2020-06-02 13:23:11 +00:00
|
|
|
def __init__(self, bootscreen: bool = False) -> None:
|
|
|
|
if bootscreen:
|
|
|
|
self.BACKLIGHT_LEVEL = ui.BACKLIGHT_NORMAL
|
|
|
|
self.lock_label = "Not connected"
|
|
|
|
self.tap_label = "Tap to connect"
|
|
|
|
else:
|
|
|
|
self.lock_label = "Locked"
|
|
|
|
self.tap_label = "Tap to unlock"
|
|
|
|
|
2020-04-22 08:58:24 +00:00
|
|
|
super().__init__()
|
|
|
|
|
2021-04-06 12:31:03 +00:00
|
|
|
def do_render(self) -> None:
|
2020-06-02 13:23:11 +00:00
|
|
|
# homescreen with label text on top
|
|
|
|
ui.display.text_center(
|
|
|
|
ui.WIDTH // 2, 35, self.label, ui.BOLD, ui.TITLE_GREY, ui.BG
|
|
|
|
)
|
2021-04-16 10:16:10 +00:00
|
|
|
ui.display.avatar(48, 48, self.get_image(), ui.WHITE, ui.BLACK)
|
2020-06-02 13:23:11 +00:00
|
|
|
|
|
|
|
# lock bar
|
2020-04-22 08:58:24 +00:00
|
|
|
ui.display.bar_radius(40, 100, 160, 40, ui.TITLE_GREY, ui.BG, 4)
|
|
|
|
ui.display.bar_radius(42, 102, 156, 36, ui.BG, ui.TITLE_GREY, 4)
|
|
|
|
ui.display.text_center(
|
|
|
|
ui.WIDTH // 2, 128, self.lock_label, ui.BOLD, ui.TITLE_GREY, ui.BG
|
|
|
|
)
|
|
|
|
|
2020-06-02 13:23:11 +00:00
|
|
|
# "tap to unlock"
|
2020-04-22 08:58:24 +00:00
|
|
|
ui.display.text_center(
|
2020-04-24 10:02:01 +00:00
|
|
|
ui.WIDTH // 2 + 10, 220, self.tap_label, ui.BOLD, ui.TITLE_GREY, ui.BG
|
2020-04-22 08:58:24 +00:00
|
|
|
)
|
|
|
|
ui.display.icon(45, 202, res.load(ui.ICON_CLICK), ui.TITLE_GREY, ui.BG)
|
|
|
|
|
2021-01-18 20:18:56 +00:00
|
|
|
def on_touch_end(self, _x: int, _y: int) -> None:
|
2020-04-14 10:21:32 +00:00
|
|
|
raise ui.Result(None)
|