Merge lp:~albaguirre/powerd/remove-input-inactivity-handling into lp:powerd

Proposed by Alberto Aguirre
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 137
Merged at revision: 131
Proposed branch: lp:~albaguirre/powerd/remove-input-inactivity-handling
Merge into: lp:powerd
Diff against target: 2971 lines (+166/-2029)
16 files modified
CMakeLists.txt (+1/-11)
cli/powerd-cli.c (+39/-411)
data/com.canonical.powerd.gschema.xml (+0/-15)
data/com.canonical.powerd.xml (+0/-28)
debian/changelog (+7/-0)
debian/control (+3/-4)
debian/powerd.conf (+0/-6)
src/backlight.c (+93/-5)
src/display-request.c (+0/-458)
src/display.c (+0/-438)
src/power-request.c (+0/-1)
src/powerd-internal.h (+8/-51)
src/powerd-object.c (+0/-38)
src/powerd.cpp (+15/-250)
src/powerd.h (+0/-18)
src/stats.c (+0/-295)
To merge this branch: bzr merge lp:~albaguirre/powerd/remove-input-inactivity-handling
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+219449@code.launchpad.net

Commit message

Remove display power state and input inactivity handling.

Description of the change

Remove display power state and input inactivity handling.

Display power state changes and inactivity tracking will be handled in unity-system-compositor:
https://code.launchpad.net/~albaguirre/unity-system-compositor/screen-power-state-handling/+merge/213957

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
131. By Alberto Aguirre

uas_light_event_get_light api has changed - use new signature.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
132. By Alberto Aguirre

More cleanup

Call Unity.Screen to turn display when receving call/message/etc
Call Unity.Screen to turn on/off display during an active call based on proximity events.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
133. By Alberto Aguirre

Merge trunk

134. By Alberto Aguirre

powerd-cli: Proxy display on requests to USC

135. By Alberto Aguirre

More display request related removals

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

Comments inline.

review: Needs Information
Revision history for this message
Alberto Aguirre (albaguirre) :
136. By Alberto Aguirre

Keep display on when running in emulator

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
137. By Alberto Aguirre

Update changelog

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

