其他分享
首页 > 其他分享> > 使用getevent在Android中调试输入子系统

使用getevent在Android中调试输入子系统

作者:互联网

# Android getevent用法详解

背景

在调试安卓设备按键,想使用hexdump,但是发现没有找到,反而找到了这个更好用的工具。

以下是我的调试片段

# getevent -l /dev/input/event0
EV_KEY       KEY_ENTER            DOWN
EV_SYN       SYN_REPORT           00000000
EV_KEY       KEY_ENTER            UP
EV_SYN       SYN_REPORT           00000000

EV_KEY       KEY_UP               DOWN
EV_SYN       SYN_REPORT           00000000
EV_KEY       KEY_UP               UP
EV_SYN       SYN_REPORT           00000000
EV_KEY       KEY_BACK             DOWN
EV_SYN       SYN_REPORT           00000000

前言

修改来自:Android getevent用法详解

getevent 指令用于获取 input 输入事件,比如获取按键上报信息、获取触摸屏上报信息等。

程序的实现:system/core/toolbox/getevent.c

用法

getevent -h:查看 getevent 帮助信息

# getevent -h
Usage: getevent [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-d] [-p] [-i] [-l] [-q] [-c count] [-r] [device]
    -t: show time stamps
    -n: don't print newlines
    -s: print switch states for given bits
    -S: print all switch states
    -v: verbosity mask (errs=1, dev=2, name=4, info=8, vers=16, pos. events=32, props=64)
    -d: show HID descriptor, if available
    -p: show possible events (errs, dev, name, pos. events)
    -i: show all device info and possible events
    -l: label event types and names in plain text
    -q: quiet (clear verbosity mask)
    -c: print given number of events then exit
    -r: print rate events are received

getevent:显示当前有那些输入设备,数量与 /dev/input 目录下相同。

由于会将对应的设备节点以及设备描述打印出来,因此非常方便调试人员后续选择对应的设备。

此时,接收任何一切输入

#  getevent -l
add device 1: /dev/input/event6
  name:     "msm8909-snd-card Headset Jack"
add device 2: /dev/input/event5
  name:     "msm8909-snd-card Button Jack"
add device 3: /dev/input/event2
  name:     "qpnp_pon"
add device 4: /dev/input/event1
  name:     "gpiokey-pulley"
could not get driver version for /dev/input/mice, Not a typewriter
add device 5: /dev/input/event3
  name:     "gpio-keys"
add device 6: /dev/input/event0
  name:     "aw9523-keys"
add device 7: /dev/input/event4
  name:     "accelerometer"
/dev/input/event0: EV_KEY       KEY_UP               DOWN
/dev/input/event0: EV_SYN       SYN_REPORT           00000000
/dev/input/event0: EV_KEY       KEY_UP               UP
/dev/input/event0: EV_SYN       SYN_REPORT           00000000
/dev/input/event0: EV_KEY       KEY_LEFT             DOWN
/dev/input/event0: EV_SYN       SYN_REPORT           00000000
/dev/input/event0: EV_KEY       KEY_LEFT             UP
/dev/input/event0: EV_SYN       SYN_REPORT           00000000
/dev/input/event2: EV_KEY       KEY_POWER            UP
/dev/input/event2: EV_SYN       SYN_REPORT           00000000
/dev/input/event3: EV_KEY       KEY_F1               DOWN
/dev/input/event3: EV_SYN       SYN_REPORT           00000000
/dev/input/event3: EV_KEY       KEY_F1               UP
/dev/input/event3: EV_SYN       SYN_REPORT           00000000
/dev/input/event3: EV_KEY       KEY_F1               DOWN
/dev/input/event3: EV_SYN       SYN_REPORT           00000000

# ls /dev/input/
event0 event1 event2 event3 event4 event5 event6 mice

读取指定的设备 读取 event3 数据(触摸屏)

# getevent /dev/input/event3
0003 0039 00000004
0003 0035 00002324
0003 0036 00001a9f
0001 014a 00000001
0003 0000 00002324
0003 0001 00001a9f
0000 0000 00000000
0003 0039 ffffffff
0001 014a 00000000
0000 0000 00000000

-t:显示时间戳


# getevent -t /dev/input/event3
[    1141.248434] 0003 0039 0000000e
[    1141.248434] 0003 0035 00002cd4
[    1141.248434] 0003 0036 00001a09
[    1141.248434] 0001 014a 00000001
[    1141.248434] 0003 0000 00002cd4
[    1141.248434] 0003 0001 00001a09
[    1141.248434] 0000 0000 00000000
[    1141.322181] 0003 0039 ffffffff
[    1141.322181] 0001 014a 00000000
[    1141.322181] 0000 0000 00000000

-n:不换行打印

# getevent -n /dev/input/event3
0003 0039 000000020003 0035 00002f000003 0036 00001a4e0001 014a 000000010003 0000 00002f000003 0001 00001a4e0000 0000 000000000003 0039 ffffffff0001 014a 000000000000 0000 000000000003 0039 000000030003 0035 00002e880003 0036 000019b80001 014a 000000010003 0000 00002e880003 0001 000019b80000 0000 000000000003 0039 ffffffff0001 014a 000000000000 0000 000000000003 0039 000000040003 0035 00002d700003 0036 00001a000001 014a 000000010003 0000 00002d700003 0001 00001a000000 0000 000000000003 0039 ffffffff0001 014a 000000000000 0000 000000000003 0039 000000050003 0035 00002d080003 0036 000019a50001 014a 000000010003 0000 00002d080003 0001 000019a50000 0000 000000000003 0039 ffffffff0001 014a 000000000000

