Merge lp:~andreas-pokorny/powerd/blank-on-proximity-powerstate into lp:powerd

Proposed by Andreas Pokorny
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 143
Merged at revision: 143
Proposed branch: lp:~andreas-pokorny/powerd/blank-on-proximity-powerstate
Merge into: lp:powerd
Diff against target: 514 lines (+148/-198)
9 files modified
CMakeLists.txt (+1/-0)
cli/powerd-cli.c (+50/-0)
data/com.canonical.powerd.xml (+8/-0)
src/power-request.c (+2/-1)
src/powerd-internal.h (+6/-0)
src/powerd-object.c (+4/-29)
src/powerd-proximity.cpp (+63/-0)
src/powerd.cpp (+2/-168)
src/powerd.h (+12/-0)
To merge this branch: bzr merge lp:~andreas-pokorny/powerd/blank-on-proximity-powerstate
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+235356@code.launchpad.net

Commit message

Adds two dbus messages to control proximity sensor based blanking from other processes

Those messages are used by telepathy-ofono during a call to blank on proximity depending on the used audio outputs. Since now proximity handling is requested externally the builtin handling ofono voice calls is removed.
powerd-cli now supports a proximity command:
powerd-cli proximity on|off

Description of the change

This change deactivates the builtin proximity handling during calls, and lets an external requester deactivate and activate proximity using a new dbus methods.

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
Ricardo Salveti (rsalveti) wrote :

