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

Commit 39b81688 authored by Philip Quinn's avatar Philip Quinn
Browse files

Add a system property test before scanning touch video devices.

EventHub opens and requests buffers for all touch video devices that
it finds on the system. As V4L does not allow multiple clients, this
prevents anyone else from using them.

This property permits touch video devices to be accessible to other
clients for testing/development.

Fixes: 122690279
Test: toggle property; restart services; examine lsof /dev/v4l-touch*
Change-Id: I46a3d9980c8fb1a241e4791709f2f4c07f8f3987
parent 92b66e18
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include <hardware_legacy/power.h>

#include <android-base/stringprintf.h>
#include <cutils/properties.h>
#include <openssl/sha.h>
#include <utils/Log.h>
#include <utils/Timers.h>
@@ -108,6 +109,19 @@ static bool isV4lTouchNode(const char* name) {
    return strstr(name, "v4l-touch") == name;
}

/**
 * Returns true if V4L devices should be scanned.
 *
 * The system property ro.input.video_enabled can be used to control whether
 * EventHub scans and opens V4L devices. As V4L does not support multiple
 * clients, EventHub effectively blocks access to these devices when it opens
 * them. This property enables other clients to read these devices for testing
 * and development.
 */
static bool isV4lScanningEnabled() {
  return property_get_bool("ro.input.video_enabled", true /* default_value */);
}

static nsecs_t processEventTimestamp(const struct input_event& event) {
    // Use the time specified in the event instead of the current time
    // so that downstream code can get more accurate estimates of
@@ -237,9 +251,14 @@ EventHub::EventHub(void) :
    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));
    if (isV4lScanningEnabled()) {
        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));
    } else {
        mVideoWd = -1;
        ALOGI("Video device scanning disabled");
    }

    struct epoll_event eventItem;
    memset(&eventItem, 0, sizeof(eventItem));
@@ -1056,10 +1075,12 @@ void EventHub::scanDevicesLocked() {
    if(result < 0) {
        ALOGE("scan dir failed for %s", DEVICE_PATH);
    }
    if (isV4lScanningEnabled()) {
        result = scanVideoDirLocked(VIDEO_DEVICE_PATH);
        if (result != OK) {
            ALOGE("scan video dir failed for %s", VIDEO_DEVICE_PATH);
        }
    }
    if (mDevices.indexOfKey(VIRTUAL_KEYBOARD_ID) < 0) {
        createVirtualKeyboardLocked();
    }