Make sure EventHub reports added/removed devices immediately.

Fixed a bug where EventHub would not report changes in devices
until the next event.

Bug: 3096147
Change-Id: Ie4c3e1d14d0ad806cfaa212611ce06034d1b94d4
This commit is contained in:
Jeff Brown 2010-10-14 02:23:43 -07:00
parent 3c8e66f9a4
commit 7e40f36237

View File

@ -439,11 +439,10 @@ bool EventHub::getEvent(RawEvent* outEvent)
// Since mFDs[0] is used for inotify, we process regular events starting at index 1. // Since mFDs[0] is used for inotify, we process regular events starting at index 1.
mInputDeviceIndex += 1; mInputDeviceIndex += 1;
if (mInputDeviceIndex >= mFDCount) { if (mInputDeviceIndex >= mFDCount) {
mInputDeviceIndex = 0;
break; break;
} }
const struct pollfd &pfd = mFDs[mInputDeviceIndex]; const struct pollfd& pfd = mFDs[mInputDeviceIndex];
if (pfd.revents & POLLIN) { if (pfd.revents & POLLIN) {
int32_t readSize = read(pfd.fd, mInputBufferData, int32_t readSize = read(pfd.fd, mInputBufferData,
sizeof(struct input_event) * INPUT_BUFFER_SIZE); sizeof(struct input_event) * INPUT_BUFFER_SIZE);
@ -460,11 +459,17 @@ bool EventHub::getEvent(RawEvent* outEvent)
} }
} }
#if HAVE_INOTIFY
// readNotify() will modify mFDs and mFDCount, so this must be done after // readNotify() will modify mFDs and mFDCount, so this must be done after
// processing all other events. // processing all other events.
if(mFDs[0].revents & POLLIN) { if(mFDs[0].revents & POLLIN) {
readNotify(mFDs[0].fd); readNotify(mFDs[0].fd);
mFDs[0].revents = 0;
continue; // report added or removed devices immediately
} }
#endif
mInputDeviceIndex = 0;
// Poll for events. Mind the wake lock dance! // Poll for events. Mind the wake lock dance!
// We hold a wake lock at all times except during poll(). This works due to some // We hold a wake lock at all times except during poll(). This works due to some
@ -482,7 +487,7 @@ bool EventHub::getEvent(RawEvent* outEvent)
if (pollResult <= 0) { if (pollResult <= 0) {
if (errno != EINTR) { if (errno != EINTR) {
LOGW("select failed (errno=%d)\n", errno); LOGW("poll failed (errno=%d)\n", errno);
usleep(100000); usleep(100000);
} }
} }