OSDN Git Service

Prevent EventHub from adding input device twice
authorDaniel Leung <daniel.leung@intel.com>
Thu, 13 Sep 2012 20:43:41 +0000 (13:43 -0700)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 25 Sep 2013 02:48:22 +0000 (10:48 +0800)
When Android first starts up, it scans /dev/input for input devices.
In some rare instances, the EventHub gets another notification that
some device nodes are created. It then proceeds to add the same
input device again. This causes the system to get two events per
touch or key stroke.

This adds a check to prevent adding the same device if the operation
is triggerd by inotify.

Issue: AXIA-858
Change-Id: I68b02594f1c7f14067611735db0b3763378ec7ea
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
services/input/EventHub.cpp
services/input/EventHub.h

index f4e1cec..00a9765 100644 (file)
@@ -991,8 +991,17 @@ static const int32_t GAMEPAD_KEYCODES[] = {
 };
 
 status_t EventHub::openDeviceLocked(const char *devicePath) {
+    return openDeviceLocked(devicePath, false);
+}
+
+status_t EventHub::openDeviceLocked(const char *devicePath, bool ignoreAlreadyOpened) {
     char buffer[80];
 
+    if (ignoreAlreadyOpened && (getDeviceByPathLocked(devicePath) != 0)) {
+        ALOGV("Ignoring device '%s' that has already been opened.", devicePath);
+        return 0;
+    }
+
     ALOGV("Opening device: %s", devicePath);
 
     int fd = open(devicePath, O_RDWR | O_CLOEXEC);
@@ -1454,7 +1463,7 @@ status_t EventHub::readNotifyLocked() {
         if(event->len) {
             strcpy(filename, event->name);
             if(event->mask & IN_CREATE) {
-                openDeviceLocked(devname);
+                openDeviceLocked(devname, true);
             } else {
                 ALOGI("Removing device '%s' due to inotify event\n", devname);
                 closeDeviceByPathLocked(devname);
index c93fc7a..7838e49 100644 (file)
@@ -362,6 +362,7 @@ private:
     };
 
     status_t openDeviceLocked(const char *devicePath);
+    status_t openDeviceLocked(const char *devicePath, bool ignoreAlreadyOpened);
     void createVirtualKeyboardLocked();
     void addDeviceLocked(Device* device);