From b28b950b0a85805fd52186c18264f01763fe8e7c Mon Sep 17 00:00:00 2001 From: Lukas Bielesch Date: Fri, 22 Nov 2024 15:12:12 +0100 Subject: [PATCH 1/2] fix(core): fix broken flow for changing brightness [no changelog] --- core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs | 4 +++- core/embed/rust/src/ui/model_mercury/layout.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs b/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs index 8461eaa078a..938a96d3a61 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/set_brightness.rs @@ -64,7 +64,8 @@ impl FlowController for SetBrightness { static BRIGHTNESS: AtomicU8 = AtomicU8::new(0); -pub fn new_set_brightness(brightness: u8) -> Result { +pub fn new_set_brightness(brightness: Option) -> Result { + let brightness = brightness.unwrap_or(theme::backlight::get_backlight_normal()); let content_slider = Frame::left_aligned( TR::brightness__title.into(), NumberInputSliderDialog::new( @@ -122,6 +123,7 @@ pub fn new_set_brightness(brightness: u8) -> Result { ) .with_footer(TR::instructions__swipe_up.into(), None) .with_swipe(Direction::Up, SwipeSettings::default()) + .with_result_icon(theme::ICON_BULLET_CHECKMARK, theme::GREEN_LIGHT) .map(move |_msg| Some(FlowMsg::Confirmed)); let res = SwipeFlow::new(&SetBrightness::Slider)? diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index 65358ce6c06..b2e39603a66 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -676,7 +676,7 @@ extern "C" fn new_confirm_summary(n_args: usize, args: *const Obj, kwargs: *mut extern "C" fn new_set_brightness(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj { let block = move |_args: &[Obj], kwargs: &Map| { - let current: u8 = kwargs.get(Qstr::MP_QSTR_current)?.try_into()?; + let current: Option = kwargs.get(Qstr::MP_QSTR_current)?.try_into_option()?; let flow = flow::set_brightness::new_set_brightness(current)?; Ok(LayoutObj::new_root(flow)?.into()) }; From d6fecf7488731f77765b3d0c85d0d590015bf7aa Mon Sep 17 00:00:00 2001 From: Lukas Bielesch Date: Mon, 25 Nov 2024 15:01:17 +0100 Subject: [PATCH 2/2] fixup! fix(core): fix broken flow for changing brightness [no changelog] --- tests/device_tests/test_msg_applysettings.py | 15 ++++++++++++++- tests/input_flows.py | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/device_tests/test_msg_applysettings.py b/tests/device_tests/test_msg_applysettings.py index c879a122d21..0f512ac44a3 100644 --- a/tests/device_tests/test_msg_applysettings.py +++ b/tests/device_tests/test_msg_applysettings.py @@ -22,7 +22,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client from trezorlib.tools import parse_path -from ..input_flows import InputFlowConfirmAllWarnings +from ..input_flows import InputFlowConfirmAllWarnings, InputFlowSetBrightness HERE = Path(__file__).parent.resolve() @@ -421,3 +421,16 @@ def test_label_too_long(client: Client): with pytest.raises(exceptions.TrezorFailure), client: client.set_expected_responses([messages.Failure]) device.apply_settings(client, label="A" * 33) + + +@pytest.mark.models(skip=["legacy", "safe3"]) +@pytest.mark.setup_client(pin=None) +def test_set_brightness(client: Client): + with client: + IF = InputFlowSetBrightness(client) + client.set_input_flow(IF.get()) + # Set brightness to a default value + device.set_brightness( + client, + None, + ) diff --git a/tests/input_flows.py b/tests/input_flows.py index 79dbc566733..900cf0cd7c6 100644 --- a/tests/input_flows.py +++ b/tests/input_flows.py @@ -291,6 +291,23 @@ def input_flow_t3t1(self) -> BRGeneratorType: self.debug.press_yes() +class InputFlowSetBrightness(InputFlowBase): + def __init__(self, client: Client): + super().__init__(client) + + def input_flow_tt(self) -> BRGeneratorType: + self.debug.press_yes() + yield + self.debug.press_yes() + yield + + def input_flow_t3t1(self) -> BRGeneratorType: + self.debug.swipe_up() + yield + self.debug.press_yes() + yield + + class InputFlowShowAddressQRCode(InputFlowBase): def __init__(self, client: Client): super().__init__(client)