am ea58d1ba: am e951ef07: Merge "Wait for initial device scan to finish before updating config." into gingerbread

Merge commit 'ea58d1bac2960c1794f048bfa5d1a60b1a3d23a1'

* commit 'ea58d1bac2960c1794f048bfa5d1a60b1a3d23a1':
  Wait for initial device scan to finish before updating config.
This commit is contained in:
Jeff Brown 2010-10-01 21:49:39 -07:00 committed by Android Git Automerger
commit c0242197ea
4 changed files with 46 additions and 34 deletions

View File

@ -142,8 +142,13 @@ protected:
public:
// Synthetic raw event type codes produced when devices are added or removed.
enum {
// Sent when a device is added.
DEVICE_ADDED = 0x10000000,
DEVICE_REMOVED = 0x20000000
// Sent when a device is removed.
DEVICE_REMOVED = 0x20000000,
// Sent when all added/removed devices from the most recent scan have been reported.
// This event is always sent at least once.
FINISHED_DEVICE_SCAN = 0x30000000,
};
virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0;
@ -221,10 +226,10 @@ protected:
private:
bool openPlatformInput(void);
int open_device(const char *device);
int close_device(const char *device);
int scan_dir(const char *dirname);
int read_notify(int nfd);
int openDevice(const char *device);
int closeDevice(const char *device);
int scanDir(const char *dirname);
int readNotify(int nfd);
status_t mError;
@ -273,6 +278,7 @@ private:
int mFDCount;
bool mOpened;
bool mNeedToSendFinishedDeviceScan;
List<String8> mExcludedDevices;
// device ids that report particular switches.

View File

@ -279,14 +279,14 @@ private:
// low-level input event decoding and device management
void process(const RawEvent* rawEvent);
void addDevice(nsecs_t when, int32_t deviceId);
void removeDevice(nsecs_t when, int32_t deviceId);
void addDevice(int32_t deviceId);
void removeDevice(int32_t deviceId);
InputDevice* createDevice(int32_t deviceId, const String8& name, uint32_t classes);
void configureExcludedDevices();
void consumeEvent(const RawEvent* rawEvent);
void handleConfigurationChanged(nsecs_t when);
void handleConfigurationChanged();
// state management for all devices
Mutex mStateLock;

View File

