Merge lp:~unity-api-team/indicator-power/lp-1370791-15.05-adjust-slider-when-brightness-is-changed-by-powerd into lp:indicator-power/15.04

Proposed by Charles Kerr
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 289
Merged at revision: 287
Proposed branch: lp:~unity-api-team/indicator-power/lp-1370791-15.05-adjust-slider-when-brightness-is-changed-by-powerd
Merge into: lp:indicator-power/15.04
Diff against target: 339 lines (+186/-70)
3 files modified
src/CMakeLists.txt (+4/-0)
src/brightness.c (+98/-70)
src/com.canonical.powerd.xml (+84/-0)
To merge this branch: bzr merge lp:~unity-api-team/indicator-power/lp-1370791-15.05-adjust-slider-when-brightness-is-changed-by-powerd
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+259676@code.launchpad.net

Commit message

When in autobrightness mode, keep the brightness slider's value in sync with the system brightness

Description of the change

== Description of the Change

In the brightness code, add a powerd proxy that listens to property changes from the com.canonical.powerd.Brightness property. When this changes, update the indicator's power slider to reflect the change.

== Checklist

* Are there any related MPs required for this MP to build/function as expected? Please list.

Yes, https://code.launchpad.net/~charlesk/powerd/lp-1370791-add-brightness-property is required to publish powerd's brightness changes on the bus.

> * Is your branch in sync with latest trunk? (e.g. bzr pull lp:trunk -> no changes)

Targeted for lp:indicator-power/15.04. bzr pull lp:indicator-power/15.04 -> no changes

> * Did the code build without warnings?

Yes

> * Did the tests run successfully?

Yes

> * Did you perform an exploratory manual test run of your code change and any related functionality?

Yes

> * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?

N/A

> * Did your component test plan pass? If on a device, what image number?

Yes mako wily r202

> * Please list which manual tests are germane for the reviewer in this MR.

indicator-power/device-brightness-slider-auto and
indicator-power/device-brightness-slider

> Did you provide a link to this page https://wiki.ubuntu.com/Process/Merges/Checklists/indicator-power

Yes

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
Alejandro J. Cura (alecu) wrote :

== Reviewer Checklist

* Have you checked that the submitter has accurately filled out the submitter checklist and has taken no shortcuts?

Yes, checked.

* Did you run the manual tests listed by the submitter?

I followed both manual tests, everything seems to work ok.

* Did you do exploratory testing related to the component you own with the MP changeset included?

I did exploratory testing around the new feature, checking the slider with sunlight, flashlight, darkened indoors and covering the sensor. It all seems to work just fine.

* If new features have been added, are the manual tests sufficient to cover them?

The manual tests added to the test plan seem to cover all new features in this MP.

---

