diff options
author | 2019-01-09 22:20:39 -0800 | |
---|---|---|
committer | 2019-01-10 18:06:59 -0800 | |
commit | 39b81688e91cb59a2b6c0d5353f85f1a6e08acbd (patch) | |
tree | c2969b077e406640a49a1edd21fc2e563563599d | |
parent | 92b66e1871c43778988db9ca31bea26df68a6462 (diff) |
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
-rw-r--r-- | services/inputflinger/EventHub.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/services/inputflinger/EventHub.cpp b/services/inputflinger/EventHub.cpp index 18c3ded880..cf9d3c7aa5 100644 --- a/services/inputflinger/EventHub.cpp +++ b/services/inputflinger/EventHub.cpp @@ -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)); - 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)); + 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,9 +1075,11 @@ void EventHub::scanDevicesLocked() { if(result < 0) { ALOGE("scan dir failed for %s", DEVICE_PATH); } - result = scanVideoDirLocked(VIDEO_DEVICE_PATH); - if (result != OK) { - ALOGE("scan video dir failed for %s", VIDEO_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(); |