The InputChannel provides a mechanism for exchanging InputMessage
structures across processes.The InputPublisher and InputConsumer each handle one end-point of an
input channel. The InputPublisher is used by the input dispatcher to
send events to the application. The InputConsumer is used by the
application to receive events from the input dispatcher.
InputPublisher:
Publishes input events to an input channel
InputEventReceiver
WindowInputEventReceiver 继承于 InputEventReceiver 。
public InputEventReceiver(InputChannel inputChannel, Looper looper)
第一个参数是事件来源,
在它的构造方法中,
调用 nativeInit 在 native 层生成一个NativeInputEventReceiver
并调用它的 initialize() 方法 。
ALOOPER_EVENT_INPUT = 1 << 0,
InputConsumer:
Consumes input events from an input channel
什么时候创建的?:
InputConsumer 作为 NativeInputEventReceiver 的一个成员变量,在 jni的NativeInputEventReceiver 的构造方法中被创建的 。
它的consume方法是什么时候调用的?
Looper 收到事件之后调用NativeInputEventReceiver::handleEvent ,
调用NativeInputEventReceiver::consumeEvents,到
InputChannel:
An input channel consists of a local unix domain socket used to send and receive input messages across processes。
openInputChannelPair : 创建收和发的fd 。
receiveMessage方法被谁调用?:
InputReader(服务端)
InputReader 的 loopOnce 方法会调用 mEventHub->getEvents获取到输入事件,然后会调用到比如 InputDispatcher::notifyKey方法,然后通知epoll ,
然后到 InputDispatcher::dispatchOnce方法,
InputDispatcher(服务端)
Dispatches events to input targets .
start方法会启动线程 InputThread ,循环调用 InputDispatcher::dispatchOnce方法。
mPendingEvent : 已经发生,但还没有发送出去的事件。
InputDispatcher::createInputChannel 调用 InputChannel的openInputChannelPair方法来创建收和发的fd ,
InputDispatcher::startDispatchCycleLocked 调用 InputPublisher::publishKeyEvent ,
然后 InputPublisher 通过写入fd把事件发送出去。
android::inputdispatcher:: Connection:
何时创建:
InputDevice
何时创建: