refactor(core): move power management modules
What changed, and why it matters
This commit simply moves two small power-management files from one folder to another and updates the build scripts and import paths accordingly. The actual code behavior is unchanged. There is no security fix or vulnerability here.
No security action needed; treat as routine code reorganization.
Security signals we found
No strong security signals were identified.
Evidence from the diff
A pure refactor: core/src/apps/management/pm/{autodim,suspend}.py are moved to core/src/trezor/power_management/{autodim,suspend}.py, an empty __init__.py is created, SConscript files are adjusted to include the new path and stop excluding the old one, qstr definitions are updated, and the import in trezor/ui/__init__.py is changed. No functional changes are present in the moved modules.
Changed components
core/src/trezor/power_management/autodim.pycore/src/trezor/power_management/suspend.pycore/src/trezor/ui/__init__.pycore/SConscript.firmwarecore/SConscript.unixcore/embed/upymod/qstrdefsport.hInspect captured patch +54 / −50
diff --git a/core/SConscript.firmware b/core/SConscript.firmware
index 227ad3dc..67a8d4e1 100644
--- a/core/SConscript.firmware
+++ b/core/SConscript.firmware
@@ -656,6 +656,9 @@ if FROZEN:
] if PYOPT != '0' else []
))
+ if 'power_manager' in FEATURES_AVAILABLE:
+ SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/power_management/*.py'))
+
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py',
exclude=(
([SOURCE_PY_DIR + 'storage/sd_salt.py'] if not SDCARD else []) +
@@ -717,8 +720,7 @@ if FROZEN:
)
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py',
exclude=(
- ([SOURCE_PY_DIR + 'apps/management/ble/*.py'] if "ble" not in FEATURES_AVAILABLE else []) +
- ([SOURCE_PY_DIR + 'apps/management/pm/*.py'] if "power_manager" not in FEATURES_AVAILABLE else [])
+ ([SOURCE_PY_DIR + 'apps/management/ble/*.py'] if "ble" not in FEATURES_AVAILABLE else [])
))
)
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/misc/*.py'))
diff --git a/core/SConscript.unix b/core/SConscript.unix
index 4a01cd0d..5f51ebf8 100644
--- a/core/SConscript.unix
+++ b/core/SConscript.unix
@@ -666,6 +666,9 @@ if FROZEN:
] if PYOPT != '0' else []
))
+ if 'power_manager' in FEATURES_AVAILABLE:
+ SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/power_management/*.py'))
+
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'storage/*.py',
exclude=(
([SOURCE_PY_DIR + 'storage/sd_salt.py'] if 'sd_card' not in FEATURES_AVAILABLE else []) +
@@ -729,8 +732,7 @@ if FROZEN:
)
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/management/*/*.py',
exclude=(
- ([SOURCE_PY_DIR + 'apps/management/ble/*.py'] if "ble" not in FEATURES_AVAILABLE else []) +
- ([SOURCE_PY_DIR + 'apps/management/pm/*.py'] if "power_manager" not in FEATURES_AVAILABLE else [])
+ [SOURCE_PY_DIR + 'apps/management/ble/*.py'] if "ble" not in FEATURES_AVAILABLE else []
))
)
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/misc/*.py'))
diff --git a/core/embed/upymod/qstrdefsport.h b/core/embed/upymod/qstrdefsport.h
index 5ed36480..d720a19d 100644
--- a/core/embed/upymod/qstrdefsport.h
+++ b/core/embed/upymod/qstrdefsport.h
@@ -133,9 +133,6 @@ Q(apps.management.change_pin)
Q(apps.management.change_wipe_code)
Q(apps.management.get_next_u2f_counter)
Q(apps.management.get_nonce)
-Q(apps.management.pm)
-Q(apps.management.pm.autodim)
-Q(apps.management.pm.suspend)
Q(apps.management.reboot_to_bootloader)
Q(apps.management.recovery_device)
Q(apps.management.recovery_device.homescreen)
@@ -255,7 +252,7 @@ Q(paths)
Q(payment_notification)
Q(payment_request)
Q(pin)
-Q(pm)
+Q(power_management)
Q(progress)
Q(protobuf)
Q(protocol_common)
@@ -345,6 +342,9 @@ Q(trezor.log)
Q(trezor.loop)
Q(trezor.messages)
Q(trezor.pin)
+Q(trezor.power_management)
+Q(trezor.power_management.autodim)
+Q(trezor.power_management.suspend)
Q(trezor.protobuf)
Q(trezor.sdcard)
Q(trezor.strings)
diff --git a/core/src/apps/management/pm/__init__.py b/core/src/apps/management/pm/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/core/src/apps/management/pm/autodim.py b/core/src/apps/management/pm/autodim.py
deleted file mode 100644
index 40920c2a..00000000
--- a/core/src/apps/management/pm/autodim.py
+++ /dev/null
@@ -1,24 +0,0 @@
-from trezor import io
-from trezorui_api import BacklightLevels, backlight_fade, backlight_get, backlight_set
-
-_AUTODIM_FROM: int | None = None
-"""Indicates whether the display is auto-dimmed. If so, it stores the user-set backlight level."""
-
-
-def autodim_display() -> None:
- """Autodim the display if the device is not connected to USB."""
- global _AUTODIM_FROM
- if io.pm.is_usb_connected():
- return
- current_backlight = backlight_get()
- if current_backlight > BacklightLevels.LOW:
- _AUTODIM_FROM = current_backlight
- backlight_fade(BacklightLevels.LOW)
-
-
-def autodim_clear() -> None:
- """Clear autodim state and restore previous backlight level if applicable."""
- global _AUTODIM_FROM
- if _AUTODIM_FROM is not None:
- backlight_set(_AUTODIM_FROM)
- _AUTODIM_FROM = None
diff --git a/core/src/apps/management/pm/suspend.py b/core/src/apps/management/pm/suspend.py
deleted file mode 100644
index bdce87a6..00000000
--- a/core/src/apps/management/pm/suspend.py
+++ /dev/null
@@ -1,17 +0,0 @@
-from trezor import io
-
-_HANDLED_WAKEUP_FLAGS = (
- io.pm.WAKEUP_FLAG_BUTTON,
- io.pm.WAKEUP_FLAG_BLE,
- io.pm.WAKEUP_FLAG_POWER,
-)
-
-
-def suspend_device() -> int:
- """Suspend the device and wait for a wakeup event. Wakeup flag is returned."""
- while True:
- wakeup_flag = io.pm.suspend()
- if wakeup_flag not in _HANDLED_WAKEUP_FLAGS:
- # other wakeup flags are ignored, suspend again
- continue
- return wakeup_flag
diff --git a/core/src/trezor/power_management/__init__.py b/core/src/trezor/power_management/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/core/src/trezor/power_management/autodim.py b/core/src/trezor/power_management/autodim.py
new file mode 100644
index 00000000..40920c2a
--- /dev/null
+++ b/core/src/trezor/power_management/autodim.py
@@ -0,0 +1,24 @@
+from trezor import io
+from trezorui_api import BacklightLevels, backlight_fade, backlight_get, backlight_set
+
+_AUTODIM_FROM: int | None = None
+"""Indicates whether the display is auto-dimmed. If so, it stores the user-set backlight level."""
+
+
+def autodim_display() -> None:
+ """Autodim the display if the device is not connected to USB."""
+ global _AUTODIM_FROM
+ if io.pm.is_usb_connected():
+ return
+ current_backlight = backlight_get()
+ if current_backlight > BacklightLevels.LOW:
+ _AUTODIM_FROM = current_backlight
+ backlight_fade(BacklightLevels.LOW)
+
+
+def autodim_clear() -> None:
+ """Clear autodim state and restore previous backlight level if applicable."""
+ global _AUTODIM_FROM
+ if _AUTODIM_FROM is not None:
+ backlight_set(_AUTODIM_FROM)
+ _AUTODIM_FROM = None
diff --git a/core/src/trezor/power_management/suspend.py b/core/src/trezor/power_management/suspend.py
new file mode 100644
index 00000000..bdce87a6
--- /dev/null
+++ b/core/src/trezor/power_management/suspend.py
@@ -0,0 +1,17 @@
+from trezor import io
+
+_HANDLED_WAKEUP_FLAGS = (
+ io.pm.WAKEUP_FLAG_BUTTON,
+ io.pm.WAKEUP_FLAG_BLE,
+ io.pm.WAKEUP_FLAG_POWER,
+)
+
+
+def suspend_device() -> int:
+ """Suspend the device and wait for a wakeup event. Wakeup flag is returned."""
+ while True:
+ wakeup_flag = io.pm.suspend()
+ if wakeup_flag not in _HANDLED_WAKEUP_FLAGS:
+ # other wakeup flags are ignored, suspend again
+ continue
+ return wakeup_flag
diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py
index 05c47330..b458dc11 100644
--- a/core/src/trezor/ui/__init__.py
+++ b/core/src/trezor/ui/__init__.py
@@ -17,7 +17,7 @@ from trezorui_api import (
)
if utils.USE_POWER_MANAGER:
- from apps.management.pm.autodim import autodim_clear
+ from trezor.power_management.autodim import autodim_clear
if TYPE_CHECKING:
from typing import Any, Callable, Generator, Generic, Iterator, TypeVar
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.