OSDN Git Service

powerbtnd: simulate power key on resuming
authorChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 31 Dec 2014 14:48:42 +0000 (22:48 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 5 May 2016 09:45:06 +0000 (17:45 +0800)
power/powerbtnd.c

index fc706e9..f8fd656 100644 (file)
@@ -43,13 +43,13 @@ int openfds(struct pollfd pfds[])
                        }
                        name[sizeof(name) - 1] = '\0';
                        if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
-                               ALOGE("could not get device name for %s, %s\n", name, strerror(errno));
+                               ALOGE("could not get device name for %s, %s", name, strerror(errno));
                                name[0] = '\0';
                        }
 
                        // TODO: parse /etc/excluded-input-devices.xml
                        if (!strcmp(name, "Power Button")) {
-                               ALOGI("open %s(%s) ok", de->d_name, name);
+                               ALOGI("open %s(%s) ok fd=%d", de->d_name, name, fd);
                                pfds[cnt].events = POLLIN;
                                pfds[cnt++].fd = fd;
                                if (cnt < MAX_POWERBTNS)
@@ -91,6 +91,7 @@ int main()
        struct pollfd pfds[MAX_POWERBTNS];
        int cnt = openfds(pfds);
        int timeout = -1;
+       int longpress = 1;
        char prop[PROPERTY_VALUE_MAX];
 
        int ufd = open("/dev/uinput", O_WRONLY | O_NDELAY);
@@ -117,9 +118,11 @@ int main()
                        ALOGE("poll error: %s", strerror(errno));
                        break;
                }
-               if (pollres == 0) { // timeout, send one power key
+               if (pollres == 0) {
+                       ALOGI("timeout, send one power key");
                        simulate_powerkey(ufd, 0);
                        timeout = -1;
+                       longpress = 1;
                        continue;
                }
                for (i = 0; i < cnt; ++i) {
@@ -130,14 +133,18 @@ int main()
                                        ALOGW("insufficient input data(%d)? fd=%d", res, pfds[i].fd);
                                        continue;
                                }
-                               ALOGV("type=%d scancode=%d value=%d from fd=%d", iev.type, iev.code, iev.value, pfds[i].fd);
+                               ALOGD("type=%d scancode=%d value=%d from fd=%d", iev.type, iev.code, iev.value, pfds[i].fd);
                                if (iev.type == EV_KEY && iev.code == KEY_POWER && !iev.value) {
                                        if (prop[0] != '1' || timeout > 0) {
-                                               simulate_powerkey(ufd, 1);
+                                               simulate_powerkey(ufd, longpress);
                                                timeout = -1;
                                        } else {
                                                timeout = 1000; // one second
                                        }
+                               } else if (iev.type == EV_SYN && iev.code == SYN_REPORT && iev.value) {
+                                       ALOGI("got a resuming event");
+                                       longpress = 0;
+                                       timeout = 1000; // one second
                                }
                        }
                }