Android输入系统(7)——Linux input子系统代码分析与调试


一、代码分析

TODO

二、DEBUG方法汇总

1. getevent

直接使用 getevent 以数值的形式显示,不直观。后面显示的数值依次是 input_handler.event 回调中的 type code value 字段。

# getevent
/dev/input/event2: 0003 0039 000001de //type code value,3:EV_ABS
/dev/input/event2: 0001 014a 00000001 //1:EV_KEY, 014a: BTN_TOUCH, 1: 按下
/dev/input/event2: 0000 0000 00000000 //0:EV_SYN, 对应 input_sync-->input_event(dev, EV_SYN, SYN_REPORT, 0)

# getevent -lt 会以字符串的形式显示事件

# getevent -lt
按键
[    3545.977259] /dev/input/event1: EV_KEY       KEY_POWER            DOWN
[    3545.977259] /dev/input/event1: EV_SYN       SYN_REPORT           00000000
[    3546.102923] /dev/input/event1: EV_KEY       KEY_POWER            UP
[    3546.102923] /dev/input/event1: EV_SYN       SYN_REPORT           00000000
点击:
[    3552.165411] /dev/input/event2: EV_ABS       ABS_MT_TRACKING_ID   000001e6
[    3552.165411] /dev/input/event2: EV_KEY       BTN_TOUCH            DOWN
[    3552.165411] /dev/input/event2: EV_ABS       ABS_MT_PRESSURE      00000009
[    3552.165411] /dev/input/event2: EV_ABS       ABS_MT_POSITION_X    000011ba
[    3552.165411] /dev/input/event2: EV_ABS       ABS_MT_POSITION_Y    00003a0d
[    3552.165411] /dev/input/event2: EV_SYN       SYN_REPORT           00000000

2. /proc/bus/input/devices

会列出系统中所有输入设备的信息

# cat /proc/bus/input/devices
I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="mtk-kpd"
P: Phys=
S: Sysfs=/devices/platform/soc/1c00e000.kp/input/input0
U: Uniq=
H: Handlers=event0 //若还有别的handle会显示在这里,可用于看匹配创建了哪些handle。
B: PROP=0
B: EV=3
B: KEY=4000000000000 0

...

3. /proc/bus/input/handlers

显示系统中所有handler的名字

# cat /proc/bus/input/handlers
N: Number=0 Name=leds
N: Number=1 Name=evdev Minor=64

4. /sys/class/input 目录

显示是否是平台设备、外设接口、地址、和event的对应关系

# ls /sys/class/input -l
lrwxrwxrwx 1 root root 0 2022-01-01 03:12 event0 -> ../../devices/platform/soc/1c00e000.kp/input/input0/event0
lrwxrwxrwx 1 root root 0 2022-01-01 03:12 event1 -> ../../devices/platform/1c804000.spmi/spmi-0/0-04/mtk-pmic-keys/input/input1/event1
...

优秀博文: