Merge lp:~afrantzis/unity-system-compositor/proximity into lp:unity-system-compositor

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: 231
Merged at revision: 237
Proposed branch: lp:~afrantzis/unity-system-compositor/proximity
Merge into: lp:unity-system-compositor
Prerequisite: lp:~afrantzis/unity-system-compositor/notification-timeouts
Diff against target: 724 lines (+413/-35)
7 files modified
src/mir_screen.cpp (+71/-23)
src/mir_screen.h (+4/-1)
src/powerd_mediator.cpp (+26/-0)
src/powerd_mediator.h (+5/-0)
src/screen_hardware.h (+2/-0)
tests/integration-tests/test_powerd_mediator.cpp (+81/-0)
tests/unit-tests/test_mir_screen.cpp (+224/-11)
To merge this branch: bzr merge lp:~afrantzis/unity-system-compositor/proximity
Reviewer Review Type Date Requested Status
Kevin DuBois (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+265120@code.launchpad.net

Commit message

Enable and handle proximity events properly

Description of the change

Enable and handle proximity events properly

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
Kevin DuBois (kdub) wrote :

240 +void usc::PowerdMediator::enable_proximity_l
I think this would be a bit more understandable if a force_proximity_l() function was split out, but other than that lgtm

review: Approve

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-07-17 12:45:10 +0000
3+++ src/mir_screen.cpp 2015-07-17 12:45:10 +0000
4@@ -55,7 +55,8 @@
5 notification_timeouts(notification_timeouts),
6 current_power_mode{MirPowerMode::mir_power_mode_on},
7 restart_timers{true},
8- power_state_change_handler{[](MirPowerMode,PowerStateChangeReason){}}
9+ power_state_change_handler{[](MirPowerMode,PowerStateChangeReason){}},
10+ allow_proximity_to_turn_on_screen{false}
11 {
12 /*
13 * Make sure the compositor is running as certain conditions can
14@@ -73,7 +74,10 @@
15 std::lock_guard<std::mutex> lock{guard};
16 reset_timers_l(PowerStateChangeReason::inactivity);
17 if (current_power_mode == MirPowerMode::mir_power_mode_on)
18+ {
19 screen_hardware->set_normal_backlight();
20+ screen_hardware->enable_proximity(false);
21+ }
22 }
23
24 void usc::MirScreen::enable_inactivity_timers(bool enable)
25@@ -129,12 +133,25 @@
26 if (raw_dimmer_timeout >= 0)
27 inactivity_timeouts.dimming_timeout = std::chrono::duration_cast<std::chrono::milliseconds>(the_dimming_timeout);
28
29- cancel_timers_l();
30+ cancel_timers_l(PowerStateChangeReason::inactivity);
31 reset_timers_l(PowerStateChangeReason::inactivity);
32 }
33
34 void usc::MirScreen::set_screen_power_mode_l(MirPowerMode mode, PowerStateChangeReason reason)
35 {
36+ if (!is_screen_change_allowed(mode, reason))
37+ return;
38+
39+ // Notifications don't turn on the screen directly, they rely on proximity events
40+ if (mode == MirPowerMode::mir_power_mode_on &&
41+ reason == PowerStateChangeReason::notification)
42+ {
43+ allow_proximity_to_turn_on_screen = true;
44+ screen_hardware->enable_proximity(true);
45+ reset_timers_ignoring_power_mode_l(reason);
46+ return;
47+ }
48+
49 if (mode == MirPowerMode::mir_power_mode_on)
50 {
51 /* The screen may be dim, but on - make sure to reset backlight */
52@@ -145,16 +162,26 @@
53 }
54 else
55 {
56- cancel_timers_l();
57+ cancel_timers_l(reason);
58 configure_display_l(mode, reason);
59 }
60 }
61
62 void usc::MirScreen::configure_display_l(MirPowerMode mode, PowerStateChangeReason reason)
63 {
64+ if (reason != PowerStateChangeReason::proximity)
65+ {
66+ screen_hardware->enable_proximity(false);
67+ allow_proximity_to_turn_on_screen = false;
68+ }
69+
70 if (current_power_mode == mode)
71 return;
72
73+ allow_proximity_to_turn_on_screen =
74+ mode == mir_power_mode_off &&
75+ reason == PowerStateChangeReason::proximity;
76+
77 std::shared_ptr<mg::DisplayConfiguration> displayConfig = display->configuration();
78
79 displayConfig->for_each_output(
80@@ -193,8 +220,11 @@
81 screen_hardware->allow_suspend();
82 }
83
84-void usc::MirScreen::cancel_timers_l()
85+void usc::MirScreen::cancel_timers_l(PowerStateChangeReason reason)
86 {
87+ if (reason == PowerStateChangeReason::proximity)
88+ return;
89+
90 power_off_alarm->cancel();
91 dimmer_alarm->cancel();
92 next_power_off = {};
93@@ -203,29 +233,35 @@
94
95 void usc::MirScreen::reset_timers_l(PowerStateChangeReason reason)
96 {
97- if (restart_timers && current_power_mode != MirPowerMode::mir_power_mode_off)
98+ if (current_power_mode != MirPowerMode::mir_power_mode_off)
99+ reset_timers_ignoring_power_mode_l(reason);
100+}
101+
102+void usc::MirScreen::reset_timers_ignoring_power_mode_l(PowerStateChangeReason reason)
103+{
104+ if (!restart_timers || reason == PowerStateChangeReason::proximity)
105+ return;
106+
107+ auto const timeouts = timeouts_for(reason);
108+ auto const now = clock->now();
109+
110+ if (timeouts.power_off_timeout.count() > 0)
111 {
112- auto const timeouts = timeouts_for(reason);
113- auto const now = clock->now();
114-
115- if (timeouts.power_off_timeout.count() > 0)
116+ auto const new_next_power_off = now + timeouts.power_off_timeout;
117+ if (new_next_power_off > next_power_off)
118 {
119- auto const new_next_power_off = now + timeouts.power_off_timeout;
120- if (new_next_power_off > next_power_off)
121- {
122- power_off_alarm->reschedule_in(timeouts.power_off_timeout);
123- next_power_off = new_next_power_off;
124- }
125+ power_off_alarm->reschedule_in(timeouts.power_off_timeout);
126+ next_power_off = new_next_power_off;
127 }
128+ }
129
130- if (timeouts.dimming_timeout.count() > 0)
131+ if (timeouts.dimming_timeout.count() > 0)
132+ {
133+ auto const new_next_dimming = now + timeouts.dimming_timeout;
134+ if (new_next_dimming > next_dimming)
135 {
136- auto const new_next_dimming = now + timeouts.dimming_timeout;
137- if (new_next_dimming > next_dimming)
138- {
139- dimmer_alarm->reschedule_in(timeouts.dimming_timeout);
140- next_dimming = new_next_dimming;
141- }
142+ dimmer_alarm->reschedule_in(timeouts.dimming_timeout);
143+ next_dimming = new_next_dimming;
144 }
145 }
146 }
147@@ -235,7 +271,7 @@
148 if (enable)
149 reset_timers_l(PowerStateChangeReason::inactivity);
150 else
151- cancel_timers_l();
152+ cancel_timers_l(PowerStateChangeReason::inactivity);
153 }
154
155 usc::MirScreen::Timeouts usc::MirScreen::timeouts_for(PowerStateChangeReason reason)
156@@ -246,6 +282,18 @@
157 return inactivity_timeouts;
158 }
159
160+bool usc::MirScreen::is_screen_change_allowed(MirPowerMode mode, PowerStateChangeReason reason)
161+{
162+ if (mode == MirPowerMode::mir_power_mode_on &&
163+ reason == PowerStateChangeReason::proximity &&
164+ !allow_proximity_to_turn_on_screen)
165+ {
166+ return false;
167+ }
168+
169+ return true;
170+}
171+
172 void usc::MirScreen::power_off_alarm_notification()
173 {
174 std::lock_guard<std::mutex> lock{guard};
175
176=== modified file 'src/mir_screen.h'
177--- src/mir_screen.h 2015-07-17 12:45:10 +0000
178+++ src/mir_screen.h 2015-07-17 12:45:10 +0000
179@@ -77,10 +77,12 @@
180 void set_screen_power_mode_l(MirPowerMode mode, PowerStateChangeReason reason);
181 void configure_display_l(MirPowerMode mode, PowerStateChangeReason reason);
182
183- void cancel_timers_l();
184+ void cancel_timers_l(PowerStateChangeReason reason);
185 void reset_timers_l(PowerStateChangeReason reason);
186+ void reset_timers_ignoring_power_mode_l(PowerStateChangeReason reason);
187 void enable_inactivity_timers_l(bool flag);
188 Timeouts timeouts_for(PowerStateChangeReason reason);
189+ bool is_screen_change_allowed(MirPowerMode mode, PowerStateChangeReason reason);
190
191 void power_off_alarm_notification();
192 void dimmer_alarm_notification();
193@@ -103,6 +105,7 @@
194 MirPowerMode current_power_mode;
195 bool restart_timers;
196 PowerStateChangeHandler power_state_change_handler;
197+ bool allow_proximity_to_turn_on_screen;
198 };
199
200 }
201
202=== modified file 'src/powerd_mediator.cpp'
203--- src/powerd_mediator.cpp 2015-04-24 14:40:28 +0000
204+++ src/powerd_mediator.cpp 2015-07-17 12:45:10 +0000
205@@ -56,6 +56,7 @@
206 backlight_state{BacklightState::normal},
207 auto_brightness_supported_{false},
208 auto_brightness_requested{false},
209+ proximity_enabled{false},
210 sys_state{SysState::unknown}
211 {
212 connection.add_match(
213@@ -197,6 +198,13 @@
214 return max_brightness_;
215 }
216
217+void usc::PowerdMediator::enable_proximity(bool enable)
218+{
219+ std::lock_guard<decltype(mutex)> lock{mutex};
220+
221+ enable_proximity_l(enable, ForceProximity::no);
222+}
223+
224 bool usc::PowerdMediator::is_system_suspended()
225 {
226 std::lock_guard<decltype(mutex)> lock{mutex};
227@@ -290,6 +298,8 @@
228
229 // Powerd may have restarted, re-apply backlight settings
230 change_backlight_state(backlight_state, ForceBacklightState::yes);
231+
232+ enable_proximity_l(false, ForceProximity::yes);
233 }
234
235 void usc::PowerdMediator::init_brightness_params()
236@@ -362,6 +372,22 @@
237 }
238 }
239
240+void usc::PowerdMediator::enable_proximity_l(
241+ bool enable, ForceProximity force_proximity)
242+{
243+ if (proximity_enabled == enable && force_proximity == ForceProximity::no)
244+ return;
245+
246+ auto const name = "unity-system-compositor";
247+ auto const request = enable ? "enableProximityHandling" :
248+ "disableProximityHandling";
249+ invoke_with_reply(request,
250+ DBUS_TYPE_STRING, &name,
251+ DBUS_TYPE_INVALID);
252+
253+ proximity_enabled = enable;
254+}
255+
256 bool usc::PowerdMediator::is_valid_brightness(int brightness)
257 {
258 return brightness >= min_brightness_ && brightness <= max_brightness_;
259
260=== modified file 'src/powerd_mediator.h'
261--- src/powerd_mediator.h 2015-04-07 13:36:48 +0000
262+++ src/powerd_mediator.h 2015-07-17 12:45:10 +0000
263@@ -46,6 +46,8 @@
264 int min_brightness() override;
265 int max_brightness() override;
266
267+ void enable_proximity(bool enable) override;
268+
269 bool is_system_suspended();
270
271 private:
272@@ -66,6 +68,7 @@
273
274 enum class ForceDisableSuspend { no, yes };
275 enum class ForceBacklightState { no, yes };
276+ enum class ForceProximity { no, yes };
277
278 static ::DBusHandlerResult handle_dbus_message_thunk(
279 ::DBusConnection* connection, ::DBusMessage* message, void* user_data);
280@@ -76,6 +79,7 @@
281 void init_brightness_params();
282 void change_backlight_state(
283 BacklightState new_state, ForceBacklightState force_backlight_state);
284+ void enable_proximity_l(bool enable, ForceProximity force_proximity);
285 bool is_valid_brightness(int brightness);
286 bool request_suspend_block();
287 void wait_for_sys_state(SysState state);
288@@ -98,6 +102,7 @@
289 BacklightState backlight_state;
290 bool auto_brightness_supported_;
291 bool auto_brightness_requested;
292+ bool proximity_enabled;
293 std::string suspend_block_cookie;
294 std::mutex sys_state_mutex;
295 SysState sys_state;
296
297=== modified file 'src/screen_hardware.h'
298--- src/screen_hardware.h 2015-02-18 14:40:29 +0000
299+++ src/screen_hardware.h 2015-07-17 12:45:10 +0000
300@@ -39,6 +39,8 @@
301 virtual int min_brightness() = 0;
302 virtual int max_brightness() = 0;
303
304+ virtual void enable_proximity(bool enable) = 0;
305+
306 protected:
307 ScreenHardware() = default;
308 ScreenHardware(ScreenHardware const&) = delete;
309
310=== modified file 'tests/integration-tests/test_powerd_mediator.cpp'
311--- tests/integration-tests/test_powerd_mediator.cpp 2015-04-07 13:36:48 +0000
312+++ tests/integration-tests/test_powerd_mediator.cpp 2015-07-17 12:45:10 +0000
313@@ -84,6 +84,8 @@
314 MOCK_METHOD1(dbus_userAutobrightnessEnable, void(dbus_bool_t enable));
315 MOCK_METHOD2(dbus_requestSysState, std::string(char const* name, int state));
316 MOCK_METHOD1(dbus_clearSysState, void(char const* cookie));
317+ MOCK_METHOD1(dbus_enableProximityHandling, void(char const* name));
318+ MOCK_METHOD1(dbus_disableProximityHandling, void(char const* name));
319
320 int32_t const dim_brightness = 13;
321 int32_t const min_brightness = 5;
322@@ -192,6 +194,32 @@
323
324 emit_SysPowerStateChange(0);
325 }
326+ else if (dbus_message_is_method_call(message, powerd_service_name, "enableProximityHandling"))
327+ {
328+ char const* name{nullptr};
329+ dbus_message_get_args(
330+ message, nullptr,
331+ DBUS_TYPE_STRING, &name,
332+ DBUS_TYPE_INVALID);
333+
334+ dbus_enableProximityHandling(name);
335+
336+ usc::DBusMessageHandle reply{dbus_message_new_method_return(message)};
337+ dbus_connection_send(connection, reply, nullptr);
338+ }
339+ else if (dbus_message_is_method_call(message, powerd_service_name, "disableProximityHandling"))
340+ {
341+ char const* name{nullptr};
342+ dbus_message_get_args(
343+ message, nullptr,
344+ DBUS_TYPE_STRING, &name,
345+ DBUS_TYPE_INVALID);
346+
347+ dbus_disableProximityHandling(name);
348+
349+ usc::DBusMessageHandle reply{dbus_message_new_method_return(message)};
350+ dbus_connection_send(connection, reply, nullptr);
351+ }
352
353 return DBUS_HANDLER_RESULT_HANDLED;
354 }
355@@ -462,6 +490,41 @@
356 mediator->allow_suspend();
357 }
358
359+TEST_F(APowerdMediator, enables_and_disables_proximity_handling)
360+{
361+ using namespace testing;
362+ auto const proximity_name = "unity-system-compositor";
363+
364+ InSequence s;
365+ EXPECT_CALL(powerd_service, dbus_enableProximityHandling(StrEq(proximity_name)));
366+ EXPECT_CALL(powerd_service, dbus_disableProximityHandling(StrEq(proximity_name)));
367+
368+ mediator->enable_proximity(true);
369+ mediator->enable_proximity(false);
370+}
371+
372+TEST_F(APowerdMediator, ignores_requests_for_redundant_proximity_handling)
373+{
374+ using namespace testing;
375+
376+ auto const proximity_name = "unity-system-compositor";
377+
378+ InSequence s;
379+ EXPECT_CALL(powerd_service, dbus_enableProximityHandling(StrEq(proximity_name)));
380+ EXPECT_CALL(powerd_service, dbus_disableProximityHandling(StrEq(proximity_name)));
381+
382+ // Should be ignore, proximity already disabled
383+ mediator->enable_proximity(false);
384+
385+ // Should be handled only once
386+ mediator->enable_proximity(true);
387+ mediator->enable_proximity(true);
388+
389+ // Should be handled only once
390+ mediator->enable_proximity(false);
391+ mediator->enable_proximity(false);
392+}
393+
394 namespace
395 {
396
397@@ -637,6 +700,24 @@
398 EXPECT_CALL(powerd_service, dbus_setUserBrightness(0)).Times(AtMost(1));
399 }
400
401+TEST(APowerdMediatorAtStartup, disables_proximity_handling)
402+{
403+ using namespace testing;
404+
405+ dbus_bool_t const auto_brightness_supported{TRUE};
406+
407+ ut::DBusBus bus;
408+ NiceMock<PowerdService> powerd_service{
409+ bus.address(), auto_brightness_supported, PowerdService::StartNow::yes};
410+
411+ EXPECT_CALL(powerd_service, dbus_disableProximityHandling(_));
412+
413+ usc::PowerdMediator mediator{bus.address()};
414+ powerd_service.wait_for_initial_setup();
415+
416+ Mock::VerifyAndClearExpectations(&powerd_service);
417+}
418+
419 TEST(APowerdMediatorAtShutdown, turns_off_backlight)
420 {
421 using namespace testing;
422
423=== modified file 'tests/unit-tests/test_mir_screen.cpp'
424--- tests/unit-tests/test_mir_screen.cpp 2015-07-17 12:45:10 +0000
425+++ tests/unit-tests/test_mir_screen.cpp 2015-07-17 12:45:10 +0000
426@@ -116,6 +116,25 @@
427 MOCK_METHOD1(set_brightness, void(int));
428 int min_brightness() override { return 100; }
429 int max_brightness() override { return 0; }
430+
431+ enum class Proximity {near, far};
432+
433+ void enable_proximity(bool enable) override
434+ {
435+ proximity_enabled = enable;
436+ set_proximity(current_proximity);
437+ }
438+
439+ void set_proximity(Proximity proximity)
440+ {
441+ current_proximity = proximity;
442+ if (proximity_enabled)
443+ on_proximity_changed(current_proximity);
444+ }
445+
446+ std::function<void(Proximity)> on_proximity_changed = [](Proximity){};
447+ Proximity current_proximity{Proximity::far};
448+ bool proximity_enabled{false};
449 };
450
451 struct MockTouchVisualizer : mir::input::TouchVisualizer
452@@ -129,6 +148,36 @@
453
454 struct AMirScreen : testing::Test
455 {
456+ AMirScreen()
457+ {
458+ using namespace testing;
459+
460+ screen_hardware->on_proximity_changed =
461+ [this] (MockScreenHardware::Proximity p) { defer_proximity_event(p); };
462+ }
463+
464+ void defer_proximity_event(MockScreenHardware::Proximity proximity)
465+ {
466+ deferred_actions.push_back(
467+ [this, proximity]
468+ {
469+ mir_screen.set_screen_power_mode(
470+ proximity == MockScreenHardware::Proximity::far ?
471+ MirPowerMode::mir_power_mode_on :
472+ MirPowerMode::mir_power_mode_off,
473+ PowerStateChangeReason::proximity);
474+ });
475+ }
476+
477+ void process_deferred_actions()
478+ {
479+ for (auto const& a : deferred_actions)
480+ a();
481+ deferred_actions.clear();
482+ }
483+
484+ std::vector<std::function<void(void)>> deferred_actions;
485+
486 std::chrono::seconds const power_off_timeout{60};
487 std::chrono::seconds const dimmer_timeout{50};
488 std::chrono::seconds const notification_power_off_timeout{15};
489@@ -185,6 +234,26 @@
490 verify_and_clear_expectations();
491 }
492
493+ void receive_notification()
494+ {
495+ mir_screen.set_screen_power_mode(
496+ MirPowerMode::mir_power_mode_on,
497+ PowerStateChangeReason::notification);
498+ process_deferred_actions();
499+ }
500+
501+ void cover_screen()
502+ {
503+ screen_hardware->set_proximity(MockScreenHardware::Proximity::near);
504+ process_deferred_actions();
505+ }
506+
507+ void uncover_screen()
508+ {
509+ screen_hardware->set_proximity(MockScreenHardware::Proximity::far);
510+ process_deferred_actions();
511+ }
512+
513 void verify_and_clear_expectations()
514 {
515 using namespace testing;
516@@ -378,13 +447,12 @@
517 EXPECT_THAT(handler_mode, Eq(MirPowerMode::mir_power_mode_off));
518 }
519
520-TEST_F(AMirScreen, turns_screen_off_after_15s_for_notification)
521+TEST_F(AMirScreen, turns_screen_off_after_notification_timeout)
522 {
523 turn_screen_off();
524
525 expect_screen_is_turned_on();
526- mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
527- PowerStateChangeReason::notification);
528+ receive_notification();
529 verify_and_clear_expectations();
530
531 expect_screen_is_turned_off();
532@@ -396,8 +464,7 @@
533 turn_screen_off();
534
535 expect_screen_is_turned_on();
536- mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
537- PowerStateChangeReason::notification);
538+ receive_notification();
539 verify_and_clear_expectations();
540
541 // At T=10 we request a temporary keep display on (e.g. user has touched
542@@ -426,8 +493,7 @@
543
544 // At T=50 we get a notification
545 timer->advance_by(fifty_seconds);
546- mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
547- PowerStateChangeReason::notification);
548+ receive_notification();
549 verify_and_clear_expectations();
550
551 // At T=60 the screen should still be active because the notification
552@@ -452,8 +518,7 @@
553
554 // At T=30 we get a notification
555 timer->advance_by(thirty_seconds);
556- mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
557- PowerStateChangeReason::notification);
558+ receive_notification();
559 verify_and_clear_expectations();
560
561 // At T=45 the screen should still be active because the notification
562@@ -485,8 +550,7 @@
563
564 // At T=40 we get a notification
565 timer->advance_by(fourty_seconds);
566- mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
567- PowerStateChangeReason::notification);
568+ receive_notification();
569 verify_and_clear_expectations();
570
571 // At T=50 nothing should happen since the notification has
572@@ -506,3 +570,152 @@
573 expect_screen_is_turned_off();
574 timer->advance_by(eight_seconds);
575 }
576+
577+TEST_F(AMirScreen, proximity_requests_affect_screen_state)
578+{
579+ expect_screen_is_turned_off();
580+ mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
581+ PowerStateChangeReason::proximity);
582+ verify_and_clear_expectations();
583+
584+ expect_screen_is_turned_on();
585+ mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
586+ PowerStateChangeReason::proximity);
587+ verify_and_clear_expectations();
588+}
589+
590+TEST_F(AMirScreen, proximity_requests_do_not_reset_timeouts)
591+{
592+ // At T=0 we turn the screen on, and normal inactivity timeouts
593+ // are reset
594+ mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
595+ PowerStateChangeReason::power_key);
596+
597+ // At T=30 we get a screen off request due to proximity
598+ timer->advance_by(thirty_seconds);
599+ mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_off,
600+ PowerStateChangeReason::proximity);
601+
602+ // At T=40 we get a screen on request due to proximity
603+ timer->advance_by(ten_seconds);
604+ mir_screen.set_screen_power_mode(MirPowerMode::mir_power_mode_on,
605+ PowerStateChangeReason::proximity);
606+
607+ verify_and_clear_expectations();
608+
609+ // At T=50 screen should be dimmed due to the inactivity
610+ // dimming timeout
611+ expect_screen_is_turned_dim();
612+ timer->advance_by(ten_seconds);
613+ verify_and_clear_expectations();
614+
615+ // At T=60 the screen should turn off due to the normal
616+ // inactivity timeout
617+ expect_screen_is_turned_off();
618+ timer->advance_by(ten_seconds);
619+}
620+
621+TEST_F(AMirScreen, does_not_turn_on_screen_when_notification_arrives_with_phone_covered)
622+{
623+ turn_screen_off();
624+ cover_screen();
625+
626+ expect_no_reconfiguration();
627+ receive_notification();
628+}
629+
630+TEST_F(AMirScreen, turns_screen_on_when_phone_is_uncovered_after_notification_arrives)
631+{
632+ turn_screen_off();
633+ cover_screen();
634+
635+ expect_no_reconfiguration();
636+ receive_notification();
637+ verify_and_clear_expectations();
638+
639+ expect_screen_is_turned_on();
640+ uncover_screen();
641+}
642+
643+TEST_F(AMirScreen, cancels_proximity_handling_when_phone_is_turned_off_after_notification)
644+{
645+ turn_screen_off();
646+ cover_screen();
647+
648+ receive_notification();
649+ timer->advance_by(notification_power_off_timeout);
650+ verify_and_clear_expectations();
651+
652+ expect_no_reconfiguration();
653+ uncover_screen();
654+ cover_screen();
655+}
656+
657+TEST_F(AMirScreen, cancels_proximity_handling_when_screen_is_touched_after_notification)
658+{
659+ turn_screen_off();
660+
661+ receive_notification();
662+ mir_screen.keep_display_on_temporarily();
663+ verify_and_clear_expectations();
664+
665+ expect_no_reconfiguration();
666+ cover_screen();
667+ uncover_screen();
668+}
669+
670+TEST_F(AMirScreen, does_not_allow_proximity_to_turn_on_screen_not_turned_off_by_proximity)
671+{
672+ turn_screen_off();
673+
674+ expect_no_reconfiguration();
675+ mir_screen.set_screen_power_mode(
676+ MirPowerMode::mir_power_mode_on,
677+ PowerStateChangeReason::proximity);
678+ verify_and_clear_expectations();
679+
680+ expect_no_reconfiguration();
681+ mir_screen.set_screen_power_mode(
682+ MirPowerMode::mir_power_mode_off,
683+ PowerStateChangeReason::proximity);
684+ verify_and_clear_expectations();
685+
686+ expect_no_reconfiguration();
687+ mir_screen.set_screen_power_mode(
688+ MirPowerMode::mir_power_mode_on,
689+ PowerStateChangeReason::proximity);
690+}
691+
692+TEST_F(AMirScreen, does_not_allow_proximity_to_turn_on_screen_not_turned_off_by_proximity_2)
693+{
694+ mir_screen.set_screen_power_mode(
695+ MirPowerMode::mir_power_mode_off,
696+ PowerStateChangeReason::proximity);
697+
698+ mir_screen.set_screen_power_mode(
699+ MirPowerMode::mir_power_mode_off,
700+ PowerStateChangeReason::power_key);
701+
702+ verify_and_clear_expectations();
703+
704+ expect_no_reconfiguration();
705+ mir_screen.set_screen_power_mode(
706+ MirPowerMode::mir_power_mode_on,
707+ PowerStateChangeReason::proximity);
708+}
709+
710+TEST_F(AMirScreen, proximity_can_affect_screen_after_keep_display_on)
711+{
712+ mir_screen.keep_display_on(true);
713+
714+ expect_screen_is_turned_off();
715+ mir_screen.set_screen_power_mode(
716+ MirPowerMode::mir_power_mode_off,
717+ PowerStateChangeReason::proximity);
718+ verify_and_clear_expectations();
719+
720+ expect_screen_is_turned_on();
721+ mir_screen.set_screen_power_mode(
722+ MirPowerMode::mir_power_mode_on,
723+ PowerStateChangeReason::proximity);
724+}

Subscribers

People subscribed via source and target branches