Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 951f3620 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Add a watch for touch video devices to EventHub

EventHub will now be responsible for reading touch video devices in
addition to the input devices. We add the initial infrastructure for
that here.

We keep track of the watch descriptor inside inotify, and check which
event was generated.

All of the video devices go directly into /dev. For the heatmap-specific
video devices, the prefix will be "v4l-touch". For example, a
touchscreen device on C1 is currently "/dev/v4l-touch22". Although we
don't anticipate having pluggable video devices which report touch
heatmaps, we should still account for that possibility here for
completeness. Every time a device appears in /dev after the initial
scan, this inotify will trigger the check for whether it is a v4l2
touchscreen node.

Currently, we just add a log for when the device appears, without taking
any action. In the future commits, we will create touch video devices
for this node, and associate them with input devices.

Bug: 62940136
Test: interaction with booted device
Change-Id: I99bf29c3786ec4b21fed1ddf2e1e87f5a53c172a
parent 7b7c8f6d
Loading
Loading
Loading
Loading
+34 −18
Original line number Diff line number Diff line
@@ -73,6 +73,8 @@ static constexpr bool DEBUG = false;

static const char *WAKE_LOCK_ID = "KeyEvents";
static const char *DEVICE_PATH = "/dev/input";
// v4l2 devices go directly into /dev
static const char *VIDEO_DEVICE_PATH = "/dev";

static inline const char* toString(bool value) {
    return value ? "true" : "false";
@@ -100,6 +102,13 @@ static void getLinuxRelease(int* major, int* minor) {
    }
}

/**
 * Return true if name matches "v4l-touch*"
 */
static bool isV4lTouchNode(const char* name) {
    return strstr(name, "v4l-touch") == name;
}

// --- Global Functions ---

uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses) {
@@ -206,18 +215,21 @@ EventHub::EventHub(void) :
    acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);

    mEpollFd = epoll_create1(EPOLL_CLOEXEC);
    LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance.  errno=%d", errno);
    LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance: %s", strerror(errno));

    mINotifyFd = inotify_init();
    int result = inotify_add_watch(mINotifyFd, DEVICE_PATH, IN_DELETE | IN_CREATE);
    LOG_ALWAYS_FATAL_IF(result < 0, "Could not register INotify for %s.  errno=%d",
            DEVICE_PATH, errno);
    mInputWd = inotify_add_watch(mINotifyFd, DEVICE_PATH, IN_DELETE | IN_CREATE);
    LOG_ALWAYS_FATAL_IF(mInputWd < 0, "Could not register INotify for %s: %s",
            DEVICE_PATH, strerror(errno));
    mVideoWd = inotify_add_watch(mINotifyFd, VIDEO_DEVICE_PATH, IN_DELETE | IN_CREATE);
    LOG_ALWAYS_FATAL_IF(mVideoWd < 0, "Could not register INotify for %s: %s",
            VIDEO_DEVICE_PATH, strerror(errno));

    struct epoll_event eventItem;
    memset(&eventItem, 0, sizeof(eventItem));
    eventItem.events = EPOLLIN;
    eventItem.data.fd = mINotifyFd;
    result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mINotifyFd, &eventItem);
    int result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mINotifyFd, &eventItem);
    LOG_ALWAYS_FATAL_IF(result != 0, "Could not add INotify to epoll instance.  errno=%d", errno);

    int wakeFds[2];
@@ -1667,8 +1679,6 @@ void EventHub::closeDeviceLocked(Device* device) {

status_t EventHub::readNotifyLocked() {
    int res;
    char devname[PATH_MAX];
    char *filename;
    char event_buf[512];
    int event_size;
    int event_pos = 0;
@@ -1682,21 +1692,27 @@ status_t EventHub::readNotifyLocked() {
        ALOGW("could not get event, %s\n", strerror(errno));
        return -1;
    }
    //printf("got %d bytes of event information\n", res);

    strcpy(devname, DEVICE_PATH);
    filename = devname + strlen(devname);
    *filename++ = '/';

    while(res >= (int)sizeof(*event)) {
        event = (struct inotify_event *)(event_buf + event_pos);
        if(event->len) {
            strcpy(filename, event->name);
            if (event->wd == mInputWd) {
                std::string filename = StringPrintf("%s/%s", DEVICE_PATH, event->name);
                if(event->mask & IN_CREATE) {
                openDeviceLocked(devname);
                    openDeviceLocked(filename.c_str());
                } else {
                ALOGI("Removing device '%s' due to inotify event\n", devname);
                closeDeviceByPathLocked(devname);
                    ALOGI("Removing device '%s' due to inotify event\n", filename.c_str());
                    closeDeviceByPathLocked(filename.c_str());
                }
            }
            else if (event->wd == mVideoWd) {
                if (isV4lTouchNode(event->name)) {
                    std::string filename = StringPrintf("%s/%s", VIDEO_DEVICE_PATH, event->name);
                    ALOGV("Received an inotify event for a video device %s", filename.c_str());
                }
            }
            else {
                LOG_ALWAYS_FATAL("Unexpected inotify event, wd = %i", event->wd);
            }
        }
        event_size = sizeof(*event) + event->len;
+3 −0
Original line number Diff line number Diff line
@@ -452,6 +452,9 @@ private:
    int mWakeReadPipeFd;
    int mWakeWritePipeFd;

    int mInputWd;
    int mVideoWd;

    // Epoll FD list size hint.
    static const int EPOLL_SIZE_HINT = 8;