Android input event reporting Overview
How does Android obtain input events? How to dispatch input events to the corresponding window?
1. Android input Design Philosophy
The driver listens to the input events of users on different devices and outputs the events to files. Android listens to these files to learn about event reporting and then sends the event to the corresponding view. The following are the event output files in the mobile phone system. Each file represents one or more event types.
add device 1: /dev/input/event0 name: "lsm303dlhc_acc" add device 2: /dev/input/event1 name: "lsm303dlhc_mag" add device 3: /dev/input/event5 name: "7k_handset" add device 4: /dev/input/event4 name: "7x27a_kp" add device 5: /dev/input/event3 name: "ft5x0x_ts" add device 6: /dev/input/event2 name: "tmd2771x"
Lsm303dlhc_acc:Msensor
Lsm303dlhc_mag:Gsensor
7k_handset:Earphone plugging event
7x27a_kp:Keypad is mainly used for physical key events, Volume addition and subtraction keys, etc.
Ft5x0x_ts:TP, including virtual buttons and screen touch events
Tmd2771x:Psensor and lsensor
2. Function Analysis
When the corresponding device driver detects an event change, the corresponding event is written to the above file. When Android detects a change in these files, it reads the current event and distributes the event.
Android framework has two threads that are responsible for reading and distributing data. They are started During WMS initialization and run continuously. inputreaderthread is responsible for reading events in device files, the inputdispatcherthread is responsible for dispatching the obtained events.
Dispatch events. Keys are pre-processed in WMS before they are distributed to the corresponding window. Touch events are directly distributed to the corresponding window, how is Android distributed to the customer window? In Android 2.3 and later versions, pipelines are used. In earlier versions, binder communication is used. The customer window registers the MPs queue in advance, reads the events in the MPs queue by the customer process, and distributes the events within the MPs queue.
3. Summary The processing of each piece of Android will be parsed separately in the subsequent articles.