2023-02-21 11:30:24 +00:00
|
|
|
# isort:skip_file
|
|
|
|
|
2023-11-28 10:45:22 +00:00
|
|
|
import utime
|
2023-02-21 11:30:24 +00:00
|
|
|
|
2023-11-29 13:51:25 +00:00
|
|
|
# Welcome screen is shown immediately after display init.
|
|
|
|
# Then it takes about 120ms to get here.
|
2023-02-21 11:30:24 +00:00
|
|
|
# (display is also prepared on that occasion).
|
|
|
|
# Remembering time to control how long we show it.
|
2023-11-28 10:45:22 +00:00
|
|
|
welcome_screen_start_ms = utime.ticks_ms()
|
2023-02-21 11:30:24 +00:00
|
|
|
|
2019-10-25 15:43:55 +00:00
|
|
|
import storage
|
|
|
|
import storage.device
|
2024-05-07 13:46:15 +00:00
|
|
|
from trezor import config, io, log, loop, ui, utils, wire, translations
|
2023-02-21 11:30:24 +00:00
|
|
|
from trezor.pin import (
|
|
|
|
allow_all_loader_messages,
|
|
|
|
ignore_nonpin_loader_messages,
|
|
|
|
show_pin_timeout,
|
|
|
|
)
|
2022-09-26 21:07:29 +00:00
|
|
|
from trezor.ui.layouts.homescreen import Lockscreen
|
2018-07-03 14:20:26 +00:00
|
|
|
|
2020-04-22 08:54:09 +00:00
|
|
|
from apps.common.request_pin import can_lock_device, verify_user_pin
|
2017-12-14 16:14:15 +00:00
|
|
|
|
2024-07-06 14:36:03 +00:00
|
|
|
if utils.USE_OPTIGA:
|
|
|
|
from trezor.crypto import optiga
|
|
|
|
|
2024-05-17 13:03:04 +00:00
|
|
|
# have to use "==" over "in (list)" so that it can be statically replaced
|
|
|
|
# with the correct value during the build process
|
2024-08-27 10:21:40 +00:00
|
|
|
if ( # pylint: disable-next=consider-using-in
|
|
|
|
utils.INTERNAL_MODEL == "T2T1"
|
|
|
|
or utils.INTERNAL_MODEL == "T2B1"
|
|
|
|
or utils.INTERNAL_MODEL == "T3B1"
|
|
|
|
):
|
2024-05-17 13:03:04 +00:00
|
|
|
_WELCOME_SCREEN_MS = 1000 # how long do we want to show welcome screen (minimum)
|
|
|
|
else:
|
|
|
|
_WELCOME_SCREEN_MS = 0
|
2023-11-28 10:45:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def enforce_welcome_screen_duration() -> None:
|
|
|
|
"""Make sure we will show the welcome screen for appropriate amount of time."""
|
|
|
|
# Not wasting the time in emulator debug builds (debugging and development)
|
|
|
|
if __debug__ and utils.EMULATOR:
|
|
|
|
return
|
2024-03-12 00:53:39 +00:00
|
|
|
while (
|
|
|
|
utime.ticks_diff(utime.ticks_ms(), welcome_screen_start_ms) < _WELCOME_SCREEN_MS
|
|
|
|
):
|
2023-11-28 10:45:22 +00:00
|
|
|
utime.sleep_ms(100)
|
|
|
|
|
2017-12-14 16:14:15 +00:00
|
|
|
|
2019-07-03 13:07:04 +00:00
|
|
|
async def bootscreen() -> None:
|
2023-02-21 11:30:24 +00:00
|
|
|
"""Sequence of actions to be done on boot (after device is connected).
|
|
|
|
|
|
|
|
We are starting with welcome_screen on the screen and want to show it
|
|
|
|
for at least _WELCOME_SCREEN_MS before any other screen.
|
|
|
|
|
|
|
|
Any non-PIN loaders are ignored during this function.
|
|
|
|
Allowing all of them before returning.
|
|
|
|
"""
|
2017-10-24 11:59:09 +00:00
|
|
|
while True:
|
2018-02-19 19:36:12 +00:00
|
|
|
try:
|
2024-01-05 14:58:11 +00:00
|
|
|
|
2020-04-22 08:54:09 +00:00
|
|
|
if can_lock_device():
|
2023-11-28 10:45:22 +00:00
|
|
|
enforce_welcome_screen_duration()
|
2024-07-01 11:15:43 +00:00
|
|
|
if utils.INTERNAL_MODEL == "T2T1":
|
|
|
|
ui.backlight_fade(ui.BacklightLevels.NONE)
|
2024-01-05 14:58:11 +00:00
|
|
|
ui.display.orientation(storage.device.get_rotation())
|
2024-05-07 13:46:15 +00:00
|
|
|
if utils.USE_HAPTIC:
|
|
|
|
io.haptic.haptic_set_enabled(storage.device.get_haptic_feedback())
|
2024-05-22 20:19:50 +00:00
|
|
|
lockscreen = Lockscreen(
|
|
|
|
label=storage.device.get_label(), bootscreen=True
|
|
|
|
)
|
2024-07-04 07:32:59 +00:00
|
|
|
await lockscreen.get_result()
|
2024-05-28 17:36:51 +00:00
|
|
|
lockscreen.__del__()
|
2024-01-05 14:58:11 +00:00
|
|
|
await verify_user_pin()
|
|
|
|
storage.init_unlocked()
|
|
|
|
allow_all_loader_messages()
|
|
|
|
return
|
|
|
|
else:
|
2024-07-06 14:36:03 +00:00
|
|
|
# Even if PIN is not configured, storage needs to be unlocked, unless it has just been initialized.
|
|
|
|
if not config.is_unlocked():
|
|
|
|
await verify_user_pin()
|
2024-01-05 14:58:11 +00:00
|
|
|
storage.init_unlocked()
|
|
|
|
enforce_welcome_screen_duration()
|
|
|
|
rotation = storage.device.get_rotation()
|
2024-05-07 13:46:15 +00:00
|
|
|
if utils.USE_HAPTIC:
|
|
|
|
io.haptic.haptic_set_enabled(storage.device.get_haptic_feedback())
|
|
|
|
|
2024-01-05 14:58:11 +00:00
|
|
|
if rotation != ui.display.orientation():
|
|
|
|
# there is a slight delay before next screen is shown,
|
|
|
|
# so we don't fade unless there is a change of orientation
|
2024-07-01 11:15:43 +00:00
|
|
|
if utils.INTERNAL_MODEL == "T2T1":
|
|
|
|
ui.backlight_fade(ui.BacklightLevels.NONE)
|
2024-01-05 14:58:11 +00:00
|
|
|
ui.display.orientation(rotation)
|
|
|
|
allow_all_loader_messages()
|
|
|
|
return
|
2020-04-21 12:31:24 +00:00
|
|
|
except wire.PinCancelled:
|
2020-03-20 10:18:18 +00:00
|
|
|
# verify_user_pin will convert a SdCardUnavailable (in case of sd salt)
|
|
|
|
# to PinCancelled exception.
|
2020-04-21 12:31:24 +00:00
|
|
|
# Ignore exception, retry loop.
|
|
|
|
pass
|
2019-11-04 14:34:00 +00:00
|
|
|
except BaseException as e:
|
2020-03-20 10:18:18 +00:00
|
|
|
# other exceptions here are unexpected and should halt the device
|
2019-11-06 12:57:00 +00:00
|
|
|
if __debug__:
|
|
|
|
log.exception(__name__, e)
|
2019-10-17 15:56:09 +00:00
|
|
|
utils.halt(e.__class__.__name__)
|
2018-02-19 19:36:12 +00:00
|
|
|
|
|
|
|
|
2024-07-06 14:36:03 +00:00
|
|
|
# Ignore all automated PIN messages in the boot-phase (turned off in `bootscreen()`), unless Optiga throttling delays are active.
|
|
|
|
if not utils.USE_OPTIGA or (optiga.get_sec() or 0) < 150:
|
|
|
|
ignore_nonpin_loader_messages()
|
2023-02-21 11:30:24 +00:00
|
|
|
|
2019-02-21 13:06:20 +00:00
|
|
|
config.init(show_pin_timeout)
|
2023-08-11 15:57:32 +00:00
|
|
|
translations.init()
|
2021-03-22 14:30:36 +00:00
|
|
|
|
|
|
|
if __debug__ and not utils.EMULATOR:
|
|
|
|
config.wipe()
|
|
|
|
|
2018-02-19 19:36:12 +00:00
|
|
|
loop.schedule(bootscreen())
|
2017-10-24 11:59:09 +00:00
|
|
|
loop.run()
|