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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-01-14 03:14:22 +0000
+++ CMakeLists.txt 2014-06-20 19:46:21 +0000
@@ -21,8 +21,6 @@
2121
22find_package(PkgConfig)22find_package(PkgConfig)
23pkg_check_modules(ANDROID_HEADERS android-headers)23pkg_check_modules(ANDROID_HEADERS android-headers)
24pkg_check_modules(HYBRIS_IS libis)
25pkg_check_modules(HYBRIS_SF libsf)
26pkg_check_modules(GLIB glib-2.0)24pkg_check_modules(GLIB glib-2.0)
27pkg_check_modules(GIO gio-2.0)25pkg_check_modules(GIO gio-2.0)
28pkg_check_modules(GIO-UNIX gio-unix-2.0)26pkg_check_modules(GIO-UNIX gio-unix-2.0)
@@ -45,11 +43,10 @@
45 SRCS43 SRCS
4644
47 src/powerd.cpp45 src/powerd.cpp
46 src/display.c
48 src/autobrightness.c47 src/autobrightness.c
49 src/backlight.c48 src/backlight.c
50 src/device-config.c49 src/device-config.c
51 src/display.c
52 src/display-request.c
53 src/log.c50 src/log.c
54 src/power-request.c51 src/power-request.c
55 src/power-source.c52 src/power-source.c
@@ -85,10 +82,6 @@
85add_subdirectory(src)82add_subdirectory(src)
86add_subdirectory(cli)83add_subdirectory(cli)
8784
88include(UseGSettings)
89SET (POWERD_SCHEMAS "data/com.canonical.powerd.gschema.xml")
90add_schema(${POWERD_SCHEMAS})
91
92add_executable(85add_executable(
93 powerd86 powerd
9487
@@ -99,7 +92,6 @@
99 powerd92 powerd
10093
101 dbus_bindings94 dbus_bindings
102 ${POWERD_SCHEMAS}
103)95)
10496
105target_link_libraries(97target_link_libraries(
@@ -107,8 +99,6 @@
107 suspend99 suspend
108100
109 ${CMAKE_THREAD_LIBS_INIT}101 ${CMAKE_THREAD_LIBS_INIT}
110 ${HYBRIS_IS_LIBRARIES}
111 ${HYBRIS_SF_LIBRARIES}
112 ${GLIB_LIBRARIES}102 ${GLIB_LIBRARIES}
113 ${GIO_LIBRARIES}103 ${GIO_LIBRARIES}
114 ${GIO-UNIX_LIBRARIES}104 ${GIO-UNIX_LIBRARIES}
115105
=== modified file 'cli/powerd-cli.c'
--- cli/powerd-cli.c 2014-04-23 02:21:33 +0000
+++ cli/powerd-cli.c 2014-06-20 19:46:21 +0000
@@ -41,6 +41,7 @@
41gboolean silent_errors = FALSE;41gboolean silent_errors = FALSE;
4242
43GDBusProxy *powerd_proxy = NULL;43GDBusProxy *powerd_proxy = NULL;
44GDBusProxy *uscreen_proxy = NULL;
44char test_dbusname[128] = "";45char test_dbusname[128] = "";
4546
46/* For tests */47/* For tests */
@@ -53,13 +54,6 @@
53 int state;54 int state;
54};55};
5556
56struct PublicDispRequest {
57 const char *name;
58 const char *owner;
59 enum powerd_display_state state;
60 guint32 flags;
61};
62
63struct SysRequestStats {57struct SysRequestStats {
64 const char *owner;58 const char *owner;
65 const char *name;59 const char *name;
@@ -69,19 +63,6 @@
69 guint64 active_since;63 guint64 active_since;
70};64};
7165
72struct DispRequestStats {
73 const char *owner;
74 const char *name;
75 unsigned active_count;
76 guint64 active_time;
77 guint64 max_active_time;
78 guint64 active_since;
79 guint64 disp_on_time;
80 guint64 disp_on_since;
81 guint64 flag_on_time[POWERD_NUM_DISPLAY_FLAGS];
82 guint64 flag_on_since[POWERD_NUM_DISPLAY_FLAGS];
83};
84
85static GMainLoop *main_loop = NULL;66static GMainLoop *main_loop = NULL;
86static powerd_cookie_t main_cookie;67static powerd_cookie_t main_cookie;
87static gboolean checkForDbusName(const char *dbusname, int count,68static gboolean checkForDbusName(const char *dbusname, int count,
@@ -160,22 +141,20 @@
160}141}
161142
162static gboolean143static gboolean
163requestDisplayState(struct PublicDispRequest pdr, const char *name,144requestDisplayState(int *cookie)
164 powerd_cookie_t *cookie)
165{145{
166 GVariant *ret = NULL;146 GVariant *ret = NULL;
167 GError *error = NULL;147 GError *error = NULL;
168 const char *cookie_ptr;
169 gboolean success = TRUE;148 gboolean success = TRUE;
170149
171 if (cookie == NULL) {150 if (cookie == NULL) {
172 cli_warn("NULL cookie passed to %s", __func__);151 cli_warn("NULL cookie store passed to %s", __func__);
173 return FALSE;152 return FALSE;
174 }153 }
175154
176 ret = g_dbus_proxy_call_sync(powerd_proxy,155 ret = g_dbus_proxy_call_sync(uscreen_proxy,
177 "requestDisplayState",156 "keepDisplayOn",
178 g_variant_new("(siu)", name, pdr.state, pdr.flags),157 NULL,
179 G_DBUS_CALL_FLAGS_NONE,158 G_DBUS_CALL_FLAGS_NONE,
180 -1,159 -1,
181 NULL,160 NULL,
@@ -186,44 +165,8 @@
186 return FALSE;165 return FALSE;
187 }166 }
188167
189 g_variant_get(ret, "(&s)", &cookie_ptr);168 g_variant_get(ret, "(i)", cookie);
190 if (strlen(cookie_ptr) != sizeof(powerd_cookie_t) - 1) {169 cli_debug("Got cookie: %d", *cookie);
191 cli_warn("Returned cookie has incorrect size");
192 success = FALSE;
193 } else {
194 strncpy(*cookie, cookie_ptr, sizeof(powerd_cookie_t));
195 cli_debug("Got cookie: %s", *cookie);
196 }
197
198 g_variant_unref(ret);
199 return success;
200}
201
202static gboolean
203updateDisplayState(struct PublicDispRequest pdr,
204 powerd_cookie_t cookie)
205{
206 GVariant *ret = NULL;
207 GError *error = NULL;
208 gboolean success = TRUE;
209
210 if (cookie == NULL) {
211 cli_warn("NULL cookie passed to %s", __func__);
212 return FALSE;
213 }
214
215 ret = g_dbus_proxy_call_sync(powerd_proxy,
216 "updateDisplayState",
217 g_variant_new("(siu)", cookie, pdr.state, pdr.flags),
218 G_DBUS_CALL_FLAGS_NONE,
219 -1,
220 NULL,
221 &error);
222 if (!ret) {
223 cli_warn("updateDisplayState failed: %s", error->message);
224 g_error_free(error);
225 return FALSE;
226 }
227170
228 g_variant_unref(ret);171 g_variant_unref(ret);
229 return success;172 return success;
@@ -280,58 +223,6 @@
280 }223 }
281}224}
282225
283static GArray*
284listDisplayRequests()
285{
286 GVariant *ret, *item = NULL;
287 GVariantIter *iter = NULL;
288 GArray *retarray = g_array_new(FALSE, FALSE, sizeof(struct PublicDispRequest));
289 GError *error = NULL;
290 struct PublicDispRequest pdr;
291
292 ret = g_dbus_proxy_call_sync(powerd_proxy,
293 "listDisplayRequests",
294 NULL,
295 G_DBUS_CALL_FLAGS_NONE,
296 -1,
297 NULL,
298 &error);
299 if (ret == NULL) {
300 cli_warn("listDisplayRequests failed: %s", error->message);
301 g_error_free(error);
302 }
303 else {
304 g_variant_get(ret, "(a(ssiu))", &iter);
305 while ((item = g_variant_iter_next_value (iter))) {
306 g_variant_get_child(item, 0, "s", &pdr.name);
307 g_variant_get_child(item, 1, "s", &pdr.owner);
308 g_variant_get_child(item, 2, "i", &pdr.state);
309 g_variant_get_child(item, 3, "u", &pdr.flags);
310 g_array_append_val(retarray, pdr);
311 g_variant_unref(item);
312 }
313 g_variant_unref(ret);
314 }
315 return retarray;
316}
317
318static void
319printDisplayRequests(GArray *requests)
320{
321 int i;
322 struct PublicDispRequest *pdr;
323 printf("Display State Requests:\n");
324 if (requests->len == 0) {
325 printf(" None\n");
326 } else {
327 for (i = 0; i < requests->len; i++) {
328 pdr = &g_array_index(requests, struct PublicDispRequest, i);
329 printf(" Name: %s, Owner: %s, State: %d, Flags: %#08x\n",
330 pdr->name, pdr->owner, pdr->state, pdr->flags);
331 }
332 }
333}
334
335static GArray *226static GArray *
336getSysRequestStats(void)227getSysRequestStats(void)
337{228{
@@ -395,108 +286,6 @@
395 }286 }
396}287}
397288
398static GArray *
399getDispRequestStats(void)
400{
401 GVariant *ret, *item;
402 GVariantIter *iter;
403 GArray *retarray;
404 GError *error;
405
406 retarray = g_array_new(FALSE, FALSE, sizeof(struct DispRequestStats));
407
408 error = NULL;
409 ret = g_dbus_proxy_call_sync(powerd_proxy,
410 "getDispRequestStats",
411 NULL,
412 G_DBUS_CALL_FLAGS_NONE,
413 -1,
414 NULL,
415 &error);
416 if (ret == NULL) {
417 cli_warn("getDispRequestStats failed: %s", error->message);
418 g_error_free(error);
419 } else {
420 g_variant_get(ret, "(a(ssutttttatat))", &iter);
421 while ((item = g_variant_iter_next_value (iter))) {
422 struct DispRequestStats stats;
423 GVariantIter *array_iter;
424 guint64 val;
425 int i;
426
427 g_variant_get_child(item, 0, "s", &stats.owner);
428 g_variant_get_child(item, 1, "s", &stats.name);
429 g_variant_get_child(item, 2, "u", &stats.active_count);
430 g_variant_get_child(item, 3, "t", &stats.active_time);
431 g_variant_get_child(item, 4, "t", &stats.max_active_time);
432 g_variant_get_child(item, 5, "t", &stats.active_since);
433 g_variant_get_child(item, 6, "t", &stats.disp_on_time);
434 g_variant_get_child(item, 7, "t", &stats.disp_on_since);
435
436 g_variant_get_child(item, 8, "at", &array_iter);
437 i = 0;
438 while (g_variant_iter_loop(array_iter, "t", &val)) {
439 if (i >= POWERD_NUM_DISPLAY_FLAGS)
440 break;
441 stats.flag_on_time[i++] = val;
442 }
443 g_variant_iter_free(array_iter);
444
445 g_variant_get_child(item, 9, "at", &array_iter);
446 i = 0;
447 while (g_variant_iter_loop(array_iter, "t", &val)) {
448 if (i >= POWERD_NUM_DISPLAY_FLAGS)
449 break;
450 stats.flag_on_since[i++] = val;
451 }
452 g_variant_iter_free(array_iter);
453
454 g_array_append_val(retarray, stats);
455 g_variant_unref(item);
456 }
457 g_variant_unref(ret);
458 }
459 return retarray;
460}
461
462static void
463printDispRequestStats(GArray *stats)
464{
465 int i, j;
466 struct DispRequestStats *stat;
467 printf("Display Request Statistics:\n");
468 if (stats->len == 0) {
469 printf(" None\n");
470 } else {
471 printf(" %-16.16s %-20.20s %-8.8s %-16.16s %-16.16s %-16.16s %-16.16s %-16.16s",
472 "", "", "Active", "", "Max Active", "", "Display On",
473 "Display On");
474 for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++)
475 printf(" Flag %-2d Flag %-2d ", i, i);
476 printf("\n %-16.16s %-20.20s %-8.8s %-16.16s %-16.16s %-16.16s %-16.16s %-16.16s",
477 "Owner", "Name", "Count", "Active Time", "Time", "Active Since",
478 "Time", "Since");
479 for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++)
480 printf(" On Time On Since ");
481 printf("\n");
482 for (i = 0; i < stats->len; i++) {
483 stat = &g_array_index(stats, struct DispRequestStats, i);
484 printf(" %-16.16s %-20.20s %-8u %-16.6f %-16.6f %-16.6f %-16.6f %-16.6f",
485 stat->owner, stat->name, stat->active_count,
486 (double)stat->active_time / 1000000.0f,
487 (double)stat->max_active_time / 1000000.0f,
488 (double)stat->active_since / 1000000.0f,
489 (double)stat->disp_on_time / 1000000.0f,
490 (double)stat->disp_on_since / 1000000.0f);
491 for (j = 0; j < POWERD_NUM_DISPLAY_FLAGS; j++) {
492 printf(" %-16.6f", (double)stat->flag_on_time[j] / 1000000.0f);
493 printf(" %-16.6f", (double)stat->flag_on_since[j] / 1000000.0f);
494 }
495 printf("\n");
496 }
497 }
498}
499
500gboolean289gboolean
501clearSysState(powerd_cookie_t cookie)290clearSysState(powerd_cookie_t cookie)
502{291{
@@ -520,20 +309,20 @@
520}309}
521310
522static gboolean311static gboolean
523clearDisplayState(powerd_cookie_t cookie)312clearDisplayState(int cookie)
524{313{
525 GVariant *ret = NULL;314 GVariant *ret = NULL;
526 GError *error = NULL;315 GError *error = NULL;
527316
528 ret = g_dbus_proxy_call_sync(powerd_proxy,317 ret = g_dbus_proxy_call_sync(uscreen_proxy,
529 "clearDisplayState",318 "removeDisplayOnRequest",
530 g_variant_new("(s)", cookie),319 g_variant_new("(i)", cookie),
531 G_DBUS_CALL_FLAGS_NONE,320 G_DBUS_CALL_FLAGS_NONE,
532 -1,321 -1,
533 NULL,322 NULL,
534 &error);323 &error);
535 if (ret == NULL) {324 if (ret == NULL) {
536 cli_warn("clearDisplayState failed: %s", error->message);325 cli_warn("removeDisplayOnRequest failed: %s", error->message);
537 g_error_free(error);326 g_error_free(error);
538 return FALSE;327 return FALSE;
539 }328 }
@@ -567,9 +356,6 @@
567 requests = listSysRequests();356 requests = listSysRequests();
568 do_test(checkForDbusName(test_dbusname, 0, requests, TRUE));357 do_test(checkForDbusName(test_dbusname, 0, requests, TRUE));
569 g_array_free(requests, TRUE);358 g_array_free(requests, TRUE);
570 requests = listDisplayRequests();
571 do_test(checkForDbusName(test_dbusname, 0, requests, TRUE));
572 g_array_free(requests, TRUE);
573 }359 }
574 else {360 else {
575 printf("Did not find child's dbus name\n");361 printf("Did not find child's dbus name\n");
@@ -712,102 +498,6 @@
712 silence_errors(FALSE);498 silence_errors(FALSE);
713}499}
714500
715static void
716runDisplayTests()
717{
718 int i;
719 int state = 0;
720 gboolean bright = FALSE;
721 powerd_cookie_t cookie, cookies[TEST_NUM_DISP_REQUESTS];
722 GArray *requests = NULL;
723 struct PublicDispRequest pdr = {0,};
724
725 silence_errors(TRUE);
726
727 // Hold active state request as long we're running tests
728 requestSysState("main-req", POWERD_SYS_STATE_ACTIVE, &main_cookie);
729
730 for (i = 0; i < TEST_NUM_DISP_REQUESTS; i++) {
731 char name[16];
732 snprintf(name, sizeof(name), "disp-test-%d", i);
733 pdr.state = state++;
734 pdr.flags = 0;
735 if (bright) {
736 pdr.flags |= POWERD_DISPLAY_FLAG_BRIGHT;
737 }
738 do_test(requestDisplayState(pdr, name, &cookies[i]) == TRUE);
739 if (state >= POWERD_NUM_DISPLAY_STATES) {
740 state = 0;
741 }
742 bright = !bright;
743 }
744
745 // Make sure we have at least NUM_REQUESTS
746 requests = listDisplayRequests();
747 do_test(requests->len >= TEST_NUM_DISP_REQUESTS);
748 // We should see our PID NUM_REQUESTS times
749 do_test(checkForDbusName(powerd_cli_bus_name, TEST_NUM_DISP_REQUESTS, requests, FALSE));
750 g_array_free(requests, TRUE);
751
752 for (i = 0; i < TEST_NUM_DISP_REQUESTS; i++)
753 do_test(clearDisplayState(cookies[i]) == TRUE);
754
755 requests = listDisplayRequests();
756 // We aren't holding anymore with this PID
757 do_test(checkForDbusName(powerd_cli_bus_name, 0, requests, FALSE));
758 g_array_free(requests, TRUE);
759
760 // Now try and freeing the same cookies again. They should all be
761 // invalid and thus the request fails.
762 for (i = 0; i < TEST_NUM_DISP_REQUESTS; i++)
763 do_test(clearDisplayState(cookies[i]) == FALSE);
764
765 // Test releasing an invalid cookie format
766 do_test(clearDisplayState("bad cookie") == FALSE);
767
768 //invalid values
769 pdr.state = -1;
770 do_test(requestDisplayState(pdr, "disp-test", &cookie) == FALSE);
771
772 pdr.state = POWERD_NUM_DISPLAY_STATES;
773 do_test(requestDisplayState(pdr, "disp-test", &cookie) == FALSE);
774
775 pdr.state = POWERD_DISPLAY_STATE_ON;
776 pdr.flags = 0xdeadbeef;
777 do_test(requestDisplayState(pdr, "disp-test", &cookie) == FALSE);
778
779 // updateDisplayState tests
780 pdr.state = POWERD_DISPLAY_STATE_ON;
781 pdr.flags = 0;
782 do_test(requestDisplayState(pdr, "disp-test", &cookie) == TRUE);
783
784 // update with same state should be okay
785 do_test(updateDisplayState(pdr, cookie) == TRUE);
786
787 pdr.state = POWERD_DISPLAY_STATE_DONT_CARE;
788 do_test(updateDisplayState(pdr, cookie) == TRUE);
789
790 pdr.flags = POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS;
791 do_test(updateDisplayState(pdr, cookie) == TRUE);
792
793 pdr.state = -1;
794 do_test(updateDisplayState(pdr, cookie) == FALSE);
795
796 do_test(clearDisplayState(cookie) == TRUE);
797
798 // update with same cookie after clear should fail
799 do_test(updateDisplayState(pdr, cookie) == FALSE);
800
801 // update with garbage cookie should faile
802 do_test(updateDisplayState(pdr, "bad cookie") == FALSE);
803
804 //cleanup
805 do_test(clearSysState(main_cookie) == TRUE);
806 do_test(checkForDbusName(powerd_cli_bus_name, 0, requests, TRUE));
807
808 silence_errors(FALSE);
809}
810
811// Check that dbus owner appears count times in a list of sys/disp requests501// Check that dbus owner appears count times in a list of sys/disp requests
812static gboolean502static gboolean
813checkForDbusName(const char *dbusname,503checkForDbusName(const char *dbusname,
@@ -818,7 +508,6 @@
818 int i;508 int i;
819 int found = 0;509 int found = 0;
820 struct PublicSysRequest *psr;510 struct PublicSysRequest *psr;
821 struct PublicDispRequest *pdr;
822511
823 if (requests == NULL) {512 if (requests == NULL) {
824 cli_warn("NULL requests passed to %s", __func__);513 cli_warn("NULL requests passed to %s", __func__);
@@ -833,12 +522,6 @@
833 found++;522 found++;
834 }523 }
835 }524 }
836 else {
837 pdr = &g_array_index(requests, struct PublicDispRequest, i);
838 if (!(strcmp(pdr->owner, dbusname))) {
839 found++;
840 }
841 }
842 }525 }
843526
844 if (found != count) {527 if (found != count) {
@@ -855,47 +538,6 @@
855 g_main_loop_quit(main_loop);538 g_main_loop_quit(main_loop);
856}539}
857540
858/* Caller ensures that we have at least 4 arguments in argv */
859static gboolean
860buildDisplayRequest(char **argv,
861 int argc,
862 struct PublicDispRequest *pdr)
863{
864 int i;
865
866 if (!strcasecmp(argv[2],"on")) {
867 pdr->state = POWERD_DISPLAY_STATE_ON;
868 cli_debug("Requesting Display On");
869 }
870 else if (!strcasecmp(argv[2],"dc")) {
871 pdr->state = POWERD_DISPLAY_STATE_DONT_CARE;
872 cli_debug("Requesting Display Don't Care");
873 }
874 else {
875 fprintf(stderr,"invalid state %s, must be either on or dc\n",
876 argv[2]);
877 return FALSE;
878 }
879
880 pdr->flags = 0;
881 for (i=3; i<argc; i++) {
882 if (!strcmp(argv[i],"proximity")) {
883 pdr->flags |= POWERD_DISPLAY_FLAG_USE_PROXIMITY;
884 cli_debug("Requesting Proximity Sensor Enabled");
885 }
886 else if (!strcmp(argv[i],"disableab")) {
887 pdr->flags |= POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS;
888 cli_debug("Requesting Proximity Disable AutoBrightness");
889 }
890 else if (!strcasecmp(argv[i],"bright")) {
891 pdr->flags |= POWERD_DISPLAY_FLAG_BRIGHT;
892 cli_debug("Requesting Bright");
893 }
894 }
895
896 return TRUE;
897}
898
899static void541static void
900setUserAutobrightness(gboolean enable)542setUserAutobrightness(gboolean enable)
901{543{
@@ -968,16 +610,9 @@
968 printf("brightness <brightness> - set user screen brightness.\n");610 printf("brightness <brightness> - set user screen brightness.\n");
969 printf("brightness-params - get brightness parameters (dim, min, max, etc.)\n");611 printf("brightness-params - get brightness parameters (dim, min, max, etc.)\n");
970 printf("clear-sys <cookie> - clear a System state request given a cookie.\n");612 printf("clear-sys <cookie> - clear a System state request given a cookie.\n");
971 printf("clear-disp <cookie> - clear a Display state request given a cookie.\n");
972 printf("client-test - test powerd registration / ack API.\n");613 printf("client-test - test powerd registration / ack API.\n");
973 printf("display <on|dc> [bright] [proximity] [disableab]\n"\614 printf("display <on>\n"\
974 "\tMake a display state request with the input parameters.\n"\615 "\tMake the display stay on\n");
975 "\tThe first argument represents the state of the display:\n"\
976 "\tOn (on) or Don't Care (dc),\n"\
977 "\tThe final optional arguments respectively:\n"\
978 "\t * make the screen bright [bright]\n"\
979 "\t * enable the proximity sensor [proximity]\n"\
980 "\t * disable autobrightness [disableab]\n");
981 printf("help\t- display this usage information.\n");616 printf("help\t- display this usage information.\n");
982 printf("list\t- list outstanding requests.\n");617 printf("list\t- list outstanding requests.\n");
983 printf("listen\t- listen for signals from powerd. This runs a\n"\618 printf("listen\t- listen for signals from powerd. This runs a\n"\
@@ -997,7 +632,6 @@
997 GError *error = NULL;632 GError *error = NULL;
998 uid_t myeuid;633 uid_t myeuid;
999 GArray *requests = NULL;634 GArray *requests = NULL;
1000 struct PublicDispRequest pdr;
1001 GDBusConnection *bus = NULL;635 GDBusConnection *bus = NULL;
1002 const char *bus_name = NULL;636 const char *bus_name = NULL;
1003 powerd_cookie_t cookie;637 powerd_cookie_t cookie;
@@ -1017,7 +651,6 @@
1017 (strcmp(argv[1],"listen")) &&651 (strcmp(argv[1],"listen")) &&
1018 (strcmp(argv[1],"display")) &&652 (strcmp(argv[1],"display")) &&
1019 (strcmp(argv[1],"help")) &&653 (strcmp(argv[1],"help")) &&
1020 (strcmp(argv[1],"clear-disp")) &&
1021 (strcmp(argv[1],"clear-sys")) &&654 (strcmp(argv[1],"clear-sys")) &&
1022 (strcmp(argv[1],"client-test")) &&655 (strcmp(argv[1],"client-test")) &&
1023 (strcmp(argv[1], "autobrightness")) &&656 (strcmp(argv[1], "autobrightness")) &&
@@ -1055,22 +688,30 @@
1055 return -1;688 return -1;
1056 }689 }
1057690
691 uscreen_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
692 G_DBUS_PROXY_FLAGS_NONE,
693 NULL,
694 "com.canonical.Unity.Screen",
695 "/com/canonical/Unity/Screen",
696 "com.canonical.Unity.Screen",
697 NULL,
698 &error);
699
700 if (error != NULL) {
701 cli_warn("could not connect to unity screen: %s", error->message);
702 g_error_free(error);
703 return -1;
704 }
705
1058 if (!strcmp(argv[1],"list")) {706 if (!strcmp(argv[1],"list")) {
1059 requests = listSysRequests();707 requests = listSysRequests();
1060 printSysRequests(requests);708 printSysRequests(requests);
1061 g_array_free(requests, TRUE);709 g_array_free(requests, TRUE);
1062 requests = listDisplayRequests();
1063 printDisplayRequests(requests);
1064 g_array_free(requests, TRUE);
1065 }710 }
1066 else if (!strcmp(argv[1], "stats")) {711 else if (!strcmp(argv[1], "stats")) {
1067 requests = getSysRequestStats();712 requests = getSysRequestStats();
1068 printSysRequestStats(requests);713 printSysRequestStats(requests);
1069 g_array_free(requests, TRUE);714 g_array_free(requests, TRUE);
1070
1071 requests = getDispRequestStats();
1072 printDispRequestStats(requests);
1073 g_array_free(requests, TRUE);
1074 }715 }
1075 else if (!strcmp(argv[1],"active-nc")) {716 else if (!strcmp(argv[1],"active-nc")) {
1076 requestSysState("active-nc", POWERD_SYS_STATE_ACTIVE,&cookie);717 requestSysState("active-nc", POWERD_SYS_STATE_ACTIVE,&cookie);
@@ -1086,20 +727,16 @@
1086 return 0;727 return 0;
1087 }728 }
1088 else if (!strcmp(argv[1],"display")) {729 else if (!strcmp(argv[1],"display")) {
1089 if (argc < 3) {730 int disp_cookie;
1090 fprintf(stderr,"display requires other arguments\n");731 cli_debug("Requesting Display On");
1091 usage(argv[0]);732 if (requestDisplayState(&disp_cookie) == FALSE) {
1092 return -1;733 fprintf(stderr,"failed display request\n");
1093 }734 return -1;
1094 if (buildDisplayRequest(argv,argc,&pdr) == FALSE) {735 }
1095 usage(argv[0]);736 printf("Display State requested, cookie is %d.\nPress ctrl-c to exit.\n",
1096 return -1;737 disp_cookie);
1097 }
1098 requestDisplayState(pdr, "disp-test", &cookie);
1099 printf("Display State requested, cookie is %s.\nPress ctrl-c to exit.\n",
1100 cookie);
1101 pause(); /* wait for SIGINT */738 pause(); /* wait for SIGINT */
1102 clearDisplayState(cookie);739 clearDisplayState(disp_cookie);
1103 return 0;740 return 0;
1104 }741 }
1105 else if (!strncmp(argv[1],"clear",strlen("clear"))) {742 else if (!strncmp(argv[1],"clear",strlen("clear"))) {
@@ -1114,9 +751,6 @@
1114 if (!strcmp(argv[1],"clear-sys")) {751 if (!strcmp(argv[1],"clear-sys")) {
1115 clearSysState(argv[2]);752 clearSysState(argv[2]);
1116 }753 }
1117 else if (!strcmp(argv[1],"clear-disp")) {
1118 clearDisplayState(argv[2]);
1119 }
1120 else {754 else {
1121 // Note: We should never get here due to earlier checks755 // Note: We should never get here due to earlier checks
1122 fprintf(stderr,"Invalid option %s\n",argv[1]);756 fprintf(stderr,"Invalid option %s\n",argv[1]);
@@ -1144,7 +778,6 @@
1144778
1145 runDbusNameVanishTests(argv[0]);779 runDbusNameVanishTests(argv[0]);
1146 runSysTests();780 runSysTests();
1147 runDisplayTests();
1148781
1149 g_object_unref(powerd_cli_bus);782 g_object_unref(powerd_cli_bus);
1150 powerd_cli_bus = NULL;783 powerd_cli_bus = NULL;
@@ -1163,11 +796,6 @@
1163 requestSysState("dbusnametest1", POWERD_SYS_STATE_ACTIVE,&cookie);796 requestSysState("dbusnametest1", POWERD_SYS_STATE_ACTIVE,&cookie);
1164 requestSysState("dbusnametest2", POWERD_SYS_STATE_ACTIVE,&cookie);797 requestSysState("dbusnametest2", POWERD_SYS_STATE_ACTIVE,&cookie);
1165 requestSysState("dbusnametest3", POWERD_SYS_STATE_ACTIVE,&cookie);798 requestSysState("dbusnametest3", POWERD_SYS_STATE_ACTIVE,&cookie);
1166 pdr.state = POWERD_DISPLAY_STATE_DONT_CARE;
1167 pdr.flags = 0;
1168 requestDisplayState(pdr, "dbusnametest1", &cookie);
1169 requestDisplayState(pdr, "dbusnametest2", &cookie);
1170 requestDisplayState(pdr, "dbusnametest3", &cookie);
1171 g_object_unref(bus);799 g_object_unref(bus);
1172 // Exit here without cleanup800 // Exit here without cleanup
1173 return 0;801 return 0;
1174802
=== removed file 'data/com.canonical.powerd.gschema.xml'
--- data/com.canonical.powerd.gschema.xml 2013-10-04 14:43:05 +0000
+++ data/com.canonical.powerd.gschema.xml 1970-01-01 00:00:00 +0000
@@ -1,15 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<schemalist gettext-domain="powerd">
3 <schema id="com.canonical.powerd" path="/com/canonical/powerd/">
4 <key name="activity-timeout" type="u">
5 <range min="5" max="3600"/>
6 <default>60</default>
7 <summary>Timeout in seconds for turning off the screen if there is no user activity</summary>
8 </key>
9 <key name="dim-timeout" type="u">
10 <range min="0" max="3600"/>
11 <default>45</default>
12 <summary>Timeout in seconds for dimming the screen if there is no user activity. A value of 0 disables auto-dimming.</summary>
13 </key>
14 </schema>
15</schemalist>
160
=== modified file 'data/com.canonical.powerd.xml'
--- data/com.canonical.powerd.xml 2014-04-23 02:08:02 +0000
+++ data/com.canonical.powerd.xml 2014-06-20 19:46:21 +0000
@@ -14,23 +14,6 @@
14 <arg type="s" name="cookie" direction="in" />14 <arg type="s" name="cookie" direction="in" />
15 </method>15 </method>
1616
17 <method name="requestDisplayState">
18 <arg type="s" name="name" direction="in" />
19 <arg type="i" name="state" direction="in" />
20 <arg type="u" name="flags" direction="in" />
21 <arg type="s" name="cookie" direction="out" />
22 </method>
23
24 <method name="updateDisplayState">
25 <arg type="s" name="cookie" direction="in" />
26 <arg type="i" name="state" direction="in" />
27 <arg type="u" name="flags" direction="in" />
28 </method>
29
30 <method name="clearDisplayState">
31 <arg type="s" name="cookie" direction="in" />
32 </method>
33
34 <method name="registerClient">17 <method name="registerClient">
35 <arg type="s" name="name" direction="in" />18 <arg type="s" name="name" direction="in" />
36 </method>19 </method>
@@ -63,25 +46,14 @@
63 <arg type="a(ssi)" name="requestList" direction="out" />46 <arg type="a(ssi)" name="requestList" direction="out" />
64 </method>47 </method>
6548
66 <method name="listDisplayRequests">
67 <arg type="a(ssiu)" name="requestList" direction="out" />
68 </method>
69
70 <method name="getSysRequestStats">49 <method name="getSysRequestStats">
71 <arg type="a(ssuttt)" name="requestStats" direction="out" />50 <arg type="a(ssuttt)" name="requestStats" direction="out" />
72 </method>51 </method>
7352
74 <method name="getDispRequestStats">
75 <arg type="a(ssutttttatat)" name="requestStats" direction="out" />
76 </method>
77
78 <!-- Signals -->53 <!-- Signals -->
79 <signal name="SysPowerStateChange">54 <signal name="SysPowerStateChange">
80 <arg type="i" name="sysState" direction="out" />55 <arg type="i" name="sysState" direction="out" />
81 </signal>56 </signal>
8257
83 <signal name="DisplayPowerStateChange">
84 <arg type="(iu)" name="displayState" direction="out" />
85 </signal>
86 </interface>58 </interface>
87</node>59</node>
8860
=== modified file 'debian/changelog'
--- debian/changelog 2014-06-12 10:36:19 +0000
+++ debian/changelog 2014-06-20 19:46:21 +0000
@@ -1,3 +1,10 @@
1powerd (0.16-0ubuntu1) UNRELEASED; urgency=medium
2
3 * Remove support for inactivity and display power state handling
4 * Bump major version due to some dbus API removals
5
6 -- Alberto Aguirre <alberto.aguirre@canonical.com> Fri, 20 Jun 2014 14:41:43 -0500
7
1powerd (0.15+14.10.20140612-0ubuntu1) utopic; urgency=low8powerd (0.15+14.10.20140612-0ubuntu1) utopic; urgency=low
29
3 [ Ubuntu daily release ]10 [ Ubuntu daily release ]
411
=== modified file 'debian/control'
--- debian/control 2014-05-29 06:53:15 +0000
+++ debian/control 2014-06-20 19:46:21 +0000
@@ -23,8 +23,7 @@
23Architecture: any23Architecture: any
24Depends: ${misc:Depends}, ${shlibs:Depends}, upower24Depends: ${misc:Depends}, ${shlibs:Depends}, upower
25Recommends: ofono25Recommends: ofono
26Description: Power daemon to monitor and control system and display power state26Description: Power daemon to monitor and control system power state
27 This daemon monitors and controls system and display power states for Ubuntu27 This daemon monitors and controls system power states for Ubuntu
28 phone and tablet. It provides a dbus interface for system services to request28 phone and tablet. It provides a dbus interface for system services to request
29 a power state, essentially allowing services to block suspend. Additionally29 a power state, essentially allowing services to block suspend.
30 it monitors user activity and power button presses.
3130
=== modified file 'debian/powerd.conf'
--- debian/powerd.conf 2014-03-28 10:10:28 +0000
+++ debian/powerd.conf 2014-06-20 19:46:21 +0000
@@ -42,16 +42,10 @@
42 <allow send_destination="com.canonical.powerd"42 <allow send_destination="com.canonical.powerd"
43 send_interface="com.canonical.powerd"43 send_interface="com.canonical.powerd"
44 send_type="method_call" send_member="listSysRequests" />44 send_type="method_call" send_member="listSysRequests" />
45 <allow send_destination="com.canonical.powerd"
46 send_interface="com.canonical.powerd"
47 send_type="method_call" send_member="listDisplayRequests" />
4845
49 <allow send_destination="com.canonical.powerd"46 <allow send_destination="com.canonical.powerd"
50 send_interface="com.canonical.powerd"47 send_interface="com.canonical.powerd"
51 send_type="method_call" send_member="getSysRequestStats" />48 send_type="method_call" send_member="getSysRequestStats" />
52 <allow send_destination="com.canonical.powerd"
53 send_interface="com.canonical.powerd"
54 send_type="method_call" send_member="getDispRequestStats" />
5549
56 <allow send_destination="com.canonical.powerd"50 <allow send_destination="com.canonical.powerd"
57 send_interface="com.canonical.powerd"51 send_interface="com.canonical.powerd"
5852
=== modified file 'src/backlight.c'
--- src/backlight.c 2014-04-23 02:08:02 +0000
+++ src/backlight.c 2014-06-20 19:46:21 +0000
@@ -33,6 +33,14 @@
3333
34struct light_device_t *light_dev;34struct light_device_t *light_dev;
3535
36enum bl_state {
37 BL_OFF,
38 BL_ON,
39 BL_AUTO,
40
41 NUM_BL_STATES
42};
43
36/*44/*
37 * Defaults are Android default settings. They may not work if we45 * Defaults are Android default settings. They may not work if we
38 * can't read the per-device values, but they're as good as46 * can't read the per-device values, but they're as good as
@@ -44,6 +52,8 @@
44int dim_brightness = 10;52int dim_brightness = 10;
45int current_brightness = -1;53int current_brightness = -1;
4654
55static int user_brightness;
56
47int powerd_get_brightness(void)57int powerd_get_brightness(void)
48{58{
49 return current_brightness;59 return current_brightness;
@@ -91,11 +101,6 @@
91 min_user_brightness : brightness);101 min_user_brightness : brightness);
92}102}
93103
94void powerd_dim_screen(void)
95{
96 powerd_set_brightness(dim_brightness);
97}
98
99int powerd_backlight_init(void)104int powerd_backlight_init(void)
100{105{
101 GValue v = G_VALUE_INIT;106 GValue v = G_VALUE_INIT;
@@ -144,6 +149,7 @@
144 * Unfortunately the HAL provides no way for us to read the149 * Unfortunately the HAL provides no way for us to read the
145 * current brightness when we start. */150 * current brightness when we start. */
146 powerd_set_brightness(default_brightness);151 powerd_set_brightness(default_brightness);
152 user_brightness = default_brightness;
147153
148 return 0;154 return 0;
149}155}
@@ -153,6 +159,58 @@
153 light_dev = NULL;159 light_dev = NULL;
154}160}
155161
162static void set_user_brightness(int brightness)
163{
164 int max = powerd_get_max_brightness();
165 if (brightness > max)
166 brightness = max;
167 user_brightness = brightness;
168}
169
170static void set_backlight(enum bl_state state)
171{
172 static enum bl_state current_state = BL_ON;
173 static int restore_brightness = 0;
174
175 if (state >= NUM_BL_STATES) {
176 powerd_warn("Unknown backlight state %d\n", state);
177 return;
178 }
179
180 if (state != BL_AUTO)
181 powerd_autobrightness_disable();
182
183 /*
184 * When autobrightness is enabled, it takes a second to
185 * settle on a brightness level after enabling. This delay
186 * becomes very noticeable when going from the dim to bright
187 * state. To avoid this lag, save off the current brightness
188 * and restore it when transitioning to AUTO mode again.
189 */
190 if (current_state != BL_OFF && state == BL_OFF)
191 restore_brightness = powerd_get_brightness();
192
193 switch (state) {
194 case BL_OFF:
195 powerd_set_brightness(0);
196 break;
197 case BL_ON:
198 powerd_set_user_brightness(user_brightness);
199 break;
200 case BL_AUTO:
201 if (current_state == BL_OFF && restore_brightness > 0)
202 powerd_set_brightness(restore_brightness);
203 powerd_autobrightness_enable();
204 break;
205 default:
206 /* default case is to satisfy static analysis tools, should
207 * never actually get here */
208 powerd_error("Unknwown backlight state %d\n", state);
209 return;
210 }
211 current_state = state;
212}
213
156214
157/** dbus interfaces **/215/** dbus interfaces **/
158216
@@ -169,3 +227,33 @@
169 ab_available));227 ab_available));
170 return TRUE;228 return TRUE;
171}229}
230
231gboolean handle_user_autobrightness_enable(PowerdSource *obj,
232 GDBusMethodInvocation *invocation,
233 gboolean enable)
234{
235 if (powerd_autobrightness_available() && enable)
236 set_backlight(BL_AUTO);
237 else
238 set_backlight(BL_ON);
239
240 g_dbus_method_invocation_return_value(invocation, NULL);
241 return TRUE;
242}
243
244gboolean handle_set_user_brightness(PowerdSource *obj,
245 GDBusMethodInvocation *invocation,
246 gint brightness)
247{
248 if (brightness == 0)
249 {
250 set_backlight(BL_OFF);
251 }
252 else
253 {
254 set_user_brightness(brightness);
255 set_backlight(BL_ON);
256 }
257 g_dbus_method_invocation_return_value(invocation, NULL);
258 return TRUE;
259}
172260
=== removed file 'src/display-request.c'
--- src/display-request.c 2014-04-14 21:17:04 +0000
+++ src/display-request.c 1970-01-01 00:00:00 +0000
@@ -1,458 +0,0 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * Authors:
5 * Michael Frey: michael.frey@canonical.com
6 * Matthew Fischer: matthew.fischer@canonical.com
7 * Seth Forshee: seth.forshee@canonical.com
8 *
9 * This file is part of powerd.
10 *
11 * powerd is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 3.
14 *
15 * powerd is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#include <string.h>
25#include <errno.h>
26#include <uuid/uuid.h>
27
28#include <glib.h>
29#include <glib-object.h>
30#include <gio/gio.h>
31
32#include "powerd.h"
33#include "powerd-internal.h"
34#include "log.h"
35
36struct display_request_internal {
37 struct powerd_display_request req;
38 const char *name;
39 const char *owner;
40};
41
42static struct {
43 unsigned int state[POWERD_NUM_DISPLAY_STATES];
44 unsigned int flags[POWERD_NUM_DISPLAY_FLAGS];
45} display_state_count;
46
47static struct powerd_display_request internal_state = {
48 .state = POWERD_DISPLAY_STATE_DONT_CARE,
49 .flags = 0,
50};
51
52static GHashTable *display_request_hash;
53
54static void update_internal_state(void)
55{
56 struct powerd_display_request new_state;
57 int i;
58
59 memset(&new_state, 0, sizeof(new_state));
60
61 /* Default to off if no request for display to be on */
62 if (display_state_count.state[POWERD_DISPLAY_STATE_ON] > 0)
63 new_state.state = POWERD_DISPLAY_STATE_ON;
64 else
65 new_state.state = POWERD_DISPLAY_STATE_DONT_CARE;
66
67 for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
68 if (display_state_count.flags[i] > 0)
69 new_state.flags |= (1U << i);
70 }
71
72 if (!memcmp(&internal_state, &new_state, sizeof(new_state))) {
73 powerd_debug("display state not changed");
74 return;
75 }
76
77 powerd_debug("Internal state updated: state %d flags 0x%08x",
78 new_state.state, new_state.flags);
79 internal_state = new_state;
80 powerd_set_display_state(&internal_state);
81}
82
83static void __add_request(struct powerd_display_request *req)
84{
85 unsigned int flags;
86 int i;
87
88 display_state_count.state[req->state]++;
89
90 flags = req->flags;
91 for (i = 0; flags && i < POWERD_NUM_DISPLAY_FLAGS; flags >>= 1, i++) {
92 if (flags & 1)
93 display_state_count.flags[i]++;
94 }
95}
96
97static void __remove_request(struct powerd_display_request *req)
98{
99 unsigned int flags;
100 int i;
101
102 if (display_state_count.state[req->state] > 0)
103 display_state_count.state[req->state]--;
104
105 flags = req->flags;
106 for (i = 0; flags && i < POWERD_NUM_DISPLAY_FLAGS; flags >>= 1, i++) {
107 if ((flags & 1) && display_state_count.flags[i] > 0)
108 display_state_count.flags[i]--;
109 }
110}
111
112static void add_request(struct display_request_internal *request)
113{
114 g_hash_table_insert(display_request_hash, request->req.cookie, request);
115 powerd_dbus_name_watch_add(request->owner);
116 __add_request(&request->req);
117 update_internal_state();
118 powerd_account_add_display_req(request->owner, request->name,
119 &request->req);
120}
121
122static gboolean update_request(struct powerd_display_request *new_req)
123{
124 struct display_request_internal *ireq;
125
126 ireq = g_hash_table_lookup(display_request_hash, new_req->cookie);
127 if (!ireq) {
128 powerd_debug("Display request to update not found");
129 return FALSE;
130 }
131
132 __remove_request(&ireq->req);
133 __add_request(new_req);
134
135 ireq->req.state = new_req->state;
136 ireq->req.flags = new_req->flags;
137
138 update_internal_state();
139 powerd_account_update_display_req(ireq->owner, ireq->name, &ireq->req);
140 return TRUE;
141}
142
143static gboolean remove_request(uuid_t cookie)
144{
145 struct display_request_internal *ireq;
146 struct powerd_display_request req;
147 gboolean found = FALSE;
148
149 /*
150 * This involves two lookups into the hash, one to find the
151 * request so we can retrieve the state and another to remove
152 * it. GHashTable doesn't seem to provide any more efficient
153 * way to do this; too bad g_hash_table_steal() doesn't return
154 * a pointer to the data.
155 */
156 ireq = g_hash_table_lookup(display_request_hash, cookie);
157 if (ireq) {
158 req = ireq->req;
159 /* We need to remove it from our watch hash and do accounting
160 * before we remove it from the state hash or the ireq->owner
161 * memory will be freed before we try to use it.
162 */
163 powerd_dbus_name_watch_remove(ireq->owner);
164 powerd_account_clear_display_req(ireq->owner, ireq->name);
165 found = g_hash_table_remove(display_request_hash, cookie);
166 if (!found)
167 powerd_warn("Display request found on lookup but not on remove");
168 }
169
170 if (found) {
171 __remove_request(&req);
172 update_internal_state();
173 }
174
175 return found;
176}
177
178static gboolean request_valid(struct powerd_display_request *request)
179{
180 if ((unsigned)request->state >= POWERD_NUM_DISPLAY_STATES) {
181 powerd_warn("Invalid display state requested: %d", request->state);
182 return FALSE;
183 }
184
185 /*
186 * XXX: This will warn if we get up to 32 flags, but in that
187 * case the check should just be removed.
188 */
189 if (request->flags & (-1U << POWERD_NUM_DISPLAY_FLAGS)) {
190 powerd_warn("Invalid display flags requested: 0x%08x", request->flags);
191 return FALSE;
192 }
193
194 return TRUE;
195}
196
197static int add_request_worker(gpointer data)
198{
199 struct display_request_internal *req = data;
200 add_request(req);
201 return 0;
202}
203
204/*
205 * @request need not refer to persistent memory, as the data from
206 * the struct will be copied into internally-managed storage.
207 */
208static int __powerd_add_display_request(struct powerd_display_request *request,
209 const char *name, const char *owner)
210{
211 struct display_request_internal *hash_req;
212
213 if (!request_valid(request))
214 return -EINVAL;
215
216 uuid_generate(request->cookie);
217 hash_req = g_new(struct display_request_internal, 1);
218 hash_req->req = *request;
219 hash_req->name = g_strdup(name);
220 hash_req->owner = g_strdup(owner);
221 powerd_run_mainloop_sync(add_request_worker, hash_req);
222 return 0;
223}
224
225/*
226 * @request need not refer to persistent memory, as the data from
227 * the struct will be copied into internally-managed storage.
228 */
229int powerd_add_display_request(struct powerd_display_request *request,
230 const char *name)
231{
232 if (!request || !name) {
233 powerd_warn("powerd_add_display_request() called with invalid args");
234 return -EINVAL;
235 }
236 return __powerd_add_display_request(request, name, "internal");
237}
238
239static int update_request_worker(gpointer data)
240{
241 struct powerd_display_request *req = data;
242 return update_request(req);
243}
244
245int powerd_update_display_request(struct powerd_display_request *request)
246{
247 gboolean found;
248
249 if (!request_valid(request))
250 return -EINVAL;
251
252 found = powerd_run_mainloop_sync(update_request_worker, request);
253 return found ? 0 : -EINVAL;
254}
255
256static int remove_request_worker(gpointer data)
257{
258 unsigned char *uuid = data;
259 return remove_request(uuid);
260}
261
262int powerd_remove_display_request(uuid_t cookie)
263{
264 gboolean found;
265
266 found = powerd_run_mainloop_sync(remove_request_worker, cookie);
267 return found ? 0 : -EINVAL;
268}
269
270/** dbus method handling **/
271
272gboolean handle_add_display_request(PowerdSource *obj,
273 GDBusMethodInvocation *invocation,
274 const char *name, int state, guint32 flags)
275{
276 struct powerd_display_request req;
277 const char *owner;
278 char ext_cookie[UUID_STR_LEN];
279 int ret;
280
281 memset(&req, 0, sizeof(req));
282
283 owner = g_dbus_method_invocation_get_sender(invocation);
284 powerd_debug("%s from %s: state %d flags %#08x",
285 __func__, owner, state, flags);
286
287 req.state = state;
288 req.flags = flags;
289
290 ret = __powerd_add_display_request(&req, name, owner);
291 if (ret) {
292 g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
293 G_DBUS_ERROR_INVALID_ARGS,
294 "Invalid display request");
295 } else {
296 powerd_debug("%s: SUCCESS", __func__);
297 uuid_unparse(req.cookie, ext_cookie);
298 g_dbus_method_invocation_return_value(invocation,
299 g_variant_new("(s)", ext_cookie));
300 }
301
302 return TRUE;
303}
304
305gboolean handle_update_display_request(PowerdSource *obj,
306 GDBusMethodInvocation *invocation,
307 const gchar *ext_cookie, int state,
308 guint32 flags)
309{
310 struct powerd_display_request req;
311 uuid_t cookie;
312 int ret;
313
314 memset(&req, 0, sizeof(req));
315
316 powerd_debug("%s from %s: cookie: %s state %d flags %#08x",
317 __func__, g_dbus_method_invocation_get_sender(invocation),
318 ext_cookie, state, flags);
319
320 if (uuid_parse(ext_cookie, cookie)) {
321 g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
322 G_DBUS_ERROR_INVALID_ARGS,
323 "Invalid cookie: %s",
324 ext_cookie);
325 return TRUE;
326 }
327
328 memcpy(req.cookie, cookie, sizeof(uuid_t));
329 req.state = state;
330 req.flags = flags;
331
332 ret = powerd_update_display_request(&req);
333 if (ret) {
334 g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
335 G_DBUS_ERROR_INVALID_ARGS,
336 "Invalid display request");
337 } else {
338 powerd_debug("%s: SUCCESS", __func__);
339 g_dbus_method_invocation_return_value(invocation, NULL);
340 }
341
342 return TRUE;
343}
344
345gboolean handle_clear_display_request(PowerdSource *obj,
346 GDBusMethodInvocation *invocation,
347 const gchar *ext_cookie)
348{
349 int ret;
350 uuid_t cookie;
351
352 powerd_debug("%s from %s, cookie: %s", __func__,
353 g_dbus_method_invocation_get_sender(invocation), ext_cookie);
354
355 if (uuid_parse(ext_cookie, cookie)) {
356 g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
357 G_DBUS_ERROR_INVALID_ARGS,
358 "Invalid cookie: %s",
359 ext_cookie);
360 return TRUE;
361 }
362
363 ret = powerd_remove_display_request(cookie);
364 if (ret) {
365 g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
366 G_DBUS_ERROR_INVALID_ARGS,
367 "Invalid cookie: %s", ext_cookie);
368 } else {
369 g_dbus_method_invocation_return_value(invocation, NULL);
370 }
371
372 return TRUE;
373}
374
375static int build_display_request_list(GVariantBuilder *builder)
376{
377 GHashTableIter iter;
378 gpointer key, value;
379 int count = 0;
380
381 g_hash_table_iter_init(&iter, display_request_hash);
382 while (g_hash_table_iter_next(&iter, &key, &value)) {
383 struct display_request_internal *ireq = value;
384 struct powerd_display_request *req = &ireq->req;
385 g_variant_builder_add(builder, "(ssiu)", ireq->name, ireq->owner,
386 req->state, req->flags);
387 count++;
388 }
389 return count;
390}
391
392gboolean handle_list_display_requests(PowerdSource *obj,
393 GDBusMethodInvocation *invocation)
394{
395 GVariant *list, *tuple;
396 GVariantBuilder *builder;
397 int count;
398
399 builder = g_variant_builder_new(G_VARIANT_TYPE("a(ssiu)"));
400 count = build_display_request_list(builder);
401 if (count > 0) {
402 list = g_variant_builder_end(builder);
403 } else {
404 g_variant_builder_clear(builder);
405 list = g_variant_new_array(G_VARIANT_TYPE("(ssiu)"), NULL, 0);
406 }
407
408 tuple = g_variant_new_tuple(&list, 1);
409 g_dbus_method_invocation_return_value(invocation, tuple);
410 g_variant_builder_unref(builder);
411
412 return TRUE;
413}
414
415/* Destructor for hash table */
416static void display_request_destroy(gpointer data)
417{
418 struct display_request_internal *req = data;
419
420 g_free((gpointer)req->name);
421 g_free((gpointer)req->owner);
422 g_free(req);
423}
424
425void display_request_init(void)
426{
427 display_request_hash = g_hash_table_new_full(powerd_uuid_hash,
428 powerd_uuid_equal,
429 NULL, display_request_destroy);
430}
431
432void display_request_deinit(void)
433{
434 g_hash_table_destroy(display_request_hash);
435}
436
437/*
438 * Callers may use this to clear all requests that the specified owner
439 * is holding. This is used when the owner drops off of dbus
440 */
441void
442clear_disp_state_by_owner(const char *owner)
443{
444 GHashTableIter iter;
445 gpointer key, value;
446
447 g_hash_table_iter_init(&iter, display_request_hash);
448 while (g_hash_table_iter_next(&iter, &key, &value)) {
449 struct display_request_internal *ireq = value;
450 if (!strcmp(owner, ireq->owner)) {
451 powerd_account_clear_display_req(ireq->owner, ireq->name);
452 __remove_request(&ireq->req);
453 powerd_dbus_name_watch_remove(ireq->owner);
454 g_hash_table_iter_remove(&iter);
455 }
456 }
457 update_internal_state();
458}
4590
=== added file 'src/display.c'
--- src/display.c 1970-01-01 00:00:00 +0000
+++ src/display.c 2014-06-20 19:46:21 +0000
@@ -0,0 +1,132 @@
1/*
2 * Copyright 2013-2014 Canonical Ltd.
3 *
4 * Authors:
5 * Michael Frey: michael.frey@canonical.com
6 * Matthew Fischer: matthew.fischer@canonical.com
7 * Seth Forshee: seth.forshee@canonical.com
8 *
9 * This file is part of powerd.
10 *
11 * powerd is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 3.
14 *
15 * powerd is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#include <string.h>
25
26#include <glib.h>
27#include <gio/gio.h>
28
29#include "powerd-internal.h"
30#include "log.h"
31
32static GDBusProxy* create_uscreen_proxy()
33{
34 GError *error = NULL;
35 GDBusProxy *uscreen_proxy = NULL;
36 uscreen_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
37 G_DBUS_PROXY_FLAGS_NONE,
38 NULL,
39 "com.canonical.Unity.Screen",
40 "/com/canonical/Unity/Screen",
41 "com.canonical.Unity.Screen",
42 NULL,
43 &error);
44
45 if (error != NULL) {
46 powerd_warn("could not connect to Unity.Screen: %s", error->message);
47 g_error_free(error);
48 return NULL;
49 }
50
51 return uscreen_proxy;
52}
53
54static void request_keep_display_on(GDBusConnection *connection,
55 const gchar *name,
56 const gchar *name_owner,
57 gpointer user_data)
58{
59 GDBusProxy *uscreen_proxy = NULL;
60 GVariant *ret = NULL;
61 GError *error = NULL;
62 int request_id;
63
64 powerd_debug("request_keep_display_on");
65
66 uscreen_proxy = create_uscreen_proxy();
67 if (uscreen_proxy == NULL)
68 {
69 powerd_warn("failed creating unity screen proxy to keep display on");
70 return;
71 }
72
73 ret = g_dbus_proxy_call_sync(uscreen_proxy,
74 "keepDisplayOn",
75 NULL,
76 G_DBUS_CALL_FLAGS_NONE,
77 -1,
78 NULL,
79 &error);
80
81 if (ret == NULL) {
82 powerd_warn("keepDisplayOn failed: %s", error->message);
83 g_error_free(error);
84 return;
85 }
86
87 g_variant_get(ret, "(i)", &request_id);
88 powerd_debug("keepDisplayOn request succeeded - id: %d", request_id);
89
90 g_variant_unref(ret);
91 g_object_unref(uscreen_proxy);
92}
93
94gboolean turn_display_on(gboolean on, enum DisplayStateChangeReason reason)
95{
96 GDBusProxy *uscreen_proxy = NULL;
97
98 powerd_debug("turn_display_on(%d)", on);
99
100 if (on)
101 powerd_hal_signal_activity();
102
103 uscreen_proxy = create_uscreen_proxy();
104 if (uscreen_proxy == NULL)
105 return FALSE;
106
107 g_dbus_proxy_call(uscreen_proxy,
108 "setScreenPowerMode",
109 g_variant_new("(si)", (on ? "on" : "off"), reason),
110 G_DBUS_CALL_FLAGS_NONE,
111 -1,
112 NULL,
113 NULL,
114 NULL);
115
116 g_object_unref(uscreen_proxy);
117
118 return TRUE;
119}
120
121void keep_display_on()
122{
123 powerd_debug("issuing keep_display_on request");
124
125 g_bus_watch_name(G_BUS_TYPE_SYSTEM,
126 "com.canonical.Unity.Screen",
127 G_BUS_NAME_WATCHER_FLAGS_NONE,
128 request_keep_display_on,
129 NULL,
130 NULL,
131 NULL);
132}
0133
=== removed file 'src/display.c'
--- src/display.c 2014-04-14 21:17:04 +0000
+++ src/display.c 1970-01-01 00:00:00 +0000
@@ -1,438 +0,0 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * Authors:
5 * Michael Frey: michael.frey@canonical.com
6 * Matthew Fischer: matthew.fischer@canonical.com
7 * Seth Forshee: seth.forshee@canonical.com
8 *
9 * This file is part of powerd.
10 *
11 * powerd is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 3.
14 *
15 * powerd is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#include <stdio.h>
25#include <string.h>
26#include <errno.h>
27#include <unistd.h>
28#include <sys/types.h>
29#include <sys/stat.h>
30#include <fcntl.h>
31
32#include <glib.h>
33#include <glib-object.h>
34
35#include "powerd.h"
36#include "powerd-internal.h"
37#include "log.h"
38
39enum bl_state {
40 BL_OFF,
41 BL_DIM,
42 BL_BRIGHT,
43 BL_AUTO,
44
45 NUM_BL_STATES
46};
47static enum bl_state target_bl_state = BL_BRIGHT;
48
49/* Treat "don't care" display state as off */
50#define DISPLAY_STATE_OFF POWERD_DISPLAY_STATE_DONT_CARE
51
52/* Autobrightness only enabled when bright && !disabled */
53#define AB_ENABLED_MASK (POWERD_DISPLAY_FLAG_BRIGHT | \
54 POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS)
55#define AB_ENABLED POWERD_DISPLAY_FLAG_BRIGHT
56
57static int user_brightness;
58static gboolean user_ab_enabled;
59
60/* Assume screen is off to start; we will force it on */
61static uuid_t internal_request_cookie;
62
63/* Currently requested state of the display */
64struct powerd_display_request internal_state = {
65 .state = DISPLAY_STATE_OFF,
66 .flags = 0,
67};
68
69/*
70 * When using the proximity sensor, our actual state of the screen
71 * may not match the requested state in internal_state. Therefore
72 * this variable keeps track of the actual state of the screen.
73 */
74enum powerd_display_state actual_screen_state = DISPLAY_STATE_OFF;
75
76/*
77 * Screen state overrides. These are used when powerd needs to force
78 * the screen off regardless of the requested display state.
79 */
80static unsigned screen_off_overrides;
81
82static const char *display_state_strs[POWERD_NUM_DISPLAY_STATES] = {
83 [POWERD_DISPLAY_STATE_DONT_CARE] = "off",
84 [POWERD_DISPLAY_STATE_ON] = "on",
85};
86
87static const char *display_state_to_str(enum powerd_display_state state)
88{
89 if (state >= POWERD_NUM_DISPLAY_STATES)
90 return "invalid";
91 return display_state_strs[state];
92}
93
94static gboolean ab_enabled(guint32 flags)
95{
96 if (!powerd_autobrightness_available())
97 return FALSE;
98 if (!user_ab_enabled)
99 return FALSE;
100 return (flags & AB_ENABLED_MASK) == AB_ENABLED;
101}
102
103static void set_backlight(enum bl_state state)
104{
105 static enum bl_state current_state = BL_BRIGHT;
106 static int restore_brightness = 0;
107
108 if (state >= NUM_BL_STATES) {
109 powerd_warn("Unknown backlight state %d\n", state);
110 return;
111 }
112 if (state != BL_AUTO)
113 powerd_autobrightness_disable();
114
115 /*
116 * When we're enabling autobrightness it takes a second to
117 * settle on a brightness level after enabling. This delay
118 * becomes very noticible when going from the dim to bright
119 * state. To avoid this lag, save off the current brightness
120 * any time the state goes from BRIGHT or AUTO and restore
121 * it if transitioning back to AUTO.
122 */
123 if (current_state >= BL_BRIGHT && state < BL_BRIGHT)
124 restore_brightness = powerd_get_brightness();
125
126 switch (state) {
127 case BL_OFF:
128 powerd_set_brightness(0);
129 break;
130 case BL_DIM:
131 powerd_dim_screen();
132 break;
133 case BL_BRIGHT:
134 powerd_set_user_brightness(user_brightness);
135 break;
136 case BL_AUTO:
137 if (current_state < BL_BRIGHT && restore_brightness > 0)
138 powerd_set_brightness(restore_brightness);
139 powerd_autobrightness_enable();
140 break;
141 default:
142 /* default case is to satisfy static analysis tools, should
143 * never actually get here */
144 powerd_error("Unknwown backlight state %d\n", state);
145 return;
146 }
147 current_state = state;
148}
149
150gboolean display_set_power_mode(int display, const char *power_mode)
151{
152 GError *error = NULL;
153 GDBusProxy *unity_proxy = NULL;
154
155 powerd_debug("display_set_power_mode(%s)", power_mode);
156
157 if (strcmp(power_mode, "on") == 0)
158 powerd_hal_signal_activity();
159
160 unity_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
161 G_DBUS_PROXY_FLAGS_NONE,
162 NULL,
163 "com.canonical.Unity.Screen",
164 "/com/canonical/Unity/Screen",
165 "com.canonical.Unity.Screen",
166 NULL,
167 &error);
168
169 if (error != NULL) {
170 powerd_warn("could not connect to Unity: %s", error->message);
171 g_error_free(error);
172 return FALSE;
173 }
174
175 GVariant *ret = g_dbus_proxy_call_sync(unity_proxy,
176 "setScreenPowerMode",
177 g_variant_new("(s)", power_mode),
178 G_DBUS_CALL_FLAGS_NONE,
179 -1,
180 NULL,
181 &error);
182
183 if (ret == NULL) {
184 powerd_warn("screen power setting failed: %s", error->message);
185 g_error_free(error);
186 g_object_unref(unity_proxy);
187 return FALSE;
188 }
189
190 g_object_unref(unity_proxy);
191
192 return TRUE;
193}
194
195static void turn_on_display(void)
196{
197 powerd_debug("turning on display");
198 display_set_power_mode(0, "on");
199 set_backlight(target_bl_state);
200}
201
202gboolean powerd_display_enabled(void)
203{
204 return actual_screen_state == POWERD_DISPLAY_STATE_ON;
205}
206
207static void update_display_state(struct powerd_display_request *req)
208{
209 enum powerd_display_state state = req->state;
210 int applied_state;
211 int ret;
212
213 applied_state = screen_off_overrides ? DISPLAY_STATE_OFF : state;
214
215 switch (applied_state) {
216 case DISPLAY_STATE_OFF:
217 if (actual_screen_state == DISPLAY_STATE_OFF) {
218 /* Nothing to do */
219 return;
220 }
221
222 powerd_debug("turning off display");
223 set_backlight(BL_OFF);
224 if (!display_set_power_mode(0, "off")) {
225 powerd_warn("failed to set display power mode, not clearing state");
226 return;
227 }
228
229 powerd_debug("Releasing internal active state request");
230 ret = clear_sys_state_internal(internal_request_cookie);
231 if (!ret) {
232 char cookie_str[UUID_STR_LEN];
233 uuid_unparse(internal_request_cookie, cookie_str);
234 powerd_warn("Internal system state request cookie invalid: %s",
235 cookie_str);
236 }
237 break;
238 case POWERD_DISPLAY_STATE_ON:
239 if (ab_enabled(req->flags))
240 target_bl_state = BL_AUTO;
241 else if (req->flags & POWERD_DISPLAY_FLAG_BRIGHT)
242 target_bl_state = BL_BRIGHT;
243 else
244 target_bl_state = BL_DIM;
245
246 if (actual_screen_state != POWERD_DISPLAY_STATE_ON) {
247 powerd_debug("Requesting active state internally");
248 ret = request_sys_state_internal("display-request",
249 POWERD_SYS_STATE_ACTIVE,
250 &internal_request_cookie, NULL);
251 if (!ret)
252 powerd_warn("Request for active state failed");
253
254 /*
255 * If currently in the suspend state we need to wait for
256 * notification of entering the active state, otherwise the
257 * screen may fail to turn on for devices using earlysuspend.
258 * Otherwise we can turn on the screen right away.
259 */
260 if (!powerd_suspend_active())
261 turn_on_display();
262 } else {
263 /* Only updating backlight state */
264 set_backlight(target_bl_state);
265 }
266 break;
267 default:
268 powerd_warn("Invalid display state %d", applied_state);
269 return;
270 }
271
272 actual_screen_state = applied_state;
273
274 powerd_display_state_signal_emit(actual_screen_state, req->flags);
275}
276
277static void update_flags(guint32 flags)
278{
279 int prox_enabled, internal_prox_enabled;
280
281 prox_enabled = (flags & POWERD_DISPLAY_FLAG_USE_PROXIMITY);
282 internal_prox_enabled = (internal_state.flags & POWERD_DISPLAY_FLAG_USE_PROXIMITY);
283
284 if (prox_enabled != internal_prox_enabled) {
285 if (prox_enabled) {
286 powerd_sensors_proximity_enable();
287 } else {
288 powerd_sensors_proximity_disable();
289 powerd_display_clear_override(POWERD_OVERRIDE_REASON_PROXIMITY);
290 }
291 }
292}
293
294/*
295 * *** WARNING ***
296 *
297 * This should now only be called by display request code. Everyone
298 * else must use powerd_{add,remove}_display_request()!!!
299 */
300void powerd_set_display_state(struct powerd_display_request *req)
301{
302 powerd_debug("powerd_set_display_state: %s -> %s, 0x%x -> 0x%x",
303 display_state_to_str(internal_state.state),
304 display_state_to_str(req->state),
305 internal_state.flags, req->flags);
306
307 /* Update flags before display state to ensure proximity flag is
308 * taken into account */
309 update_flags(req->flags);
310 update_display_state(req);
311
312 internal_state = *req;
313}
314
315static void user_ab_enable(gboolean enable)
316{
317 user_ab_enabled = enable;
318 update_display_state(&internal_state);
319}
320
321static gboolean prox_update_worker(gpointer data)
322{
323 unsigned long near = (unsigned long)data;
324 if (near)
325 powerd_display_set_override(POWERD_OVERRIDE_REASON_PROXIMITY);
326 else
327 powerd_display_clear_override(POWERD_OVERRIDE_REASON_PROXIMITY);
328 return FALSE;
329}
330
331void powerd_proximity_event(gboolean near)
332{
333 unsigned long data = (unsigned long)near;
334 g_timeout_add(0, prox_update_worker, (gpointer)data);
335}
336
337struct apply_override_data {
338 enum powerd_override_reason reason;
339 int set;
340};
341
342static int apply_override_worker(gpointer data)
343{
344 struct apply_override_data *ovr_data = data;
345 unsigned orig_overrides = screen_off_overrides;
346 unsigned mask;
347
348 mask = 1 << ovr_data->reason;
349 if (ovr_data->set)
350 screen_off_overrides |= mask;
351 else
352 screen_off_overrides &= ~mask;
353
354 if (orig_overrides != screen_off_overrides)
355 update_display_state(&internal_state);
356 return 0;
357}
358
359void powerd_display_set_override(enum powerd_override_reason reason)
360{
361 struct apply_override_data ovr_data;
362
363 if (reason >= POWERD_NUM_OVERRIDE_REASONS) {
364 powerd_debug("Refusing to set invalid override reason (%d)", reason);
365 return;
366 }
367
368 ovr_data.reason = reason;
369 ovr_data.set = 1;
370 powerd_run_mainloop_sync(apply_override_worker, &ovr_data);
371}
372
373void powerd_display_clear_override(enum powerd_override_reason reason)
374{
375 struct apply_override_data ovr_data;
376
377 if (reason >= POWERD_NUM_OVERRIDE_REASONS) {
378 powerd_debug("Refusing to clear invalid override reason (%d)", reason);
379 return;
380 }
381
382 ovr_data.reason = reason;
383 ovr_data.set = 0;
384 powerd_run_mainloop_sync(apply_override_worker, &ovr_data);
385}
386
387static void set_user_brightness(int brightness)
388{
389 int max = powerd_get_max_brightness();
390 if (brightness > max)
391 brightness = max;
392 user_brightness = brightness;
393 update_display_state(&internal_state);
394}
395
396static gboolean exit_suspend_worker(gpointer unused)
397{
398 /* Make sure suspend is still disabled */
399 if (!powerd_suspend_active() && powerd_display_enabled())
400 turn_on_display();
401 return FALSE;
402}
403
404void powerd_display_exit_suspend(void)
405{
406 g_timeout_add(0, exit_suspend_worker, NULL);
407}
408
409int powerd_display_init(void)
410{
411 struct stat stats;
412
413 /* Use the current brightness until we're told another value */
414 user_brightness = powerd_get_brightness();
415
416 return 0;
417}
418
419
420/** dbus interfaces **/
421
422gboolean handle_user_autobrightness_enable(PowerdSource *obj,
423 GDBusMethodInvocation *invocation,
424 gboolean enable)
425{
426 user_ab_enable(enable);
427 g_dbus_method_invocation_return_value(invocation, NULL);
428 return TRUE;
429}
430
431gboolean handle_set_user_brightness(PowerdSource *obj,
432 GDBusMethodInvocation *invocation,
433 gint brightness)
434{
435 set_user_brightness(brightness);
436 g_dbus_method_invocation_return_value(invocation, NULL);
437 return TRUE;
438}
4390
=== modified file 'src/power-request.c'
--- src/power-request.c 2014-01-03 15:23:38 +0000
+++ src/power-request.c 2014-06-20 19:46:21 +0000
@@ -372,7 +372,6 @@
372 int ret = libsuspend_exit_suspend();372 int ret = libsuspend_exit_suspend();
373 if (!ret) {373 if (!ret) {
374 suspend_active = FALSE;374 suspend_active = FALSE;
375 powerd_display_exit_suspend();
376 }375 }
377 return ret;376 return ret;
378}377}
379378
=== modified file 'src/powerd-internal.h'
--- src/powerd-internal.h 2014-04-14 21:17:04 +0000
+++ src/powerd-internal.h 2014-06-20 19:46:21 +0000
@@ -33,17 +33,10 @@
33/* Length of a UUID string, including trailing nul */33/* Length of a UUID string, including trailing nul */
34#define UUID_STR_LEN 3734#define UUID_STR_LEN 37
3535
36struct powerd_display_request {36enum DisplayStateChangeReason
37 uuid_t cookie;37{
38 enum powerd_display_state state;38 UNITY_SCREEN_REASON_NORMAL = 0,
39 guint32 flags;39 UNITY_SCREEN_REASON_PROXIMITY = 3,
40};
41
42enum powerd_override_reason {
43 POWERD_OVERRIDE_REASON_POWER_BUTTON,
44 POWERD_OVERRIDE_REASON_PROXIMITY,
45
46 POWERD_NUM_OVERRIDE_REASONS
47};40};
4841
49struct DbusNameWatch {42struct DbusNameWatch {
@@ -64,6 +57,10 @@
64void powerd_dbus_init_complete(void);57void powerd_dbus_init_complete(void);
65int powerd_is_mainloop(void);58int powerd_is_mainloop(void);
6659
60/* Display functions */
61gboolean turn_display_on(gboolean on, enum DisplayStateChangeReason reason);
62void keep_display_on();
63
67/* Autobrightness functions */64/* Autobrightness functions */
68void powerd_new_als_event(double lux);65void powerd_new_als_event(double lux);
69void powerd_autobrightness_enable(void);66void powerd_autobrightness_enable(void);
@@ -79,19 +76,11 @@
79int powerd_get_max_brightness(void);76int powerd_get_max_brightness(void);
80int powerd_set_brightness(int brightness);77int powerd_set_brightness(int brightness);
81int powerd_set_user_brightness(int brightness);78int powerd_set_user_brightness(int brightness);
82void powerd_dim_screen(void);
83gboolean handle_get_brightness_params(PowerdSource *obj,79gboolean handle_get_brightness_params(PowerdSource *obj,
84 GDBusMethodInvocation *invocation);80 GDBusMethodInvocation *invocation);
8581
86/* Display functions */
87void powerd_brightness_set_value(gint value);82void powerd_brightness_set_value(gint value);
88gboolean powerd_display_enabled(void);
89gboolean display_set_power_mode(int display, const char *powerd_mode);
90void powerd_set_display_state(struct powerd_display_request *req);
91int powerd_display_init(void);
92void powerd_proximity_event(gboolean near);83void powerd_proximity_event(gboolean near);
93void powerd_display_set_override(enum powerd_override_reason reason);
94void powerd_display_clear_override(enum powerd_override_reason reason);
95gboolean handle_user_autobrightness_enable(PowerdSource *obj,84gboolean handle_user_autobrightness_enable(PowerdSource *obj,
96 GDBusMethodInvocation *invocation,85 GDBusMethodInvocation *invocation,
97 gboolean enable);86 gboolean enable);
@@ -99,28 +88,6 @@
99 GDBusMethodInvocation *invocation,88 GDBusMethodInvocation *invocation,
100 gint brightness);89 gint brightness);
10190
102/* Display request functions */
103int powerd_add_display_request(struct powerd_display_request *request,
104 const char *name);
105int powerd_update_display_request(struct powerd_display_request *request);
106int powerd_remove_display_request(uuid_t cookie);
107void display_request_init(void);
108void display_request_deinit(void);
109gboolean handle_add_display_request(PowerdSource *obj,
110 GDBusMethodInvocation *invocation,
111 const char *name, int state, guint32 flags);
112gboolean handle_update_display_request(PowerdSource *obj,
113 GDBusMethodInvocation *invocation,
114 const gchar *ext_cookie, int state,
115 guint32 flags);
116gboolean handle_clear_display_request(PowerdSource *obj,
117 GDBusMethodInvocation *invocation,
118 const gchar *ext_cookie);
119gboolean handle_list_display_requests(PowerdSource *obj,
120 GDBusMethodInvocation *invocation);
121void clear_disp_state_by_owner(const char *owner);
122void powerd_display_exit_suspend(void);
123
124/* System power state requests */91/* System power state requests */
125gboolean handle_list_sys_requests(PowerdSource *obj,92gboolean handle_list_sys_requests(PowerdSource *obj,
126 GDBusMethodInvocation *invocation);93 GDBusMethodInvocation *invocation);
@@ -140,8 +107,6 @@
140enum SysPowerStates current_system_power_state(void);107enum SysPowerStates current_system_power_state(void);
141const gchar * state_to_string(int state);108const gchar * state_to_string(int state);
142void powerd_sys_state_signal_emit(enum SysPowerStates state);109void powerd_sys_state_signal_emit(enum SysPowerStates state);
143void powerd_display_state_signal_emit(enum powerd_display_state state,
144 guint32 flags);
145void clear_sys_state_by_owner(const char *owner);110void clear_sys_state_by_owner(const char *owner);
146gboolean powerd_suspend_active(void);111gboolean powerd_suspend_active(void);
147112
@@ -207,19 +172,11 @@
207/* Statistics functions */172/* Statistics functions */
208void powerd_account_request_sys_state(const char *dbus_name, const char *name);173void powerd_account_request_sys_state(const char *dbus_name, const char *name);
209void powerd_account_clear_sys_state(const char *dbus_name, const char *name);174void powerd_account_clear_sys_state(const char *dbus_name, const char *name);
210void powerd_account_add_display_req(const char *dbus_name, const char *name,
211 const struct powerd_display_request *req);
212void powerd_account_update_display_req(const char *dbus_name,
213 const char *name,
214 const struct powerd_display_request *req);
215void powerd_account_clear_display_req(const char *dbus_name, const char *name);
216void powerd_log_stats(void);175void powerd_log_stats(void);
217int powerd_stats_init(void);176int powerd_stats_init(void);
218void powerd_stats_deinit(void);177void powerd_stats_deinit(void);
219gboolean handle_get_sys_request_stats(PowerdSource *obj,178gboolean handle_get_sys_request_stats(PowerdSource *obj,
220 GDBusMethodInvocation *invocation);179 GDBusMethodInvocation *invocation);
221gboolean handle_get_disp_request_stats(PowerdSource *obj,
222 GDBusMethodInvocation *invocation);
223180
224/* Utility functions */181/* Utility functions */
225int powerd_run_mainloop_sync(int (*func)(gpointer), gpointer data);182int powerd_run_mainloop_sync(int (*func)(gpointer), gpointer data);
226183
=== modified file 'src/powerd-object.c'
--- src/powerd-object.c 2014-04-14 21:17:04 +0000
+++ src/powerd-object.c 2014-06-20 19:46:21 +0000
@@ -163,24 +163,14 @@
163 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-list-sys-requests",163 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-list-sys-requests",
164 G_CALLBACK(handle_list_sys_requests), powerd_source);164 G_CALLBACK(handle_list_sys_requests), powerd_source);
165165
166 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-request-display-state",
167 G_CALLBACK(handle_add_display_request), powerd_source);
168 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-update-display-state",
169 G_CALLBACK(handle_update_display_request), powerd_source);
170 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-clear-display-state",
171 G_CALLBACK(handle_clear_display_request), powerd_source);
172 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-register-client",166 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-register-client",
173 G_CALLBACK(handle_register_client), powerd_source);167 G_CALLBACK(handle_register_client), powerd_source);
174 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-unregister-client",168 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-unregister-client",
175 G_CALLBACK(handle_unregister_client), powerd_source);169 G_CALLBACK(handle_unregister_client), powerd_source);
176 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-ack-state-change",170 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-ack-state-change",
177 G_CALLBACK(handle_ack_state_change), powerd_source);171 G_CALLBACK(handle_ack_state_change), powerd_source);
178 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-list-display-requests",
179 G_CALLBACK(handle_list_display_requests), powerd_source);
180 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-get-sys-request-stats",172 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-get-sys-request-stats",
181 G_CALLBACK(handle_get_sys_request_stats), powerd_source);173 G_CALLBACK(handle_get_sys_request_stats), powerd_source);
182 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-get-disp-request-stats",
183 G_CALLBACK(handle_get_disp_request_stats), powerd_source);
184 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-user-autobrightness-enable",174 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-user-autobrightness-enable",
185 G_CALLBACK(handle_user_autobrightness_enable), powerd_source);175 G_CALLBACK(handle_user_autobrightness_enable), powerd_source);
186 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-get-brightness-params",176 g_signal_connect(G_OBJECT(powerd_source->priv->skel), "handle-get-brightness-params",
@@ -234,32 +224,6 @@
234}224}
235225
236void226void
237powerd_display_state_signal_emit(enum powerd_display_state state,
238 guint32 flags)
239{
240 GError *error = NULL;
241
242 /* Make sure dbus has been set up */
243 if (!powerd_source)
244 return;
245
246 powerd_debug("Emitting signal for display state change: state=%d flags=0x%08x",
247 state, flags);
248 g_dbus_connection_emit_signal(
249 POWERD_SOURCE_GET_PRIVATE(powerd_source)->system_bus,
250 NULL, /* destination */
251 "/com/canonical/powerd",
252 "com.canonical.powerd",
253 "DisplayPowerStateChange",
254 g_variant_new("(iu)", state, flags),
255 &error);
256 if (error) {
257 powerd_warn("Unable to signal a state change update: %s", error->message);
258 g_error_free(error);
259 }
260}
261
262void
263ofono_manager_proxy_connect_cb(GObject *source_object,227ofono_manager_proxy_connect_cb(GObject *source_object,
264 GAsyncResult *res,228 GAsyncResult *res,
265 gpointer user_data)229 gpointer user_data)
@@ -355,8 +319,6 @@
355 gpointer user_data)319 gpointer user_data)
356{320{
357 powerd_warn("%s vanished from dbus, clearing associated requests", name);321 powerd_warn("%s vanished from dbus, clearing associated requests", name);
358 clear_sys_state_by_owner(name);
359 clear_disp_state_by_owner(name);
360 powerd_client_unregister(name);322 powerd_client_unregister(name);
361 // This can return false if the hash entry was removed because the323 // This can return false if the hash entry was removed because the
362 // last request was dropped, in other words, this call will fail324 // last request was dropped, in other words, this call will fail
363325
=== modified file 'src/powerd.cpp'
--- src/powerd.cpp 2014-03-28 08:00:33 +0000
+++ src/powerd.cpp 2014-06-20 19:46:21 +0000
@@ -44,10 +44,6 @@
44#include "log.h"44#include "log.h"
4545
46#include <hybris/properties/properties.h>46#include <hybris/properties/properties.h>
47#include <hybris/input/input_stack_compatibility_layer.h>
48#include <hybris/input/input_stack_compatibility_layer_codes_key.h>
49
50#include <hybris/surface_flinger/surface_flinger_compatibility_layer.h>
5147
52#include "libsuspend.h"48#include "libsuspend.h"
5349
@@ -57,74 +53,11 @@
5753
58namespace54namespace
59{55{
60
61#define SHUTDOWN_HOLD_SECS 2
62
63static uint button_timer = 0;
64
65/*
66 * Do not modify activity_timer directly. Instead, call
67 * reset_activity_timer();
68 */
69static uint activity_timer = 0;
70GMutex activity_timer_mutex;
71
72static time_t curtime;
73static int lasttime;
74struct tm *tm;
75
76/* The real default for this is set in the gschema file, but set 60 here
77 * as a sanity check */
78static const int activity_timeout = 60;
79static const int dim_timeout = 45;
80
81static GMainLoop *main_loop = NULL;56static GMainLoop *main_loop = NULL;
82static guint name_id;57static guint name_id;
8358
84enum state {
85 BUTTON_DOWN,
86 BUTTON_UP,
87 SHUTDOWN
88};
89
90static state button_state = BUTTON_UP;
91
92enum {
93 SCREEN_STATE_OFF = 0,
94 SCREEN_STATE_DIM,
95 SCREEN_STATE_BRIGHT
96};
97
98/* Assume screen starts off when powerd starts */
99int activity_timer_screen_state = SCREEN_STATE_OFF;
100
101static int g_exit_code = 0;59static int g_exit_code = 0;
10260
103/*
104 * Display request for activity timer
105 *
106 * Stupid C++ compiler won't let me use designated initializers ...
107 */
108static struct powerd_display_request activity_timer_req = {
109 {0,}, /* cookie */
110 POWERD_DISPLAY_STATE_ON, /* state */
111 POWERD_DISPLAY_FLAG_BRIGHT /* flags */
112};
113
114/* Display request for use of proximity sensor during phone calls */
115static struct powerd_display_request prox_sensor_req = {
116 {0,}, /* cookie */
117 POWERD_DISPLAY_STATE_ON, /* state */
118 POWERD_DISPLAY_FLAG_USE_PROXIMITY /* flags */
119};
120
121/* Default display request in case running in emulator */
122static struct powerd_display_request emulator_req = {
123 {0,}, /* cookie */
124 POWERD_DISPLAY_STATE_ON, /* state */
125 POWERD_DISPLAY_FLAG_BRIGHT /* flags */
126};
127
128/* List with detected modems */61/* List with detected modems */
129static GSList *g_modems = NULL;62static GSList *g_modems = NULL;
13063
@@ -150,86 +83,8 @@
150/* Flag set when proximity sensor is on */83/* Flag set when proximity sensor is on */
151static gboolean g_proximity_on = FALSE;84static gboolean g_proximity_on = FALSE;
15285
153gboolean activity_monitor(gpointer data);
154void update_screen_state(int state);
155
156gboolean call_shutdown(gpointer data)
157{
158 if (button_state == BUTTON_DOWN) {
159 button_state = SHUTDOWN;
160 powerd_set_brightness(0);
161 display_set_power_mode(0, "off");
162 powerd_shutdown();
163 }
164
165 return FALSE;
166}
167
168gboolean activity_monitor(gpointer data)
169{
170 int new_state;
171
172 g_mutex_lock(&activity_timer_mutex);
173
174 if (activity_timer_screen_state > SCREEN_STATE_OFF) {
175 if (dim_timeout > 0 && activity_timeout > dim_timeout)
176 new_state = activity_timer_screen_state - 1;
177 else
178 new_state = SCREEN_STATE_OFF;
179
180 update_screen_state(new_state);
181 if (new_state != SCREEN_STATE_OFF && activity_timer > 0)
182 activity_timer = g_timeout_add_seconds(activity_timeout - dim_timeout,
183 activity_monitor, NULL);
184 }
185
186 g_mutex_unlock(&activity_timer_mutex);
187 return FALSE;
188}
189
190static struct power_module* _power_module;86static struct power_module* _power_module;
19187
192void on_new_event(Event* event, void* context)
193{
194 switch(event->type)
195 {
196 case KEY_EVENT_TYPE:
197 if (event->details.key.key_code == ISCL_KEYCODE_POWER && button_state != SHUTDOWN) {
198 if (event->action == 1) {
199 powerd_debug("power button pressed");
200 button_state = BUTTON_UP;
201 curtime = time(0);
202 tm = localtime (&curtime);
203 if (tm->tm_sec - lasttime < SHUTDOWN_HOLD_SECS) {
204 gboolean enabled = powerd_display_enabled();
205 if (enabled)
206 powerd_display_set_override(POWERD_OVERRIDE_REASON_POWER_BUTTON);
207 else
208 powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON);
209 powerd_reset_activity_timer(!enabled);
210 }
211 } else if (event->action == 0) {
212 button_state = BUTTON_DOWN;
213 curtime = time(0);
214 tm = localtime (&curtime);
215 lasttime = tm->tm_sec;
216 if (button_timer > 0)
217 {
218 g_source_remove(button_timer);
219 button_timer = 0;
220 }
221 button_timer = g_timeout_add_seconds(SHUTDOWN_HOLD_SECS,
222 call_shutdown, NULL);
223 }
224 }
225 break;
226 default:
227 if (powerd_display_enabled())
228 powerd_reset_activity_timer(1);
229 break;
230 }
231}
232
233static void88static void
234sigterm_quit(int signal)89sigterm_quit(int signal)
235{90{
@@ -237,43 +92,6 @@
237 powerd_exit(0);92 powerd_exit(0);
238}93}
23994
240int update_screen_state_worker(gpointer data)
241{
242 long new_state = (long)data;
243 int ret;
244
245 if (new_state == activity_timer_screen_state)
246 return 0;
247
248 if (new_state == SCREEN_STATE_OFF) {
249 powerd_remove_display_request(activity_timer_req.cookie);
250 } else {
251 if (new_state == SCREEN_STATE_DIM)
252 activity_timer_req.flags &= ~POWERD_DISPLAY_FLAG_BRIGHT;
253 else
254 activity_timer_req.flags |= POWERD_DISPLAY_FLAG_BRIGHT;
255
256 if (activity_timer_screen_state == SCREEN_STATE_OFF)
257 ret = powerd_add_display_request(&activity_timer_req,
258 "activity-timer");
259 else
260 ret = powerd_update_display_request(&activity_timer_req);
261
262 if (ret)
263 powerd_warn("Error adding display state request for activity timer");
264 }
265
266 activity_timer_screen_state = new_state;
267 return 0;
268}
269
270void update_screen_state(int new_state)
271{
272 long data = new_state;
273 if (new_state < SCREEN_STATE_OFF || new_state > SCREEN_STATE_BRIGHT)
274 return;
275 powerd_run_mainloop_sync(update_screen_state_worker, (gpointer)data);
276}
27795
278} //namespace96} //namespace
27997
@@ -284,39 +102,12 @@
284 _power_module->powerHint(_power_module, POWER_HINT_INTERACTION, NULL);102 _power_module->powerHint(_power_module, POWER_HINT_INTERACTION, NULL);
285}103}
286104
287void powerd_reset_activity_timer(int add)
288{
289 int timeout;
290
291 g_mutex_lock(&activity_timer_mutex);
292
293 if (activity_timer > 0) {
294 g_source_remove(activity_timer);
295 activity_timer = 0;
296 }
297
298 if (add) {
299 if (dim_timeout > 0 && dim_timeout < activity_timeout)
300 timeout = dim_timeout;
301 else
302 timeout = activity_timeout;
303
304 update_screen_state(SCREEN_STATE_BRIGHT);
305 activity_timer = g_timeout_add_seconds(timeout, activity_monitor, NULL);
306 } else {
307 update_screen_state(SCREEN_STATE_OFF);
308 }
309
310 g_mutex_unlock(&activity_timer_mutex);
311}
312
313/*105/*
314 * Once dbus is ready, force the screen on to make the system state106 * Once dbus is ready, force the screen on to make the system state
315 * match the powerd iternal state107 * match the powerd iternal state
316 */108 */
317void powerd_dbus_init_complete(void)109void powerd_dbus_init_complete(void)
318{110{
319 powerd_reset_activity_timer(1);
320}111}
321112
322static void watch_modem(const char *modem)113static void watch_modem(const char *modem)
@@ -411,8 +202,7 @@
411202
412 if (strcmp("active", call_state) == 0203 if (strcmp("active", call_state) == 0
413 || strcmp("dialing", call_state) == 0) {204 || strcmp("dialing", call_state) == 0) {
414 if (powerd_add_display_request(&prox_sensor_req, "prox-sensor"))205 powerd_sensors_proximity_enable();
415 powerd_warn("Request to use proximity sensor failed");
416 g_proximity_on = TRUE;206 g_proximity_on = TRUE;
417 }207 }
418}208}
@@ -422,10 +212,19 @@
422 if (!g_proximity_on)212 if (!g_proximity_on)
423 return;213 return;
424214
425 powerd_remove_display_request(prox_sensor_req.cookie);215 powerd_sensors_proximity_disable();
426 g_proximity_on = FALSE;216 g_proximity_on = FALSE;
427}217}
428218
219
220void powerd_proximity_event(gboolean near)
221{
222 if (near)
223 turn_display_on(FALSE, UNITY_SCREEN_REASON_PROXIMITY);
224 else
225 turn_display_on(TRUE, UNITY_SCREEN_REASON_PROXIMITY);
226}
227
429void228void
430ofono_voicecall_get_props_cb(GObject *source_object, GAsyncResult *res,229ofono_voicecall_get_props_cb(GObject *source_object, GAsyncResult *res,
431 gpointer user_data)230 gpointer user_data)
@@ -509,8 +308,7 @@
509 if (!strcmp(signal_name, "CallAdded")) {308 if (!strcmp(signal_name, "CallAdded")) {
510 struct call_data *call;309 struct call_data *call;
511310
512 powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON);311 turn_display_on(TRUE, UNITY_SCREEN_REASON_NORMAL);
513 powerd_reset_activity_timer(1);
514312
515 call = (struct call_data *) calloc(1, sizeof(*call));313 call = (struct call_data *) calloc(1, sizeof(*call));
516 tmp = g_variant_get_child_value(parameters, 0);314 tmp = g_variant_get_child_value(parameters, 0);
@@ -589,8 +387,7 @@
589 if ((!strcmp(signal_name, "IncomingMessage")) ||387 if ((!strcmp(signal_name, "IncomingMessage")) ||
590 (!strcmp(signal_name, "ImmediateMessage"))) {388 (!strcmp(signal_name, "ImmediateMessage"))) {
591 powerd_debug("Waking up the device - Incoming SMS");389 powerd_debug("Waking up the device - Incoming SMS");
592 powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON);390 turn_display_on(TRUE, UNITY_SCREEN_REASON_NORMAL);
593 powerd_reset_activity_timer(1);
594 }391 }
595}392}
596393
@@ -605,8 +402,7 @@
605 if ((!strcmp(signal_name, "NotificationReceived")) ||402 if ((!strcmp(signal_name, "NotificationReceived")) ||
606 (!strcmp(signal_name, "RequestReceived"))) {403 (!strcmp(signal_name, "RequestReceived"))) {
607 powerd_debug("Waking up the device - Incoming USSD");404 powerd_debug("Waking up the device - Incoming USSD");
608 powerd_display_clear_override(POWERD_OVERRIDE_REASON_POWER_BUTTON);405 turn_display_on(TRUE, UNITY_SCREEN_REASON_NORMAL);
609 powerd_reset_activity_timer(1);
610 }406 }
611}407}
612408
@@ -632,9 +428,7 @@
632428
633 if (property_get("ro.kernel.qemu", propbuf, NULL) > 0) {429 if (property_get("ro.kernel.qemu", propbuf, NULL) > 0) {
634 powerd_info("Running in emulator, forcing display, blocking suspend.");430 powerd_info("Running in emulator, forcing display, blocking suspend.");
635 /* Request screen to be always on */431 keep_display_on();
636 if (powerd_add_display_request(&emulator_req, "emulator-display"))
637 powerd_warn("Request to force screen on for emulator failed");
638 /* Block suspend */432 /* Block suspend */
639 request_sys_state_internal("emulator-request",433 request_sys_state_internal("emulator-request",
640 POWERD_SYS_STATE_ACTIVE,434 POWERD_SYS_STATE_ACTIVE,
@@ -686,45 +480,21 @@
686 powerd_stats_init();480 powerd_stats_init();
687 powerd_client_init();481 powerd_client_init();
688 power_request_init();482 power_request_init();
689 display_request_init();
690 dbus_name_watch_init();483 dbus_name_watch_init();
691 powerd_backlight_init();484 powerd_backlight_init();
692 powerd_autobrightness_init();485 powerd_autobrightness_init();
693 powerd_display_init();
694 powerd_sensors_init();486 powerd_sensors_init();
695 powerd_ps_init();487 powerd_ps_init();
696488
697 main_loop = g_main_loop_new (NULL, FALSE);489 main_loop = g_main_loop_new (NULL, FALSE);
698 signal(SIGTERM, sigterm_quit);490 signal(SIGTERM, sigterm_quit);
699491
700 AndroidEventListener listener;
701 listener.on_new_event = on_new_event;
702 listener.context = NULL;
703
704 InputStackConfiguration config = {
705 enable_touch_point_visualization : false,
706 default_layer_for_touch_point_visualization : 10000,
707 input_area_width : 2048,
708 input_area_height : 2048
709 };
710
711 int err = hw_get_module(POWER_HARDWARE_MODULE_ID,492 int err = hw_get_module(POWER_HARDWARE_MODULE_ID,
712 (hw_module_t const**)&_power_module);493 (hw_module_t const**)&_power_module);
713494
714 if (!err)495 if (!err)
715 _power_module->init(_power_module);496 _power_module->init(_power_module);
716497
717 /* Compat input is needed otherwise there's no way to know when
718 * the user is actively using the system */
719 if (!android_input_check_availability()) {
720 powerd_error("Android compat input library not found, aborting");
721 g_exit_code = -1;
722 goto fail_compat_init;
723 }
724
725 android_input_stack_initialize(&listener, &config);
726 android_input_stack_start();
727
728 /* Config use should be done during init, okay to free now */498 /* Config use should be done during init, okay to free now */
729 device_config_deinit();499 device_config_deinit();
730500
@@ -736,15 +506,10 @@
736 g_bus_unown_name(name_id);506 g_bus_unown_name(name_id);
737 g_main_loop_unref(main_loop);507 g_main_loop_unref(main_loop);
738508
739 android_input_stack_stop();
740 android_input_stack_shutdown();
741
742fail_compat_init:
743 powerd_ps_deinit();509 powerd_ps_deinit();
744 dbus_name_watch_deinit();510 dbus_name_watch_deinit();
745 powerd_autobrightness_deinit();511 powerd_autobrightness_deinit();
746 powerd_backlight_deinit();512 powerd_backlight_deinit();
747 display_request_deinit();
748 power_request_deinit();513 power_request_deinit();
749 powerd_client_deinit();514 powerd_client_deinit();
750 powerd_stats_deinit();515 powerd_stats_deinit();
751516
=== modified file 'src/powerd.h'
--- src/powerd.h 2013-07-18 21:08:49 +0000
+++ src/powerd.h 2014-06-20 19:46:21 +0000
@@ -34,24 +34,6 @@
34 POWERD_NUM_POWER_STATES34 POWERD_NUM_POWER_STATES
35};35};
3636
37enum powerd_display_state {
38 POWERD_DISPLAY_STATE_DONT_CARE = 0,
39 POWERD_DISPLAY_STATE_ON,
40
41 /* Keep last */
42 POWERD_NUM_DISPLAY_STATES
43};
44
45/* Use proximity sensor to override screen state */
46#define POWERD_DISPLAY_FLAG_USE_PROXIMITY (1 << 0)
47/* Force autobrightness to be disabled */
48#define POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS (1 << 1)
49/* Request the screen to stay bright */
50#define POWERD_DISPLAY_FLAG_BRIGHT (1 << 2)
51
52/* Must be updated when new flags are added */
53#define POWERD_NUM_DISPLAY_FLAGS 3
54
55/*37/*
56 * Clients should treat this as an opaque type. Though this isn't really38 * Clients should treat this as an opaque type. Though this isn't really
57 * possible until the client library is written.39 * possible until the client library is written.
5840
=== modified file 'src/stats.c'
--- src/stats.c 2013-09-03 14:10:41 +0000
+++ src/stats.c 2014-06-20 19:46:21 +0000
@@ -48,19 +48,6 @@
48 guint64 active_since;48 guint64 active_since;
49};49};
5050
51struct disp_request_stats {
52 const char *name;
53 unsigned active_count;
54 guint64 active_time;
55 guint64 max_active_time;
56 guint64 active_since;
57 guint64 disp_on_time;
58 guint64 disp_on_since;
59 guint64 flag_on_time[POWERD_NUM_DISPLAY_FLAGS];
60 guint64 flag_on_since[POWERD_NUM_DISPLAY_FLAGS];
61 struct powerd_display_request last_req;
62};
63
64GHashTable *stats_hash;51GHashTable *stats_hash;
6552
66static guint64 get_usecs(void)53static guint64 get_usecs(void)
@@ -111,24 +98,6 @@
111 return stats;98 return stats;
112}99}
113100
114static struct disp_request_stats *alloc_disp_stats(const char *name)
115{
116 struct disp_request_stats *stats = calloc(1, sizeof(*stats));
117 if (!stats) {
118 powerd_error("Error allocating memory for display request statistics");
119 return NULL;
120 }
121
122 stats->name = strdup(name);
123 if (!stats->name) {
124 powerd_error("Error duplicating request name for statistics");
125 free(stats);
126 return NULL;
127 }
128
129 return stats;
130}
131
132static gint sys_stats_comp(gconstpointer a, gconstpointer b)101static gint sys_stats_comp(gconstpointer a, gconstpointer b)
133{102{
134 const struct sys_request_stats *stats = a;103 const struct sys_request_stats *stats = a;
@@ -136,13 +105,6 @@
136 return strcmp(stats->name, name);105 return strcmp(stats->name, name);
137}106}
138107
139static gint disp_stats_comp(gconstpointer a, gconstpointer b)
140{
141 const struct disp_request_stats *stats = a;
142 const char *name = b;
143 return strcmp(stats->name, name);
144}
145
146static struct client_stats *lookup_client(const char *dbus_name,108static struct client_stats *lookup_client(const char *dbus_name,
147 gboolean alloc)109 gboolean alloc)
148{110{
@@ -210,122 +172,6 @@
210 stats->max_active_time = duration;172 stats->max_active_time = duration;
211}173}
212174
213static void aggregate_disp_stats(struct disp_request_stats *stats,
214 const struct powerd_display_request *new)
215{
216 guint64 us;
217 int i;
218
219 us = get_usecs();
220 if (new->state != stats->last_req.state) {
221 if (new->state == POWERD_DISPLAY_STATE_ON) {
222 stats->disp_on_since = us;
223 } else {
224 stats->disp_on_time += us - stats->disp_on_since;
225 stats->disp_on_since = 0;
226 }
227 }
228 for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
229 guint32 mask = 1 << i;
230 if ((new->flags & mask) != (stats->last_req.flags & mask)) {
231 if (new->flags & mask) {
232 stats->flag_on_since[i] = us;
233 } else {
234 stats->flag_on_time[i] += us - stats->flag_on_since[i];
235 stats->flag_on_since[i] = 0;
236 }
237 }
238 }
239}
240
241void powerd_account_add_display_req(const char *dbus_name, const char *name,
242 const struct powerd_display_request *req)
243{
244 struct client_stats *client;
245 struct disp_request_stats *stats;
246 GSList *item;
247 guint64 us;
248 int i;
249
250 if (!stats_hash)
251 return;
252
253 client = lookup_client(dbus_name, TRUE);
254 if (!client)
255 return;
256
257 item = g_slist_find_custom(client->disp_stats, name, disp_stats_comp);
258 if (item) {
259 stats = item->data;
260 } else {
261 stats = alloc_disp_stats(name);
262 if (!stats)
263 return;
264 client->disp_stats = g_slist_prepend(client->disp_stats, stats);
265 }
266
267 us = get_usecs();
268 stats->active_count++;
269 stats->active_since = us;
270 if (req->state == POWERD_DISPLAY_STATE_ON)
271 stats->disp_on_since = us;
272 for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
273 if (req->flags & (1 << i))
274 stats->flag_on_since[i] = us;
275 }
276 stats->last_req = *req;
277}
278
279void powerd_account_update_display_req(const char *dbus_name,
280 const char *name,
281 const struct powerd_display_request *req)
282{
283 struct client_stats *client;
284 struct disp_request_stats *stats;
285 GSList *item;
286
287 client = lookup_client(dbus_name, FALSE);
288 if (!client)
289 return;
290
291 item = g_slist_find_custom(client->disp_stats, name, disp_stats_comp);
292 if (!item)
293 return;
294 stats = item->data;
295
296 aggregate_disp_stats(stats, req);
297 stats->last_req = *req;
298}
299
300void powerd_account_clear_display_req(const char *dbus_name, const char *name)
301{
302 struct client_stats *client;
303 struct disp_request_stats *stats;
304 GSList *item;
305 struct powerd_display_request req;
306 guint64 duration;
307
308 client = lookup_client(dbus_name, FALSE);
309 if (!client)
310 return;
311
312 item = g_slist_find_custom(client->disp_stats, name, disp_stats_comp);
313 if (!item)
314 return;
315 stats = item->data;
316
317 memset(&req, 0, sizeof(req));
318 aggregate_disp_stats(stats, &req);
319
320 duration = get_usecs() - stats->active_since;
321 stats->active_time += duration;
322 stats->active_since = 0;
323 if (duration > stats->max_active_time)
324 stats->max_active_time = duration;
325
326 stats->last_req = req;
327}
328
329static void log_sys_req_stats(struct client_stats *client)175static void log_sys_req_stats(struct client_stats *client)
330{176{
331 const char *dbus_name = client->dbus_name;177 const char *dbus_name = client->dbus_name;
@@ -361,56 +207,6 @@
361 }207 }
362}208}
363209
364static void log_disp_req_stats(struct client_stats *client)
365{
366 const char *dbus_name = client->dbus_name;
367 GSList *cur;
368 guint64 us;
369
370 us = get_usecs();
371 for (cur = client->disp_stats; cur; cur = g_slist_next(cur)) {
372 struct disp_request_stats *stats = cur->data;
373 guint64 active_time, max_active_time;
374 guint64 disp_on_time;
375 int i;
376
377 active_time = stats->active_time;
378 max_active_time = stats->max_active_time;
379 if (stats->active_since != 0) {
380 guint64 duration = us - stats->active_since;
381 active_time += duration;
382 if (duration > max_active_time)
383 max_active_time = duration;
384 }
385
386 disp_on_time = stats->disp_on_time;
387 if (stats->disp_on_since != 0)
388 disp_on_time += us - stats->disp_on_since;
389
390 powerd_info(" Name: %s", stats->name);
391 powerd_info(" Owner: %s", dbus_name);
392 powerd_info(" Active Count: %u", stats->active_count);
393 powerd_info(" Active Time: %f", (double)active_time / 1000000.0f);
394 powerd_info(" Max Active Time: %f",
395 (double)max_active_time / 1000000.0f);
396 powerd_info(" Active Since: %f",
397 (double)stats->active_since / 1000000.0f);
398 powerd_info(" Display On Time: %f",
399 (double)disp_on_time / 1000000.0f);
400 powerd_info(" Display On Since: %f",
401 (double)stats->disp_on_since / 1000000.0f);
402 for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
403 guint64 on_time = stats->flag_on_time[i];
404 if (stats->flag_on_since[i] != 0)
405 on_time += us - stats->flag_on_since[i];
406 powerd_info(" Flag %d On Time: %f", i,
407 (double)on_time / 1000000.0f);
408 powerd_info(" Flag %d On Since: %f", i,
409 (double)stats->flag_on_since[i] / 1000000.0f);
410 }
411 }
412}
413
414void powerd_log_stats(void)210void powerd_log_stats(void)
415{211{
416 struct sysinfo si;212 struct sysinfo si;
@@ -425,11 +221,6 @@
425 g_hash_table_iter_init(&iter, stats_hash);221 g_hash_table_iter_init(&iter, stats_hash);
426 while (g_hash_table_iter_next(&iter, &key, &value))222 while (g_hash_table_iter_next(&iter, &key, &value))
427 log_sys_req_stats(value);223 log_sys_req_stats(value);
428
429 powerd_info("Display Request Statistics:");
430 g_hash_table_iter_init(&iter, stats_hash);
431 while (g_hash_table_iter_next(&iter, &key, &value))
432 log_disp_req_stats(value);
433 }224 }
434}225}
435226
@@ -440,18 +231,10 @@
440 free(stats);231 free(stats);
441}232}
442233
443static void disp_stats_list_destroy(gpointer data)
444{
445 struct disp_request_stats *stats = data;
446 free((void *)stats->name);
447 free(stats);
448}
449
450static void stats_hash_destroy(gpointer data)234static void stats_hash_destroy(gpointer data)
451{235{
452 struct client_stats *client = data;236 struct client_stats *client = data;
453 g_slist_free_full(client->sys_stats, sys_stats_list_destroy);237 g_slist_free_full(client->sys_stats, sys_stats_list_destroy);
454 g_slist_free_full(client->disp_stats, disp_stats_list_destroy);
455 free((void *)client->dbus_name);238 free((void *)client->dbus_name);
456 free(client);239 free(client);
457}240}
@@ -538,81 +321,3 @@
538 return TRUE;321 return TRUE;
539}322}
540323
541static int build_disp_request_list(GVariantBuilder *builder,
542 struct client_stats *client)
543{
544 const char *dbus_name = client->dbus_name;
545 GSList *cur;
546 guint64 us;
547 int count = 0;
548
549 us = get_usecs();
550 for (cur = client->disp_stats; cur; cur = g_slist_next(cur)) {
551 struct disp_request_stats *stats = cur->data;
552 guint64 active_time, max_active_time;
553 guint64 disp_on_time;
554 GVariantBuilder *fot_builder, *fos_builder;
555 int i;
556
557 active_time = stats->active_time;
558 max_active_time = stats->max_active_time;
559 if (stats->active_since != 0) {
560 guint64 duration = us - stats->active_since;
561 active_time += duration;
562 if (duration > max_active_time)
563 max_active_time = duration;
564 }
565
566 disp_on_time = stats->disp_on_time;
567 if (stats->disp_on_since != 0)
568 disp_on_time += us - stats->disp_on_since;
569
570 fot_builder = g_variant_builder_new(G_VARIANT_TYPE("at"));
571 fos_builder = g_variant_builder_new(G_VARIANT_TYPE("at"));
572 for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
573 guint64 flag_on_time = stats->flag_on_time[i];
574 if (stats->flag_on_since[i] != 0)
575 flag_on_time += us - stats->flag_on_since[i];
576 g_variant_builder_add(fot_builder, "t", flag_on_time);
577 g_variant_builder_add(fos_builder, "t", stats->flag_on_since[i]);
578 }
579 g_variant_builder_add(builder, "(ssutttttatat)", dbus_name,
580 stats->name, stats->active_count, active_time,
581 max_active_time, stats->active_since,
582 disp_on_time, stats->disp_on_since,
583 fot_builder, fos_builder);
584 g_variant_builder_unref(fot_builder);
585 g_variant_builder_unref(fos_builder);
586 count++;
587 }
588 return count;
589}
590
591gboolean handle_get_disp_request_stats(PowerdSource *obj,
592 GDBusMethodInvocation *invocation)
593{
594 GVariantBuilder *builder;
595 GVariant *list, *tuple;
596 GHashTableIter iter;
597 gpointer key, value;
598 int count = 0;
599
600 builder = g_variant_builder_new(G_VARIANT_TYPE("a(ssutttttatat)"));
601 if (stats_hash) {
602 g_hash_table_iter_init(&iter, stats_hash);
603 while (g_hash_table_iter_next(&iter, &key, &value))
604 count += build_disp_request_list(builder, value);
605 }
606
607 if (count == 0) {
608 g_variant_builder_clear(builder);
609 list = g_variant_new_array(G_VARIANT_TYPE("a(ssutttttatat)"), NULL, 0);
610 } else {
611 list = g_variant_builder_end(builder);
612 }
613 tuple = g_variant_new_tuple(&list, 1);
614 g_dbus_method_invocation_return_value(invocation, tuple);
615 g_variant_builder_unref(builder);
616
617 return TRUE;
618}

Subscribers

People subscribed via source and target branches