@ -106,7 +106,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), mOpened(false)
, mDevices(0), mFDs(0), mFDCount(0), mOpened(false), mNeedToSendFinishedDeviceScan(false)
, mInputBufferIndex(0), mInputBufferCount(0), mInputDeviceIndex(0)
{
acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
@ -354,6 +354,7 @@ bool EventHub::getEvent(RawEvent* outEvent)
if (!mOpened) {
mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR;
mOpened = true;
mNeedToSendFinishedDeviceScan = true;
}
for (;;) {
@ -370,6 +371,7 @@ bool EventHub::getEvent(RawEvent* outEvent)
}
outEvent->type = DEVICE_REMOVED;
delete device;
mNeedToSendFinishedDeviceScan = true;
return true;
}
@ -384,6 +386,13 @@ bool EventHub::getEvent(RawEvent* outEvent)
outEvent->deviceId = device->id;
}
outEvent->type = DEVICE_ADDED;
mNeedToSendFinishedDeviceScan = true;
return true;
}
if (mNeedToSendFinishedDeviceScan) {
mNeedToSendFinishedDeviceScan = false;
outEvent->type = FINISHED_DEVICE_SCAN;
return true;
}
@ -451,10 +460,10 @@ bool EventHub::getEvent(RawEvent* outEvent)
}
}
// read_notify() 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.
if(mFDs[0].revents & POLLIN) {
read_notify(mFDs[0].fd);
readNotify(mFDs[0].fd);
}
// Poll for events. Mind the wake lock dance!
@ -510,10 +519,9 @@ bool EventHub::openPlatformInput(void)
mFDs[0].fd = -1;
#endif
res = scan_dir(device_path);
res = scanDir(device_path);
if(res < 0) {
LOGE("scan dir failed for %s\n", device_path);
//open_device("/dev/input/event0");
}
return true;
@ -541,8 +549,7 @@ static const int32_t GAMEPAD_KEYCODES[] = {
AKEYCODE_BUTTON_START, AKEYCODE_BUTTON_SELECT, AKEYCODE_BUTTON_MODE
};
int EventHub::open_device(const char *deviceName)
{
int EventHub::openDevice(const char *deviceName) {
int version;
int fd;
struct pollfd *new_mFDs;
@ -859,10 +866,9 @@ bool EventHub::hasKeycodeLocked(device_t* device, int keycode) const
return false;
}
int EventHub::close_device(const char *deviceName)
{
int EventHub::closeDevice(const char *deviceName) {
AutoMutex _l(mLock);
int i;
for(i = 1; i < mFDCount; i++) {
if(strcmp(mDevices[i]->path.string(), deviceName) == 0) {
@ -912,8 +918,7 @@ int EventHub::close_device(const char *deviceName)
return -1;
}
int EventHub::read_notify(int nfd)
{
int EventHub::readNotify(int nfd) {
#ifdef HAVE_INOTIFY
int res;
char devname[PATH_MAX];
@ -923,7 +928,7 @@ int EventHub::read_notify(int nfd)
int event_pos = 0;
struct inotify_event *event;
LOGV("EventHub::read_notify nfd: %d\n", nfd);
LOGV("EventHub::readNotify nfd: %d\n", nfd);
res = read(nfd, event_buf, sizeof(event_buf));
if(res < (int)sizeof(*event)) {
if(errno == EINTR)
@ -943,10 +948,10 @@ int EventHub::read_notify(int nfd)
if(event->len) {
strcpy(filename, event->name);
if(event->mask & IN_CREATE) {
open_device(devname);
openDevice(devname);
}
else {
close_device(devname);
closeDevice(devname);
}
}
event_size = sizeof(*event) + event->len;
@ -958,7 +963,7 @@ int EventHub::read_notify(int nfd)
}
int EventHub::scan_dir(const char *dirname)
int EventHub::scanDir(const char *dirname)
{
char devname[PATH_MAX];
char *filename;
@ -976,7 +981,7 @@ int EventHub::scan_dir(const char *dirname)
(de->d_name[1] == '.' && de->d_name[2] == '\0')))
continue;
strcpy(filename, de->d_name);
open_device(devname);
openDevice(devname);
}
closedir(dir);
return 0;

View File

@ -226,11 +226,15 @@ void InputReader::loopOnce() {
void InputReader::process(const RawEvent* rawEvent) {
switch (rawEvent->type) {
case EventHubInterface::DEVICE_ADDED:
addDevice(rawEvent->when, rawEvent->deviceId);
addDevice(rawEvent->deviceId);
break;
case EventHubInterface::DEVICE_REMOVED:
removeDevice(rawEvent->when, rawEvent->deviceId);
removeDevice(rawEvent->deviceId);
break;
case EventHubInterface::FINISHED_DEVICE_SCAN:
handleConfigurationChanged();
break;
default:
@ -239,7 +243,7 @@ void InputReader::process(const RawEvent* rawEvent) {
}
}
void InputReader::addDevice(nsecs_t when, int32_t deviceId) {
void InputReader::addDevice(int32_t deviceId) {
String8 name = mEventHub->getDeviceName(deviceId);
uint32_t classes = mEventHub->getDeviceClasses(deviceId);
@ -269,11 +273,9 @@ void InputReader::addDevice(nsecs_t when, int32_t deviceId) {
delete device;
return;
}
handleConfigurationChanged(when);
}
void InputReader::removeDevice(nsecs_t when, int32_t deviceId) {
void InputReader::removeDevice(int32_t deviceId) {
bool removed = false;
InputDevice* device = NULL;
{ // acquire device registry writer lock
@ -303,8 +305,6 @@ void InputReader::removeDevice(nsecs_t when, int32_t deviceId) {
device->reset();
delete device;
handleConfigurationChanged(when);
}
InputDevice* InputReader::createDevice(int32_t deviceId, const String8& name, uint32_t classes) {
@ -372,7 +372,7 @@ void InputReader::consumeEvent(const RawEvent* rawEvent) {
} // release device registry reader lock
}
void InputReader::handleConfigurationChanged(nsecs_t when) {
void InputReader::handleConfigurationChanged() {
// Reset global meta state because it depends on the list of all configured devices.
updateGlobalMetaState();
@ -380,6 +380,7 @@ void InputReader::handleConfigurationChanged(nsecs_t when) {
updateInputConfiguration();
// Enqueue configuration changed.
nsecs_t when = systemTime(SYSTEM_TIME_MONOTONIC);
mDispatcher->notifyConfigurationChanged(when);
}