When a user taps the screen of an Android device, a highly complex chain of events converts that physical electrical change into a software touch event. This all begins at the kernel level with the Touch Driver.
Most modern smartphone touchscreens are capacitive panels controlled by a dedicated IC (Integrated Circuit) bonded directly to the glass. This controller communicates with the main CPU, typically via an I2C or SPI bus.
The Linux Input Subsystem
Touchscreen drivers do not invent their own proprietary way of talking to user-space. They utilize the standard Linux Input Subsystem.
The input subsystem is a massive abstraction layer that handles everything from USB mice and Bluetooth keyboards to complex multi-touch displays.
- Hardware Interrupt: When a user touches the screen, the touch controller pulls a GPIO pin low, triggering a hardware interrupt on the CPU.
- I2C Read: The kernel touch driver's interrupt handler wakes up. It sends an I2C command to the touch controller asking, "Where did the user touch?"
- Input Event Registration: The touch controller replies with the raw X and Y coordinates. The driver formats these coordinates and passes them to the Linux Input Core using functions like
input_report_abs().
The evdev Interface
The Linux Input Core takes these raw coordinates and exposes them to the Android user-space via the evdev (Event Device) interface.
Every input device on the system gets a character device file mapped to /dev/input/eventX.
# You can monitor live touch events directly from the kernel using getevent
adb shell getevent -l /dev/input/event1
When you run getevent, you will see a constant stream of data as you drag your finger across the screen. The Android InputManagerService (and specifically the native EventHub) reads directly from these /dev/input nodes to translate Linux kernel events into Android MotionEvent objects.
The Multi-Touch Protocol (Protocol B)
Modern smartphones support 10-finger multi-touch. To handle this cleanly, the kernel uses the Multi-Touch (MT) Protocol. There are two versions, but Android heavily relies on Type B.
In Protocol B, the kernel explicitly tracks individual fingers (slots).
- When a finger touches the screen, the driver assigns it a unique slot ID and reports
ABS_MT_TRACKING_ID. - As the finger moves, the driver only reports the updated X/Y coordinates for that specific slot.
- When the finger lifts off, the driver reports
ABS_MT_TRACKING_ID -1to signal the touch has ended.
// Conceptual snippet of reporting a multi-touch event in the kernel driver
input_mt_slot(input_dev, finger_id);
input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, true);
input_report_abs(input_dev, ABS_MT_POSITION_X, x_coordinate);
input_report_abs(input_dev, ABS_MT_POSITION_Y, y_coordinate);
input_sync(input_dev); // Tells user-space this frame of data is complete
If the touch driver fails or the I2C bus locks up, the device will completely stop responding to touch, even if the display is updating perfectly.