-s:显示指定位的开关状态

# getevent -s5 /dev/input/event3
0000

-S:显示所有位的开关状态

# getevent -S /dev/input/event3
getevent -S /dev/input/event3
0000 

-v:根据 mask 值显示相关信息,执行后会一直显示上报数据

errs=1, dev=2, name=4, info=8, vers=16, pos. events=32, props=64

默认显示 dev| name| info| vers = 30;

# getevent -v /dev/input/event3
add device 1: /dev/input/event3
  bus:      0003
  vendor    222a
  product   004d
  version   0110
  name:     "ILITEK Multi-Touch-V3020"
  location: "usb-ff540000.usb-1.3/input0"
  id:       ""
  version:  1.0.1

# getevent -v30 /dev/input/event3
add device 1: /dev/input/event3
  bus:      0003
  vendor    222a
  product   004d
  version   0110
  name:     "ILITEK Multi-Touch-V3020"
  location: "usb-ff540000.usb-1.3/input0"
  id:       ""
  version:  1.0.1

# getevent -v2 /dev/input/event3
add device 1: /dev/input/event3

# getevent -v8 /dev/input/event3
getevent -v8 /dev/input/event3
  bus:      0003
  vendor    222a
  product   004d
  version   0110
  location: "usb-ff540000.usb-1.3/input0"
  id:       ""

# getevent -v16 /dev/input/event3
  version:  1.0.1

# getevent -v32 /dev/input/event3
  events:
    KEY (0001): 014a
    ABS (0003): 0000  : value 12008, min 0, max 16384, fuzz 0, flat 0, resolution 31
                0001  : value 5790, min 0, max 9600, fuzz 0, flat 0, resolution 32
                002f  : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0
                0035  : value 0, min 0, max 16384, fuzz 0, flat 0, resolution 31
                0036  : value 0, min 0, max 9600, fuzz 0, flat 0, resolution 32
                0039  : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0

-d:如果设备可用,显示设备隐藏的描述信息

-p:显示设备支持的事件类型和编码方式

# getevent -p /dev/input/event3
add device 1: /dev/input/event3
  name:     "ILITEK Multi-Touch-V3020"
  events:
    KEY (0001): 014a
    ABS (0003): 0000  : value 13084, min 0, max 16384, fuzz 0, flat 0, resolution 31
                0001  : value 5284, min 0, max 9600, fuzz 0, flat 0, resolution 32
                002f  : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0
                0035  : value 0, min 0, max 16384, fuzz 0, flat 0, resolution 31
                0036  : value 0, min 0, max 9600, fuzz 0, flat 0, resolution 32
                0039  : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0
  input props:
    INPUT_PROP_DIRECT

-i:显示设备的所有信息和支持的事件,比 -p 显示更多信息

# getevent -i /dev/input/event3

-l:以文本形式输出事件类型和名称,比 -t 更清楚直观

# getevent -l /dev/input/event3
getevent -l /dev/input/event3
// 事件类型      事件码              事件值
EV_ABS       ABS_MT_TRACKING_ID   0000000f
EV_ABS       ABS_MT_POSITION_X    00002bbc
EV_ABS       ABS_MT_POSITION_Y    00001b6d
EV_KEY       BTN_TOUCH            DOWN
EV_ABS       ABS_X                00002bbc
EV_ABS       ABS_Y                00001b6d
EV_SYN       SYN_REPORT           00000000
EV_ABS       ABS_MT_TRACKING_ID   ffffffff
EV_KEY       BTN_TOUCH            UP
EV_SYN       SYN_REPORT           00000000

-q:暂时不会使用

-c:打印固定数量的事件并退出

# getevent -c 10 /dev/input/event3
getevent -c 10 /dev/input/event3
0003 0039 00000012
0003 0035 000038a4
0003 0036 000008f5
0001 014a 00000001
0003 0000 000038a4
0003 0001 000008f5
0000 0000 00000000
0003 0039 ffffffff
0001 014a 00000000
0000 0000 00000000

-r:显示事件上报速率

// 检测触摸屏报点速率
# getevent -r /dev/input/event3
getevent -r /dev/input/event3
0003 0039 00000015
0003 0035 000030d8
0003 0036 00001954
0001 014a 00000001
0003 0000 000030d8
0003 0001 00001954
0000 0000 00000000 rate 0
0003 0039 ffffffff
0001 014a 00000000
0000 0000 00000000 rate 9

参数可以组合使用,一次性查看需要的输入信息

# getevent -tlr /dev/input/event3
[    2514.550104] EV_ABS       ABS_MT_TRACKING_ID   0000001c
[    2514.550104] EV_ABS       ABS_MT_POSITION_X    00002dac
[    2514.550104] EV_ABS       ABS_MT_POSITION_Y    000018ca
[    2514.550104] EV_KEY       BTN_TOUCH            DOWN
[    2514.550104] EV_ABS       ABS_X                00002dac
[    2514.550104] EV_ABS       ABS_Y                000018ca
[    2514.550104] EV_SYN       SYN_REPORT           00000000             rate 0
[    2514.638845] EV_ABS       ABS_MT_TRACKING_ID   ffffffff
[    2514.638845] EV_KEY       BTN_TOUCH            UP
[    2514.638845] EV_SYN       SYN_REPORT           00000000             rate 11

标签:getevent,0000,dev,event3,input,Android,EV,子系统
来源: https://www.cnblogs.com/schips/p/android_using_getevent_to_debug_input-subsystem.html