Merge lp:~afrantzis/unity-system-compositor/notification-timeouts into lp:unity-system-compositor
- notification-timeouts
- Merge into trunk
Proposed by
Alexandros Frantzis
Status: | Merged |
---|---|
Approved by: | Alexandros Frantzis |
Approved revision: | 230 |
Merged at revision: | 236 |
Proposed branch: | lp:~afrantzis/unity-system-compositor/notification-timeouts |
Merge into: | lp:unity-system-compositor |
Diff against target: |
773 lines (+374/-56) 12 files modified
src/CMakeLists.txt (+1/-0) src/clock.h (+41/-0) src/mir_screen.cpp (+49/-17) src/mir_screen.h (+18/-5) src/power_state_change_reason.h (+2/-1) src/server.cpp (+19/-2) src/server.h (+17/-0) src/steady_clock.cpp (+22/-0) src/steady_clock.h (+36/-0) tests/unit-tests/advanceable_timer.cpp (+9/-15) tests/unit-tests/advanceable_timer.h (+8/-3) tests/unit-tests/test_mir_screen.cpp (+152/-13) |
To merge this branch: | bzr merge lp:~afrantzis/unity-system-compositor/notification-timeouts |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alan Griffiths | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+264853@code.launchpad.net |
Commit message
Support different screen timeout values for notifications.
Description of the change
Support different screen timeout values for notifications.
The notification timeouts are configurable during USC startup as Mir options (either command line or env. variables). Their default values are 15s for power-off and 12s for dimming.
Other components that want to wake the screen up for a notification need to use the existing dbus method:
com.canonical.
with mode 1 (on) and reason 'notification' (= integer value 4)
To post a comment you must log in.
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 : | # |
Looks reasonable
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/CMakeLists.txt' |
2 | --- src/CMakeLists.txt 2015-04-07 13:36:48 +0000 |
3 | +++ src/CMakeLists.txt 2015-07-15 14:20:45 +0000 |
4 | @@ -25,6 +25,7 @@ |
5 | screen_event_handler.cpp |
6 | server.cpp |
7 | session_switcher.cpp |
8 | + steady_clock.cpp |
9 | system_compositor.cpp |
10 | thread_name.cpp |
11 | unity_screen_service.cpp |
12 | |
13 | === added file 'src/clock.h' |
14 | --- src/clock.h 1970-01-01 00:00:00 +0000 |
15 | +++ src/clock.h 2015-07-15 14:20:45 +0000 |
16 | @@ -0,0 +1,41 @@ |
17 | +/* |
18 | + * Copyright © 2015 Canonical Ltd. |
19 | + * |
20 | + * This program is free software: you can redistribute it and/or modify |
21 | + * it under the terms of the GNU General Public License version 3 as |
22 | + * published by the Free Software Foundation. |
23 | + * |
24 | + * This program is distributed in the hope that it will be useful, |
25 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 | + * GNU General Public License for more details. |
28 | + * |
29 | + * You should have received a copy of the GNU General Public License |
30 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31 | + */ |
32 | + |
33 | +#ifndef USC_CLOCK_H_ |
34 | +#define USC_CLOCK_H_ |
35 | + |
36 | +#include <mir/time/types.h> |
37 | +#include <chrono> |
38 | + |
39 | +namespace usc |
40 | +{ |
41 | + |
42 | +class Clock |
43 | +{ |
44 | +public: |
45 | + virtual ~Clock() = default; |
46 | + |
47 | + virtual mir::time::Timestamp now() const = 0; |
48 | + |
49 | +protected: |
50 | + Clock() = default; |
51 | + Clock(Clock const&) = delete; |
52 | + Clock& operator=(Clock const&) = delete; |
53 | +}; |
54 | + |
55 | +} |
56 | + |
57 | +#endif |
58 | |
59 | === modified file 'src/mir_screen.cpp' |
60 | --- src/mir_screen.cpp 2015-04-22 21:01:37 +0000 |
61 | +++ src/mir_screen.cpp 2015-07-15 14:20:45 +0000 |
62 | @@ -15,6 +15,7 @@ |
63 | */ |
64 | |
65 | #include "mir_screen.h" |
66 | +#include "clock.h" |
67 | |
68 | #include <mir/main_loop.h> |
69 | #include <mir/time/alarm_factory.h> |
70 | @@ -37,19 +38,21 @@ |
71 | std::shared_ptr<mir::graphics::Display> const& display, |
72 | std::shared_ptr<mir::input::TouchVisualizer> const& touch_visualizer, |
73 | std::shared_ptr<mir::time::AlarmFactory> const& alarm_factory, |
74 | - std::chrono::milliseconds power_off_timeout, |
75 | - std::chrono::milliseconds dimmer_timeout) |
76 | + std::shared_ptr<usc::Clock> const& clock, |
77 | + Timeouts inactivity_timeouts, |
78 | + Timeouts notification_timeouts) |
79 | : screen_hardware{screen_hardware}, |
80 | compositor{compositor}, |
81 | display{display}, |
82 | touch_visualizer{touch_visualizer}, |
83 | alarm_factory{alarm_factory}, |
84 | + clock{clock}, |
85 | power_off_alarm{alarm_factory->create_alarm( |
86 | std::bind(&usc::MirScreen::power_off_alarm_notification, this))}, |
87 | dimmer_alarm{alarm_factory->create_alarm( |
88 | std::bind(&usc::MirScreen::dimmer_alarm_notification, this))}, |
89 | - power_off_timeout{power_off_timeout}, |
90 | - dimming_timeout{dimmer_timeout}, |
91 | + inactivity_timeouts(inactivity_timeouts), |
92 | + notification_timeouts(notification_timeouts), |
93 | current_power_mode{MirPowerMode::mir_power_mode_on}, |
94 | restart_timers{true}, |
95 | power_state_change_handler{[](MirPowerMode,PowerStateChangeReason){}} |
96 | @@ -60,7 +63,7 @@ |
97 | * to this point. See bug #1410381. |
98 | */ |
99 | compositor->start(); |
100 | - reset_timers_l(); |
101 | + reset_timers_l(PowerStateChangeReason::inactivity); |
102 | } |
103 | |
104 | usc::MirScreen::~MirScreen() = default; |
105 | @@ -68,7 +71,7 @@ |
106 | void usc::MirScreen::keep_display_on_temporarily() |
107 | { |
108 | std::lock_guard<std::mutex> lock{guard}; |
109 | - reset_timers_l(); |
110 | + reset_timers_l(PowerStateChangeReason::inactivity); |
111 | if (current_power_mode == MirPowerMode::mir_power_mode_on) |
112 | screen_hardware->set_normal_backlight(); |
113 | } |
114 | @@ -121,13 +124,13 @@ |
115 | std::chrono::seconds the_dimming_timeout{raw_dimmer_timeout}; |
116 | |
117 | if (raw_poweroff_timeout >= 0) |
118 | - power_off_timeout = std::chrono::duration_cast<std::chrono::milliseconds>(the_power_off_timeout); |
119 | + inactivity_timeouts.power_off_timeout = std::chrono::duration_cast<std::chrono::milliseconds>(the_power_off_timeout); |
120 | |
121 | if (raw_dimmer_timeout >= 0) |
122 | - dimming_timeout = std::chrono::duration_cast<std::chrono::milliseconds>(the_dimming_timeout); |
123 | + inactivity_timeouts.dimming_timeout = std::chrono::duration_cast<std::chrono::milliseconds>(the_dimming_timeout); |
124 | |
125 | cancel_timers_l(); |
126 | - reset_timers_l(); |
127 | + reset_timers_l(PowerStateChangeReason::inactivity); |
128 | } |
129 | |
130 | void usc::MirScreen::set_screen_power_mode_l(MirPowerMode mode, PowerStateChangeReason reason) |
131 | @@ -138,7 +141,7 @@ |
132 | if (current_power_mode == MirPowerMode::mir_power_mode_on) |
133 | screen_hardware->set_normal_backlight(); |
134 | configure_display_l(mode, reason); |
135 | - reset_timers_l(); |
136 | + reset_timers_l(reason); |
137 | } |
138 | else |
139 | { |
140 | @@ -194,38 +197,67 @@ |
141 | { |
142 | power_off_alarm->cancel(); |
143 | dimmer_alarm->cancel(); |
144 | + next_power_off = {}; |
145 | + next_dimming = {}; |
146 | } |
147 | |
148 | -void usc::MirScreen::reset_timers_l() |
149 | +void usc::MirScreen::reset_timers_l(PowerStateChangeReason reason) |
150 | { |
151 | if (restart_timers && current_power_mode != MirPowerMode::mir_power_mode_off) |
152 | { |
153 | - if (power_off_timeout.count() > 0) |
154 | - power_off_alarm->reschedule_in(power_off_timeout); |
155 | - |
156 | - if (dimming_timeout.count() > 0) |
157 | - dimmer_alarm->reschedule_in(dimming_timeout); |
158 | + auto const timeouts = timeouts_for(reason); |
159 | + auto const now = clock->now(); |
160 | + |
161 | + if (timeouts.power_off_timeout.count() > 0) |
162 | + { |
163 | + auto const new_next_power_off = now + timeouts.power_off_timeout; |
164 | + if (new_next_power_off > next_power_off) |
165 | + { |
166 | + power_off_alarm->reschedule_in(timeouts.power_off_timeout); |
167 | + next_power_off = new_next_power_off; |
168 | + } |
169 | + } |
170 | + |
171 | + if (timeouts.dimming_timeout.count() > 0) |
172 | + { |
173 | + auto const new_next_dimming = now + timeouts.dimming_timeout; |
174 | + if (new_next_dimming > next_dimming) |
175 | + { |
176 | + dimmer_alarm->reschedule_in(timeouts.dimming_timeout); |
177 | + next_dimming = new_next_dimming; |
178 | + } |
179 | + } |
180 | } |
181 | } |
182 | |
183 | void usc::MirScreen::enable_inactivity_timers_l(bool enable) |
184 | { |
185 | if (enable) |
186 | - reset_timers_l(); |
187 | + reset_timers_l(PowerStateChangeReason::inactivity); |
188 | else |
189 | cancel_timers_l(); |
190 | } |
191 | |
192 | +usc::MirScreen::Timeouts usc::MirScreen::timeouts_for(PowerStateChangeReason reason) |
193 | +{ |
194 | + if (reason == PowerStateChangeReason::notification) |
195 | + return notification_timeouts; |
196 | + else |
197 | + return inactivity_timeouts; |
198 | +} |
199 | + |
200 | void usc::MirScreen::power_off_alarm_notification() |
201 | { |
202 | std::lock_guard<std::mutex> lock{guard}; |
203 | configure_display_l(MirPowerMode::mir_power_mode_off, PowerStateChangeReason::inactivity); |
204 | + next_power_off = {}; |
205 | } |
206 | |
207 | void usc::MirScreen::dimmer_alarm_notification() |
208 | { |
209 | std::lock_guard<std::mutex> lock{guard}; |
210 | screen_hardware->set_dim_backlight(); |
211 | + next_dimming = {}; |
212 | } |
213 | |
214 | void usc::MirScreen::set_touch_visualization_enabled(bool enabled) |
215 | |
216 | === modified file 'src/mir_screen.h' |
217 | --- src/mir_screen.h 2015-04-22 21:01:37 +0000 |
218 | +++ src/mir_screen.h 2015-07-15 14:20:45 +0000 |
219 | @@ -18,6 +18,7 @@ |
220 | #define USC_MIR_SCREEN_H_ |
221 | |
222 | #include "screen.h" |
223 | +#include <mir/time/types.h> |
224 | |
225 | #include <chrono> |
226 | #include <memory> |
227 | @@ -37,17 +38,25 @@ |
228 | { |
229 | class Server; |
230 | class ScreenHardware; |
231 | +class Clock; |
232 | |
233 | class MirScreen: public Screen |
234 | { |
235 | public: |
236 | + struct Timeouts |
237 | + { |
238 | + std::chrono::milliseconds power_off_timeout; |
239 | + std::chrono::milliseconds dimming_timeout; |
240 | + }; |
241 | + |
242 | MirScreen(std::shared_ptr<usc::ScreenHardware> const& screen_hardware, |
243 | std::shared_ptr<mir::compositor::Compositor> const& compositor, |
244 | std::shared_ptr<mir::graphics::Display> const& display, |
245 | std::shared_ptr<mir::input::TouchVisualizer> const& touch_visualizer, |
246 | std::shared_ptr<mir::time::AlarmFactory> const& alarm_factory, |
247 | - std::chrono::milliseconds power_off_timeout, |
248 | - std::chrono::milliseconds dimmer_timeout); |
249 | + std::shared_ptr<usc::Clock> const& clock, |
250 | + Timeouts inactivity_timeouts, |
251 | + Timeouts notification_timeouts); |
252 | ~MirScreen(); |
253 | |
254 | void enable_inactivity_timers(bool enable) override; |
255 | @@ -69,8 +78,9 @@ |
256 | void configure_display_l(MirPowerMode mode, PowerStateChangeReason reason); |
257 | |
258 | void cancel_timers_l(); |
259 | - void reset_timers_l(); |
260 | + void reset_timers_l(PowerStateChangeReason reason); |
261 | void enable_inactivity_timers_l(bool flag); |
262 | + Timeouts timeouts_for(PowerStateChangeReason reason); |
263 | |
264 | void power_off_alarm_notification(); |
265 | void dimmer_alarm_notification(); |
266 | @@ -81,12 +91,15 @@ |
267 | std::shared_ptr<mir::graphics::Display> const display; |
268 | std::shared_ptr<mir::input::TouchVisualizer> const touch_visualizer; |
269 | std::shared_ptr<mir::time::AlarmFactory> const alarm_factory; |
270 | + std::shared_ptr<usc::Clock> const clock; |
271 | std::unique_ptr<mir::time::Alarm> const power_off_alarm; |
272 | std::unique_ptr<mir::time::Alarm> const dimmer_alarm; |
273 | |
274 | std::mutex guard; |
275 | - std::chrono::milliseconds power_off_timeout; |
276 | - std::chrono::milliseconds dimming_timeout; |
277 | + Timeouts inactivity_timeouts; |
278 | + Timeouts notification_timeouts; |
279 | + mir::time::Timestamp next_power_off{}; |
280 | + mir::time::Timestamp next_dimming{}; |
281 | MirPowerMode current_power_mode; |
282 | bool restart_timers; |
283 | PowerStateChangeHandler power_state_change_handler; |
284 | |
285 | === modified file 'src/power_state_change_reason.h' |
286 | --- src/power_state_change_reason.h 2014-06-17 00:35:13 +0000 |
287 | +++ src/power_state_change_reason.h 2015-07-15 14:20:45 +0000 |
288 | @@ -22,7 +22,8 @@ |
289 | unknown = 0, |
290 | inactivity = 1, |
291 | power_key = 2, |
292 | - proximity = 3 |
293 | + proximity = 3, |
294 | + notification = 4 |
295 | }; |
296 | |
297 | #endif |
298 | |
299 | === modified file 'src/server.cpp' |
300 | --- src/server.cpp 2015-06-03 16:21:07 +0000 |
301 | +++ src/server.cpp 2015-07-15 14:20:45 +0000 |
302 | @@ -25,6 +25,7 @@ |
303 | #include "screen_event_handler.h" |
304 | #include "powerd_mediator.h" |
305 | #include "unity_screen_service.h" |
306 | +#include "steady_clock.h" |
307 | |
308 | #include <mir/input/cursor_listener.h> |
309 | #include <mir/server_status_listener.h> |
310 | @@ -117,6 +118,8 @@ |
311 | add_configuration_option("shutdown-timeout", "The time in milli-seconds the power key must be held to initiate a clean system shutdown", mir::OptionType::integer); |
312 | add_configuration_option("power-key-ignore-timeout", "The time in milli-seconds the power key must be held to ignore - must be less than shutdown-timeout", mir::OptionType::integer); |
313 | add_configuration_option("disable-inactivity-policy", "Disables handling user inactivity and power key", mir::OptionType::boolean); |
314 | + add_configuration_option("notification-display-off-timeout", "The time in seconds before the screen is turned off after a notification arrives", mir::OptionType::integer); |
315 | + add_configuration_option("notification-display-dim-timeout", "The time in seconds before the screen is dimmed after a notification arrives", mir::OptionType::integer); |
316 | |
317 | set_command_line(argc, const_cast<char const **>(argv)); |
318 | |
319 | @@ -237,8 +240,13 @@ |
320 | the_display(), |
321 | the_touch_visualizer(), |
322 | the_main_loop(), |
323 | - inactivity_display_off_timeout(), |
324 | - inactivity_display_dim_timeout()); |
325 | + the_clock(), |
326 | + MirScreen::Timeouts{ |
327 | + inactivity_display_off_timeout(), |
328 | + inactivity_display_dim_timeout()}, |
329 | + MirScreen::Timeouts{ |
330 | + notification_display_off_timeout(), |
331 | + notification_display_dim_timeout()}); |
332 | }); |
333 | } |
334 | |
335 | @@ -276,6 +284,15 @@ |
336 | }); |
337 | } |
338 | |
339 | +std::shared_ptr<usc::Clock> usc::Server::the_clock() |
340 | +{ |
341 | + return clock( |
342 | + [this] |
343 | + { |
344 | + return std::make_shared<SteadyClock>(); |
345 | + }); |
346 | +} |
347 | + |
348 | std::string usc::Server::dbus_bus_address() |
349 | { |
350 | static char const* const default_bus_address{"unix:path=/var/run/dbus/system_bus_socket"}; |
351 | |
352 | === modified file 'src/server.h' |
353 | --- src/server.h 2015-04-24 14:40:28 +0000 |
354 | +++ src/server.h 2015-07-15 14:20:45 +0000 |
355 | @@ -42,6 +42,7 @@ |
356 | class Screen; |
357 | class ScreenHardware; |
358 | class UnityScreenService; |
359 | +class Clock; |
360 | |
361 | class Server : private mir::Server |
362 | { |
363 | @@ -63,6 +64,7 @@ |
364 | virtual std::shared_ptr<mir::input::EventFilter> the_screen_event_handler(); |
365 | virtual std::shared_ptr<ScreenHardware> the_screen_hardware(); |
366 | virtual std::shared_ptr<UnityScreenService> the_unity_screen_service(); |
367 | + virtual std::shared_ptr<Clock> the_clock(); |
368 | |
369 | bool show_version() |
370 | { |
371 | @@ -110,6 +112,20 @@ |
372 | seconds{the_options()->get("inactivity-display-dim-timeout", 45)}); |
373 | } |
374 | |
375 | + std::chrono::milliseconds notification_display_off_timeout() |
376 | + { |
377 | + using namespace std::chrono; |
378 | + return duration_cast<milliseconds>( |
379 | + seconds{the_options()->get("notification-display-off-timeout", 15)}); |
380 | + } |
381 | + |
382 | + std::chrono::milliseconds notification_display_dim_timeout() |
383 | + { |
384 | + using namespace std::chrono; |
385 | + return duration_cast<milliseconds>( |
386 | + seconds{the_options()->get("notification-display-dim-timeout", 12)}); |
387 | + } |
388 | + |
389 | std::chrono::milliseconds shutdown_timeout() |
390 | { |
391 | return std::chrono::milliseconds{ |
392 | @@ -145,6 +161,7 @@ |
393 | mir::CachedPtr<mir::input::EventFilter> screen_event_handler; |
394 | mir::CachedPtr<ScreenHardware> screen_hardware; |
395 | mir::CachedPtr<UnityScreenService> unity_screen_service; |
396 | + mir::CachedPtr<Clock> clock; |
397 | }; |
398 | |
399 | } |
400 | |
401 | === added file 'src/steady_clock.cpp' |
402 | --- src/steady_clock.cpp 1970-01-01 00:00:00 +0000 |
403 | +++ src/steady_clock.cpp 2015-07-15 14:20:45 +0000 |
404 | @@ -0,0 +1,22 @@ |
405 | +/* |
406 | + * Copyright © 2015 Canonical Ltd. |
407 | + * |
408 | + * This program is free software: you can redistribute it and/or modify |
409 | + * it under the terms of the GNU General Public License version 3 as |
410 | + * published by the Free Software Foundation. |
411 | + * |
412 | + * This program is distributed in the hope that it will be useful, |
413 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
414 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
415 | + * GNU General Public License for more details. |
416 | + * |
417 | + * You should have received a copy of the GNU General Public License |
418 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
419 | + */ |
420 | + |
421 | +#include "steady_clock.h" |
422 | + |
423 | +mir::time::Timestamp usc::SteadyClock::now() const |
424 | +{ |
425 | + return clock.now(); |
426 | +} |
427 | |
428 | === added file 'src/steady_clock.h' |
429 | --- src/steady_clock.h 1970-01-01 00:00:00 +0000 |
430 | +++ src/steady_clock.h 2015-07-15 14:20:45 +0000 |
431 | @@ -0,0 +1,36 @@ |
432 | +/* |
433 | + * Copyright © 2015 Canonical Ltd. |
434 | + * |
435 | + * This program is free software: you can redistribute it and/or modify |
436 | + * it under the terms of the GNU General Public License version 3 as |
437 | + * published by the Free Software Foundation. |
438 | + * |
439 | + * This program is distributed in the hope that it will be useful, |
440 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
441 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
442 | + * GNU General Public License for more details. |
443 | + * |
444 | + * You should have received a copy of the GNU General Public License |
445 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
446 | + */ |
447 | + |
448 | +#ifndef USC_STEADY_CLOCK_H_ |
449 | +#define USC_STEADY_CLOCK_H_ |
450 | + |
451 | +#include "clock.h" |
452 | + |
453 | +namespace usc |
454 | +{ |
455 | + |
456 | +class SteadyClock : public Clock |
457 | +{ |
458 | +public: |
459 | + mir::time::Timestamp now() const override; |
460 | + |
461 | +private: |
462 | + std::chrono::steady_clock clock; |
463 | +}; |
464 | + |
465 | +} |
466 | + |
467 | +#endif |
468 | |
469 | === modified file 'tests/unit-tests/advanceable_timer.cpp' |
470 | --- tests/unit-tests/advanceable_timer.cpp 2015-03-16 10:24:45 +0000 |
471 | +++ tests/unit-tests/advanceable_timer.cpp 2015-07-15 14:20:45 +0000 |
472 | @@ -123,14 +123,8 @@ |
473 | std::unique_ptr<mir::time::Alarm> AdvanceableTimer::create_alarm( |
474 | std::function<void()> const& callback) |
475 | { |
476 | - decltype(now) now_tmp; |
477 | - { |
478 | - std::lock_guard<std::mutex> lock{now_mutex}; |
479 | - now_tmp = now; |
480 | - } |
481 | - |
482 | auto const adv_alarm = |
483 | - std::make_shared<detail::AdvanceableAlarm>(now_tmp, callback); |
484 | + std::make_shared<detail::AdvanceableAlarm>(now(), callback); |
485 | |
486 | register_alarm(adv_alarm); |
487 | |
488 | @@ -147,7 +141,7 @@ |
489 | { |
490 | { |
491 | std::lock_guard<std::mutex> lock{now_mutex}; |
492 | - now += advance; |
493 | + now_ += advance; |
494 | } |
495 | trigger_alarms(); |
496 | } |
497 | @@ -189,13 +183,7 @@ |
498 | if (alarm) |
499 | { |
500 | lock.unlock(); |
501 | - decltype(now) now_tmp; |
502 | - { |
503 | - std::lock_guard<std::mutex> lock{now_mutex}; |
504 | - now_tmp = now; |
505 | - } |
506 | - |
507 | - alarm->update_now(now_tmp); |
508 | + alarm->update_now(now()); |
509 | lock.lock(); |
510 | } |
511 | } |
512 | @@ -209,3 +197,9 @@ |
513 | }), |
514 | end(alarms)); |
515 | } |
516 | + |
517 | +mir::time::Timestamp AdvanceableTimer::now() const |
518 | +{ |
519 | + std::lock_guard<std::mutex> lock{now_mutex}; |
520 | + return now_; |
521 | +} |
522 | |
523 | === modified file 'tests/unit-tests/advanceable_timer.h' |
524 | --- tests/unit-tests/advanceable_timer.h 2015-03-16 10:24:45 +0000 |
525 | +++ tests/unit-tests/advanceable_timer.h 2015-07-15 14:20:45 +0000 |
526 | @@ -20,6 +20,7 @@ |
527 | #define USC_TESTS_ADVANCEABLE_TIMER_H_ |
528 | |
529 | #include <mir/time/alarm_factory.h> |
530 | +#include "src/clock.h" |
531 | |
532 | #include <vector> |
533 | #include <mutex> |
534 | @@ -30,22 +31,26 @@ |
535 | class AdvanceableAlarm; |
536 | } |
537 | |
538 | -class AdvanceableTimer : public mir::time::AlarmFactory |
539 | +class AdvanceableTimer : public mir::time::AlarmFactory, public usc::Clock |
540 | { |
541 | public: |
542 | + // mir::time::AlarmFactory |
543 | std::unique_ptr<mir::time::Alarm> create_alarm( |
544 | std::function<void()> const& callback) override; |
545 | std::unique_ptr<mir::time::Alarm> create_alarm( |
546 | std::shared_ptr<mir::LockableCallback> const& callback) override; |
547 | |
548 | + // usc::Clock |
549 | + mir::time::Timestamp now() const override; |
550 | + |
551 | void advance_by(std::chrono::milliseconds advance); |
552 | |
553 | private: |
554 | void register_alarm(std::shared_ptr<detail::AdvanceableAlarm> const& alarm); |
555 | void trigger_alarms(); |
556 | |
557 | - std::mutex now_mutex; |
558 | - mir::time::Timestamp now{}; |
559 | + mutable std::mutex now_mutex; |
560 | + mir::time::Timestamp now_{}; |
561 | std::mutex alarms_mutex; |
562 | std::vector<std::weak_ptr<detail::AdvanceableAlarm>> alarms; |
563 | }; |
564 | |
565 | === modified file 'tests/unit-tests/test_mir_screen.cpp' |
566 | --- tests/unit-tests/test_mir_screen.cpp 2015-04-29 14:30:49 +0000 |
567 | +++ tests/unit-tests/test_mir_screen.cpp 2015-07-15 14:20:45 +0000 |
568 | @@ -129,8 +129,17 @@ |
569 | |
570 | struct AMirScreen : testing::Test |
571 | { |
572 | - std::chrono::milliseconds power_off_timeout{5000}; |
573 | - std::chrono::milliseconds dimmer_timeout{4000}; |
574 | + std::chrono::seconds const power_off_timeout{60}; |
575 | + std::chrono::seconds const dimmer_timeout{50}; |
576 | + std::chrono::seconds const notification_power_off_timeout{15}; |
577 | + std::chrono::seconds const notification_dimmer_timeout{12}; |
578 | + |
579 | + std::chrono::seconds const five_seconds{5}; |
580 | + std::chrono::seconds const ten_seconds{10}; |
581 | + std::chrono::seconds const fifteen_seconds{15}; |
582 | + std::chrono::seconds const thirty_seconds{30}; |
583 | + std::chrono::seconds const fourty_seconds{40}; |
584 | + std::chrono::seconds const fifty_seconds{50}; |
585 | |
586 | void expect_screen_is_turned_off() |
587 | { |
588 | @@ -201,8 +210,9 @@ |
589 | display, |
590 | touch_visualizer, |
591 | timer, |
592 | - power_off_timeout, |
593 | - dimmer_timeout}; |
594 | + timer, |
595 | + {power_off_timeout, dimmer_timeout}, |
596 | + {notification_power_off_timeout, notification_dimmer_timeout}}; |
597 | }; |
598 | |
599 | } |
600 | @@ -259,31 +269,31 @@ |
601 | TEST_F(AMirScreen, keeps_screen_on_temporarily_when_already_on) |
602 | { |
603 | using namespace testing; |
604 | - std::chrono::seconds const three_seconds{3}; |
605 | - std::chrono::seconds const one_second{1}; |
606 | + std::chrono::seconds const fourty_seconds{40}; |
607 | + std::chrono::seconds const ten_seconds{10}; |
608 | |
609 | expect_no_reconfiguration(); |
610 | |
611 | // After keep_display_on_temporarily the timeouts should |
612 | // be reset... |
613 | - timer->advance_by(three_seconds); |
614 | + timer->advance_by(fourty_seconds); |
615 | mir_screen.keep_display_on_temporarily(); |
616 | |
617 | - // ... so 3 seconds after the reset (total 6 from start) |
618 | + // ... so 40 seconds after the reset (total 80 from start) |
619 | // should trigger neither dim nor power off |
620 | - timer->advance_by(three_seconds); |
621 | + timer->advance_by(fourty_seconds); |
622 | |
623 | verify_and_clear_expectations(); |
624 | |
625 | - // A second more, 4 seconds from reset, the screen should dim |
626 | + // Tens seconds more, 50 seconds from reset, the screen should dim |
627 | expect_screen_is_turned_dim(); |
628 | - timer->advance_by(one_second); |
629 | + timer->advance_by(ten_seconds); |
630 | |
631 | verify_and_clear_expectations(); |
632 | |
633 | - // A second more, 5 seconds from reset, the screen should power off |
634 | + // Ten seconds second more, 60 seconds from reset, the screen should power off |
635 | expect_screen_is_turned_off(); |
636 | - timer->advance_by(one_second); |
637 | + timer->advance_by(ten_seconds); |
638 | |
639 | verify_and_clear_expectations(); |
640 | } |
641 | @@ -367,3 +377,132 @@ |
642 | EXPECT_THAT(handler_reason, Eq(toggle_reason)); |
643 | EXPECT_THAT(handler_mode, Eq(MirPowerMode::mir_power_mode_off)); |
644 | } |
645 | + |
646 | +TEST_F(AMirScreen, turns_screen_off_after_15s_for_notification) |
647 | +{ |
648 | + turn_screen_off(); |
649 | + |
650 | + expect_screen_is_turned_on(); |
651 | + mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, |
652 | + PowerStateChangeReason::notification); |
653 | + verify_and_clear_expectations(); |
654 | + |
655 | + expect_screen_is_turned_off(); |
656 | + timer->advance_by(notification_power_off_timeout); |
657 | +} |
658 | + |
659 | +TEST_F(AMirScreen, keep_display_on_temporarily_overrides_notification_timeout) |
660 | +{ |
661 | + turn_screen_off(); |
662 | + |
663 | + expect_screen_is_turned_on(); |
664 | + mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, |
665 | + PowerStateChangeReason::notification); |
666 | + verify_and_clear_expectations(); |
667 | + |
668 | + // At T=10 we request a temporary keep display on (e.g. user has touched |
669 | + // the screen) |
670 | + timer->advance_by(ten_seconds); |
671 | + mir_screen.keep_display_on_temporarily(); |
672 | + |
673 | + // At T=20 nothing should happen since keep display on temporarily |
674 | + // has reset the timers (so the notification timeout of 15s is overriden). |
675 | + expect_no_reconfiguration(); |
676 | + timer->advance_by(ten_seconds); |
677 | + verify_and_clear_expectations(); |
678 | + |
679 | + // At T=70 (10 + 60) the screen should turn off due to the normal |
680 | + // inactivity timeout |
681 | + expect_screen_is_turned_off(); |
682 | + timer->advance_by(fifty_seconds); |
683 | +} |
684 | + |
685 | +TEST_F(AMirScreen, notification_timeout_extends_active_timeout) |
686 | +{ |
687 | + // At T=0 we turn the screen on, and normal inactivity timeouts |
688 | + // are reset |
689 | + mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, |
690 | + PowerStateChangeReason::power_key); |
691 | + |
692 | + // At T=50 we get a notification |
693 | + timer->advance_by(fifty_seconds); |
694 | + mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, |
695 | + PowerStateChangeReason::notification); |
696 | + verify_and_clear_expectations(); |
697 | + |
698 | + // At T=60 the screen should still be active because the notification |
699 | + // has extended the timeout. |
700 | + expect_no_reconfiguration(); |
701 | + timer->advance_by(ten_seconds); |
702 | + verify_and_clear_expectations(); |
703 | + |
704 | + // At T=65 (50 + 15) the screen should turn off due to the notification |
705 | + // inactivity timeout |
706 | + expect_screen_is_turned_off(); |
707 | + timer->advance_by(five_seconds); |
708 | +} |
709 | + |
710 | +TEST_F(AMirScreen, notification_timeout_does_not_reduce_active_timeout) |
711 | +{ |
712 | + // At T=0 we turn the screen on, and normal inactivity timeouts |
713 | + // are reset |
714 | + mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, |
715 | + PowerStateChangeReason::power_key); |
716 | + |
717 | + |
718 | + // At T=30 we get a notification |
719 | + timer->advance_by(thirty_seconds); |
720 | + mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, |
721 | + PowerStateChangeReason::notification); |
722 | + verify_and_clear_expectations(); |
723 | + |
724 | + // At T=45 the screen should still be active because the notification |
725 | + // has not reduced the active timeout. |
726 | + expect_no_reconfiguration(); |
727 | + timer->advance_by(fifteen_seconds); |
728 | + verify_and_clear_expectations(); |
729 | + |
730 | + // At T=50 the screen should be dimmed |
731 | + expect_screen_is_turned_dim(); |
732 | + timer->advance_by(five_seconds); |
733 | + verify_and_clear_expectations(); |
734 | + |
735 | + // At T=60 the screen should turn off due to the normal |
736 | + // inactivity timeout |
737 | + expect_screen_is_turned_off(); |
738 | + timer->advance_by(ten_seconds); |
739 | +} |
740 | + |
741 | +TEST_F(AMirScreen, notification_timeout_can_extend_only_dimming) |
742 | +{ |
743 | + std::chrono::seconds const two_seconds{2}; |
744 | + std::chrono::seconds const eight_seconds{8}; |
745 | + |
746 | + // At T=0 we turn the screen on, and normal inactivity timeouts |
747 | + // are reset |
748 | + mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, |
749 | + PowerStateChangeReason::power_key); |
750 | + |
751 | + // At T=40 we get a notification |
752 | + timer->advance_by(fourty_seconds); |
753 | + mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on, |
754 | + PowerStateChangeReason::notification); |
755 | + verify_and_clear_expectations(); |
756 | + |
757 | + // At T=50 nothing should happen since the notification has |
758 | + // extended the dimming timeout |
759 | + expect_no_reconfiguration(); |
760 | + timer->advance_by(ten_seconds); |
761 | + verify_and_clear_expectations(); |
762 | + |
763 | + // At T=52 (40 + 12) screen should be dimmed due to the notification |
764 | + // dimming timeout |
765 | + expect_screen_is_turned_dim(); |
766 | + timer->advance_by(two_seconds); |
767 | + verify_and_clear_expectations(); |
768 | + |
769 | + // At T=60 the screen should turn off due to the normal |
770 | + // inactivity timeout |
771 | + expect_screen_is_turned_off(); |
772 | + timer->advance_by(eight_seconds); |
773 | +} |
PASSED: Continuous integration, rev:230 jenkins. qa.ubuntu. com/job/ unity-system- compositor- ci/246/ jenkins. qa.ubuntu. com/job/ unity-system- compositor- wily-amd64- ci/34 jenkins. qa.ubuntu. com/job/ unity-system- compositor- wily-armhf- ci/34 jenkins. qa.ubuntu. com/job/ unity-system- compositor- wily-armhf- ci/34/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ unity-system- compositor- wily-i386- ci/34
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- system- compositor- ci/246/ rebuild
http://