inputdispatcher按键的派发

更新时间:2023-07-01 19:53:33 阅读: 评论:0

inputdispatcher按键的派发
InputReader.Event这两个函数分别定义
在frameworks/ba/libs/ui/InputReader.cpp和frameworks/ba/libs/ui/EventHub.cpp⽂件中,前⾯我们在分析InputManager的启动过程的Step 17和Step 18时,已经看到过这两个函数了。InputReaderThread线程会不断地循环调⽤InputReader.pollOnce函数来读⼊键盘事件,⽽实际的键盘事件读⼊操作是由Event函数来进⾏的。如果当前没有键盘事件发⽣,InputReaderThread线程就会睡眠在Event函数上,⽽当键盘事件发⽣后,就会把这个事件封装成⼀个RawEvent对象,然后返回到pollOnce函数中,执⾏process函数进⼀步处理:
SETP1:
InputReaderThread线程的处理:
脑力激荡法void InputReader::loopOnce() {
int32_t oldGeneration;
int32_t timeoutMillis;
bool inputDevicesChanged = fal;
Vector<InputDeviceInfo> inputDevices;
{// acquire lock
AutoMutex _l(mLock);
oldGeneration = mGeneration;
timeoutMillis = -1;
uint32_t changes = mConfigurationChangesToRefresh;
if (changes) {
mConfigurationChangesToRefresh = 0;
timeoutMillis = 0;
refreshConfigurationLocked(changes);
} el if (mNextTimeout != LLONG_MAX) {
ncs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
timeoutMillis = toMillicondTimeoutDelay(now, mNextTimeout);
}
}// relea lock
size_t count =mEventHub->getEvents(timeoutMillis, mEventBuffer, EVENT_BUFFER_SIZE);
//最关键的步骤,获取按键事件。前⾯有分析过。这⾥就是调⽤的地⽅。
{// acquire lock
nuxeAutoMutex _l(mLock);
mReaderIsAliveCondition.broadcast();
if (count) {
processEventsLocked(mEventBuffer, count);
//继续处理获取到的mEventBuffer.这⾥只关注流程,细节判断暂时不跟进。
}
。。。。。。。。。。。
}
SETP2:
frameworks\native\rvices\inputflinger\InputReader.cpp
void InputReader::processEventsLocked(constRawEvent* rawEvents, size_t count) {
for (const RawEvent* rawEvent = rawEvents; count;) {
int32_t type = rawEvent->type;
size_t batchSize = 1;
if (type <EventHubInterface::FIRST_SYNTHETIC_EVENT) {
int32_t deviceId = rawEvent->deviceId;
while (batchSize < count) {
if (rawEvent[batchSize].type>= EventHubInterface::FIRST_SYNTHETIC_EVENT                        || rawEvent[batchSize].deviceId !=deviceId) {
break;
}
batchSize += 1;
}
#if DEBUG_RAW_EVENTS
ALOGD("BatchSize: %d Count: %d", batchSize, count);
#endif
processEventsForDeviceLocked(deviceId,rawEvent, batchSize);
} el {
…….
手背纹身图案大全
}
count -= batchSize;
rawEvent += batchSize;
妖精的眼}
}
Setp3:
void InputReader::processEventsForDeviceLocked(int32_tdeviceId,
const RawEvent* rawEvents, size_t count) {
ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
if (deviceIndex < 0) {
ALOGW("Discarding event for unknown deviceId %d.", deviceId);
return;
}
InputDevice* device = mDevices.valueAt(deviceIndex);
if (device->isIgnored()) {
//ALOGD("Discarding event for ignored deviceId %d.",deviceId);
return;
}
device->process(rawEvents, count);
/
/⾸先从rawEvent中取得触发键盘事件设备对象device,然后调⽤它的process函数进⾏处理
}
SETP4:
void InputDevice::process(constRawEvent* rawEvents, size_t count) {
// Process all of the events in order for each mapper.
// We cannot simply ask each mapper to process them in bulk becaumappers may
// have side-effects that must be interleaved.  For example, joystick movement events and    // gamepad button press are handled by different mappers but theyshould be dispatched    // in the order received.
size_t numMappers = mMappers.size();
for (const RawEvent* rawEvent = rawEvents; count--; rawEvent++) {
#if DEBUG_RAW_EVENTS
ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08xwhen=%lld",                rawEvent->deviceId,rawEvent->type, rawEvent->code, rawEvent->value,
rawEvent->when);
#endif
if (mDropUntilNextSync) {
if (rawEvent->type == EV_SYN && rawEvent->code ==SYN_REPORT) {
mDropUntilNextSync = fal;
个人劣势#if DEBUG_RAW_EVENTS
ALOGD("Recovered from input event bufferoverrun.");
#endif
} el {
盖公章
#if DEBUG_RAW_EVENTS
ALOGD("Dropped input eventwhile waiting for next input sync.");
#endif
}
} el if (rawEvent->type == EV_SYN && rawEvent->code ==SYN_DROPPED) {
ALOGI("Detected input event buffer overrun for device %s.",getName().string());
mDropUntilNextSync = true;
ret(rawEvent->when);
} el {
for (size_t i = 0; i < numMappers; i++) {
InputMapper* mapper =mMappers[i];
mapper->process(rawEvent);
/
*
这⾥的mMapper成员变量保存了⼀系列输⼊设备事件处理象,例如负责处理键盘事件的KeyboardKeyMapper对象、负责处理轨迹球事件的TrackballInputMapper对象以及负责处理触摸屏事件的TouchInputMapper对象,它们是在InputReader类的成员函
数createDevice中创建的。这⾥查询每⼀个InputMapper对象是否要对当前发⽣的事件进⾏处理。由于发⽣的是键盘事件,真正会对该事件进⾏处理的只有KeyboardKeyMapper对象。
*/
}
}
}
}
STEP5:
frameworks\native\rvices\inputflinger\InputReader.cpp
void KeyboardInputMapper::process(constRawEvent* rawEvent) {
switch (rawEvent->type) {
ca EV_KEY: {
int32_t scanCode = rawEvent->code;
int32_t usageCode = mCurrentHidUsage;
mCurrentHidUsage = 0;
if (isKeyboardOrGamepadKey(scanCode)) {
int32_t keyCode;
uint32_t flags;
if (getEventHub()->mapKey(getDeviceId(),scanCode, usageCode, &keyCode, &flags))
/
人工呼吸的方法/      这⾥应该是将linux_code的键值,转换为了android_key的键值。很关键的⼀个转换。后⾯专门分析如何转换。⼀般是通过generac.lk⽂件对应的。带验证。
{
keyCode = AKEYCODE_UNKNOWN;
flags = 0;
}
processKey(rawEvent->when, rawEvent->value!= 0, keyCode, scanCode, flags);
清明节在什么时候}
break;
}
。。。。。。
}
STEP6:
voidKeyboardInputMapper::processKey(ncs_t when, bool down, int32_t keyCode,
int32_t scanCode, uint32_t policyFlags) {
。。。。。。
NotifyKeyArgs args(when, getDeviceId(), mSource, policyFlags,
down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,
AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, newMetaState, downTime);
getListener()->notifyKey(&args);

本文发布于:2023-07-01 19:53:33,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1063562.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:事件   键盘   处理   对象   函数
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图