一. 新发现设备的处理流程
当设备第一次插入时或者在扫描/dev/input/event*时,
inputreader会收到event
InputReader::loopOnce
--> InputReader::processEventsLocked
InputReader::loopOnce
--> InputReader::processEventsLocked
--> InputReader::addDeviceLocked
当设备第一次插入时或者在扫描/dev/input/event*时,
inputreader会收到event
-
void InputReader::loopOnce()
- {
-
//获取event
-
size_t count = mEventHub->getEvents(timeoutMillis, mEventBuffer, EVENT_BUFFER_SIZE);
-
if (count) {
-
processEventsLocked(mEventBuffer, count); //对event进行处理
-
}
-
mQueuedListener->flush();
- }
--> InputReader::processEventsLocked
-
void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t
count)
-
{
-
for (const RawEvent* rawEvent = rawEvents; count;)
-
{
-
if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) {
-
//数据处理流程
-
} else {
-
switch (rawEvent->type) {
-
case EventHubInterface::DEVICE_ADDED: //新发现的设备的处理
-
addDeviceLocked(rawEvent->when, rawEvent->deviceId);
-
break;
-
case EventHubInterface::DEVICE_REMOVED:
-
removeDeviceLocked(rawEvent->when, rawEvent->deviceId);
-
break;
-
case EventHubInterface::FINISHED_DEVICE_SCAN: //最后会调用这个
-
handleConfigurationChangedLocked(rawEvent->when);
-
break;
-
default:
-
ALOG_ASSERT(false); // can't
happen
-
break;
-
}
-
}
-
}
- }
InputReader::loopOnce
--> InputReader::processEventsLocked
--> InputReader::addDeviceLocked
-
void InputReader::addDeviceLocked(nsecs_t
when, int32_t deviceId)
-
{
-
ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
-
InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(deviceId);
-
uint32_t classes = mEventHub->getDeviceClasses(deviceId);
-
-
InputDevice* device = createDeviceLocked(deviceId, identifier, classes);
-
device->configure(when, &mConfig, 0);
-
device->reset(when);
-
mDevices.add(deviceId, device);
-
bumpGenerationLocked();
- }