App端通过Looper来监听InputChannel的fd,获取数据后,调用相应的处理方法,最后会再调用InputEventReceiver的finishInputEvent方法,向InputDispatcher进行反馈,表示当前的事件处理完成,InputDispatcher收到反馈后,删除掉waitQueue(wq)中对应的记录。wq中第一个元素的时间戳可以作为超时ANR的判断依据。
在某些特殊场景,也许我们可以考虑不进行input的反馈来提高性能。
概图如下:
较为详细的处理流程如下:
这里我们来看看finishDispatchCycleLocked是怎么处理到waitQueue的,
finishDispatchCycleLocked
调用到
onDispatchCycleFinishedLocked(currentTime, connection, seq, handled);
3499void InputDispatcher::onDispatchCycleFinishedLocked( 3500 nsecs_t currentTime, const sp<Connection>& connection, uint32_t seq, bool handled) { 3501 CommandEntry* commandEntry = postCommandLocked( 3502 & InputDispatcher::doDispatchCycleFinishedLockedInterruptible); 3503 commandEntry->connection = connection; 3504 commandEntry->eventTime = currentTime; 3505 commandEntry->seq = seq; 3506 commandEntry->handled = handled; 3507}
又调用到
3620void InputDispatcher::doDispatchCycleFinishedLockedInterruptible( 3621 CommandEntry* commandEntry) {
3656 if (dispatchEntry == connection->findWaitQueueEntry(seq)) { 3657 connection->waitQueue.dequeue(dispatchEntry); 3658 traceWaitQueueLengthLocked(connection);
这里进行了waitQueue的dequeue处理,弹出了处理过的事件记录,
traceWaitQueueLengthLocked更新了trace记录中的wq数量等数据。
参考资料: