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>
Sun, 10 Dec 2017 15:10:37 +0000 (23:10 +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/inputflinger/EventHub.cpp
services/inputflinger/EventHub.h

index 50589b4..89716a1 100644 (file)
@@ -1111,8 +1111,17 @@ status_t EventHub::unregisterDeviceFromEpollLocked(Device* device) {
 }
 
 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 | O_NONBLOCK);
@@ -1695,7 +1704,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 727b73a..d925a6c 100644 (file)
@@ -394,6 +394,7 @@ private:
     };
 
     status_t openDeviceLocked(const char *devicePath);
+    status_t openDeviceLocked(const char *devicePath, bool ignoreAlreadyOpened);
     void createVirtualKeyboardLocked();
     void addDeviceLocked(Device* device);
     void assignDescriptorLocked(InputDeviceIdentifier& identifier);