Code looks good, and manual testing works as expected.

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 2014-10-14 19:09:32 +0000
3+++ src/CMakeLists.txt 2015-05-20 19:36:35 +0000
4@@ -17,6 +17,10 @@
5 # generated sources
6 include(GdbusCodegen)
7 set(SERVICE_GENERATED_SOURCES)
8+add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-powerd
9+ com.canonical
10+ Dbus
11+ ${CMAKE_SOURCE_DIR}/src/com.canonical.powerd.xml)
12 add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-battery
13 com.canonical.indicator.power
14 Dbus
15
16=== modified file 'src/brightness.c'
17--- src/brightness.c 2014-09-12 16:37:02 +0000
18+++ src/brightness.c 2015-05-20 19:36:35 +0000
19@@ -18,6 +18,7 @@
20 */
21
22 #include "brightness.h"
23+#include "dbus-powerd.h"
24
25 #include <gio/gio.h>
26
27@@ -45,7 +46,8 @@
28
29 GSettings * settings;
30
31- guint powerd_name_tag;
32+ DbusPowerd * powerd_proxy;
33+ char * powerd_name_owner;
34
35 double percentage;
36
37@@ -136,14 +138,15 @@
38 g_clear_object(&p->cancellable);
39 }
40
41- if (p->powerd_name_tag)
42+ if (p->powerd_proxy != NULL)
43 {
44- g_bus_unwatch_name(p->powerd_name_tag);
45- p->powerd_name_tag = 0;
46+ g_signal_handlers_disconnect_by_data(p->powerd_proxy, o);
47+ g_clear_object(&p->powerd_proxy);
48 }
49
50 g_clear_object(&p->settings);
51 g_clear_object(&p->system_bus);
52+ g_clear_pointer(&p->powerd_name_owner, g_free);
53
54 G_OBJECT_CLASS(indicator_power_brightness_parent_class)->dispose(o);
55 }
56@@ -202,36 +205,30 @@
57 */
58
59 static void set_brightness_global(IndicatorPowerBrightness*, int);
60+static void set_brightness_local(IndicatorPowerBrightness*, int);
61
62 static void
63-on_powerd_brightness_params_ready(GObject * source,
64+on_powerd_brightness_params_ready(GObject * oproxy,
65 GAsyncResult * res,
66 gpointer gself)
67 {
68 GError * error;
69 GVariant * v;
70
71+ v = NULL;
72 error = NULL;
73- v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error);
74- if (v == NULL)
75- {
76- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
77- g_warning("Unable to get system bus: %s", error->message);
78-
79- g_error_free(error);
80- }
81- else
82+ if (dbus_powerd_call_get_brightness_params_finish(DBUS_POWERD(oproxy), &v, res, &error))
83 {
84 IndicatorPowerBrightness * self = INDICATOR_POWER_BRIGHTNESS(gself);
85 priv_t * p = get_priv(self);
86 const gboolean old_ab_supported = p->powerd_ab_supported;
87
88 p->have_powerd_params = TRUE;
89- g_variant_get(v, "((iiiib))", &p->powerd_dim,
90- &p->powerd_min,
91- &p->powerd_max,
92- &p->powerd_default_value,
93- &p->powerd_ab_supported);
94+ g_variant_get(v, "(iiiib)", &p->powerd_dim,
95+ &p->powerd_min,
96+ &p->powerd_max,
97+ &p->powerd_default_value,
98+ &p->powerd_ab_supported);
99 g_debug("powerd brightness settings: dim=%d, min=%d, max=%d, default=%d, ab_supported=%d",
100 p->powerd_dim,
101 p->powerd_min,
102@@ -262,52 +259,83 @@
103 /* cleanup */
104 g_variant_unref(v);
105 }
106-}
107-
108-static void
109-call_powerd_get_brightness_params(IndicatorPowerBrightness * self)
110-{
111- priv_t * p = get_priv(self);
112-
113- g_dbus_connection_call(p->system_bus,
114- "com.canonical.powerd",
115- "/com/canonical/powerd",
116- "com.canonical.powerd",
117- "getBrightnessParams",
118- NULL,
119- G_VARIANT_TYPE("((iiiib))"),
120- G_DBUS_CALL_FLAGS_NONE,
121- -1, /* default timeout */
122- p->cancellable,
123- on_powerd_brightness_params_ready,
124- self);
125-}
126-
127-static void
128-on_powerd_appeared(GDBusConnection * connection,
129- const gchar * bus_name G_GNUC_UNUSED,
130- const gchar * name_owner G_GNUC_UNUSED,
131- gpointer gself)
132-{
133- IndicatorPowerBrightness * self = INDICATOR_POWER_BRIGHTNESS(gself);
134- priv_t * p = get_priv(self);
135-
136- /* keep a handle to the system bus */
137- g_clear_object(&p->system_bus);
138- p->system_bus = g_object_ref(connection);
139-
140- /* update our cache of powerd's brightness params */
141- call_powerd_get_brightness_params(self);
142-}
143-
144-static void
145-on_powerd_vanished(GDBusConnection * connection G_GNUC_UNUSED,
146- const gchar * bus_name G_GNUC_UNUSED,
147- gpointer gself)
148+ else if (error != NULL)
149+ {
150+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
151+ g_warning("Unable to get system bus: %s", error->message);
152+
153+ g_error_free(error);
154+ }
155+}
156+
157+static void
158+on_powerd_name_owner_changed(GDBusProxy * powerd_proxy,
159+ GParamSpec * pspec G_GNUC_UNUSED,
160+ gpointer gself)
161 {
162 priv_t * p = get_priv(INDICATOR_POWER_BRIGHTNESS(gself));
163-
164- p->have_powerd_params = FALSE;
165+ gchar * owner = g_dbus_proxy_get_name_owner(powerd_proxy);
166+
167+ if (g_strcmp0(p->powerd_name_owner, owner))
168+ {
169+ p->have_powerd_params = FALSE;
170+
171+ if (owner != NULL)
172+ {
173+ dbus_powerd_call_get_brightness_params(DBUS_POWERD(powerd_proxy),
174+ p->cancellable,
175+ on_powerd_brightness_params_ready,
176+ gself);
177+ }
178+
179+ g_free(p->powerd_name_owner);
180+ p->powerd_name_owner = owner;
181+ }
182+}
183+
184+static void
185+on_powerd_brightness_changed(DbusPowerd * powerd_proxy,
186+ GParamSpec * pspec G_GNUC_UNUSED,
187+ gpointer gself)
188+{
189+ set_brightness_local(gself, dbus_powerd_get_brightness(powerd_proxy));
190+}
191+
192+static void
193+on_powerd_proxy_ready(GObject * source_object G_GNUC_UNUSED,
194+ GAsyncResult * res,
195+ gpointer gself)
196+{
197+ GError * error;
198+ DbusPowerd * powerd_proxy;
199+
200+ error = NULL;
201+ powerd_proxy = dbus_powerd_proxy_new_for_bus_finish(res, &error);
202+
203+ if (powerd_proxy != NULL)
204+ {
205+ priv_t * p;
206+ p = get_priv(INDICATOR_POWER_BRIGHTNESS(gself));
207+
208+ /* keep a handle to the system bus */
209+ g_clear_object(&p->system_bus);
210+ p->system_bus = g_object_ref(g_dbus_proxy_get_connection(G_DBUS_PROXY(powerd_proxy)));
211+
212+ /* keep the proxy and listen to owner changes */
213+ p->powerd_proxy = powerd_proxy;
214+ g_signal_connect(p->powerd_proxy, "notify::g-name-owner",
215+ G_CALLBACK(on_powerd_name_owner_changed), gself);
216+ g_signal_connect(p->powerd_proxy, "notify::brightness",
217+ G_CALLBACK(on_powerd_brightness_changed), gself);
218+ on_powerd_name_owner_changed(G_DBUS_PROXY(powerd_proxy), NULL, gself);
219+ }
220+ else if (error != NULL)
221+ {
222+ if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
223+ g_warning("Unable to get powerd proxy: %s", error->message);
224+
225+ g_error_free(error);
226+ }
227 }
228
229 /**
230@@ -433,13 +461,13 @@
231 g_settings_schema_unref(schema);
232 }
233
234- p->powerd_name_tag = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
235- "com.canonical.powerd",
236- G_BUS_NAME_WATCHER_FLAGS_NONE,
237- on_powerd_appeared,
238- on_powerd_vanished,
239- self,
240- NULL);
241+ dbus_powerd_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
242+ G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
243+ "com.canonical.powerd",
244+ "/com/canonical/powerd",
245+ p->cancellable,
246+ on_powerd_proxy_ready,
247+ self);
248 }
249
250 static void
251
252=== added file 'src/com.canonical.powerd.xml'
253--- src/com.canonical.powerd.xml 1970-01-01 00:00:00 +0000
254+++ src/com.canonical.powerd.xml 2015-05-20 19:36:35 +0000
255@@ -0,0 +1,84 @@
256+<?xml version="1.0" encoding="UTF-8"?>
257+<node name="/">
258+ <interface name="com.canonical.powerd">
259+ <!-- Properties -->
260+
261+ <property name="brightness" type="i" access="readwrite">
262+ </property>
263+
264+
265+ <!-- Functions -->
266+ <method name="requestSysState">
267+ <arg type="s" name="name" direction="in" />
268+ <arg type="i" name="state" direction="in" />
269+ <arg type="s" name="cookie" direction="out" />
270+ </method>
271+
272+ <method name="clearSysState">
273+ <arg type="s" name="cookie" direction="in" />
274+ </method>
275+
276+ <method name="requestWakeup">
277+ <arg type="s" name="name" direction="in" />
278+ <arg type="t" name="time" direction="in" />
279+ <arg type="s" name="cookie" direction="out" />
280+ </method>
281+
282+ <method name="enableProximityHandling">
283+ <arg type="s" name="name" direction="in" />
284+ </method>
285+
286+ <method name="disableProximityHandling">
287+ <arg type="s" name="name" direction="in" />
288+ </method>
289+
290+ <method name="clearWakeup">
291+ <arg type="s" name="cookie" direction="in" />
292+ </method>
293+
294+ <method name="registerClient">
295+ <arg type="s" name="name" direction="in" />
296+ </method>
297+
298+ <method name="unregisterClient">
299+ <arg type="s" name="name" direction="in" />
300+ </method>
301+
302+ <method name="ackStateChange">
303+ <arg type="i" name="state" direction="in" />
304+ </method>
305+
306+ <!-- User settings -->
307+ <method name="userAutobrightnessEnable">
308+ <arg type="b" name="enable" direction="in" />
309+ </method>
310+
311+ <method name="getBrightnessParams">
312+ <!-- Returns min, max, and default brighness and whether or not
313+ autobrightness is supported, in that order -->
314+ <arg type="(iiiib)" name="params" direction="out" />
315+ </method>
316+
317+ <method name="setUserBrightness">
318+ <arg type="i" name="brightness" direction="in" />
319+ </method>
320+
321+ <!-- for debug/testing -->
322+ <method name="listSysRequests">
323+ <arg type="a(ssi)" name="requestList" direction="out" />
324+ </method>
325+
326+ <method name="getSysRequestStats">
327+ <arg type="a(ssuttt)" name="requestStats" direction="out" />
328+ </method>
329+
330+ <!-- Signals -->
331+ <signal name="SysPowerStateChange">
332+ <arg type="i" name="sysState" direction="out" />
333+ </signal>
334+
335+ <signal name="Wakeup">
336+ </signal>
337+
338+ </interface>
339+</node>

Subscribers

People subscribed via source and target branches