Android input处理机制(三)InputDispatcher

来源:互联网 发布:ubuntu upstart 脚本 编辑:程序博客网 时间:2024/05/17 04:21

1.回顾

通过前两篇总结Android input处理机制(一)InputReader ,Android input处理机制(二)改键机制,我们大致了解了InputReader和EventHub处理机制,EventHub负责处理设备与事件相关问题。InputReader通过使用EventHub循环获取事件,当没有事件发生时InputReaderThread会休眠。

2.InputDispatcher的责任

2.1与InputReader深度配合,完成事件的分发

2.2能够妥善处理好,焦点与窗口相关问题,InputChannel,InputPublisher,Connection

3.InputDispatcher流程

3.1InputReader线程

当InputReader调用InputDispatcher::notifyKey,生成KeyEvent并包装成KeyEntry将其加入到InputDispatcher,Entry队列中并会唤醒InputDispatcher线程。

3.2InputDispatcher线程

diapatchOnce-> dispatchOnceInnerLocked->dispatchKeyLocked->(findFocusedWindowTargetLocked,dispatchEventLocked)-> prepareDispatchCyCleLocked->enqueueDispatchEntriesLocked->enqueueDispatchEntry->startDispatchCycleLocked

其中,enqueueDispatchEntry会把entry队列中的eventEntry封装成dispatchEntry

InputDispatchThread会循环调用dispatchOnce方法

// Wait for callback or timeout or wake.      nsecs_t currentTime = now();    int timeoutMillis = toMillisecondTimeoutDelay(currentTime, nextWakeupTime);    mLooper->pollOnce(timeoutMillis);
通过mLooper->pollOnce休眠,直到InputReader调用notifyKey,或是其它线程InputDispatcher::injectInputEvent等将其唤醒。

后续内容

 此为InputDispatcher一个内部类,处理相关InputChannel和InputPublisher相关内容。

InputChannel和InputPublisher会在后边继续学习

1 0
原创粉丝点击