The change looks fine, still need to test it though (together with https://code.launchpad.net/~andreas-pokorny/telepathy-ofono/control-proximity-handling-in-powerd/+merge/235358).

Created silo 10 so we can have the packages available in the same PPA.

We just need to make sure telepathy-ofono is handling the same use cases as previously done by powerd.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Works fine as well.

review: Approve
144. By Andreas Pokorny

Trigger suspend on proximity events.

+ moved proximity handling to power-request.c

145. By Andreas Pokorny

Adds two new requets to enable and disable proximity based display blanking

instead of combining that behavior with a power state it is now a separate status. That way suspend logic remains unaffected by this.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

As you added a new API, would it be possible to also change powerd-cli to support that?

146. By Andreas Pokorny

Adds an option to powerd-cli enable and disable proximty handling

this also fixes the missing dbus reponse.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Great, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-08-18 21:33:32 +0000
3+++ CMakeLists.txt 2014-10-01 07:49:36 +0000
4@@ -53,6 +53,7 @@
5 src/powerd-client.c
6 src/powerd-object.c
7 src/powerd-sensors.cpp
8+ src/powerd-proximity.cpp
9 src/spline.c
10 src/stats.c
11 src/util.c
12
13=== modified file 'cli/powerd-cli.c'
14--- cli/powerd-cli.c 2014-08-19 00:39:27 +0000
15+++ cli/powerd-cli.c 2014-10-01 07:49:36 +0000
16@@ -101,6 +101,32 @@
17 }
18
19 gboolean
20+requestProximityBlanking(gboolean enable)
21+{
22+ GVariant *ret = NULL;
23+ GError *error = NULL;
24+ const char *method = enable ?
25+ "enableProximityHandling":
26+ "disableProximityHandling";
27+
28+ ret = g_dbus_proxy_call_sync(powerd_proxy,
29+ method,
30+ g_variant_new("(s)", "powerd-cli"),
31+ G_DBUS_CALL_FLAGS_NONE,
32+ -1,
33+ NULL,
34+ &error);
35+ if (ret == NULL) {
36+ cli_warn("%s failed: %s", method, error->message);
37+ g_error_free(error);
38+ return FALSE;
39+ }
40+
41+ g_variant_unref(ret);
42+ return TRUE;
43+}
44+
45+gboolean
46 requestSysState(const char *name, int state,
47 powerd_cookie_t *cookie)
48 {
49@@ -691,6 +717,8 @@
50 printf("client-test - test powerd registration / ack API.\n");
51 printf("display <on>\n"\
52 "\tMake the display stay on\n");
53+ printf("proximity on|off\n"\
54+ "\tEnable disable proximity based screen blanking\n");
55 printf("help\t- display this usage information.\n");
56 printf("list\t- list outstanding requests.\n");
57 printf("listen\t- listen for signals from powerd. This runs a\n"\
58@@ -732,6 +760,7 @@
59 (strcmp(argv[1],"dbusnametest")) &&
60 (strcmp(argv[1],"listen")) &&
61 (strcmp(argv[1],"display")) &&
62+ (strcmp(argv[1],"proximity")) &&
63 (strcmp(argv[1],"help")) &&
64 (strcmp(argv[1],"clear-sys")) &&
65 (strcmp(argv[1],"client-test")) &&
66@@ -821,6 +850,27 @@
67 clearDisplayState(disp_cookie);
68 return 0;
69 }
70+ else if (!strcmp(argv[1],"proximity")) {
71+ gboolean enable = TRUE;
72+ if (argc != 3) {
73+ fprintf(stderr,"proximity requires a parameter: 'on'|'off'\n");
74+ return -1;
75+ }
76+ if (!strcmp(argv[2],"on"))
77+ enable = TRUE;
78+ else if (!strcmp(argv[2],"off"))
79+ enable = FALSE;
80+ else {
81+ fprintf(stderr,"proximity requires a parameter: 'on'|'off'\n");
82+ return -1;
83+ }
84+
85+ if (requestProximityBlanking(enable) == FALSE) {
86+ fprintf(stderr,"failed powerd proximity request\n");
87+ return -1;
88+ }
89+ return 0;
90+ }
91 else if (!strncmp(argv[1],"clear",strlen("clear"))) {
92 if (argc != 3) {
93 fprintf(stderr,"clear requires a cookie\n");
94
95=== modified file 'data/com.canonical.powerd.xml'
96--- data/com.canonical.powerd.xml 2014-08-18 21:33:32 +0000
97+++ data/com.canonical.powerd.xml 2014-10-01 07:49:36 +0000
98@@ -20,6 +20,14 @@
99 <arg type="s" name="cookie" direction="out" />
100 </method>
101
102+ <method name="enableProximityHandling">
103+ <arg type="s" name="name" direction="in" />
104+ </method>
105+
106+ <method name="disableProximityHandling">
107+ <arg type="s" name="name" direction="in" />
108+ </method>
109+
110 <method name="clearWakeup">
111 <arg type="s" name="cookie" direction="in" />
112 </method>
113
114=== modified file 'src/power-request.c'
115--- src/power-request.c 2014-08-12 07:23:07 +0000
116+++ src/power-request.c 2014-10-01 07:49:36 +0000
117@@ -43,6 +43,7 @@
118 const char *owner;
119 uuid_t cookie;
120 enum SysPowerStates state;
121+ int power_state_flags;
122 };
123
124 /*
125@@ -438,6 +439,7 @@
126 if (ret)
127 powerd_warn("Failed to prepare for suspend: %d", ret);
128 }
129+
130 ack_pending = powerd_client_transition_start(pending_system_state);
131 powerd_sys_state_signal_emit(pending_system_state);
132
133@@ -523,7 +525,6 @@
134 delayed_state_transition_process,
135 NULL);
136 }
137-
138 }
139
140 /* Must be called from main loop */
141
142=== modified file 'src/powerd-internal.h'
143--- src/powerd-internal.h 2014-08-18 21:33:32 +0000
144+++ src/powerd-internal.h 2014-10-01 07:49:36 +0000
145@@ -97,6 +97,12 @@
146 gboolean handle_clear_sys_state(PowerdSource *obj,
147 GDBusMethodInvocation *invocation,
148 gchar *cookie);
149+gboolean handle_enable_proximity_handling(PowerdSource *obj,
150+ GDBusMethodInvocation *invocation,
151+ const char *name);
152+gboolean handle_disable_proximity_handling(PowerdSource *obj,
153+ GDBusMethodInvocation *invocation,
154+ const char *name);
155 gboolean request_sys_state_internal(const char *name, int state,
156 uuid_t *cookie, const char *owner);
157 gboolean clear_sys_state_internal(uuid_t cookie);
158
159=== modified file 'src/powerd-object.c'
160--- src/powerd-object.c 2014-08-18 21:33:32 +0000
161+++ src/powerd-object.c 2014-10-01 07:49:36 +0000
162@@ -223,6 +223,10 @@
163 G_CALLBACK(handle_clear_sys_state), powerd_source);
164 g_signal_connect(oskel, "handle-list-sys-requests",
165 G_CALLBACK(handle_list_sys_requests), powerd_source);
166+ g_signal_connect(oskel, "handle-enable-proximity-handling",
167+ G_CALLBACK(handle_enable_proximity_handling), powerd_source);
168+ g_signal_connect(oskel, "handle-disable-proximity-handling",
169+ G_CALLBACK(handle_disable_proximity_handling), powerd_source);
170
171 g_signal_connect(oskel, "handle-register-client",
172 G_CALLBACK(handle_register_client), powerd_source);
173@@ -343,35 +347,6 @@
174 }
175
176 void
177-ofono_voicecall_proxy_connect_cb(GObject *source_object,
178- GAsyncResult *res,
179- gpointer user_data)
180-{
181- GError *error = NULL;
182- GDBusProxy *ofono_proxy;
183- struct call_data *call;
184-
185- ofono_proxy = g_dbus_proxy_new_finish(res, &error);
186- if (error) {
187- powerd_warn("%s failed: %s", __func__, error->message);
188- g_error_free(error);
189- return;
190- }
191-
192- call = user_data;
193- call->ofono_proxy = ofono_proxy;
194-
195- /* Register for voicecall signals */
196- g_signal_connect(ofono_proxy, "g-signal",
197- G_CALLBACK(on_ofono_voicecall_signal), NULL);
198-
199- /* Get current voice call state */
200- g_dbus_proxy_call(ofono_proxy, "GetProperties", NULL,
201- G_DBUS_CALL_FLAGS_NONE, -1, NULL,
202- ofono_voicecall_get_props_cb, NULL);
203-}
204-
205-void
206 ofono_proxy_connect_cb(GObject *source_object,
207 GAsyncResult *res,
208 gpointer user_data)
209
210=== added file 'src/powerd-proximity.cpp'
211--- src/powerd-proximity.cpp 1970-01-01 00:00:00 +0000
212+++ src/powerd-proximity.cpp 2014-10-01 07:49:36 +0000
213@@ -0,0 +1,63 @@
214+/*
215+ * Copyright 2013 Canonical Ltd.
216+ *
217+ * This file is part of powerd.
218+ *
219+ * powerd is free software; you can redistribute it and/or modify
220+ * it under the terms of the GNU General Public License as published by
221+ * the Free Software Foundation; version 3.
222+ *
223+ * powerd is distributed in the hope that it will be useful,
224+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
225+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
226+ * GNU General Public License for more details.
227+ *
228+ * You should have received a copy of the GNU General Public License
229+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
230+ */
231+
232+
233+#include "powerd-internal.h"
234+
235+#include "libsuspend.h"
236+#include "powerd-dbus.h"
237+
238+#include <unordered_set>
239+
240+static std::unordered_set<std::string> active_proximity_users;
241+gboolean handle_enable_proximity_handling(PowerdSource *obj,
242+ GDBusMethodInvocation *invocation,
243+ const char *name)
244+{
245+ if (active_proximity_users.empty())
246+ powerd_sensors_proximity_enable();
247+ active_proximity_users.insert(name);
248+
249+ g_dbus_method_invocation_return_value(invocation, NULL);
250+
251+ return TRUE;
252+}
253+
254+
255+gboolean handle_disable_proximity_handling(PowerdSource *obj,
256+ GDBusMethodInvocation *invocation,
257+ const char *name)
258+{
259+ bool was_empty = active_proximity_users.empty();
260+ active_proximity_users.erase(name);
261+ if (!was_empty && active_proximity_users.empty())
262+ powerd_sensors_proximity_disable();
263+
264+ g_dbus_method_invocation_return_value(invocation, NULL);
265+
266+ return TRUE;
267+}
268+
269+void powerd_proximity_event(gboolean near)
270+{
271+ if (near)
272+ turn_display_on(FALSE, UNITY_SCREEN_REASON_PROXIMITY);
273+ else
274+ turn_display_on(TRUE, UNITY_SCREEN_REASON_PROXIMITY);
275+}
276+
277
278=== modified file 'src/powerd.cpp'
279--- src/powerd.cpp 2014-08-19 20:22:10 +0000
280+++ src/powerd.cpp 2014-10-01 07:49:36 +0000
281@@ -92,31 +92,9 @@
282 /* List with detected modems */
283 static GSList *g_modems = NULL;
284
285-static void free_call_data(void *data)
286-{
287- struct call_data *call = (struct call_data *) data;
288- g_free(call->obj_name);
289- if (call->ofono_proxy)
290- g_object_unref(call->ofono_proxy);
291-}
292-
293-static gint call_data_cmp(gconstpointer a, gconstpointer b)
294-{
295- const struct call_data *call = (const struct call_data *) a;
296- const char *call_name = (const char *) b;
297-
298- return strcmp(call->obj_name, call_name);
299-}
300-
301 static GDBusProxy *g_ofono_proxy;
302 static GDBusProxy *g_unity_proxy;
303
304-/* List with existing calls */
305-static GSList *g_calls = NULL;
306-
307-/* Flag set when proximity sensor is on */
308-static gboolean g_proximity_on = FALSE;
309-
310 static struct power_module* _power_module;
311
312 static void
313@@ -231,87 +209,6 @@
314 g_variant_unref(result);
315 }
316
317-static void notify_proximity_sensor(const char *call_state)
318-{
319- /*
320- * This function enables the proximity sensor in case the new state of the
321- * call is:
322- *
323- * Active - meaning, the call is in progress --> Proximity On
324- * Dialing - a signal made on outbound calls only which means that
325- * we have started to talk to the network, but the call has not
326- * been picked up. --> Proximity On (this signal is not
327- * sent on inbound calls)
328- * Note that the proximity sensor is not activated for "incoming" state
329- * For more details on states see voicecall-api.txt in the ofono source
330- */
331-
332- if (g_proximity_on)
333- return;
334-
335- if (strcmp("active", call_state) == 0
336- || strcmp("dialing", call_state) == 0) {
337- powerd_sensors_proximity_enable();
338- g_proximity_on = TRUE;
339- }
340-}
341-
342-static void deactivate_proximity_sensor(void)
343-{
344- if (!g_proximity_on)
345- return;
346-
347- powerd_sensors_proximity_disable();
348- g_proximity_on = FALSE;
349-}
350-
351-
352-void powerd_proximity_event(gboolean near)
353-{
354- if (near)
355- turn_display_on(FALSE, UNITY_SCREEN_REASON_PROXIMITY);
356- else
357- turn_display_on(TRUE, UNITY_SCREEN_REASON_PROXIMITY);
358-}
359-
360-void
361-ofono_voicecall_get_props_cb(GObject *source_object, GAsyncResult *res,
362- gpointer user_data)
363-{
364- GDBusProxy *client = G_DBUS_PROXY(source_object);
365- GVariant *result;
366- GVariant *item;
367- GError *error = NULL;
368- GVariantIter *iter = NULL;
369-
370- result = g_dbus_proxy_call_finish(client, res, &error);
371- if (result == NULL) {
372- powerd_warn("%s: call error", __func__);
373- return;
374- }
375-
376- g_variant_get(result, "(a{sv})", &iter);
377-
378- while ((item = g_variant_iter_next_value(iter))) {
379- GVariant *value = NULL;
380- const char *prop_name = NULL;
381- const char *call_state = NULL;
382-
383- g_variant_get(item, "{&sv}", &prop_name, &value);
384-
385- if (strcmp("State", prop_name) == 0) {
386- g_variant_get(value, "&s", &call_state);
387- notify_proximity_sensor(call_state);
388- powerd_info("GetProperties. Call State = %s", call_state);
389- }
390-
391- g_variant_unref(value);
392- g_variant_unref(item);
393- }
394-
395- g_variant_unref(result);
396-}
397-
398 void on_ofono_manager_signal(GDBusProxy *proxy, gchar *sender_name,
399 gchar *signal_name, GVariant *parameters, gpointer user_data)
400 {
401@@ -354,75 +251,13 @@
402 GVariant *parameters,
403 gpointer user_data)
404 {
405- GVariant *tmp;
406-
407 if (!strcmp(signal_name, "CallAdded")) {
408- struct call_data *call;
409-
410 turn_display_on(TRUE, UNITY_SCREEN_REASON_NORMAL);
411
412- call = (struct call_data *) calloc(1, sizeof(*call));
413- tmp = g_variant_get_child_value(parameters, 0);
414- call->obj_name = g_variant_dup_string(tmp, NULL);
415- g_calls = g_slist_prepend(g_calls, call);
416-
417- powerd_info("%s incoming call", call->obj_name);
418-
419- /* Connect to voicecall interface */
420- g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM,
421- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
422- NULL,
423- "org.ofono",
424- call->obj_name,
425- "org.ofono.VoiceCall",
426- NULL,
427- (GAsyncReadyCallback) ofono_voicecall_proxy_connect_cb,
428- call);
429-
430- g_variant_unref(tmp);
431+ powerd_info("incoming call");
432
433 } else if (!strcmp(signal_name, "CallRemoved")) {
434- const gchar *object_path;
435- GSList *node;
436-
437- tmp = g_variant_get_child_value(parameters, 0);
438- object_path = g_variant_get_string(tmp, NULL);
439- node = g_slist_find_custom(g_calls, object_path, call_data_cmp);
440- if (node != NULL) {
441- free_call_data(node->data);
442- g_calls = g_slist_delete_link(g_calls, node);
443- powerd_info("%s call removed", object_path);
444- }
445-
446- if (g_calls == NULL)
447- deactivate_proximity_sensor();
448-
449- g_variant_unref(tmp);
450- }
451-}
452-
453-void
454-on_ofono_voicecall_signal (GDBusProxy *proxy,
455- gchar *sender_name,
456- gchar *signal_name,
457- GVariant *parameters,
458- gpointer user_data)
459-{
460- GVariant *value = NULL;
461- const char *prop_name = NULL;
462- const char *call_state = NULL;
463-
464- if (!strcmp(signal_name, "PropertyChanged")) {
465- g_variant_get(parameters, "(&sv)", &prop_name, &value);
466-
467- if (!strcmp(prop_name, "State")) {
468- g_variant_get(value, "&s", &call_state);
469-
470- powerd_info("Call State = %s", call_state);
471- notify_proximity_sensor(call_state);
472- }
473-
474- g_variant_unref(value);
475+ powerd_info("call removed");
476 }
477 }
478
479@@ -608,7 +443,6 @@
480 powerd_client_deinit();
481 powerd_stats_deinit();
482 g_slist_free_full(g_modems, free_modem_data);
483- g_slist_free_full(g_calls, free_call_data);
484 if (g_ofono_proxy)
485 g_object_unref(g_ofono_proxy);
486 if (g_unity_proxy)
487
488=== modified file 'src/powerd.h'
489--- src/powerd.h 2014-05-21 03:17:03 +0000
490+++ src/powerd.h 2014-10-01 07:49:36 +0000
491@@ -30,11 +30,23 @@
492
493 //The Active state will prevent system suspend
494 POWERD_SYS_STATE_ACTIVE,
495+ //Substate of Active with disabled proximity based blanking
496+ POWERD_SYS_STATE_ACTIVE_BLANK_ON_PROXIMITY,
497
498 POWERD_NUM_POWER_STATES
499 };
500
501 /*
502+ * Flags that can be applied to power states
503+ * TODO Create dedicated power states instead?
504+ */
505+enum SysPowerStateFlags {
506+ POWERD_POWER_STATE_FLAG_MASK = 0xFFFF0000,
507+ // disables display blanking on proximity events
508+ POWERD_DISABLE_PROXIMITY_SENSOR_BLANKING = 0x10000,
509+};
510+
511+/*
512 * Clients should treat this as an opaque type. Though this isn't really
513 * possible until the client library is written.
514 */

Subscribers

People subscribed via source and target branches