Light the screen (dimmed) while a Notification's Toast shows

An Off screen turns on dimmed for the Toast's duration so the user can
see what beeped. It isn't user activity: the timeouts aren't restarted,
and a key pressed meanwhile reaches the App.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
2026-10-02 11:35:13 +02:00
co-authored by Claude Opus 5.5
parent 15ea53e17f
commit 9218a34c3e
7 changed files with 65 additions and 1 deletions
+37
View File
@@ -38,6 +38,39 @@ void test_new_timeouts_apply_immediately() {
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Off), static_cast<int>(p.update(20000)));
}
void test_notification_lights_an_off_screen_dimmed_until_it_ends() {
PowerPolicy p(30000, 60000);
p.activity(0);
p.update(70000); // off
p.notify(70000, 73000);
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Dimmed), static_cast<int>(p.update(70001)));
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Dimmed), static_cast<int>(p.update(72999)));
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Off), static_cast<int>(p.update(73000)));
}
void test_notification_does_not_count_as_activity() {
PowerPolicy p(30000, 60000);
p.activity(0);
p.notify(25000, 28000);
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::Dimmed), static_cast<int>(p.update(30000)));
}
void test_notification_never_brightens_or_dims_an_on_screen() {
PowerPolicy p(30000, 60000);
p.activity(0);
p.notify(1000, 4000);
TEST_ASSERT_EQUAL(static_cast<int>(ScreenState::On), static_cast<int>(p.update(2000)));
}
void test_key_on_a_notification_lit_screen_acts() {
PowerPolicy p(30000, 60000);
p.activity(0);
p.update(70000);
p.notify(70000, 73000);
p.update(70001);
TEST_ASSERT_FALSE(p.activity(71000)); // the screen is visible: the key reaches the App
}
void test_short_press_reported_on_release() {
PowerButton b(2000);
TEST_ASSERT_EQUAL(static_cast<int>(ButtonAction::None), static_cast<int>(b.update(true, 0)));
@@ -59,6 +92,10 @@ int main() {
RUN_TEST(test_key_on_dimmed_screen_wakes_and_still_acts);
RUN_TEST(test_key_on_off_screen_only_wakes);
RUN_TEST(test_new_timeouts_apply_immediately);
RUN_TEST(test_notification_lights_an_off_screen_dimmed_until_it_ends);
RUN_TEST(test_notification_does_not_count_as_activity);
RUN_TEST(test_notification_never_brightens_or_dims_an_on_screen);
RUN_TEST(test_key_on_a_notification_lit_screen_acts);
RUN_TEST(test_short_press_reported_on_release);
RUN_TEST(test_long_press_fires_once_while_still_held);
return UNITY_END();