Add video device to epoll in EventHub

The video device is already being watched, and we now need to start
actually reading the video frames. This is done similarly to the input
devices. The video device fd is added to epoll. Whenever an epoll
detects new data, the frames will be added to video device's internal
queue. In the subsequent commits we will consume these frames and report
them to the InputClassifier HAL.

Note here that registering for epoll is a bit complex. It is important
to only have the video device in epoll if the input device is in epoll.

There are several situations possible here:
1) Video device is found during directory traversal of /dev
2) Video device is found through inotify
3) Video device is added after matching input device
4) Video device is added before matching input device
5) Video device is added while input device is disabled
6) As long as input device is enabled, and has a video device, the video
device should be part of epoll. That means input device.enable() should
add the video device to epoll.

Therefore, the decision here was made to registerVideoDevice inside
registerDevice (=registerInputDevice), which should account for most
cases. For the other corner cases, handle adding video device to epoll
separately.

Test: video device is being read, because InputClassifier receives video
frames and classifies them.
Bug: 111480215

Change-Id: I340b44a9b17182444b8a3308e3ab322ae1ad444c
diff --git a/services/inputflinger/include/EventHub.h b/services/inputflinger/include/EventHub.h
index ae70169..dd64132 100644
--- a/services/inputflinger/include/EventHub.h
+++ b/services/inputflinger/include/EventHub.h
@@ -381,7 +381,7 @@
         }
     };
 
-    status_t openDeviceLocked(const char *devicePath);
+    status_t openDeviceLocked(const char* devicePath);
     void openVideoDeviceLocked(const std::string& devicePath);
     void createVirtualKeyboardLocked();
     void addDeviceLocked(Device* device);
@@ -400,7 +400,9 @@
     status_t registerFdForEpoll(int fd);
     status_t unregisterFdFromEpoll(int fd);
     status_t registerDeviceForEpollLocked(Device* device);
+    void registerVideoDeviceForEpollLocked(const TouchVideoDevice& videoDevice);
     status_t unregisterDeviceFromEpollLocked(Device* device);
+    void unregisterVideoDeviceFromEpollLocked(const TouchVideoDevice& videoDevice);
 
     status_t scanDirLocked(const char *dirname);
     status_t scanVideoDirLocked(const std::string& dirname);
@@ -410,6 +412,10 @@
     Device* getDeviceByDescriptorLocked(const std::string& descriptor) const;
     Device* getDeviceLocked(int32_t deviceId) const;
     Device* getDeviceByPathLocked(const char* devicePath) const;
+    /**
+     * Look through all available fd's (both for input devices and for video devices),
+     * and return the device pointer.
+     */
     Device* getDeviceByFdLocked(int fd) const;
 
     bool hasKeycodeLocked(Device* device, int keycode) const;
@@ -470,9 +476,6 @@
     int mInputWd;
     int mVideoWd;
 
-    // Epoll FD list size hint.
-    static const int EPOLL_SIZE_HINT = 8;
-
     // Maximum number of signalled FDs to handle at a time.
     static const int EPOLL_MAX_EVENTS = 16;