Looks good, and 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 'CMakeLists.txt'
2--- CMakeLists.txt 2014-01-14 03:14:22 +0000
3+++ CMakeLists.txt 2014-06-20 19:46:21 +0000
4@@ -21,8 +21,6 @@
5
6 find_package(PkgConfig)
7 pkg_check_modules(ANDROID_HEADERS android-headers)
8-pkg_check_modules(HYBRIS_IS libis)
9-pkg_check_modules(HYBRIS_SF libsf)
10 pkg_check_modules(GLIB glib-2.0)
11 pkg_check_modules(GIO gio-2.0)
12 pkg_check_modules(GIO-UNIX gio-unix-2.0)
13@@ -45,11 +43,10 @@
14 SRCS
15
16 src/powerd.cpp
17+ src/display.c
18 src/autobrightness.c
19 src/backlight.c
20 src/device-config.c
21- src/display.c
22- src/display-request.c
23 src/log.c
24 src/power-request.c
25 src/power-source.c
26@@ -85,10 +82,6 @@
27 add_subdirectory(src)
28 add_subdirectory(cli)
29
30-include(UseGSettings)
31-SET (POWERD_SCHEMAS "data/com.canonical.powerd.gschema.xml")
32-add_schema(${POWERD_SCHEMAS})
33-
34 add_executable(
35 powerd
36
37@@ -99,7 +92,6 @@
38 powerd
39
40 dbus_bindings
41- ${POWERD_SCHEMAS}
42 )
43
44 target_link_libraries(
45@@ -107,8 +99,6 @@
46 suspend
47
48 ${CMAKE_THREAD_LIBS_INIT}
49- ${HYBRIS_IS_LIBRARIES}
50- ${HYBRIS_SF_LIBRARIES}
51 ${GLIB_LIBRARIES}
52 ${GIO_LIBRARIES}
53 ${GIO-UNIX_LIBRARIES}
54
55=== modified file 'cli/powerd-cli.c'
56--- cli/powerd-cli.c 2014-04-23 02:21:33 +0000
57+++ cli/powerd-cli.c 2014-06-20 19:46:21 +0000
58@@ -41,6 +41,7 @@
59 gboolean silent_errors = FALSE;
60
61 GDBusProxy *powerd_proxy = NULL;
62+GDBusProxy *uscreen_proxy = NULL;
63 char test_dbusname[128] = "";
64
65 /* For tests */
66@@ -53,13 +54,6 @@
67 int state;
68 };
69
70-struct PublicDispRequest {
71- const char *name;
72- const char *owner;
73- enum powerd_display_state state;
74- guint32 flags;
75-};
76-
77 struct SysRequestStats {
78 const char *owner;
79 const char *name;
80@@ -69,19 +63,6 @@
81 guint64 active_since;
82 };
83
84-struct DispRequestStats {
85- const char *owner;
86- const char *name;
87- unsigned active_count;
88- guint64 active_time;
89- guint64 max_active_time;
90- guint64 active_since;
91- guint64 disp_on_time;
92- guint64 disp_on_since;
93- guint64 flag_on_time[POWERD_NUM_DISPLAY_FLAGS];
94- guint64 flag_on_since[POWERD_NUM_DISPLAY_FLAGS];
95-};
96-
97 static GMainLoop *main_loop = NULL;
98 static powerd_cookie_t main_cookie;
99 static gboolean checkForDbusName(const char *dbusname, int count,
100@@ -160,22 +141,20 @@
101 }
102
103 static gboolean
104-requestDisplayState(struct PublicDispRequest pdr, const char *name,
105- powerd_cookie_t *cookie)
106+requestDisplayState(int *cookie)
107 {
108 GVariant *ret = NULL;
109 GError *error = NULL;
110- const char *cookie_ptr;
111 gboolean success = TRUE;
112
113 if (cookie == NULL) {
114- cli_warn("NULL cookie passed to %s", __func__);
115+ cli_warn("NULL cookie store passed to %s", __func__);
116 return FALSE;
117 }
118
119- ret = g_dbus_proxy_call_sync(powerd_proxy,
120- "requestDisplayState",
121- g_variant_new("(siu)", name, pdr.state, pdr.flags),
122+ ret = g_dbus_proxy_call_sync(uscreen_proxy,
123+ "keepDisplayOn",
124+ NULL,
125 G_DBUS_CALL_FLAGS_NONE,
126 -1,
127 NULL,
128@@ -186,44 +165,8 @@
129 return FALSE;
130 }
131
132- g_variant_get(ret, "(&s)", &cookie_ptr);
133- if (strlen(cookie_ptr) != sizeof(powerd_cookie_t) - 1) {
134- cli_warn("Returned cookie has incorrect size");
135- success = FALSE;
136- } else {
137- strncpy(*cookie, cookie_ptr, sizeof(powerd_cookie_t));
138- cli_debug("Got cookie: %s", *cookie);
139- }
140-
141- g_variant_unref(ret);
142- return success;
143-}
144-
145-static gboolean
146-updateDisplayState(struct PublicDispRequest pdr,
147- powerd_cookie_t cookie)
148-{
149- GVariant *ret = NULL;
150- GError *error = NULL;
151- gboolean success = TRUE;
152-
153- if (cookie == NULL) {
154- cli_warn("NULL cookie passed to %s", __func__);
155- return FALSE;
156- }
157-
158- ret = g_dbus_proxy_call_sync(powerd_proxy,
159- "updateDisplayState",
160- g_variant_new("(siu)", cookie, pdr.state, pdr.flags),
161- G_DBUS_CALL_FLAGS_NONE,
162- -1,
163- NULL,
164- &error);
165- if (!ret) {
166- cli_warn("updateDisplayState failed: %s", error->message);
167- g_error_free(error);
168- return FALSE;
169- }
170+ g_variant_get(ret, "(i)", cookie);
171+ cli_debug("Got cookie: %d", *cookie);
172
173 g_variant_unref(ret);
174 return success;
175@@ -280,58 +223,6 @@
176 }
177 }
178
179-static GArray*
180-listDisplayRequests()
181-{
182- GVariant *ret, *item = NULL;
183- GVariantIter *iter = NULL;
184- GArray *retarray = g_array_new(FALSE, FALSE, sizeof(struct PublicDispRequest));
185- GError *error = NULL;
186- struct PublicDispRequest pdr;
187-
188- ret = g_dbus_proxy_call_sync(powerd_proxy,
189- "listDisplayRequests",
190- NULL,
191- G_DBUS_CALL_FLAGS_NONE,
192- -1,
193- NULL,
194- &error);
195- if (ret == NULL) {
196- cli_warn("listDisplayRequests failed: %s", error->message);
197- g_error_free(error);
198- }
199- else {
200- g_variant_get(ret, "(a(ssiu))", &iter);
201- while ((item = g_variant_iter_next_value (iter))) {
202- g_variant_get_child(item, 0, "s", &pdr.name);
203- g_variant_get_child(item, 1, "s", &pdr.owner);
204- g_variant_get_child(item, 2, "i", &pdr.state);
205- g_variant_get_child(item, 3, "u", &pdr.flags);
206- g_array_append_val(retarray, pdr);
207- g_variant_unref(item);
208- }
209- g_variant_unref(ret);
210- }
211- return retarray;
212-}
213-
214-static void
215-printDisplayRequests(GArray *requests)
216-{
217- int i;
218- struct PublicDispRequest *pdr;
219- printf("Display State Requests:\n");
220- if (requests->len == 0) {
221- printf(" None\n");
222- } else {
223- for (i = 0; i < requests->len; i++) {
224- pdr = &g_array_index(requests, struct PublicDispRequest, i);
225- printf(" Name: %s, Owner: %s, State: %d, Flags: %#08x\n",
226- pdr->name, pdr->owner, pdr->state, pdr->flags);
227- }
228- }
229-}
230-
231 static GArray *
232 getSysRequestStats(void)
233 {
234@@ -395,108 +286,6 @@
235 }
236 }
237
238-static GArray *
239-getDispRequestStats(void)
240-{
241- GVariant *ret, *item;
242- GVariantIter *iter;
243- GArray *retarray;
244- GError *error;
245-
246- retarray = g_array_new(FALSE, FALSE, sizeof(struct DispRequestStats));
247-
248- error = NULL;
249- ret = g_dbus_proxy_call_sync(powerd_proxy,
250- "getDispRequestStats",
251- NULL,
252- G_DBUS_CALL_FLAGS_NONE,
253- -1,
254- NULL,
255- &error);
256- if (ret == NULL) {
257- cli_warn("getDispRequestStats failed: %s", error->message);
258- g_error_free(error);
259- } else {
260- g_variant_get(ret, "(a(ssutttttatat))", &iter);
261- while ((item = g_variant_iter_next_value (iter))) {
262- struct DispRequestStats stats;
263- GVariantIter *array_iter;
264- guint64 val;
265- int i;
266-
267- g_variant_get_child(item, 0, "s", &stats.owner);
268- g_variant_get_child(item, 1, "s", &stats.name);
269- g_variant_get_child(item, 2, "u", &stats.active_count);
270- g_variant_get_child(item, 3, "t", &stats.active_time);
271- g_variant_get_child(item, 4, "t", &stats.max_active_time);
272- g_variant_get_child(item, 5, "t", &stats.active_since);
273- g_variant_get_child(item, 6, "t", &stats.disp_on_time);
274- g_variant_get_child(item, 7, "t", &stats.disp_on_since);
275-
276- g_variant_get_child(item, 8, "at", &array_iter);
277- i = 0;
278- while (g_variant_iter_loop(array_iter, "t", &val)) {
279- if (i >= POWERD_NUM_DISPLAY_FLAGS)
280- break;
281- stats.flag_on_time[i++] = val;
282- }
283- g_variant_iter_free(array_iter);
284-
285- g_variant_get_child(item, 9, "at", &array_iter);
286- i = 0;
287- while (g_variant_iter_loop(array_iter, "t", &val)) {
288- if (i >= POWERD_NUM_DISPLAY_FLAGS)
289- break;
290- stats.flag_on_since[i++] = val;
291- }
292- g_variant_iter_free(array_iter);
293-
294- g_array_append_val(retarray, stats);
295- g_variant_unref(item);
296- }
297- g_variant_unref(ret);
298- }
299- return retarray;
300-}
301-
302-static void
303-printDispRequestStats(GArray *stats)
304-{
305- int i, j;
306- struct DispRequestStats *stat;
307- printf("Display Request Statistics:\n");
308- if (stats->len == 0) {
309- printf(" None\n");
310- } else {
311- printf(" %-16.16s %-20.20s %-8.8s %-16.16s %-16.16s %-16.16s %-16.16s %-16.16s",
312- "", "", "Active", "", "Max Active", "", "Display On",
313- "Display On");
314- for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++)
315- printf(" Flag %-2d Flag %-2d ", i, i);
316- printf("\n %-16.16s %-20.20s %-8.8s %-16.16s %-16.16s %-16.16s %-16.16s %-16.16s",
317- "Owner", "Name", "Count", "Active Time", "Time", "Active Since",
318- "Time", "Since");
319- for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++)
320- printf(" On Time On Since ");
321- printf("\n");
322- for (i = 0; i < stats->len; i++) {
323- stat = &g_array_index(stats, struct DispRequestStats, i);
324- printf(" %-16.16s %-20.20s %-8u %-16.6f %-16.6f %-16.6f %-16.6f %-16.6f",
325- stat->owner, stat->name, stat->active_count,
326- (double)stat->active_time / 1000000.0f,
327- (double)stat->max_active_time / 1000000.0f,
328- (double)stat->active_since / 1000000.0f,
329- (double)stat->disp_on_time / 1000000.0f,
330- (double)stat->disp_on_since / 1000000.0f);
331- for (j = 0; j < POWERD_NUM_DISPLAY_FLAGS; j++) {
332- printf(" %-16.6f", (double)stat->flag_on_time[j] / 1000000.0f);
333- printf(" %-16.6f", (double)stat->flag_on_since[j] / 1000000.0f);
334- }
335- printf("\n");
336- }
337- }
338-}
339-
340 gboolean
341 clearSysState(powerd_cookie_t cookie)
342 {
343@@ -520,20 +309,20 @@
344 }
345
346 static gboolean
347-clearDisplayState(powerd_cookie_t cookie)
348+clearDisplayState(int cookie)
349 {
350 GVariant *ret = NULL;
351 GError *error = NULL;
352
353- ret = g_dbus_proxy_call_sync(powerd_proxy,
354- "clearDisplayState",
355- g_variant_new("(s)", cookie),
356+ ret = g_dbus_proxy_call_sync(uscreen_proxy,
357+ "removeDisplayOnRequest",
358+ g_variant_new("(i)", cookie),
359 G_DBUS_CALL_FLAGS_NONE,
360 -1,
361 NULL,
362 &error);
363 if (ret == NULL) {
364- cli_warn("clearDisplayState failed: %s", error->message);
365+ cli_warn("removeDisplayOnRequest failed: %s", error->message);
366 g_error_free(error);
367 return FALSE;
368 }
369@@ -567,9 +356,6 @@
370 requests = listSysRequests();
371 do_test(checkForDbusName(test_dbusname, 0, requests, TRUE));
372 g_array_free(requests, TRUE);
373- requests = listDisplayRequests();
374- do_test(checkForDbusName(test_dbusname, 0, requests, TRUE));
375- g_array_free(requests, TRUE);
376 }
377 else {
378 printf("Did not find child's dbus name\n");
379@@ -712,102 +498,6 @@
380 silence_errors(FALSE);
381 }
382
383-static void
384-runDisplayTests()
385-{
386- int i;
387- int state = 0;
388- gboolean bright = FALSE;
389- powerd_cookie_t cookie, cookies[TEST_NUM_DISP_REQUESTS];
390- GArray *requests = NULL;
391- struct PublicDispRequest pdr = {0,};
392-
393- silence_errors(TRUE);
394-
395- // Hold active state request as long we're running tests
396- requestSysState("main-req", POWERD_SYS_STATE_ACTIVE, &main_cookie);
397-
398- for (i = 0; i < TEST_NUM_DISP_REQUESTS; i++) {
399- char name[16];
400- snprintf(name, sizeof(name), "disp-test-%d", i);
401- pdr.state = state++;
402- pdr.flags = 0;
403- if (bright) {
404- pdr.flags |= POWERD_DISPLAY_FLAG_BRIGHT;
405- }
406- do_test(requestDisplayState(pdr, name, &cookies[i]) == TRUE);
407- if (state >= POWERD_NUM_DISPLAY_STATES) {
408- state = 0;
409- }
410- bright = !bright;
411- }
412-
413- // Make sure we have at least NUM_REQUESTS
414- requests = listDisplayRequests();
415- do_test(requests->len >= TEST_NUM_DISP_REQUESTS);
416- // We should see our PID NUM_REQUESTS times
417- do_test(checkForDbusName(powerd_cli_bus_name, TEST_NUM_DISP_REQUESTS, requests, FALSE));
418- g_array_free(requests, TRUE);
419-
420- for (i = 0; i < TEST_NUM_DISP_REQUESTS; i++)
421- do_test(clearDisplayState(cookies[i]) == TRUE);
422-
423- requests = listDisplayRequests();
424- // We aren't holding anymore with this PID
425- do_test(checkForDbusName(powerd_cli_bus_name, 0, requests, FALSE));
426- g_array_free(requests, TRUE);
427-
428- // Now try and freeing the same cookies again. They should all be
429- // invalid and thus the request fails.
430- for (i = 0; i < TEST_NUM_DISP_REQUESTS; i++)
431- do_test(clearDisplayState(cookies[i]) == FALSE);
432-
433- // Test releasing an invalid cookie format
434- do_test(clearDisplayState("bad cookie") == FALSE);
435-
436- //invalid values
437- pdr.state = -1;
438- do_test(requestDisplayState(pdr, "disp-test", &cookie) == FALSE);
439-
440- pdr.state = POWERD_NUM_DISPLAY_STATES;
441- do_test(requestDisplayState(pdr, "disp-test", &cookie) == FALSE);
442-
443- pdr.state = POWERD_DISPLAY_STATE_ON;
444- pdr.flags = 0xdeadbeef;
445- do_test(requestDisplayState(pdr, "disp-test", &cookie) == FALSE);
446-
447- // updateDisplayState tests
448- pdr.state = POWERD_DISPLAY_STATE_ON;
449- pdr.flags = 0;
450- do_test(requestDisplayState(pdr, "disp-test", &cookie) == TRUE);
451-
452- // update with same state should be okay
453- do_test(updateDisplayState(pdr, cookie) == TRUE);
454-
455- pdr.state = POWERD_DISPLAY_STATE_DONT_CARE;
456- do_test(updateDisplayState(pdr, cookie) == TRUE);
457-
458- pdr.flags = POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS;
459- do_test(updateDisplayState(pdr, cookie) == TRUE);
460-
461- pdr.state = -1;
462- do_test(updateDisplayState(pdr, cookie) == FALSE);
463-
464- do_test(clearDisplayState(cookie) == TRUE);
465-
466- // update with same cookie after clear should fail
467- do_test(updateDisplayState(pdr, cookie) == FALSE);
468-
469- // update with garbage cookie should faile
470- do_test(updateDisplayState(pdr, "bad cookie") == FALSE);
471-
472- //cleanup
473- do_test(clearSysState(main_cookie) == TRUE);
474- do_test(checkForDbusName(powerd_cli_bus_name, 0, requests, TRUE));
475-
476- silence_errors(FALSE);
477-}
478-
479 // Check that dbus owner appears count times in a list of sys/disp requests
480 static gboolean
481 checkForDbusName(const char *dbusname,
482@@ -818,7 +508,6 @@
483 int i;
484 int found = 0;
485 struct PublicSysRequest *psr;
486- struct PublicDispRequest *pdr;
487
488 if (requests == NULL) {
489 cli_warn("NULL requests passed to %s", __func__);
490@@ -833,12 +522,6 @@
491 found++;
492 }
493 }
494- else {
495- pdr = &g_array_index(requests, struct PublicDispRequest, i);
496- if (!(strcmp(pdr->owner, dbusname))) {
497- found++;
498- }
499- }
500 }
501
502 if (found != count) {
503@@ -855,47 +538,6 @@
504 g_main_loop_quit(main_loop);
505 }
506
507-/* Caller ensures that we have at least 4 arguments in argv */
508-static gboolean
509-buildDisplayRequest(char **argv,
510- int argc,
511- struct PublicDispRequest *pdr)
512-{
513- int i;
514-
515- if (!strcasecmp(argv[2],"on")) {
516- pdr->state = POWERD_DISPLAY_STATE_ON;
517- cli_debug("Requesting Display On");
518- }
519- else if (!strcasecmp(argv[2],"dc")) {
520- pdr->state = POWERD_DISPLAY_STATE_DONT_CARE;
521- cli_debug("Requesting Display Don't Care");
522- }
523- else {
524- fprintf(stderr,"invalid state %s, must be either on or dc\n",
525- argv[2]);
526- return FALSE;
527- }
528-
529- pdr->flags = 0;
530- for (i=3; i<argc; i++) {
531- if (!strcmp(argv[i],"proximity")) {
532- pdr->flags |= POWERD_DISPLAY_FLAG_USE_PROXIMITY;
533- cli_debug("Requesting Proximity Sensor Enabled");
534- }
535- else if (!strcmp(argv[i],"disableab")) {
536- pdr->flags |= POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS;
537- cli_debug("Requesting Proximity Disable AutoBrightness");
538- }
539- else if (!strcasecmp(argv[i],"bright")) {
540- pdr->flags |= POWERD_DISPLAY_FLAG_BRIGHT;
541- cli_debug("Requesting Bright");
542- }
543- }
544-
545- return TRUE;
546-}
547-
548 static void
549 setUserAutobrightness(gboolean enable)
550 {
551@@ -968,16 +610,9 @@
552 printf("brightness <brightness> - set user screen brightness.\n");
553 printf("brightness-params - get brightness parameters (dim, min, max, etc.)\n");
554 printf("clear-sys <cookie> - clear a System state request given a cookie.\n");
555- printf("clear-disp <cookie> - clear a Display state request given a cookie.\n");
556 printf("client-test - test powerd registration / ack API.\n");
557- printf("display <on|dc> [bright] [proximity] [disableab]\n"\
558- "\tMake a display state request with the input parameters.\n"\
559- "\tThe first argument represents the state of the display:\n"\
560- "\tOn (on) or Don't Care (dc),\n"\
561- "\tThe final optional arguments respectively:\n"\
562- "\t * make the screen bright [bright]\n"\
563- "\t * enable the proximity sensor [proximity]\n"\
564- "\t * disable autobrightness [disableab]\n");
565+ printf("display <on>\n"\
566+ "\tMake the display stay on\n");
567 printf("help\t- display this usage information.\n");
568 printf("list\t- list outstanding requests.\n");
569 printf("listen\t- listen for signals from powerd. This runs a\n"\
570@@ -997,7 +632,6 @@
571 GError *error = NULL;
572 uid_t myeuid;
573 GArray *requests = NULL;
574- struct PublicDispRequest pdr;
575 GDBusConnection *bus = NULL;
576 const char *bus_name = NULL;
577 powerd_cookie_t cookie;
578@@ -1017,7 +651,6 @@
579 (strcmp(argv[1],"listen")) &&
580 (strcmp(argv[1],"display")) &&
581 (strcmp(argv[1],"help")) &&
582- (strcmp(argv[1],"clear-disp")) &&
583 (strcmp(argv[1],"clear-sys")) &&
584 (strcmp(argv[1],"client-test")) &&
585 (strcmp(argv[1], "autobrightness")) &&
586@@ -1055,22 +688,30 @@
587 return -1;
588 }
589
590+ uscreen_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
591+ G_DBUS_PROXY_FLAGS_NONE,
592+ NULL,
593+ "com.canonical.Unity.Screen",
594+ "/com/canonical/Unity/Screen",
595+ "com.canonical.Unity.Screen",
596+ NULL,
597+ &error);
598+
599+ if (error != NULL) {
600+ cli_warn("could not connect to unity screen: %s", error->message);
601+ g_error_free(error);
602+ return -1;
603+ }
604+
605 if (!strcmp(argv[1],"list")) {
606 requests = listSysRequests();
607 printSysRequests(requests);
608 g_array_free(requests, TRUE);
609- requests = listDisplayRequests();
610- printDisplayRequests(requests);
611- g_array_free(requests, TRUE);
612 }
613 else if (!strcmp(argv[1], "stats")) {
614 requests = getSysRequestStats();
615 printSysRequestStats(requests);
616 g_array_free(requests, TRUE);
617-
618- requests = getDispRequestStats();
619- printDispRequestStats(requests);
620- g_array_free(requests, TRUE);
621 }
622 else if (!strcmp(argv[1],"active-nc")) {
623 requestSysState("active-nc", POWERD_SYS_STATE_ACTIVE,&cookie);
624@@ -1086,20 +727,16 @@
625 return 0;
626 }
627 else if (!strcmp(argv[1],"display")) {
628- if (argc < 3) {
629- fprintf(stderr,"display requires other arguments\n");
630- usage(argv[0]);
631- return -1;
632- }
633- if (buildDisplayRequest(argv,argc,&pdr) == FALSE) {
634- usage(argv[0]);
635- return -1;
636- }
637- requestDisplayState(pdr, "disp-test", &cookie);
638- printf("Display State requested, cookie is %s.\nPress ctrl-c to exit.\n",
639- cookie);
640+ int disp_cookie;
641+ cli_debug("Requesting Display On");
642+ if (requestDisplayState(&disp_cookie) == FALSE) {
643+ fprintf(stderr,"failed display request\n");
644+ return -1;
645+ }
646+ printf("Display State requested, cookie is %d.\nPress ctrl-c to exit.\n",
647+ disp_cookie);
648 pause(); /* wait for SIGINT */
649- clearDisplayState(cookie);
650+ clearDisplayState(disp_cookie);
651 return 0;
652 }
653 else if (!strncmp(argv[1],"clear",strlen("clear"))) {
654@@ -1114,9 +751,6 @@
655 if (!strcmp(argv[1],"clear-sys")) {
656 clearSysState(argv[2]);
657 }
658- else if (!strcmp(argv[1],"clear-disp")) {
659- clearDisplayState(argv[2]);
660- }
661 else {
662 // Note: We should never get here due to earlier checks
663 fprintf(stderr,"Invalid option %s\n",argv[1]);
664@@ -1144,7 +778,6 @@
665
666 runDbusNameVanishTests(argv[0]);
667 runSysTests();
668- runDisplayTests();
669
670 g_object_unref(powerd_cli_bus);
671 powerd_cli_bus = NULL;
672@@ -1163,11 +796,6 @@
673 requestSysState("dbusnametest1", POWERD_SYS_STATE_ACTIVE,&cookie);
674 requestSysState("dbusnametest2", POWERD_SYS_STATE_ACTIVE,&cookie);
675 requestSysState("dbusnametest3", POWERD_SYS_STATE_ACTIVE,&cookie);
676- pdr.state = POWERD_DISPLAY_STATE_DONT_CARE;
677- pdr.flags = 0;
678- requestDisplayState(pdr, "dbusnametest1", &cookie);
679- requestDisplayState(pdr, "dbusnametest2", &cookie);
680- requestDisplayState(pdr, "dbusnametest3", &cookie);
681 g_object_unref(bus);
682 // Exit here without cleanup
683 return 0;
684
685=== removed file 'data/com.canonical.powerd.gschema.xml'
686--- data/com.canonical.powerd.gschema.xml 2013-10-04 14:43:05 +0000
687+++ data/com.canonical.powerd.gschema.xml 1970-01-01 00:00:00 +0000
688@@ -1,15 +0,0 @@
689-<?xml version="1.0" encoding="UTF-8"?>
690-<schemalist gettext-domain="powerd">
691- <schema id="com.canonical.powerd" path="/com/canonical/powerd/">
692- <key name="activity-timeout" type="u">
693- <range min="5" max="3600"/>
694- <default>60</default>
695- <summary>Timeout in seconds for turning off the screen if there is no user activity</summary>
696- </key>
697- <key name="dim-timeout" type="u">
698- <range min="0" max="3600"/>
699- <default>45</default>
700- <summary>Timeout in seconds for dimming the screen if there is no user activity. A value of 0 disables auto-dimming.</summary>
701- </key>
702- </schema>
703-</schemalist>
704
705=== modified file 'data/com.canonical.powerd.xml'
706--- data/com.canonical.powerd.xml 2014-04-23 02:08:02 +0000
707+++ data/com.canonical.powerd.xml 2014-06-20 19:46:21 +0000
708@@ -14,23 +14,6 @@
709 <arg type="s" name="cookie" direction="in" />
710 </method>
711
712- <method name="requestDisplayState">
713- <arg type="s" name="name" direction="in" />
714- <arg type="i" name="state" direction="in" />
715- <arg type="u" name="flags" direction="in" />
716- <arg type="s" name="cookie" direction="out" />
717- </method>
718-
719- <method name="updateDisplayState">
720- <arg type="s" name="cookie" direction="in" />
721- <arg type="i" name="state" direction="in" />
722- <arg type="u" name="flags" direction="in" />
723- </method>
724-
725- <method name="clearDisplayState">
726- <arg type="s" name="cookie" direction="in" />
727- </method>
728-
729 <method name="registerClient">
730 <arg type="s" name="name" direction="in" />
731 </method>
732@@ -63,25 +46,14 @@
733 <arg type="a(ssi)" name="requestList" direction="out" />
734 </method>
735
736- <method name="listDisplayRequests">
737- <arg type="a(ssiu)" name="requestList" direction="out" />
738- </method>
739-
740 <method name="getSysRequestStats">
741 <arg type="a(ssuttt)" name="requestStats" direction="out" />
742 </method>
743
744- <method name="getDispRequestStats">
745- <arg type="a(ssutttttatat)" name="requestStats" direction="out" />
746- </method>
747-
748 <!-- Signals -->
749 <signal name="SysPowerStateChange">
750 <arg type="i" name="sysState" direction="out" />
751 </signal>
752
753- <signal name="DisplayPowerStateChange">
754- <arg type="(iu)" name="displayState" direction="out" />
755- </signal>
756 </interface>
757 </node>
758
759=== modified file 'debian/changelog'
760--- debian/changelog 2014-06-12 10:36:19 +0000
761+++ debian/changelog 2014-06-20 19:46:21 +0000
762@@ -1,3 +1,10 @@
763+powerd (0.16-0ubuntu1) UNRELEASED; urgency=medium
764+
765+ * Remove support for inactivity and display power state handling
766+ * Bump major version due to some dbus API removals
767+
768+ -- Alberto Aguirre <alberto.aguirre@canonical.com> Fri, 20 Jun 2014 14:41:43 -0500
769+
770 powerd (0.15+14.10.20140612-0ubuntu1) utopic; urgency=low
771
772 [ Ubuntu daily release ]
773
774=== modified file 'debian/control'
775--- debian/control 2014-05-29 06:53:15 +0000
776+++ debian/control 2014-06-20 19:46:21 +0000
777@@ -23,8 +23,7 @@
778 Architecture: any
779 Depends: ${misc:Depends}, ${shlibs:Depends}, upower
780 Recommends: ofono
781-Description: Power daemon to monitor and control system and display power state
782- This daemon monitors and controls system and display power states for Ubuntu
783+Description: Power daemon to monitor and control system power state
784+ This daemon monitors and controls system power states for Ubuntu
785 phone and tablet. It provides a dbus interface for system services to request
786- a power state, essentially allowing services to block suspend. Additionally
787- it monitors user activity and power button presses.
788+ a power state, essentially allowing services to block suspend.
789
790=== modified file 'debian/powerd.conf'
791--- debian/powerd.conf 2014-03-28 10:10:28 +0000
792+++ debian/powerd.conf 2014-06-20 19:46:21 +0000
793@@ -42,16 +42,10 @@
794 <allow send_destination="com.canonical.powerd"
795 send_interface="com.canonical.powerd"
796 send_type="method_call" send_member="listSysRequests" />
797- <allow send_destination="com.canonical.powerd"
798- send_interface="com.canonical.powerd"
799- send_type="method_call" send_member="listDisplayRequests" />
800
801 <allow send_destination="com.canonical.powerd"
802 send_interface="com.canonical.powerd"
803 send_type="method_call" send_member="getSysRequestStats" />
804- <allow send_destination="com.canonical.powerd"
805- send_interface="com.canonical.powerd"
806- send_type="method_call" send_member="getDispRequestStats" />
807
808 <allow send_destination="com.canonical.powerd"
809 send_interface="com.canonical.powerd"
810
811=== modified file 'src/backlight.c'
812--- src/backlight.c 2014-04-23 02:08:02 +0000
813+++ src/backlight.c 2014-06-20 19:46:21 +0000
814@@ -33,6 +33,14 @@
815
816 struct light_device_t *light_dev;
817
818+enum bl_state {
819+ BL_OFF,
820+ BL_ON,
821+ BL_AUTO,
822+
823+ NUM_BL_STATES
824+};
825+
826 /*
827 * Defaults are Android default settings. They may not work if we
828 * can't read the per-device values, but they're as good as
829@@ -44,6 +52,8 @@
830 int dim_brightness = 10;
831 int current_brightness = -1;
832
833+static int user_brightness;
834+
835 int powerd_get_brightness(void)
836 {
837 return current_brightness;
838@@ -91,11 +101,6 @@
839 min_user_brightness : brightness);
840 }
841
842-void powerd_dim_screen(void)
843-{
844- powerd_set_brightness(dim_brightness);
845-}
846-
847 int powerd_backlight_init(void)
848 {
849 GValue v = G_VALUE_INIT;
850@@ -144,6 +149,7 @@
851 * Unfortunately the HAL provides no way for us to read the
852 * current brightness when we start. */
853 powerd_set_brightness(default_brightness);
854+ user_brightness = default_brightness;
855
856 return 0;
857 }
858@@ -153,6 +159,58 @@
859 light_dev = NULL;
860 }
861
862+static void set_user_brightness(int brightness)
863+{
864+ int max = powerd_get_max_brightness();
865+ if (brightness > max)
866+ brightness = max;
867+ user_brightness = brightness;
868+}
869+
870+static void set_backlight(enum bl_state state)
871+{
872+ static enum bl_state current_state = BL_ON;
873+ static int restore_brightness = 0;
874+
875+ if (state >= NUM_BL_STATES) {
876+ powerd_warn("Unknown backlight state %d\n", state);
877+ return;
878+ }
879+
880+ if (state != BL_AUTO)
881+ powerd_autobrightness_disable();
882+
883+ /*
884+ * When autobrightness is enabled, it takes a second to
885+ * settle on a brightness level after enabling. This delay
886+ * becomes very noticeable when going from the dim to bright
887+ * state. To avoid this lag, save off the current brightness
888+ * and restore it when transitioning to AUTO mode again.
889+ */
890+ if (current_state != BL_OFF && state == BL_OFF)
891+ restore_brightness = powerd_get_brightness();
892+
893+ switch (state) {
894+ case BL_OFF:
895+ powerd_set_brightness(0);
896+ break;
897+ case BL_ON:
898+ powerd_set_user_brightness(user_brightness);
899+ break;
900+ case BL_AUTO:
901+ if (current_state == BL_OFF && restore_brightness > 0)
902+ powerd_set_brightness(restore_brightness);
903+ powerd_autobrightness_enable();
904+ break;
905+ default:
906+ /* default case is to satisfy static analysis tools, should
907+ * never actually get here */
908+ powerd_error("Unknwown backlight state %d\n", state);
909+ return;
910+ }
911+ current_state = state;
912+}
913+
914
915 /** dbus interfaces **/
916
917@@ -169,3 +227,33 @@
918 ab_available));
919 return TRUE;
920 }
921+
922+gboolean handle_user_autobrightness_enable(PowerdSource *obj,
923+ GDBusMethodInvocation *invocation,
924+ gboolean enable)
925+{
926+ if (powerd_autobrightness_available() && enable)
927+ set_backlight(BL_AUTO);
928+ else
929+ set_backlight(BL_ON);
930+
931+ g_dbus_method_invocation_return_value(invocation, NULL);
932+ return TRUE;
933+}
934+
935+gboolean handle_set_user_brightness(PowerdSource *obj,
936+ GDBusMethodInvocation *invocation,
937+ gint brightness)
938+{
939+ if (brightness == 0)
940+ {
941+ set_backlight(BL_OFF);
942+ }
943+ else
944+ {
945+ set_user_brightness(brightness);
946+ set_backlight(BL_ON);
947+ }
948+ g_dbus_method_invocation_return_value(invocation, NULL);
949+ return TRUE;
950+}
951
952=== removed file 'src/display-request.c'
953--- src/display-request.c 2014-04-14 21:17:04 +0000
954+++ src/display-request.c 1970-01-01 00:00:00 +0000
955@@ -1,458 +0,0 @@
956-/*
957- * Copyright 2013 Canonical Ltd.
958- *
959- * Authors:
960- * Michael Frey: michael.frey@canonical.com
961- * Matthew Fischer: matthew.fischer@canonical.com
962- * Seth Forshee: seth.forshee@canonical.com
963- *
964- * This file is part of powerd.
965- *
966- * powerd is free software; you can redistribute it and/or modify
967- * it under the terms of the GNU General Public License as published by
968- * the Free Software Foundation; version 3.
969- *
970- * powerd is distributed in the hope that it will be useful,
971- * but WITHOUT ANY WARRANTY; without even the implied warranty of
972- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
973- * GNU General Public License for more details.
974- *
975- * You should have received a copy of the GNU General Public License
976- * along with this program. If not, see <http://www.gnu.org/licenses/>.
977- */
978-
979-#include <string.h>
980-#include <errno.h>
981-#include <uuid/uuid.h>
982-
983-#include <glib.h>
984-#include <glib-object.h>
985-#include <gio/gio.h>
986-
987-#include "powerd.h"
988-#include "powerd-internal.h"
989-#include "log.h"
990-
991-struct display_request_internal {
992- struct powerd_display_request req;
993- const char *name;
994- const char *owner;
995-};
996-
997-static struct {
998- unsigned int state[POWERD_NUM_DISPLAY_STATES];
999- unsigned int flags[POWERD_NUM_DISPLAY_FLAGS];
1000-} display_state_count;
1001-
1002-static struct powerd_display_request internal_state = {
1003- .state = POWERD_DISPLAY_STATE_DONT_CARE,
1004- .flags = 0,
1005-};
1006-
1007-static GHashTable *display_request_hash;
1008-
1009-static void update_internal_state(void)
1010-{
1011- struct powerd_display_request new_state;
1012- int i;
1013-
1014- memset(&new_state, 0, sizeof(new_state));
1015-
1016- /* Default to off if no request for display to be on */
1017- if (display_state_count.state[POWERD_DISPLAY_STATE_ON] > 0)
1018- new_state.state = POWERD_DISPLAY_STATE_ON;
1019- else
1020- new_state.state = POWERD_DISPLAY_STATE_DONT_CARE;
1021-
1022- for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
1023- if (display_state_count.flags[i] > 0)
1024- new_state.flags |= (1U << i);
1025- }
1026-
1027- if (!memcmp(&internal_state, &new_state, sizeof(new_state))) {
1028- powerd_debug("display state not changed");
1029- return;
1030- }
1031-
1032- powerd_debug("Internal state updated: state %d flags 0x%08x",
1033- new_state.state, new_state.flags);
1034- internal_state = new_state;
1035- powerd_set_display_state(&internal_state);
1036-}
1037-
1038-static void __add_request(struct powerd_display_request *req)
1039-{
1040- unsigned int flags;
1041- int i;
1042-
1043- display_state_count.state[req->state]++;
1044-
1045- flags = req->flags;
1046- for (i = 0; flags && i < POWERD_NUM_DISPLAY_FLAGS; flags >>= 1, i++) {
1047- if (flags & 1)
1048- display_state_count.flags[i]++;
1049- }
1050-}
1051-
1052-static void __remove_request(struct powerd_display_request *req)
1053-{
1054- unsigned int flags;
1055- int i;
1056-
1057- if (display_state_count.state[req->state] > 0)
1058- display_state_count.state[req->state]--;
1059-
1060- flags = req->flags;
1061- for (i = 0; flags && i < POWERD_NUM_DISPLAY_FLAGS; flags >>= 1, i++) {
1062- if ((flags & 1) && display_state_count.flags[i] > 0)
1063- display_state_count.flags[i]--;
1064- }
1065-}
1066-
1067-static void add_request(struct display_request_internal *request)
1068-{
1069- g_hash_table_insert(display_request_hash, request->req.cookie, request);
1070- powerd_dbus_name_watch_add(request->owner);
1071- __add_request(&request->req);
1072- update_internal_state();
1073- powerd_account_add_display_req(request->owner, request->name,
1074- &request->req);
1075-}
1076-
1077-static gboolean update_request(struct powerd_display_request *new_req)
1078-{
1079- struct display_request_internal *ireq;
1080-
1081- ireq = g_hash_table_lookup(display_request_hash, new_req->cookie);
1082- if (!ireq) {
1083- powerd_debug("Display request to update not found");
1084- return FALSE;
1085- }
1086-
1087- __remove_request(&ireq->req);
1088- __add_request(new_req);
1089-
1090- ireq->req.state = new_req->state;
1091- ireq->req.flags = new_req->flags;
1092-
1093- update_internal_state();
1094- powerd_account_update_display_req(ireq->owner, ireq->name, &ireq->req);
1095- return TRUE;
1096-}
1097-
1098-static gboolean remove_request(uuid_t cookie)
1099-{
1100- struct display_request_internal *ireq;
1101- struct powerd_display_request req;
1102- gboolean found = FALSE;
1103-
1104- /*
1105- * This involves two lookups into the hash, one to find the
1106- * request so we can retrieve the state and another to remove
1107- * it. GHashTable doesn't seem to provide any more efficient
1108- * way to do this; too bad g_hash_table_steal() doesn't return
1109- * a pointer to the data.
1110- */
1111- ireq = g_hash_table_lookup(display_request_hash, cookie);
1112- if (ireq) {
1113- req = ireq->req;
1114- /* We need to remove it from our watch hash and do accounting
1115- * before we remove it from the state hash or the ireq->owner
1116- * memory will be freed before we try to use it.
1117- */
1118- powerd_dbus_name_watch_remove(ireq->owner);
1119- powerd_account_clear_display_req(ireq->owner, ireq->name);
1120- found = g_hash_table_remove(display_request_hash, cookie);
1121- if (!found)
1122- powerd_warn("Display request found on lookup but not on remove");
1123- }
1124-
1125- if (found) {
1126- __remove_request(&req);
1127- update_internal_state();
1128- }
1129-
1130- return found;
1131-}
1132-
1133-static gboolean request_valid(struct powerd_display_request *request)
1134-{
1135- if ((unsigned)request->state >= POWERD_NUM_DISPLAY_STATES) {
1136- powerd_warn("Invalid display state requested: %d", request->state);
1137- return FALSE;
1138- }
1139-
1140- /*
1141- * XXX: This will warn if we get up to 32 flags, but in that
1142- * case the check should just be removed.
1143- */
1144- if (request->flags & (-1U << POWERD_NUM_DISPLAY_FLAGS)) {
1145- powerd_warn("Invalid display flags requested: 0x%08x", request->flags);
1146- return FALSE;
1147- }
1148-
1149- return TRUE;
1150-}
1151-
1152-static int add_request_worker(gpointer data)
1153-{
1154- struct display_request_internal *req = data;
1155- add_request(req);
1156- return 0;
1157-}
1158-
1159-/*
1160- * @request need not refer to persistent memory, as the data from
1161- * the struct will be copied into internally-managed storage.
1162- */
1163-static int __powerd_add_display_request(struct powerd_display_request *request,
1164- const char *name, const char *owner)
1165-{
1166- struct display_request_internal *hash_req;
1167-
1168- if (!request_valid(request))
1169- return -EINVAL;
1170-
1171- uuid_generate(request->cookie);
1172- hash_req = g_new(struct display_request_internal, 1);
1173- hash_req->req = *request;
1174- hash_req->name = g_strdup(name);
1175- hash_req->owner = g_strdup(owner);
1176- powerd_run_mainloop_sync(add_request_worker, hash_req);
1177- return 0;
1178-}
1179-
1180-/*
1181- * @request need not refer to persistent memory, as the data from
1182- * the struct will be copied into internally-managed storage.
1183- */
1184-int powerd_add_display_request(struct powerd_display_request *request,
1185- const char *name)
1186-{
1187- if (!request || !name) {
1188- powerd_warn("powerd_add_display_request() called with invalid args");
1189- return -EINVAL;
1190- }
1191- return __powerd_add_display_request(request, name, "internal");
1192-}
1193-
1194-static int update_request_worker(gpointer data)
1195-{
1196- struct powerd_display_request *req = data;
1197- return update_request(req);
1198-}
1199-
1200-int powerd_update_display_request(struct powerd_display_request *request)
1201-{
1202- gboolean found;
1203-
1204- if (!request_valid(request))
1205- return -EINVAL;
1206-
1207- found = powerd_run_mainloop_sync(update_request_worker, request);
1208- return found ? 0 : -EINVAL;
1209-}
1210-
1211-static int remove_request_worker(gpointer data)
1212-{
1213- unsigned char *uuid = data;
1214- return remove_request(uuid);
1215-}
1216-
1217-int powerd_remove_display_request(uuid_t cookie)
1218-{
1219- gboolean found;
1220-
1221- found = powerd_run_mainloop_sync(remove_request_worker, cookie);
1222- return found ? 0 : -EINVAL;
1223-}
1224-
1225-/** dbus method handling **/
1226-
1227-gboolean handle_add_display_request(PowerdSource *obj,
1228- GDBusMethodInvocation *invocation,
1229- const char *name, int state, guint32 flags)
1230-{
1231- struct powerd_display_request req;
1232- const char *owner;
1233- char ext_cookie[UUID_STR_LEN];
1234- int ret;
1235-
1236- memset(&req, 0, sizeof(req));
1237-
1238- owner = g_dbus_method_invocation_get_sender(invocation);
1239- powerd_debug("%s from %s: state %d flags %#08x",
1240- __func__, owner, state, flags);
1241-
1242- req.state = state;
1243- req.flags = flags;
1244-
1245- ret = __powerd_add_display_request(&req, name, owner);
1246- if (ret) {
1247- g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
1248- G_DBUS_ERROR_INVALID_ARGS,
1249- "Invalid display request");
1250- } else {
1251- powerd_debug("%s: SUCCESS", __func__);
1252- uuid_unparse(req.cookie, ext_cookie);
1253- g_dbus_method_invocation_return_value(invocation,
1254- g_variant_new("(s)", ext_cookie));
1255- }
1256-
1257- return TRUE;
1258-}
1259-
1260-gboolean handle_update_display_request(PowerdSource *obj,
1261- GDBusMethodInvocation *invocation,
1262- const gchar *ext_cookie, int state,
1263- guint32 flags)
1264-{
1265- struct powerd_display_request req;
1266- uuid_t cookie;
1267- int ret;
1268-
1269- memset(&req, 0, sizeof(req));
1270-
1271- powerd_debug("%s from %s: cookie: %s state %d flags %#08x",
1272- __func__, g_dbus_method_invocation_get_sender(invocation),
1273- ext_cookie, state, flags);
1274-
1275- if (uuid_parse(ext_cookie, cookie)) {
1276- g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
1277- G_DBUS_ERROR_INVALID_ARGS,
1278- "Invalid cookie: %s",
1279- ext_cookie);
1280- return TRUE;
1281- }
1282-
1283- memcpy(req.cookie, cookie, sizeof(uuid_t));
1284- req.state = state;
1285- req.flags = flags;
1286-
1287- ret = powerd_update_display_request(&req);
1288- if (ret) {
1289- g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
1290- G_DBUS_ERROR_INVALID_ARGS,
1291- "Invalid display request");
1292- } else {
1293- powerd_debug("%s: SUCCESS", __func__);
1294- g_dbus_method_invocation_return_value(invocation, NULL);
1295- }
1296-
1297- return TRUE;
1298-}
1299-
1300-gboolean handle_clear_display_request(PowerdSource *obj,
1301- GDBusMethodInvocation *invocation,
1302- const gchar *ext_cookie)
1303-{
1304- int ret;
1305- uuid_t cookie;
1306-
1307- powerd_debug("%s from %s, cookie: %s", __func__,
1308- g_dbus_method_invocation_get_sender(invocation), ext_cookie);
1309-
1310- if (uuid_parse(ext_cookie, cookie)) {
1311- g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
1312- G_DBUS_ERROR_INVALID_ARGS,
1313- "Invalid cookie: %s",
1314- ext_cookie);
1315- return TRUE;
1316- }
1317-
1318- ret = powerd_remove_display_request(cookie);
1319- if (ret) {
1320- g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
1321- G_DBUS_ERROR_INVALID_ARGS,
1322- "Invalid cookie: %s", ext_cookie);
1323- } else {
1324- g_dbus_method_invocation_return_value(invocation, NULL);
1325- }
1326-
1327- return TRUE;
1328-}
1329-
1330-static int build_display_request_list(GVariantBuilder *builder)
1331-{
1332- GHashTableIter iter;
1333- gpointer key, value;
1334- int count = 0;
1335-
1336- g_hash_table_iter_init(&iter, display_request_hash);
1337- while (g_hash_table_iter_next(&iter, &key, &value)) {
1338- struct display_request_internal *ireq = value;
1339- struct powerd_display_request *req = &ireq->req;
1340- g_variant_builder_add(builder, "(ssiu)", ireq->name, ireq->owner,
1341- req->state, req->flags);
1342- count++;
1343- }
1344- return count;
1345-}
1346-
1347-gboolean handle_list_display_requests(PowerdSource *obj,
1348- GDBusMethodInvocation *invocation)
1349-{
1350- GVariant *list, *tuple;
1351- GVariantBuilder *builder;
1352- int count;
1353-
1354- builder = g_variant_builder_new(G_VARIANT_TYPE("a(ssiu)"));
1355- count = build_display_request_list(builder);
1356- if (count > 0) {
1357- list = g_variant_builder_end(builder);
1358- } else {
1359- g_variant_builder_clear(builder);
1360- list = g_variant_new_array(G_VARIANT_TYPE("(ssiu)"), NULL, 0);
1361- }
1362-
1363- tuple = g_variant_new_tuple(&list, 1);
1364- g_dbus_method_invocation_return_value(invocation, tuple);
1365- g_variant_builder_unref(builder);
1366-
1367- return TRUE;
1368-}
1369-
1370-/* Destructor for hash table */
1371-static void display_request_destroy(gpointer data)
1372-{
1373- struct display_request_internal *req = data;
1374-
1375- g_free((gpointer)req->name);
1376- g_free((gpointer)req->owner);
1377- g_free(req);
1378-}
1379-
1380-void display_request_init(void)
1381-{
1382- display_request_hash = g_hash_table_new_full(powerd_uuid_hash,
1383- powerd_uuid_equal,
1384- NULL, display_request_destroy);
1385-}
1386-
1387-void display_request_deinit(void)
1388-{
1389- g_hash_table_destroy(display_request_hash);
1390-}
1391-
1392-/*
1393- * Callers may use this to clear all requests that the specified owner
1394- * is holding. This is used when the owner drops off of dbus
1395- */
1396-void
1397-clear_disp_state_by_owner(const char *owner)
1398-{
1399- GHashTableIter iter;
1400- gpointer key, value;
1401-
1402- g_hash_table_iter_init(&iter, display_request_hash);
1403- while (g_hash_table_iter_next(&iter, &key, &value)) {
1404- struct display_request_internal *ireq = value;
1405- if (!strcmp(owner, ireq->owner)) {
1406- powerd_account_clear_display_req(ireq->owner, ireq->name);
1407- __remove_request(&ireq->req);
1408- powerd_dbus_name_watch_remove(ireq->owner);
1409- g_hash_table_iter_remove(&iter);
1410- }
1411- }
1412- update_internal_state();
1413-}
1414
1415=== added file 'src/display.c'
1416--- src/display.c 1970-01-01 00:00:00 +0000
1417+++ src/display.c 2014-06-20 19:46:21 +0000
1418@@ -0,0 +1,132 @@
1419+/*
1420+ * Copyright 2013-2014 Canonical Ltd.
1421+ *
1422+ * Authors:
1423+ * Michael Frey: michael.frey@canonical.com
1424+ * Matthew Fischer: matthew.fischer@canonical.com
1425+ * Seth Forshee: seth.forshee@canonical.com
1426+ *
1427+ * This file is part of powerd.
1428+ *
1429+ * powerd is free software; you can redistribute it and/or modify
1430+ * it under the terms of the GNU General Public License as published by
1431+ * the Free Software Foundation; version 3.
1432+ *
1433+ * powerd is distributed in the hope that it will be useful,
1434+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1435+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1436+ * GNU General Public License for more details.
1437+ *
1438+ * You should have received a copy of the GNU General Public License
1439+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1440+ */
1441+
1442+#include <string.h>
1443+
1444+#include <glib.h>
1445+#include <gio/gio.h>
1446+
1447+#include "powerd-internal.h"
1448+#include "log.h"
1449+
1450+static GDBusProxy* create_uscreen_proxy()
1451+{
1452+ GError *error = NULL;
1453+ GDBusProxy *uscreen_proxy = NULL;
1454+ uscreen_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
1455+ G_DBUS_PROXY_FLAGS_NONE,
1456+ NULL,
1457+ "com.canonical.Unity.Screen",
1458+ "/com/canonical/Unity/Screen",
1459+ "com.canonical.Unity.Screen",
1460+ NULL,
1461+ &error);
1462+
1463+ if (error != NULL) {
1464+ powerd_warn("could not connect to Unity.Screen: %s", error->message);
1465+ g_error_free(error);
1466+ return NULL;
1467+ }
1468+
1469+ return uscreen_proxy;
1470+}
1471+
1472+static void request_keep_display_on(GDBusConnection *connection,
1473+ const gchar *name,
1474+ const gchar *name_owner,
1475+ gpointer user_data)
1476+{
1477+ GDBusProxy *uscreen_proxy = NULL;
1478+ GVariant *ret = NULL;
1479+ GError *error = NULL;
1480+ int request_id;
1481+
1482+ powerd_debug("request_keep_display_on");
1483+
1484+ uscreen_proxy = create_uscreen_proxy();
1485+ if (uscreen_proxy == NULL)
1486+ {
1487+ powerd_warn("failed creating unity screen proxy to keep display on");
1488+ return;
1489+ }
1490+
1491+ ret = g_dbus_proxy_call_sync(uscreen_proxy,
1492+ "keepDisplayOn",
1493+ NULL,
1494+ G_DBUS_CALL_FLAGS_NONE,
1495+ -1,
1496+ NULL,
1497+ &error);
1498+
1499+ if (ret == NULL) {
1500+ powerd_warn("keepDisplayOn failed: %s", error->message);
1501+ g_error_free(error);
1502+ return;
1503+ }
1504+
1505+ g_variant_get(ret, "(i)", &request_id);
1506+ powerd_debug("keepDisplayOn request succeeded - id: %d", request_id);
1507+
1508+ g_variant_unref(ret);
1509+ g_object_unref(uscreen_proxy);
1510+}
1511+
1512+gboolean turn_display_on(gboolean on, enum DisplayStateChangeReason reason)
1513+{
1514+ GDBusProxy *uscreen_proxy = NULL;
1515+
1516+ powerd_debug("turn_display_on(%d)", on);
1517+
1518+ if (on)
1519+ powerd_hal_signal_activity();
1520+
1521+ uscreen_proxy = create_uscreen_proxy();
1522+ if (uscreen_proxy == NULL)
1523+ return FALSE;
1524+
1525+ g_dbus_proxy_call(uscreen_proxy,
1526+ "setScreenPowerMode",
1527+ g_variant_new("(si)", (on ? "on" : "off"), reason),
1528+ G_DBUS_CALL_FLAGS_NONE,
1529+ -1,
1530+ NULL,
1531+ NULL,
1532+ NULL);
1533+
1534+ g_object_unref(uscreen_proxy);
1535+
1536+ return TRUE;
1537+}
1538+
1539+void keep_display_on()
1540+{
1541+ powerd_debug("issuing keep_display_on request");
1542+
1543+ g_bus_watch_name(G_BUS_TYPE_SYSTEM,
1544+ "com.canonical.Unity.Screen",
1545+ G_BUS_NAME_WATCHER_FLAGS_NONE,
1546+ request_keep_display_on,
1547+ NULL,
1548+ NULL,
1549+ NULL);
1550+}
1551
1552=== removed file 'src/display.c'
1553--- src/display.c 2014-04-14 21:17:04 +0000
1554+++ src/display.c 1970-01-01 00:00:00 +0000
1555@@ -1,438 +0,0 @@
1556-/*
1557- * Copyright 2013 Canonical Ltd.
1558- *
1559- * Authors:
1560- * Michael Frey: michael.frey@canonical.com
1561- * Matthew Fischer: matthew.fischer@canonical.com
1562- * Seth Forshee: seth.forshee@canonical.com
1563- *
1564- * This file is part of powerd.
1565- *
1566- * powerd is free software; you can redistribute it and/or modify
1567- * it under the terms of the GNU General Public License as published by
1568- * the Free Software Foundation; version 3.
1569- *
1570- * powerd is distributed in the hope that it will be useful,
1571- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1572- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1573- * GNU General Public License for more details.
1574- *
1575- * You should have received a copy of the GNU General Public License
1576- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1577- */
1578-
1579-#include <stdio.h>
1580-#include <string.h>
1581-#include <errno.h>
1582-#include <unistd.h>
1583-#include <sys/types.h>
1584-#include <sys/stat.h>
1585-#include <fcntl.h>
1586-
1587-#include <glib.h>
1588-#include <glib-object.h>
1589-
1590-#include "powerd.h"
1591-#include "powerd-internal.h"
1592-#include "log.h"
1593-
1594-enum bl_state {
1595- BL_OFF,
1596- BL_DIM,
1597- BL_BRIGHT,
1598- BL_AUTO,
1599-
1600- NUM_BL_STATES
1601-};
1602-static enum bl_state target_bl_state = BL_BRIGHT;
1603-
1604-/* Treat "don't care" display state as off */
1605-#define DISPLAY_STATE_OFF POWERD_DISPLAY_STATE_DONT_CARE
1606-
1607-/* Autobrightness only enabled when bright && !disabled */
1608-#define AB_ENABLED_MASK (POWERD_DISPLAY_FLAG_BRIGHT | \
1609- POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS)
1610-#define AB_ENABLED POWERD_DISPLAY_FLAG_BRIGHT
1611-
1612-static int user_brightness;
1613-static gboolean user_ab_enabled;
1614-
1615-/* Assume screen is off to start; we will force it on */
1616-static uuid_t internal_request_cookie;
1617-
1618-/* Currently requested state of the display */
1619-struct powerd_display_request internal_state = {
1620- .state = DISPLAY_STATE_OFF,
1621- .flags = 0,
1622-};
1623-
1624-/*
1625- * When using the proximity sensor, our actual state of the screen
1626- * may not match the requested state in internal_state. Therefore
1627- * this variable keeps track of the actual state of the screen.
1628- */
1629-enum powerd_display_state actual_screen_state = DISPLAY_STATE_OFF;
1630-
1631-/*
1632- * Screen state overrides. These are used when powerd needs to force
1633- * the screen off regardless of the requested display state.
1634- */
1635-static unsigned screen_off_overrides;
1636-
1637-static const char *display_state_strs[POWERD_NUM_DISPLAY_STATES] = {
1638- [POWERD_DISPLAY_STATE_DONT_CARE] = "off",
1639- [POWERD_DISPLAY_STATE_ON] = "on",
1640-};
1641-
1642-static const char *display_state_to_str(enum powerd_display_state state)
1643-{
1644- if (state >= POWERD_NUM_DISPLAY_STATES)
1645- return "invalid";
1646- return display_state_strs[state];
1647-}
1648-
1649-static gboolean ab_enabled(guint32 flags)
1650-{
1651- if (!powerd_autobrightness_available())
1652- return FALSE;
1653- if (!user_ab_enabled)
1654- return FALSE;
1655- return (flags & AB_ENABLED_MASK) == AB_ENABLED;
1656-}
1657-
1658-static void set_backlight(enum bl_state state)
1659-{
1660- static enum bl_state current_state = BL_BRIGHT;
1661- static int restore_brightness = 0;
1662-
1663- if (state >= NUM_BL_STATES) {
1664- powerd_warn("Unknown backlight state %d\n", state);
1665- return;
1666- }
1667- if (state != BL_AUTO)
1668- powerd_autobrightness_disable();
1669-
1670- /*
1671- * When we're enabling autobrightness it takes a second to
1672- * settle on a brightness level after enabling. This delay
1673- * becomes very noticible when going from the dim to bright
1674- * state. To avoid this lag, save off the current brightness
1675- * any time the state goes from BRIGHT or AUTO and restore
1676- * it if transitioning back to AUTO.
1677- */
1678- if (current_state >= BL_BRIGHT && state < BL_BRIGHT)
1679- restore_brightness = powerd_get_brightness();
1680-
1681- switch (state) {
1682- case BL_OFF:
1683- powerd_set_brightness(0);
1684- break;
1685- case BL_DIM:
1686- powerd_dim_screen();
1687- break;
1688- case BL_BRIGHT:
1689- powerd_set_user_brightness(user_brightness);
1690- break;
1691- case BL_AUTO:
1692- if (current_state < BL_BRIGHT && restore_brightness > 0)
1693- powerd_set_brightness(restore_brightness);
1694- powerd_autobrightness_enable();
1695- break;
1696- default:
1697- /* default case is to satisfy static analysis tools, should
1698- * never actually get here */
1699- powerd_error("Unknwown backlight state %d\n", state);
1700- return;
1701- }
1702- current_state = state;
1703-}
1704-
1705-gboolean display_set_power_mode(int display, const char *power_mode)
1706-{
1707- GError *error = NULL;
1708- GDBusProxy *unity_proxy = NULL;
1709-
1710- powerd_debug("display_set_power_mode(%s)", power_mode);
1711-
1712- if (strcmp(power_mode, "on") == 0)
1713- powerd_hal_signal_activity();
1714-
1715- unity_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
1716- G_DBUS_PROXY_FLAGS_NONE,
1717- NULL,
1718- "com.canonical.Unity.Screen",
1719- "/com/canonical/Unity/Screen",
1720- "com.canonical.Unity.Screen",
1721- NULL,
1722- &error);
1723-
1724- if (error != NULL) {
1725- powerd_warn("could not connect to Unity: %s", error->message);
1726- g_error_free(error);
1727- return FALSE;
1728- }
1729-
1730- GVariant *ret = g_dbus_proxy_call_sync(unity_proxy,
1731- "setScreenPowerMode",
1732- g_variant_new("(s)", power_mode),
1733- G_DBUS_CALL_FLAGS_NONE,
1734- -1,
1735- NULL,
1736- &error);
1737-
1738- if (ret == NULL) {
1739- powerd_warn("screen power setting failed: %s", error->message);
1740- g_error_free(error);
1741- g_object_unref(unity_proxy);
1742- return FALSE;
1743- }
1744-
1745- g_object_unref(unity_proxy);
1746-
1747- return TRUE;
1748-}
1749-
1750-static void turn_on_display(void)
1751-{
1752- powerd_debug("turning on display");
1753- display_set_power_mode(0, "on");
1754- set_backlight(target_bl_state);
1755-}
1756-
1757-gboolean powerd_display_enabled(void)
1758-{
1759- return actual_screen_state == POWERD_DISPLAY_STATE_ON;
1760-}
1761-
1762-static void update_display_state(struct powerd_display_request *req)
1763-{
1764- enum powerd_display_state state = req->state;
1765- int applied_state;
1766- int ret;
1767-
1768- applied_state = screen_off_overrides ? DISPLAY_STATE_OFF : state;
1769-
1770- switch (applied_state) {
1771- case DISPLAY_STATE_OFF:
1772- if (actual_screen_state == DISPLAY_STATE_OFF) {
1773- /* Nothing to do */
1774- return;
1775- }
1776-
1777- powerd_debug("turning off display");
1778- set_backlight(BL_OFF);
1779- if (!display_set_power_mode(0, "off")) {
1780- powerd_warn("failed to set display power mode, not clearing state");
1781- return;
1782- }
1783-
1784- powerd_debug("Releasing internal active state request");
1785- ret = clear_sys_state_internal(internal_request_cookie);
1786- if (!ret) {
1787- char cookie_str[UUID_STR_LEN];
1788- uuid_unparse(internal_request_cookie, cookie_str);
1789- powerd_warn("Internal system state request cookie invalid: %s",
1790- cookie_str);
1791- }
1792- break;
1793- case POWERD_DISPLAY_STATE_ON:
1794- if (ab_enabled(req->flags))
1795- target_bl_state = BL_AUTO;
1796- else if (req->flags & POWERD_DISPLAY_FLAG_BRIGHT)
1797- target_bl_state = BL_BRIGHT;
1798- else
1799- target_bl_state = BL_DIM;
1800-
1801- if (actual_screen_state != POWERD_DISPLAY_STATE_ON) {
1802- powerd_debug("Requesting active state internally");
1803- ret = request_sys_state_internal("display-request",
1804- POWERD_SYS_STATE_ACTIVE,
1805- &internal_request_cookie, NULL);
1806- if (!ret)
1807- powerd_warn("Request for active state failed");
1808-
1809- /*
1810- * If currently in the suspend state we need to wait for
1811- * notification of entering the active state, otherwise the
1812- * screen may fail to turn on for devices using earlysuspend.
1813- * Otherwise we can turn on the screen right away.
1814- */
1815- if (!powerd_suspend_active())
1816- turn_on_display();
1817- } else {
1818- /* Only updating backlight state */
1819- set_backlight(target_bl_state);
1820- }
1821- break;
1822- default:
1823- powerd_warn("Invalid display state %d", applied_state);
1824- return;
1825- }
1826-
1827- actual_screen_state = applied_state;
1828-
1829- powerd_display_state_signal_emit(actual_screen_state, req->flags);
1830-}
1831-
1832-static void update_flags(guint32 flags)
1833-{
1834- int prox_enabled, internal_prox_enabled;
1835-
1836- prox_enabled = (flags & POWERD_DISPLAY_FLAG_USE_PROXIMITY);
1837- internal_prox_enabled = (internal_state.flags & POWERD_DISPLAY_FLAG_USE_PROXIMITY);
1838-
1839- if (prox_enabled != internal_prox_enabled) {
1840- if (prox_enabled) {
1841- powerd_sensors_proximity_enable();
1842- } else {
1843- powerd_sensors_proximity_disable();
1844- powerd_display_clear_override(POWERD_OVERRIDE_REASON_PROXIMITY);
1845- }
1846- }
1847-}
1848-
1849-/*
1850- * *** WARNING ***
1851- *
1852- * This should now only be called by display request code. Everyone
1853- * else must use powerd_{add,remove}_display_request()!!!
1854- */
1855-void powerd_set_display_state(struct powerd_display_request *req)
1856-{
1857- powerd_debug("powerd_set_display_state: %s -> %s, 0x%x -> 0x%x",
1858- display_state_to_str(internal_state.state),
1859- display_state_to_str(req->state),
1860- internal_state.flags, req->flags);
1861-
1862- /* Update flags before display state to ensure proximity flag is
1863- * taken into account */
1864- update_flags(req->flags);
1865- update_display_state(req);
1866-
1867- internal_state = *req;
1868-}
1869-
1870-static void user_ab_enable(gboolean enable)
1871-{
1872- user_ab_enabled = enable;
1873- update_display_state(&internal_state);
1874-}
1875-
1876-static gboolean prox_update_worker(gpointer data)
1877-{
1878- unsigned long near = (unsigned long)data;
1879- if (near)
1880- powerd_display_set_override(POWERD_OVERRIDE_REASON_PROXIMITY);
1881- else
1882- powerd_display_clear_override(POWERD_OVERRIDE_REASON_PROXIMITY);
1883- return FALSE;
1884-}
1885-
1886-void powerd_proximity_event(gboolean near)
1887-{
1888- unsigned long data = (unsigned long)near;
1889- g_timeout_add(0, prox_update_worker, (gpointer)data);
1890-}
1891-
1892-struct apply_override_data {
1893- enum powerd_override_reason reason;
1894- int set;
1895-};
1896-
1897-static int apply_override_worker(gpointer data)
1898-{
1899- struct apply_override_data *ovr_data = data;
1900- unsigned orig_overrides = screen_off_overrides;
1901- unsigned mask;
1902-
1903- mask = 1 << ovr_data->reason;
1904- if (ovr_data->set)
1905- screen_off_overrides |= mask;
1906- else
1907- screen_off_overrides &= ~mask;
1908-
1909- if (orig_overrides != screen_off_overrides)
1910- update_display_state(&internal_state);
1911- return 0;
1912-}
1913-
1914-void powerd_display_set_override(enum powerd_override_reason reason)
1915-{
1916- struct apply_override_data ovr_data;
1917-
1918- if (reason >= POWERD_NUM_OVERRIDE_REASONS) {
1919- powerd_debug("Refusing to set invalid override reason (%d)", reason);
1920- return;
1921- }
1922-
1923- ovr_data.reason = reason;
1924- ovr_data.set = 1;
1925- powerd_run_mainloop_sync(apply_override_worker, &ovr_data);
1926-}
1927-
1928-void powerd_display_clear_override(enum powerd_override_reason reason)
1929-{
1930- struct apply_override_data ovr_data;
1931-
1932- if (reason >= POWERD_NUM_OVERRIDE_REASONS) {
1933- powerd_debug("Refusing to clear invalid override reason (%d)", reason);
1934- return;
1935- }
1936-
1937- ovr_data.reason = reason;
1938- ovr_data.set = 0;
1939- powerd_run_mainloop_sync(apply_override_worker, &ovr_data);
1940-}
1941-
1942-static void set_user_brightness(int brightness)
1943-{
1944- int max = powerd_get_max_brightness();
1945- if (brightness > max)
1946- brightness = max;
1947- user_brightness = brightness;
1948- update_display_state(&internal_state);
1949-}
1950-
1951-static gboolean exit_suspend_worker(gpointer unused)
1952-{
1953- /* Make sure suspend is still disabled */
1954- if (!powerd_suspend_active() && powerd_display_enabled())
1955- turn_on_display();
1956- return FALSE;
1957-}
1958-
1959-void powerd_display_exit_suspend(void)
1960-{
1961- g_timeout_add(0, exit_suspend_worker, NULL);
1962-}
1963-
1964-int powerd_display_init(void)
1965-{
1966- struct stat stats;
1967-
1968- /* Use the current brightness until we're told another value */
1969- user_brightness = powerd_get_brightness();
1970-
1971- return 0;
1972-}
1973-
1974-
1975-/** dbus interfaces **/
1976-
1977-gboolean handle_user_autobrightness_enable(PowerdSource *obj,
1978- GDBusMethodInvocation *invocation,
1979- gboolean enable)
1980-{
1981- user_ab_enable(enable);
1982- g_dbus_method_invocation_return_value(invocation, NULL);
1983- return TRUE;
1984-}
1985-
1986-gboolean handle_set_user_brightness(PowerdSource *obj,
1987- GDBusMethodInvocation *invocation,
1988- gint brightness)
1989-{
1990- set_user_brightness(brightness);
1991- g_dbus_method_invocation_return_value(invocation, NULL);
1992- return TRUE;
1993-}
1994
1995=== modified file 'src/power-request.c'
1996--- src/power-request.c 2014-01-03 15:23:38 +0000
1997+++ src/power-request.c 2014-06-20 19:46:21 +0000
1998@@ -372,7 +372,6 @@
1999 int ret = libsuspend_exit_suspend();
2000 if (!ret) {
2001 suspend_active = FALSE;
2002- powerd_display_exit_suspend();
2003 }
2004 return ret;
2005 }
2006
2007=== modified file 'src/powerd-internal.h'
2008--- src/powerd-internal.h 2014-04-14 21:17:04 +0000
2009+++ src/powerd-internal.h 2014-06-20 19:46:21 +0000
2010@@ -33,17 +33,10 @@
2011 /* Length of a UUID string, including trailing nul */
2012 #define UUID_STR_LEN 37
2013
2014-struct powerd_display_request {
2015- uuid_t cookie;
2016- enum powerd_display_state state;
2017- guint32 flags;
2018-};
2019-
2020-enum powerd_override_reason {
2021- POWERD_OVERRIDE_REASON_POWER_BUTTON,
2022- POWERD_OVERRIDE_REASON_PROXIMITY,
2023-
2024- POWERD_NUM_OVERRIDE_REASONS
2025+enum DisplayStateChangeReason
2026+{
2027+ UNITY_SCREEN_REASON_NORMAL = 0,
2028+ UNITY_SCREEN_REASON_PROXIMITY = 3,
2029 };
2030
2031 struct DbusNameWatch {
2032@@ -64,6 +57,10 @@
2033 void powerd_dbus_init_complete(void);
2034 int powerd_is_mainloop(void);
2035
2036+/* Display functions */
2037+gboolean turn_display_on(gboolean on, enum DisplayStateChangeReason reason);
2038+void keep_display_on();
2039+
2040 /* Autobrightness functions */
2041 void powerd_new_als_event(double lux);
2042 void powerd_autobrightness_enable(void);
2043@@ -79,19 +76,11 @@
2044 int powerd_get_max_brightness(void);
2045 int powerd_set_brightness(int brightness);
2046 int powerd_set_user_brightness(int brightness);
2047-void powerd_dim_screen(void);
2048 gboolean handle_get_brightness_params(PowerdSource *obj,
2049 GDBusMethodInvocation *invocation);
2050
2051-/* Display functions */
2052 void powerd_brightness_set_value(gint value);
2053-gboolean powerd_display_enabled(void);
2054-gboolean display_set_power_mode(int display, const char *powerd_mode);
2055-void powerd_set_display_state(struct powerd_display_request *req);
2056-int powerd_display_init(void);
2057 void powerd_proximity_event(gboolean near);
2058-void powerd_display_set_override(enum powerd_override_reason reason);
2059-void powerd_display_clear_override(enum powerd_override_reason reason);
2060 gboolean handle_user_autobrightness_enable(PowerdSource *obj,
2061 GDBusMethodInvocation *invocation,
2062 gboolean enable);
2063@@ -99,28 +88,6 @@
2064 GDBusMethodInvocation *invocation,
2065 gint brightness);
2066
2067-/* Display request functions */
2068-int powerd_add_display_request(struct powerd_display_request *request,
2069- const char *name);
2070-int powerd_update_display_request(struct powerd_display_request *request);
2071-int powerd_remove_display_request(uuid_t cookie);
2072-void display_request_init(void);
2073-void display_request_deinit(void);
2074-gboolean handle_add_display_request(PowerdSource *obj,
2075- GDBusMethodInvocation *invocation,
2076- const char *name, int state, guint32 flags);
2077-gboolean handle_update_display_request(PowerdSource *obj,
2078- GDBusMethodInvocation *invocation,
2079- const gchar *ext_cookie, int state,
2080- guint32 flags);
2081-gboolean handle_clear_display_request(PowerdSource *obj,
2082- GDBusMethodInvocation *invocation,
2083- const gchar *ext_cookie);
2084-gboolean handle_list_display_requests(PowerdSource *obj,
2085- GDBusMethodInvocation *invocation);
2086-void clear_disp_state_by_owner(const char *owner);
2087-void powerd_display_exit_suspend(void);
2088-
2089 /* System power state requests */
2090 gboolean handle_list_sys_requests(PowerdSource *obj,
2091 GDBusMethodInvocation *invocation);
2092@@ -140,8 +107,6 @@
2093 enum SysPowerStates current_system_power_state(void);
2094 const gchar * state_to_string(int state);
2095 void powerd_sys_state_signal_emit(enum SysPowerStates state);
2096-void powerd_display_state_signal_emit(enum powerd_display_state state,
2097- guint32 flags);
2098 void clear_sys_state_by_owner(const char *owner);
2099 gboolean powerd_suspend_active(void);
2100
2101@@ -207,19 +172,11 @@
2102 /* Statistics functions */
2103 void powerd_account_request_sys_state(const char *dbus_name, const char *name);
2104 void powerd_account_clear_sys_state(const char *dbus_name, const char *name);
2105-void powerd_account_add_display_req(const char *dbus_name, const char *name,
2106- const struct powerd_display_request *req);
2107-void powerd_account_update_display_req(const char *dbus_name,
2108- const char *name,
2109- const struct powerd_display_request *req);
2110-void powerd_account_clear_display_req(const char *dbus_name, const char *name);
2111 void powerd_log_stats(void);
2112 int powerd_stats_init(void);
2113 void powerd_stats_deinit(void);
2114 gboolean handle_get_sys_request_stats(PowerdSource *obj,
2115 GDBusMethodInvocation *invocation);
2116-gboolean handle_get_disp_request_stats(PowerdSource *obj,
2117- GDBusMethodInvocation *invocation);
2118
2119 /* Utility functions */
2120 int powerd_run_mainloop_sync(int (*func)(gpointer), gpointer data);
2121
2122=== modified file 'src/powerd-object.c'
2123--- src/powerd-object.c 2014-04-14 21:17:04 +0000
2124+++ src/powerd-object.c 2014-06-20 19:46:21 +0000
2125@@ -163,24 +163,14 @@
2126 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-list-sys-requests",
2127 G_CALLBACK(handle_list_sys_requests), powerd_source);
2128
2129- g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-request-display-state",
2130- G_CALLBACK(handle_add_display_request), powerd_source);
2131- g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-update-display-state",
2132- G_CALLBACK(handle_update_display_request), powerd_source);
2133- g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-clear-display-state",
2134- G_CALLBACK(handle_clear_display_request), powerd_source);
2135 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-register-client",
2136 G_CALLBACK(handle_register_client), powerd_source);
2137 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-unregister-client",
2138 G_CALLBACK(handle_unregister_client), powerd_source);
2139 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-ack-state-change",
2140 G_CALLBACK(handle_ack_state_change), powerd_source);
2141- g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-list-display-requests",
2142- G_CALLBACK(handle_list_display_requests), powerd_source);
2143 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-get-sys-request-stats",
2144 G_CALLBACK(handle_get_sys_request_stats), powerd_source);
2145- g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-get-disp-request-stats",
2146- G_CALLBACK(handle_get_disp_request_stats), powerd_source);
2147 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-user-autobrightness-enable",
2148 G_CALLBACK(handle_user_autobrightness_enable), powerd_source);
2149 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-get-brightness-params",
2150@@ -234,32 +224,6 @@
2151 }
2152
2153 void
2154-powerd_display_state_signal_emit(enum powerd_display_state state,
2155- guint32 flags)
2156-{
2157- GError *error = NULL;
2158-
2159- /* Make sure dbus has been set up */
2160- if (!powerd_source)
2161- return;
2162-
2163- powerd_debug("Emitting signal for display state change: state=%d flags=0x%08x",
2164- state, flags);
2165- g_dbus_connection_emit_signal(
2166- POWERD_SOURCE_GET_PRIVATE(powerd_source)->system_bus,
2167- NULL, /* destination */
2168- "/com/canonical/powerd",
2169- "com.canonical.powerd",
2170- "DisplayPowerStateChange",
2171- g_variant_new("(iu)", state, flags),
2172- &error);
2173- if (error) {
2174- powerd_warn("Unable to signal a state change update: %s", error->message);
2175- g_error_free(error);
2176- }
2177-}
2178-
2179-void
2180 ofono_manager_proxy_connect_cb(GObject *source_object,
2181 GAsyncResult *res,
2182 gpointer user_data)
2183@@ -355,8 +319,6 @@
2184 gpointer user_data)
2185 {
2186 powerd_warn("%s vanished from dbus, clearing associated requests", name);
2187- clear_sys_state_by_owner(name);
2188- clear_disp_state_by_owner(name);
2189 powerd_client_unregister(name);
2190 // This can return false if the hash entry was removed because the
2191 // last request was dropped, in other words, this call will fail
2192
2193=== modified file 'src/powerd.cpp'
2194--- src/powerd.cpp 2014-03-28 08:00:33 +0000
2195+++ src/powerd.cpp 2014-06-20 19:46:21 +0000
2196@@ -44,10 +44,6 @@
2197 #include "log.h"
2198
2199 #include <hybris/properties/properties.h>
2200-#include <hybris/input/input_stack_compatibility_layer.h>
2201-#include <hybris/input/input_stack_compatibility_layer_codes_key.h>
2202-
2203-#include <hybris/surface_flinger/surface_flinger_compatibility_layer.h>
2204
2205 #include "libsuspend.h"
2206
2207@@ -57,74 +53,11 @@
2208
2209 namespace
2210 {
2211-
2212-#define SHUTDOWN_HOLD_SECS 2
2213-
2214-static uint button_timer = 0;
2215-
2216-/*
2217- * Do not modify activity_timer directly. Instead, call
2218- * reset_activity_timer();
2219- */
2220-static uint activity_timer = 0;
2221-GMutex activity_timer_mutex;
2222-
2223-static time_t curtime;
2224-static int lasttime;
2225-struct tm *tm;
2226-
2227-/* The real default for this is set in the gschema file, but set 60 here
2228- * as a sanity check */
2229-static const int activity_timeout = 60;
2230-static const int dim_timeout = 45;
2231-
2232 static GMainLoop *main_loop = NULL;
2233 static guint name_id;
2234
2235-enum state {
2236- BUTTON_DOWN,
2237- BUTTON_UP,
2238- SHUTDOWN
2239-};
2240-
2241-static state button_state = BUTTON_UP;
2242-
2243-enum {
2244- SCREEN_STATE_OFF = 0,
2245- SCREEN_STATE_DIM,
2246- SCREEN_STATE_BRIGHT
2247-};
2248-
2249-/* Assume screen starts off when powerd starts */
2250-int activity_timer_screen_state = SCREEN_STATE_OFF;
2251-
2252 static int g_exit_code = 0;
2253
2254-/*
2255- * Display request for activity timer
2256- *
2257- * Stupid C++ compiler won't let me use designated initializers ...
2258- */
2259-static struct powerd_display_request activity_timer_req = {
2260- {0,}, /* cookie */
2261- POWERD_DISPLAY_STATE_ON, /* state */
2262- POWERD_DISPLAY_FLAG_BRIGHT /* flags */
2263-};
2264-
2265-/* Display request for use of proximity sensor during phone calls */
2266-static struct powerd_display_request prox_sensor_req = {
2267- {0,}, /* cookie */
2268- POWERD_DISPLAY_STATE_ON, /* state */
2269- POWERD_DISPLAY_FLAG_USE_PROXIMITY /* flags */
2270-};
2271-
2272-/* Default display request in case running in emulator */
2273-static struct powerd_display_request emulator_req = {
2274- {0,}, /* cookie */
2275- POWERD_DISPLAY_STATE_ON, /* state */
2276- POWERD_DISPLAY_FLAG_BRIGHT /* flags */
2277-};
2278-
2279 /* List with detected modems */
2280 static GSList *g_modems = NULL;
2281
2282@@ -150,86 +83,8 @@
2283 /* Flag set when proximity sensor is on */
2284 static gboolean g_proximity_on = FALSE;
2285
2286-gboolean activity_monitor(gpointer data);
2287-void update_screen_state(int state);
2288-
2289-gboolean call_shutdown(gpointer data)
2290-{
2291- if (button_state == BUTTON_DOWN) {
2292- button_state = SHUTDOWN;
2293- powerd_set_brightness(0);
2294- display_set_power_mode(0, "off");
2295- powerd_shutdown();
2296- }
2297-
2298- return FALSE;
2299-}
2300-
2301-gboolean activity_monitor(gpointer data)
2302-{
2303- int new_state;
2304-
2305- g_mutex_lock(&activity_timer_mutex);
2306-
2307- if (activity_timer_screen_state > SCREEN_STATE_OFF) {
2308- if (dim_timeout > 0 && activity_timeout > dim_timeout)
2309- new_state = activity_timer_screen_state - 1;
2310- else
2311- new_state = SCREEN_STATE_OFF;
2312-
2313- update_screen_state(new_state);
2314- if (new_state != SCREEN_STATE_OFF && activity_timer > 0)
2315- activity_timer = g_timeout_add_seconds(activity_timeout - dim_timeout,
2316- activity_monitor, NULL);
2317- }
2318-
2319- g_mutex_unlock(&activity_timer_mutex);
2320- return FALSE;
2321-}
2322-
2323 static struct power_module* _power_module;
2324
2325-void on_new_event(Event* event, void* context)
2326-{
2327- switch(event->type)
2328- {
2329- case KEY_EVENT_TYPE:
2330- if (event->details.key.key_code == ISCL_KEYCODE_POWER && button_state != SHUTDOWN) {
2331- if (event->action == 1) {
2332- powerd_debug("power button pressed");
2333- button_state = BUTTON_UP;
2334- curtime = time(0);
2335- tm = localtime (&curtime);
2336- if (tm->tm_sec - lasttime < SHUTDOWN_HOLD_SECS) {
2337- gboolean enabled = powerd_display_enabled();
2338- if (enabled)
2339- powerd_display_set_override(POWERD_OVERRIDE_REASON_POWER_BUTTON);
2340- else
2341- powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON);
2342- powerd_reset_activity_timer(!enabled);
2343- }
2344- } else if (event->action == 0) {
2345- button_state = BUTTON_DOWN;
2346- curtime = time(0);
2347- tm = localtime (&curtime);
2348- lasttime = tm->tm_sec;
2349- if (button_timer > 0)
2350- {
2351- g_source_remove(button_timer);
2352- button_timer = 0;
2353- }
2354- button_timer = g_timeout_add_seconds(SHUTDOWN_HOLD_SECS,
2355- call_shutdown, NULL);
2356- }
2357- }
2358- break;
2359- default:
2360- if (powerd_display_enabled())
2361- powerd_reset_activity_timer(1);
2362- break;
2363- }
2364-}
2365-
2366 static void
2367 sigterm_quit(int signal)
2368 {
2369@@ -237,43 +92,6 @@
2370 powerd_exit(0);
2371 }
2372
2373-int update_screen_state_worker(gpointer data)
2374-{
2375- long new_state = (long)data;
2376- int ret;
2377-
2378- if (new_state == activity_timer_screen_state)
2379- return 0;
2380-
2381- if (new_state == SCREEN_STATE_OFF) {
2382- powerd_remove_display_request(activity_timer_req.cookie);
2383- } else {
2384- if (new_state == SCREEN_STATE_DIM)
2385- activity_timer_req.flags &= ~POWERD_DISPLAY_FLAG_BRIGHT;
2386- else
2387- activity_timer_req.flags |= POWERD_DISPLAY_FLAG_BRIGHT;
2388-
2389- if (activity_timer_screen_state == SCREEN_STATE_OFF)
2390- ret = powerd_add_display_request(&activity_timer_req,
2391- "activity-timer");
2392- else
2393- ret = powerd_update_display_request(&activity_timer_req);
2394-
2395- if (ret)
2396- powerd_warn("Error adding display state request for activity timer");
2397- }
2398-
2399- activity_timer_screen_state = new_state;
2400- return 0;
2401-}
2402-
2403-void update_screen_state(int new_state)
2404-{
2405- long data = new_state;
2406- if (new_state < SCREEN_STATE_OFF || new_state > SCREEN_STATE_BRIGHT)
2407- return;
2408- powerd_run_mainloop_sync(update_screen_state_worker, (gpointer)data);
2409-}
2410
2411 } //namespace
2412
2413@@ -284,39 +102,12 @@
2414 _power_module->powerHint(_power_module, POWER_HINT_INTERACTION, NULL);
2415 }
2416
2417-void powerd_reset_activity_timer(int add)
2418-{
2419- int timeout;
2420-
2421- g_mutex_lock(&activity_timer_mutex);
2422-
2423- if (activity_timer > 0) {
2424- g_source_remove(activity_timer);
2425- activity_timer = 0;
2426- }
2427-
2428- if (add) {
2429- if (dim_timeout > 0 && dim_timeout < activity_timeout)
2430- timeout = dim_timeout;
2431- else
2432- timeout = activity_timeout;
2433-
2434- update_screen_state(SCREEN_STATE_BRIGHT);
2435- activity_timer = g_timeout_add_seconds(timeout, activity_monitor, NULL);
2436- } else {
2437- update_screen_state(SCREEN_STATE_OFF);
2438- }
2439-
2440- g_mutex_unlock(&activity_timer_mutex);
2441-}
2442-
2443 /*
2444 * Once dbus is ready, force the screen on to make the system state
2445 * match the powerd iternal state
2446 */
2447 void powerd_dbus_init_complete(void)
2448 {
2449- powerd_reset_activity_timer(1);
2450 }
2451
2452 static void watch_modem(const char *modem)
2453@@ -411,8 +202,7 @@
2454
2455 if (strcmp("active", call_state) == 0
2456 || strcmp("dialing", call_state) == 0) {
2457- if (powerd_add_display_request(&prox_sensor_req, "prox-sensor"))
2458- powerd_warn("Request to use proximity sensor failed");
2459+ powerd_sensors_proximity_enable();
2460 g_proximity_on = TRUE;
2461 }
2462 }
2463@@ -422,10 +212,19 @@
2464 if (!g_proximity_on)
2465 return;
2466
2467- powerd_remove_display_request(prox_sensor_req.cookie);
2468+ powerd_sensors_proximity_disable();
2469 g_proximity_on = FALSE;
2470 }
2471
2472+
2473+void powerd_proximity_event(gboolean near)
2474+{
2475+ if (near)
2476+ turn_display_on(FALSE, UNITY_SCREEN_REASON_PROXIMITY);
2477+ else
2478+ turn_display_on(TRUE, UNITY_SCREEN_REASON_PROXIMITY);
2479+}
2480+
2481 void
2482 ofono_voicecall_get_props_cb(GObject *source_object, GAsyncResult *res,
2483 gpointer user_data)
2484@@ -509,8 +308,7 @@
2485 if (!strcmp(signal_name, "CallAdded")) {
2486 struct call_data *call;
2487
2488- powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON);
2489- powerd_reset_activity_timer(1);
2490+ turn_display_on(TRUE, UNITY_SCREEN_REASON_NORMAL);
2491
2492 call = (struct call_data *) calloc(1, sizeof(*call));
2493 tmp = g_variant_get_child_value(parameters, 0);
2494@@ -589,8 +387,7 @@
2495 if ((!strcmp(signal_name, "IncomingMessage")) ||
2496 (!strcmp(signal_name, "ImmediateMessage"))) {
2497 powerd_debug("Waking up the device - Incoming SMS");
2498- powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON);
2499- powerd_reset_activity_timer(1);
2500+ turn_display_on(TRUE, UNITY_SCREEN_REASON_NORMAL);
2501 }
2502 }
2503
2504@@ -605,8 +402,7 @@
2505 if ((!strcmp(signal_name, "NotificationReceived")) ||
2506 (!strcmp(signal_name, "RequestReceived"))) {
2507 powerd_debug("Waking up the device - Incoming USSD");
2508- powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON);
2509- powerd_reset_activity_timer(1);
2510+ turn_display_on(TRUE, UNITY_SCREEN_REASON_NORMAL);
2511 }
2512 }
2513
2514@@ -632,9 +428,7 @@
2515
2516 if (property_get("ro.kernel.qemu", propbuf, NULL) > 0) {
2517 powerd_info("Running in emulator, forcing display, blocking suspend.");
2518- /* Request screen to be always on */
2519- if (powerd_add_display_request(&emulator_req, "emulator-display"))
2520- powerd_warn("Request to force screen on for emulator failed");
2521+ keep_display_on();
2522 /* Block suspend */
2523 request_sys_state_internal("emulator-request",
2524 POWERD_SYS_STATE_ACTIVE,
2525@@ -686,45 +480,21 @@
2526 powerd_stats_init();
2527 powerd_client_init();
2528 power_request_init();
2529- display_request_init();
2530 dbus_name_watch_init();
2531 powerd_backlight_init();
2532 powerd_autobrightness_init();
2533- powerd_display_init();
2534 powerd_sensors_init();
2535 powerd_ps_init();
2536
2537 main_loop = g_main_loop_new (NULL, FALSE);
2538 signal(SIGTERM, sigterm_quit);
2539
2540- AndroidEventListener listener;
2541- listener.on_new_event = on_new_event;
2542- listener.context = NULL;
2543-
2544- InputStackConfiguration config = {
2545- enable_touch_point_visualization : false,
2546- default_layer_for_touch_point_visualization : 10000,
2547- input_area_width : 2048,
2548- input_area_height : 2048
2549- };
2550-
2551 int err = hw_get_module(POWER_HARDWARE_MODULE_ID,
2552 (hw_module_t const**)&_power_module);
2553
2554 if (!err)
2555 _power_module->init(_power_module);
2556
2557- /* Compat input is needed otherwise there's no way to know when
2558- * the user is actively using the system */
2559- if (!android_input_check_availability()) {
2560- powerd_error("Android compat input library not found, aborting");
2561- g_exit_code = -1;
2562- goto fail_compat_init;
2563- }
2564-
2565- android_input_stack_initialize(&listener, &config);
2566- android_input_stack_start();
2567-
2568 /* Config use should be done during init, okay to free now */
2569 device_config_deinit();
2570
2571@@ -736,15 +506,10 @@
2572 g_bus_unown_name(name_id);
2573 g_main_loop_unref(main_loop);
2574
2575- android_input_stack_stop();
2576- android_input_stack_shutdown();
2577-
2578-fail_compat_init:
2579 powerd_ps_deinit();
2580 dbus_name_watch_deinit();
2581 powerd_autobrightness_deinit();
2582 powerd_backlight_deinit();
2583- display_request_deinit();
2584 power_request_deinit();
2585 powerd_client_deinit();
2586 powerd_stats_deinit();
2587
2588=== modified file 'src/powerd.h'
2589--- src/powerd.h 2013-07-18 21:08:49 +0000
2590+++ src/powerd.h 2014-06-20 19:46:21 +0000
2591@@ -34,24 +34,6 @@
2592 POWERD_NUM_POWER_STATES
2593 };
2594
2595-enum powerd_display_state {
2596- POWERD_DISPLAY_STATE_DONT_CARE = 0,
2597- POWERD_DISPLAY_STATE_ON,
2598-
2599- /* Keep last */
2600- POWERD_NUM_DISPLAY_STATES
2601-};
2602-
2603-/* Use proximity sensor to override screen state */
2604-#define POWERD_DISPLAY_FLAG_USE_PROXIMITY (1 << 0)
2605-/* Force autobrightness to be disabled */
2606-#define POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS (1 << 1)
2607-/* Request the screen to stay bright */
2608-#define POWERD_DISPLAY_FLAG_BRIGHT (1 << 2)
2609-
2610-/* Must be updated when new flags are added */
2611-#define POWERD_NUM_DISPLAY_FLAGS 3
2612-
2613 /*
2614 * Clients should treat this as an opaque type. Though this isn't really
2615 * possible until the client library is written.
2616
2617=== modified file 'src/stats.c'
2618--- src/stats.c 2013-09-03 14:10:41 +0000
2619+++ src/stats.c 2014-06-20 19:46:21 +0000
2620@@ -48,19 +48,6 @@
2621 guint64 active_since;
2622 };
2623
2624-struct disp_request_stats {
2625- const char *name;
2626- unsigned active_count;
2627- guint64 active_time;
2628- guint64 max_active_time;
2629- guint64 active_since;
2630- guint64 disp_on_time;
2631- guint64 disp_on_since;
2632- guint64 flag_on_time[POWERD_NUM_DISPLAY_FLAGS];
2633- guint64 flag_on_since[POWERD_NUM_DISPLAY_FLAGS];
2634- struct powerd_display_request last_req;
2635-};
2636-
2637 GHashTable *stats_hash;
2638
2639 static guint64 get_usecs(void)
2640@@ -111,24 +98,6 @@
2641 return stats;
2642 }
2643
2644-static struct disp_request_stats *alloc_disp_stats(const char *name)
2645-{
2646- struct disp_request_stats *stats = calloc(1, sizeof(*stats));
2647- if (!stats) {
2648- powerd_error("Error allocating memory for display request statistics");
2649- return NULL;
2650- }
2651-
2652- stats->name = strdup(name);
2653- if (!stats->name) {
2654- powerd_error("Error duplicating request name for statistics");
2655- free(stats);
2656- return NULL;
2657- }
2658-
2659- return stats;
2660-}
2661-
2662 static gint sys_stats_comp(gconstpointer a, gconstpointer b)
2663 {
2664 const struct sys_request_stats *stats = a;
2665@@ -136,13 +105,6 @@
2666 return strcmp(stats->name, name);
2667 }
2668
2669-static gint disp_stats_comp(gconstpointer a, gconstpointer b)
2670-{
2671- const struct disp_request_stats *stats = a;
2672- const char *name = b;
2673- return strcmp(stats->name, name);
2674-}
2675-
2676 static struct client_stats *lookup_client(const char *dbus_name,
2677 gboolean alloc)
2678 {
2679@@ -210,122 +172,6 @@
2680 stats->max_active_time = duration;
2681 }
2682
2683-static void aggregate_disp_stats(struct disp_request_stats *stats,
2684- const struct powerd_display_request *new)
2685-{
2686- guint64 us;
2687- int i;
2688-
2689- us = get_usecs();
2690- if (new->state != stats->last_req.state) {
2691- if (new->state == POWERD_DISPLAY_STATE_ON) {
2692- stats->disp_on_since = us;
2693- } else {
2694- stats->disp_on_time += us - stats->disp_on_since;
2695- stats->disp_on_since = 0;
2696- }
2697- }
2698- for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
2699- guint32 mask = 1 << i;
2700- if ((new->flags & mask) != (stats->last_req.flags & mask)) {
2701- if (new->flags & mask) {
2702- stats->flag_on_since[i] = us;
2703- } else {
2704- stats->flag_on_time[i] += us - stats->flag_on_since[i];
2705- stats->flag_on_since[i] = 0;
2706- }
2707- }
2708- }
2709-}
2710-
2711-void powerd_account_add_display_req(const char *dbus_name, const char *name,
2712- const struct powerd_display_request *req)
2713-{
2714- struct client_stats *client;
2715- struct disp_request_stats *stats;
2716- GSList *item;
2717- guint64 us;
2718- int i;
2719-
2720- if (!stats_hash)
2721- return;
2722-
2723- client = lookup_client(dbus_name, TRUE);
2724- if (!client)
2725- return;
2726-
2727- item = g_slist_find_custom(client->disp_stats, name, disp_stats_comp);
2728- if (item) {
2729- stats = item->data;
2730- } else {
2731- stats = alloc_disp_stats(name);
2732- if (!stats)
2733- return;
2734- client->disp_stats = g_slist_prepend(client->disp_stats, stats);
2735- }
2736-
2737- us = get_usecs();
2738- stats->active_count++;
2739- stats->active_since = us;
2740- if (req->state == POWERD_DISPLAY_STATE_ON)
2741- stats->disp_on_since = us;
2742- for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
2743- if (req->flags & (1 << i))
2744- stats->flag_on_since[i] = us;
2745- }
2746- stats->last_req = *req;
2747-}
2748-
2749-void powerd_account_update_display_req(const char *dbus_name,
2750- const char *name,
2751- const struct powerd_display_request *req)
2752-{
2753- struct client_stats *client;
2754- struct disp_request_stats *stats;
2755- GSList *item;
2756-
2757- client = lookup_client(dbus_name, FALSE);
2758- if (!client)
2759- return;
2760-
2761- item = g_slist_find_custom(client->disp_stats, name, disp_stats_comp);
2762- if (!item)
2763- return;
2764- stats = item->data;
2765-
2766- aggregate_disp_stats(stats, req);
2767- stats->last_req = *req;
2768-}
2769-
2770-void powerd_account_clear_display_req(const char *dbus_name, const char *name)
2771-{
2772- struct client_stats *client;
2773- struct disp_request_stats *stats;
2774- GSList *item;
2775- struct powerd_display_request req;
2776- guint64 duration;
2777-
2778- client = lookup_client(dbus_name, FALSE);
2779- if (!client)
2780- return;
2781-
2782- item = g_slist_find_custom(client->disp_stats, name, disp_stats_comp);
2783- if (!item)
2784- return;
2785- stats = item->data;
2786-
2787- memset(&req, 0, sizeof(req));
2788- aggregate_disp_stats(stats, &req);
2789-
2790- duration = get_usecs() - stats->active_since;
2791- stats->active_time += duration;
2792- stats->active_since = 0;
2793- if (duration > stats->max_active_time)
2794- stats->max_active_time = duration;
2795-
2796- stats->last_req = req;
2797-}
2798-
2799 static void log_sys_req_stats(struct client_stats *client)
2800 {
2801 const char *dbus_name = client->dbus_name;
2802@@ -361,56 +207,6 @@
2803 }
2804 }
2805
2806-static void log_disp_req_stats(struct client_stats *client)
2807-{
2808- const char *dbus_name = client->dbus_name;
2809- GSList *cur;
2810- guint64 us;
2811-
2812- us = get_usecs();
2813- for (cur = client->disp_stats; cur; cur = g_slist_next(cur)) {
2814- struct disp_request_stats *stats = cur->data;
2815- guint64 active_time, max_active_time;
2816- guint64 disp_on_time;
2817- int i;
2818-
2819- active_time = stats->active_time;
2820- max_active_time = stats->max_active_time;
2821- if (stats->active_since != 0) {
2822- guint64 duration = us - stats->active_since;
2823- active_time += duration;
2824- if (duration > max_active_time)
2825- max_active_time = duration;
2826- }
2827-
2828- disp_on_time = stats->disp_on_time;
2829- if (stats->disp_on_since != 0)
2830- disp_on_time += us - stats->disp_on_since;
2831-
2832- powerd_info(" Name: %s", stats->name);
2833- powerd_info(" Owner: %s", dbus_name);
2834- powerd_info(" Active Count: %u", stats->active_count);
2835- powerd_info(" Active Time: %f", (double)active_time / 1000000.0f);
2836- powerd_info(" Max Active Time: %f",
2837- (double)max_active_time / 1000000.0f);
2838- powerd_info(" Active Since: %f",
2839- (double)stats->active_since / 1000000.0f);
2840- powerd_info(" Display On Time: %f",
2841- (double)disp_on_time / 1000000.0f);
2842- powerd_info(" Display On Since: %f",
2843- (double)stats->disp_on_since / 1000000.0f);
2844- for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
2845- guint64 on_time = stats->flag_on_time[i];
2846- if (stats->flag_on_since[i] != 0)
2847- on_time += us - stats->flag_on_since[i];
2848- powerd_info(" Flag %d On Time: %f", i,
2849- (double)on_time / 1000000.0f);
2850- powerd_info(" Flag %d On Since: %f", i,
2851- (double)stats->flag_on_since[i] / 1000000.0f);
2852- }
2853- }
2854-}
2855-
2856 void powerd_log_stats(void)
2857 {
2858 struct sysinfo si;
2859@@ -425,11 +221,6 @@
2860 g_hash_table_iter_init(&iter, stats_hash);
2861 while (g_hash_table_iter_next(&iter, &key, &value))
2862 log_sys_req_stats(value);
2863-
2864- powerd_info("Display Request Statistics:");
2865- g_hash_table_iter_init(&iter, stats_hash);
2866- while (g_hash_table_iter_next(&iter, &key, &value))
2867- log_disp_req_stats(value);
2868 }
2869 }
2870
2871@@ -440,18 +231,10 @@
2872 free(stats);
2873 }
2874
2875-static void disp_stats_list_destroy(gpointer data)
2876-{
2877- struct disp_request_stats *stats = data;
2878- free((void *)stats->name);
2879- free(stats);
2880-}
2881-
2882 static void stats_hash_destroy(gpointer data)
2883 {
2884 struct client_stats *client = data;
2885 g_slist_free_full(client->sys_stats, sys_stats_list_destroy);
2886- g_slist_free_full(client->disp_stats, disp_stats_list_destroy);
2887 free((void *)client->dbus_name);
2888 free(client);
2889 }
2890@@ -538,81 +321,3 @@
2891 return TRUE;
2892 }
2893
2894-static int build_disp_request_list(GVariantBuilder *builder,
2895- struct client_stats *client)
2896-{
2897- const char *dbus_name = client->dbus_name;
2898- GSList *cur;
2899- guint64 us;
2900- int count = 0;
2901-
2902- us = get_usecs();
2903- for (cur = client->disp_stats; cur; cur = g_slist_next(cur)) {
2904- struct disp_request_stats *stats = cur->data;
2905- guint64 active_time, max_active_time;
2906- guint64 disp_on_time;
2907- GVariantBuilder *fot_builder, *fos_builder;
2908- int i;
2909-
2910- active_time = stats->active_time;
2911- max_active_time = stats->max_active_time;
2912- if (stats->active_since != 0) {
2913- guint64 duration = us - stats->active_since;
2914- active_time += duration;
2915- if (duration > max_active_time)
2916- max_active_time = duration;
2917- }
2918-
2919- disp_on_time = stats->disp_on_time;
2920- if (stats->disp_on_since != 0)
2921- disp_on_time += us - stats->disp_on_since;
2922-
2923- fot_builder = g_variant_builder_new(G_VARIANT_TYPE("at"));
2924- fos_builder = g_variant_builder_new(G_VARIANT_TYPE("at"));
2925- for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
2926- guint64 flag_on_time = stats->flag_on_time[i];
2927- if (stats->flag_on_since[i] != 0)
2928- flag_on_time += us - stats->flag_on_since[i];
2929- g_variant_builder_add(fot_builder, "t", flag_on_time);
2930- g_variant_builder_add(fos_builder, "t", stats->flag_on_since[i]);
2931- }
2932- g_variant_builder_add(builder, "(ssutttttatat)", dbus_name,
2933- stats->name, stats->active_count, active_time,
2934- max_active_time, stats->active_since,
2935- disp_on_time, stats->disp_on_since,
2936- fot_builder, fos_builder);
2937- g_variant_builder_unref(fot_builder);
2938- g_variant_builder_unref(fos_builder);
2939- count++;
2940- }
2941- return count;
2942-}
2943-
2944-gboolean handle_get_disp_request_stats(PowerdSource *obj,
2945- GDBusMethodInvocation *invocation)
2946-{
2947- GVariantBuilder *builder;
2948- GVariant *list, *tuple;
2949- GHashTableIter iter;
2950- gpointer key, value;
2951- int count = 0;
2952-
2953- builder = g_variant_builder_new(G_VARIANT_TYPE("a(ssutttttatat)"));
2954- if (stats_hash) {
2955- g_hash_table_iter_init(&iter, stats_hash);
2956- while (g_hash_table_iter_next(&iter, &key, &value))
2957- count += build_disp_request_list(builder, value);
2958- }
2959-
2960- if (count == 0) {
2961- g_variant_builder_clear(builder);
2962- list = g_variant_new_array(G_VARIANT_TYPE("a(ssutttttatat)"), NULL, 0);
2963- } else {
2964- list = g_variant_builder_end(builder);
2965- }
2966- tuple = g_variant_new_tuple(&list, 1);
2967- g_dbus_method_invocation_return_value(invocation, tuple);
2968- g_variant_builder_unref(builder);
2969-
2970- return TRUE;
2971-}

Subscribers

People subscribed via source and target branches