当屏幕被触摸之后,linux内核会将屏幕产生的触摸事件封装为event保存到/dev/input/event[x]节点下,接着系统创建的InputReaderThread
线程Loop起来让EventHub调用getEvent不断的从/dev/input/节点下读取输入事件,然后InputReader线程将从EventHub读取的事件交给InputDispatch,
InputDispatch则将事件分发到x需要的地方.
当 MessageQueue 的 next 方法进一步调用 nativePollOnce native 方法进入睡眠等待后,当有输入事件通过驱动到达 native 层时,
就会触发 dispatchInputEvent 方法,这就是 Framework 层处理输入事件的开端。dispatchInputEvent 是 InputEventReceiver 类的一个方法.
ViewRootImpl 中有继承它的内部类,主要的逻辑就又 ViewRootImpl 来实现了。
但是在讨论 ViewRootImpl 之前我们来看一下 InputEventReceiver 是怎么被注册到系统的:
public InputEventReceiver(InputChannel inputChannel, Looper looper) {
if (inputChannel == null) {
throw new IllegalArgumentException("inputChannel must not be null");
}
if (looper == null) {
throw new IllegalArgumentException("looper must not be null");
}
mInputChannel = inputChannel;
mMessageQueue = looper.getQueue();
//根据java层的inputchannel