diff options
author | Mike Lockwood <lockwood@android.com> | 2009-07-16 11:11:18 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2009-07-16 11:51:42 -0400 |
commit | 1d9dfc5dcf459e85cffcb762ffdb9b9a4abbfd67 (patch) | |
tree | 64e951c1690a7859c67cbc3421ca41a326e3d744 /libs | |
parent | d0c0e46a4408b22599bc588ea423d9102bcee6bf (diff) | |
download | frameworks_base-1d9dfc5dcf459e85cffcb762ffdb9b9a4abbfd67.zip frameworks_base-1d9dfc5dcf459e85cffcb762ffdb9b9a4abbfd67.tar.gz frameworks_base-1d9dfc5dcf459e85cffcb762ffdb9b9a4abbfd67.tar.bz2 |
EventHub: Add support for excluding devices from being opened by as a keyboard.
This will be used to avoid unnecessarily listening to data from sensors
that function as event devices.
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ui/EventHub.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/libs/ui/EventHub.cpp b/libs/ui/EventHub.cpp index a72f055..402bce2 100644 --- a/libs/ui/EventHub.cpp +++ b/libs/ui/EventHub.cpp @@ -22,7 +22,6 @@ #include <utils/Log.h> #include <utils/Timers.h> #include <utils/threads.h> -#include <utils/List.h> #include <utils/Errors.h> #include <stdlib.h> @@ -84,7 +83,7 @@ EventHub::EventHub(void) : mError(NO_INIT), mHaveFirstKeyboard(false), mFirstKeyboardId(0) , mDevicesById(0), mNumDevicesById(0) , mOpeningDevices(0), mClosingDevices(0) - , mDevices(0), mFDs(0), mFDCount(0) + , mDevices(0), mFDs(0), mFDCount(0), mOpened(false) { acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID); #ifdef EV_SW @@ -101,11 +100,6 @@ EventHub::~EventHub(void) // we should free stuff here... } -void EventHub::onFirstRef() -{ - mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR; -} - status_t EventHub::errorCheck() const { return mError; @@ -269,6 +263,12 @@ status_t EventHub::scancodeToKeycode(int32_t deviceId, int scancode, return NAME_NOT_FOUND; } +void EventHub::addExcludedDevice(const char* deviceName) +{ + String8 name(deviceName); + mExcludedDevices.push_back(name); +} + EventHub::device_t* EventHub::getDevice(int32_t deviceId) const { if (deviceId == 0) deviceId = mFirstKeyboardId; @@ -306,7 +306,12 @@ bool EventHub::getEvent(int32_t* outDeviceId, int32_t* outType, // Note that we only allow one caller to getEvent(), so don't need // to do locking here... only when adding/removing devices. - + + if (!mOpened) { + mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR; + mOpened = true; + } + while(1) { // First, report any devices that had last been added/removed. @@ -513,6 +518,19 @@ int EventHub::open_device(const char *deviceName) idstr[0] = '\0'; } + // check to see if the device is on our excluded list + List<String8>::iterator iter = mExcludedDevices.begin(); + List<String8>::iterator end = mExcludedDevices.end(); + for ( ; iter != end; iter++) { + const char* name = *iter; + if (strcmp(name, idstr) == 0) { + LOGD("ignoring event id %s driver %s\n", deviceName, name); + close(fd); + fd = -1; + return -1; + } + } + int devid = 0; while (devid < mNumDevicesById) { if (mDevicesById[devid].device == NULL) { @@ -763,6 +781,7 @@ int EventHub::read_notify(int nfd) int event_pos = 0; struct inotify_event *event; +LOGD("EventHub::read_notify nfd: %d\n", nfd); res = read(nfd, event_buf, sizeof(event_buf)); if(res < (int)sizeof(*event)) { if(errno == EINTR) |