Merge lp:~albaguirre/unity-system-compositor/fix-1353647 into lp:unity-system-compositor

Proposed by Alberto Aguirre
Status: Merged
Approved by: kevin gunn
Approved revision: 166
Merged at revision: 167
Proposed branch: lp:~albaguirre/unity-system-compositor/fix-1353647
Merge into: lp:unity-system-compositor
Diff against target: 147 lines (+52/-22)
2 files modified
src/powerd_mediator.cpp (+48/-18)
src/powerd_mediator.h (+4/-4)
To merge this branch: bzr merge lp:~albaguirre/unity-system-compositor/fix-1353647
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michael Terry (community) Approve
Kevin DuBois (community) Approve
Review via email: mp+230370@code.launchpad.net

Commit message

Request disabling of system suspend on first boot or when powerd restarts (if needed)

Description of the change

Request disabling of system suspend on first boot or when powerd restarts (if needed)

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 :

looks okay to me

review: Approve
Revision history for this message
Kevin DuBois (kdub) wrote :

> looks okay to me
some tests would be good, but I'm unfamiliar with how hard/easy this is to do in usc.

165. By Alberto Aguirre

Merge lp:unity-system-compositor

166. By Alberto Aguirre

Simplify changes

Revision history for this message
Michael Terry (mterry) wrote :

LGTM too

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/powerd_mediator.cpp'
2--- src/powerd_mediator.cpp 2014-07-21 21:54:19 +0000
3+++ src/powerd_mediator.cpp 2014-08-14 18:06:35 +0000
4@@ -71,7 +71,7 @@
5 auto_brightness_supported_{false},
6 auto_brightness_requested{false},
7 backlight_state{BacklightState::normal},
8- acquired_sys_state{false},
9+ pending_suspend_blocker_request{true},
10 powerd_interface{new QDBusInterface("com.canonical.powerd",
11 "/com/canonical/powerd", "com.canonical.powerd", QDBusConnection::systemBus())},
12 service_watcher{new QDBusServiceWatcher("com.canonical.powerd",
13@@ -96,14 +96,18 @@
14 if (powerd_interface->isValid())
15 {
16 init_brightness_params();
17- //If powerd is already up it may already be in the active state
18- //and the SysPowerStateChange signal could have already been broadcasted
19- //before we got a chance to register a listener for it.
20- //We will assume that if the active request succeeds that the system state
21- //will become active at some point in the future - this is only a workaround
22- //for the lack of a system state query api in powerd
23- if (disable_suspend_request())
24+ if (request_suspend_blocker())
25+ {
26+ /*
27+ * If powerd is already up it may already be in the active state
28+ * and the SysPowerStateChange signal could have already been broadcasted
29+ * before we got a chance to register a listener for it.
30+ * We will assume that if the active request succeeds that the system state
31+ * will become active at some point in the future - this is only a workaround
32+ * for the lack of a system state query api in powerd
33+ */
34 system_state = active;
35+ }
36 }
37 }
38
39@@ -162,6 +166,24 @@
40 void PowerdMediator::powerd_registered()
41 {
42 init_brightness_params();
43+
44+ /* A suspend block request needs to be issued here on the following scenarios:
45+ * 1. powerd has restarted and PowerdMediator had already issued a request
46+ * to the previous powerd instance
47+ * 2. When booting up the screen is assumed to be on and consequently we need to also issue
48+ * a system suspend block request.
49+ * 3. If powerd interface is not available yet, but the screen had been turned on
50+ * then now is the time to issue the request
51+ */
52+ if (!suspend_block_cookie.isEmpty() || pending_suspend_blocker_request)
53+ {
54+ //Clear the previous cookie as powerd has restarted anyway
55+ suspend_block_cookie.clear();
56+ request_suspend_blocker();
57+ }
58+
59+ //Powerd may have restarted, re-apply backlight settings
60+ change_backlight_state(backlight_state, true);
61 }
62
63 void PowerdMediator::set_brightness(int brightness)
64@@ -172,9 +194,9 @@
65 powerd_interface->call("setUserBrightness", brightness);
66 }
67
68-void PowerdMediator::change_backlight_state(BacklightState new_state)
69+void PowerdMediator::change_backlight_state(BacklightState new_state, bool force_change)
70 {
71- if (backlight_state == new_state)
72+ if (backlight_state == new_state && !force_change)
73 return;
74
75 if (new_state == BacklightState::automatic)
76@@ -206,28 +228,36 @@
77
78 void PowerdMediator::allow_suspend()
79 {
80- if (acquired_sys_state)
81- powerd_interface->call("clearSysState", sys_state_cookie);
82- acquired_sys_state = false;
83+ if (!suspend_block_cookie.isEmpty())
84+ {
85+ powerd_interface->call("clearSysState", suspend_block_cookie);
86+ suspend_block_cookie.clear();
87+ }
88+ pending_suspend_blocker_request = false;
89 }
90
91 void PowerdMediator::disable_suspend()
92 {
93- if (disable_suspend_request())
94+ if (request_suspend_blocker())
95 wait_for_state(active);
96 }
97
98-bool PowerdMediator::disable_suspend_request()
99+bool PowerdMediator::request_suspend_blocker()
100 {
101- if (!acquired_sys_state)
102+ if (suspend_block_cookie.isEmpty())
103 {
104 QDBusReply<QString> reply = powerd_interface->call("requestSysState", "com.canonical.Unity.Screen", 1);
105 if (reply.isValid())
106 {
107- sys_state_cookie = reply.value();
108- acquired_sys_state = true;
109+ suspend_block_cookie = reply.value();
110+ pending_suspend_blocker_request = false;
111 return true;
112 }
113+ else
114+ {
115+ //Powerd may not yet be available, so save the pending request
116+ pending_suspend_blocker_request = true;
117+ }
118 }
119 return false;
120 }
121
122=== modified file 'src/powerd_mediator.h'
123--- src/powerd_mediator.h 2014-07-21 21:54:19 +0000
124+++ src/powerd_mediator.h 2014-08-14 18:06:35 +0000
125@@ -74,9 +74,9 @@
126 suspended = 0,
127 active,
128 };
129- void change_backlight_state(BacklightState state);
130+ void change_backlight_state(BacklightState state, bool force_change = false);
131 void init_brightness_params();
132- bool disable_suspend_request();
133+ bool request_suspend_blocker();
134 void wait_for_state(SystemState state);
135
136 int dim_brightness;
137@@ -88,8 +88,8 @@
138 bool auto_brightness_requested;
139 BacklightState backlight_state;
140
141- QString sys_state_cookie;
142- bool acquired_sys_state;
143+ QString suspend_block_cookie;
144+ bool pending_suspend_blocker_request;
145
146 std::unique_ptr<QDBusInterface> powerd_interface;
147 std::unique_ptr<QDBusServiceWatcher> service_watcher;

Subscribers

People subscribed via source and target branches