Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

hardware-libhardware_legacy: Commit

hardware/libhardware_legacy


Commit MetaInfo

Revision1db28bbc387a52b50187d70f80820299cff27db5 (tree)
Time2012-02-22 13:21:00
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

powerbtnd: add poweroff.doubleclick feature

On poweroff.doubleclick=0, one click to power button invokes poweroff
dialog directly.

On poweroff.doubleclick=1, one click to power button suspends the system,
while double click in one second invokes poweroff dialog.

Change Summary

Incremental Difference

--- a/Android.mk
+++ b/Android.mk
@@ -51,7 +51,7 @@ LOCAL_SRC_FILES := power/powerbtnd.c
5151
5252 LOCAL_MODULE := powerbtnd
5353 LOCAL_MODULE_TAGS := optional
54-LOCAL_SHARED_LIBRARIES := liblog
54+LOCAL_SHARED_LIBRARIES := liblog libcutils
5555
5656 include $(BUILD_EXECUTABLE)
5757
--- a/power/powerbtnd.c
+++ b/power/powerbtnd.c
@@ -1,7 +1,7 @@
11 /**
22 * A daemon to simulate power button of Android
33 *
4- * Copyright (C) 2011 The Android-x86 Open Source Project
4+ * Copyright (C) 2011-2012 The Android-x86 Open Source Project
55 *
66 * by Chih-Wei Huang <cwhuang@linux.org.tw>
77 *
@@ -19,6 +19,7 @@
1919 #include <cutils/log.h>
2020 #include <linux/input.h>
2121 #include <linux/uinput.h>
22+#include <cutils/properties.h>
2223
2324 const int MAX_POWERBTNS = 3;
2425
@@ -35,7 +36,7 @@ int openfds(struct pollfd pfds[])
3536 continue;
3637 char name[PATH_MAX];
3738 snprintf(name, PATH_MAX, "%s/%s", dirname, de->d_name);
38- fd = open(name, O_RDWR);
39+ fd = open(name, O_RDWR | O_NONBLOCK);
3940 if (fd < 0) {
4041 LOGE("could not open %s, %s", name, strerror(errno));
4142 continue;
@@ -64,11 +65,33 @@ int openfds(struct pollfd pfds[])
6465 return cnt;
6566 }
6667
68+void send_power(int ufd, int down)
69+{
70+ struct input_event iev;
71+ iev.type = EV_KEY;
72+ iev.code = KEY_POWER;
73+ iev.value = down;
74+ write(ufd, &iev, sizeof(iev));
75+ iev.type = EV_SYN;
76+ iev.code = SYN_REPORT;
77+ iev.value = 0;
78+ write(ufd, &iev, sizeof(iev));
79+}
80+
81+void simulate_powerkey(int ufd, int longpress)
82+{
83+ send_power(ufd, 1);
84+ if (longpress)
85+ sleep(2);
86+ send_power(ufd, 0);
87+}
88+
6789 int main()
6890 {
6991 struct pollfd pfds[MAX_POWERBTNS];
7092 int cnt = openfds(pfds);
71- int pollres;
93+ int timeout = -1;
94+ char prop[PROPERTY_VALUE_MAX];
7295
7396 int ufd = open("/dev/uinput", O_WRONLY | O_NDELAY);
7497 if (ufd >= 0) {
@@ -84,12 +107,21 @@ int main()
84107 return -1;
85108 }
86109
87- while ((pollres = poll(pfds, cnt, -1))) {
110+ property_get("poweroff.doubleclick", prop, NULL);
111+
112+ for (;;) {
88113 int i;
114+ int pollres = poll(pfds, cnt, timeout) ;
115+ LOGV("pollres=%d %d\n", pollres, timeout);
89116 if (pollres < 0) {
90117 LOGE("poll error: %s", strerror(errno));
91118 break;
92119 }
120+ if (pollres == 0) { // timeout, send one power key
121+ simulate_powerkey(ufd, 0);
122+ timeout = -1;
123+ continue;
124+ }
93125 for (i = 0; i < cnt; ++i) {
94126 if (pfds[i].revents & POLLIN) {
95127 struct input_event iev;
@@ -99,17 +131,14 @@ int main()
99131 continue;
100132 }
101133 LOGV("type=%d scancode=%d value=%d from fd=%d", iev.type, iev.code, iev.value, pfds[i].fd);
102- if (iev.type == EV_KEY) {
103- switch (iev.code)
104- {
105- case KEY_POWER:
106- if (!iev.value)
107- sleep(2);
108- break;
134+ if (iev.type == EV_KEY && iev.code == KEY_POWER && !iev.value) {
135+ if (prop[0] != '1' || timeout > 0) {
136+ simulate_powerkey(ufd, 1);
137+ timeout = -1;
138+ } else {
139+ timeout = 1000; // one second
109140 }
110141 }
111-
112- write(ufd, &iev, sizeof(iev));
113142 }
114143 }
115144 }
Show on old repository browser