Merge lp:~mterry/unity-system-compositor/wake-screen-on-press into lp:unity-system-compositor

Proposed by Michael Terry
Status: Merged
Approved by: Alan Griffiths
Approved revision: 210
Merged at revision: 216
Proposed branch: lp:~mterry/unity-system-compositor/wake-screen-on-press
Merge into: lp:unity-system-compositor
Diff against target: 246 lines (+44/-22)
8 files modified
src/mir_screen.cpp (+2/-5)
src/mir_screen.h (+1/-1)
src/screen.h (+1/-1)
src/screen_event_handler.cpp (+16/-2)
src/screen_event_handler.h (+1/-0)
tests/integration-tests/test_unity_screen_service.cpp (+1/-1)
tests/unit-tests/test_mir_screen.cpp (+8/-5)
tests/unit-tests/test_screen_event_handler.cpp (+14/-7)
To merge this branch: bzr merge lp:~mterry/unity-system-compositor/wake-screen-on-press
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+257181@code.launchpad.net

Commit message

Wake screen immediately upon a power button press, not its release.

Description of the change

Wake screen immediately upon a power button press, not its release.

This is a break out fix noticed in bug 1446298.

Android turns on the screen immediately upon receiving a press (and turns it off upon receiving a release like we do). This makes it feel snappier and seems like the correct thing to do (what are we waiting for anyway?).

So I've made USC turn the screen on if the display is off when the power is pressed. I've also removed a method that is no longer used (since we are never in a position where we simply toggle the screen anymore -- we always know a specific target state).

I only tested this patch on vivid's USC (not trunk's). Some files changed names and such, but the code was the same. It was faster than before (didn't wait a full long-press time), but still surprisingly non-immediate. Why would that be?

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Tests need update.

209. By Michael Terry

Fix test

210. By Michael Terry

Merge from trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Seems to do what's intended.

I'm not sure who's the right authority on whether it is a good idea, so not TAing.

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Nobody seems to object.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/mir_screen.cpp'
2--- src/mir_screen.cpp 2015-03-16 10:24:45 +0000
3+++ src/mir_screen.cpp 2015-04-29 14:39:31 +0000
4@@ -79,13 +79,10 @@
5 enable_inactivity_timers_l(enable);
6 }
7
8-void usc::MirScreen::toggle_screen_power_mode(PowerStateChangeReason reason)
9+MirPowerMode usc::MirScreen::get_screen_power_mode()
10 {
11 std::lock_guard<std::mutex> lock{guard};
12- MirPowerMode new_mode = (current_power_mode == MirPowerMode::mir_power_mode_on) ?
13- MirPowerMode::mir_power_mode_off : MirPowerMode::mir_power_mode_on;
14-
15- set_screen_power_mode_l(new_mode, reason);
16+ return current_power_mode;
17 }
18
19 void usc::MirScreen::set_screen_power_mode(MirPowerMode mode, PowerStateChangeReason reason)
20
21=== modified file 'src/mir_screen.h'
22--- src/mir_screen.h 2015-03-16 10:24:45 +0000
23+++ src/mir_screen.h 2015-04-29 14:39:31 +0000
24@@ -51,9 +51,9 @@
25 ~MirScreen();
26
27 void enable_inactivity_timers(bool enable) override;
28- void toggle_screen_power_mode(PowerStateChangeReason reason) override;
29 void keep_display_on_temporarily() override;
30
31+ MirPowerMode get_screen_power_mode() override;
32 void set_screen_power_mode(MirPowerMode mode, PowerStateChangeReason reason) override;
33 void keep_display_on(bool on) override;
34 void set_brightness(int brightness) override;
35
36=== modified file 'src/screen.h'
37--- src/screen.h 2015-02-18 14:40:29 +0000
38+++ src/screen.h 2015-04-29 14:39:31 +0000
39@@ -33,9 +33,9 @@
40 virtual ~Screen() = default;
41
42 virtual void enable_inactivity_timers(bool enable) = 0;
43- virtual void toggle_screen_power_mode(PowerStateChangeReason reason) = 0;
44 virtual void keep_display_on_temporarily() = 0;
45
46+ virtual MirPowerMode get_screen_power_mode() = 0;
47 virtual void set_screen_power_mode(MirPowerMode mode, PowerStateChangeReason reason) = 0;
48 virtual void keep_display_on(bool on) = 0;
49 virtual void set_brightness(int brightness) = 0;
50
51=== modified file 'src/screen_event_handler.cpp'
52--- src/screen_event_handler.cpp 2015-04-07 13:36:48 +0000
53+++ src/screen_event_handler.cpp 2015-04-29 14:39:31 +0000
54@@ -35,6 +35,7 @@
55 shutdown_timeout{shutdown_timeout},
56 shutdown{shutdown},
57 long_press_detected{false},
58+ mode_at_press_start{MirPowerMode::mir_power_mode_off},
59 shutdown_alarm{alarm_factory->create_alarm([this]{ shutdown_alarm_notification(); })},
60 long_press_alarm{alarm_factory->create_alarm([this]{ long_press_notification(); })}
61 {
62@@ -77,6 +78,14 @@
63 void usc::ScreenEventHandler::power_key_down()
64 {
65 std::lock_guard<std::mutex> lock{guard};
66+
67+ mode_at_press_start = screen->get_screen_power_mode();
68+ if (mode_at_press_start == MirPowerMode::mir_power_mode_off)
69+ {
70+ screen->set_screen_power_mode(
71+ MirPowerMode::mir_power_mode_on, PowerStateChangeReason::power_key);
72+ }
73+
74 screen->enable_inactivity_timers(false);
75 long_press_detected = false;
76 long_press_alarm->reschedule_in(power_key_ignore_timeout);
77@@ -88,9 +97,11 @@
78 std::lock_guard<std::mutex> lock{guard};
79 shutdown_alarm->cancel();
80 long_press_alarm->cancel();
81- if (!long_press_detected)
82+
83+ if (mode_at_press_start == MirPowerMode::mir_power_mode_on && !long_press_detected)
84 {
85- screen->toggle_screen_power_mode(PowerStateChangeReason::power_key);
86+ screen->set_screen_power_mode(
87+ MirPowerMode::mir_power_mode_off, PowerStateChangeReason::power_key);
88 }
89 }
90
91@@ -103,6 +114,9 @@
92
93 void usc::ScreenEventHandler::long_press_notification()
94 {
95+ // We know the screen is already on after power_key_down(), but we turn the
96+ // screen on here to ensure that it is also at full brightness for the
97+ // presumed system power dialog that will appear.
98 screen->set_screen_power_mode(
99 MirPowerMode::mir_power_mode_on, PowerStateChangeReason::power_key);
100 long_press_detected = true;
101
102=== modified file 'src/screen_event_handler.h'
103--- src/screen_event_handler.h 2015-04-07 13:36:48 +0000
104+++ src/screen_event_handler.h 2015-04-29 14:39:31 +0000
105@@ -65,6 +65,7 @@
106 std::function<void()> const shutdown;
107
108 std::atomic<bool> long_press_detected;
109+ std::atomic<MirPowerMode> mode_at_press_start;
110 std::unique_ptr<mir::time::Alarm> shutdown_alarm;
111 std::unique_ptr<mir::time::Alarm> long_press_alarm;
112 };
113
114=== modified file 'tests/integration-tests/test_unity_screen_service.cpp'
115--- tests/integration-tests/test_unity_screen_service.cpp 2015-03-18 13:06:10 +0000
116+++ tests/integration-tests/test_unity_screen_service.cpp 2015-04-29 14:39:31 +0000
117@@ -40,9 +40,9 @@
118 struct MockScreen : usc::Screen
119 {
120 MOCK_METHOD1(enable_inactivity_timers, void(bool enable));
121- MOCK_METHOD1(toggle_screen_power_mode, void(PowerStateChangeReason reason));
122 MOCK_METHOD0(keep_display_on_temporarily, void());
123
124+ MOCK_METHOD0(get_screen_power_mode, MirPowerMode());
125 MOCK_METHOD2(set_screen_power_mode, void(MirPowerMode mode, PowerStateChangeReason reason));
126 MOCK_METHOD1(keep_display_on, void(bool on));
127 MOCK_METHOD1(set_brightness, void(int brightness));
128
129=== modified file 'tests/unit-tests/test_mir_screen.cpp'
130--- tests/unit-tests/test_mir_screen.cpp 2015-03-16 10:24:45 +0000
131+++ tests/unit-tests/test_mir_screen.cpp 2015-04-29 14:39:31 +0000
132@@ -298,18 +298,20 @@
133 timer->advance_by(power_off_timeout);
134 }
135
136-TEST_F(AMirScreen, toggle_screen_power_mode_from_on_to_off)
137+TEST_F(AMirScreen, set_screen_power_mode_from_on_to_off)
138 {
139 expect_screen_is_turned_off();
140- mir_screen.toggle_screen_power_mode(PowerStateChangeReason::power_key);
141+ mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
142+ PowerStateChangeReason::power_key);
143 }
144
145-TEST_F(AMirScreen, toggle_screen_power_mode_from_off_to_on)
146+TEST_F(AMirScreen, set_screen_power_mode_from_off_to_on)
147 {
148 turn_screen_off();
149
150 expect_screen_is_turned_on();
151- mir_screen.toggle_screen_power_mode(PowerStateChangeReason::power_key);
152+ mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
153+ PowerStateChangeReason::power_key);
154 }
155
156 TEST_F(AMirScreen, sets_hardware_brightness)
157@@ -359,7 +361,8 @@
158 mir_screen.register_power_state_change_handler(handler);
159
160 auto const toggle_reason = PowerStateChangeReason::power_key;
161- mir_screen.toggle_screen_power_mode(PowerStateChangeReason::power_key);
162+ mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
163+ PowerStateChangeReason::power_key);
164
165 EXPECT_THAT(handler_reason, Eq(toggle_reason));
166 EXPECT_THAT(handler_mode, Eq(MirPowerMode::mir_power_mode_off));
167
168=== modified file 'tests/unit-tests/test_screen_event_handler.cpp'
169--- tests/unit-tests/test_screen_event_handler.cpp 2015-04-07 13:36:48 +0000
170+++ tests/unit-tests/test_screen_event_handler.cpp 2015-04-29 14:39:31 +0000
171@@ -36,9 +36,9 @@
172 struct MockScreen : usc::Screen
173 {
174 MOCK_METHOD1(enable_inactivity_timers, void(bool enable));
175- MOCK_METHOD1(toggle_screen_power_mode, void(PowerStateChangeReason reason));
176 MOCK_METHOD0(keep_display_on_temporarily, void());
177
178+ MirPowerMode get_screen_power_mode() override {return mock_mode;}
179 MOCK_METHOD2(set_screen_power_mode, void(MirPowerMode mode, PowerStateChangeReason reason));
180 MOCK_METHOD1(keep_display_on, void(bool on));
181 MOCK_METHOD1(set_brightness, void(int brightness));
182@@ -48,6 +48,8 @@
183 MOCK_METHOD1(set_touch_visualization_enabled, void(bool enabled));
184 MOCK_METHOD1(register_power_state_change_handler, void(
185 usc::PowerStateChangeHandler const& handler));
186+
187+ MirPowerMode mock_mode = MirPowerMode::mir_power_mode_off;
188 };
189
190 struct AScreenEventHandler : testing::Test
191@@ -101,7 +103,7 @@
192
193 }
194
195-TEST_F(AScreenEventHandler, turns_screen_on_on_long_press)
196+TEST_F(AScreenEventHandler, turns_screen_on_immediately_on_press)
197 {
198 auto const long_press_duration = power_key_ignore_timeout;
199
200@@ -110,7 +112,6 @@
201 PowerStateChangeReason::power_key));
202
203 press_power_key();
204- timer.advance_by(long_press_duration);
205 }
206
207 TEST_F(AScreenEventHandler, shuts_down_system_when_power_key_pressed_for_long_enough)
208@@ -158,28 +159,34 @@
209 move_pointer();
210 }
211
212-TEST_F(AScreenEventHandler, toggles_screen_mode_on_normal_press_release)
213+TEST_F(AScreenEventHandler, sets_screen_mode_off_normal_press_release)
214 {
215 std::chrono::milliseconds const normal_press_duration{100};
216
217 EXPECT_CALL(mock_screen,
218- toggle_screen_power_mode(PowerStateChangeReason::power_key));
219+ set_screen_power_mode(MirPowerMode::mir_power_mode_off,
220+ PowerStateChangeReason::power_key));
221
222+ mock_screen.mock_mode = MirPowerMode::mir_power_mode_on;
223 press_power_key();
224 timer.advance_by(normal_press_duration);
225 release_power_key();
226 }
227
228-TEST_F(AScreenEventHandler, does_not_toggle_screen_mode_on_long_press_release)
229+TEST_F(AScreenEventHandler, does_not_set_screen_mode_off_long_press_release)
230 {
231 using namespace testing;
232
233 auto const long_press_duration = power_key_ignore_timeout;
234
235 EXPECT_CALL(mock_screen,
236- toggle_screen_power_mode(_))
237+ set_screen_power_mode(MirPowerMode::mir_power_mode_on,
238+ PowerStateChangeReason::power_key));
239+ EXPECT_CALL(mock_screen,
240+ set_screen_power_mode(MirPowerMode::mir_power_mode_off, _))
241 .Times(0);
242
243+ mock_screen.mock_mode = MirPowerMode::mir_power_mode_on;
244 press_power_key();
245 timer.advance_by(long_press_duration);
246 release_power_key();

Subscribers

People subscribed via source and target branches