Android事件传递方:向 driver->/dev/input/eventX节点->EventHub->InputReader->EventDispatcher->ViewRootImpl->view tree
每个阶段都可以把事件打印出来看,如在InputReader读取到rawEvent 后,可以将key值解析出来看,帮助分析。
首先异常时先确定节点数据是否正常,命令如下:
adb shell getevent -l /dev/input/evnetX
异常直接往驱动找异常,正常往android框架层追查。
根据传递方向,在Input模块中打印log:
frameworks/native/services/inputflinger/InputReader.cpp
void InputDevice::process(const RawEvent* rawEvents, size_t count) {
for (const RawEvent* rawEvent = rawEvents; count != 0; rawEvent++) {
#if DEBUG_RAW_EVENTS
ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x when=%" PRId64,
rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value,
rawEvent->when);
#endif
if (mDropUntilNextSync) {
if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
mDropUntilNextSync = false;
#if DEBUG_RAW_EVENTS
ALOGD("Recovered from input event buffer overrun.");
#endif
} else {
#if DEBUG_RAW_EVENTS
ALOGD("Dropped input event while waiting for next input sync.");
#endif
}
} else if (rawEvent->type == EV_SYN && rawEvent->code == SYN_DROPPED) {
ALOGI("Detected input event buffer overrun for device %s.", getName().c_str());
mDropUntilNextSync = true;
reset(rawEvent->when);
} else {
for (InputMapper* mapper : mMappers) {
mapper->process(rawEvent);
}
}
--count;
}
}
log如下,此log需要打开DEBUG_RAW_EVENTS,
Line 6426: 03-23 12:16:42.196 455 556 D InputReader: Input event: device=13 type=0x0004 code=0x0004 value=0x00070026 when=12109695056000
Line 6427: 03-23 12:16:42.196 455 556 D InputReader: Input event: device=13 type=0x0001 code=0x000a value=0x00000001 when=12109695056000
Line 6428: 03-23 12:16:42.197 455 556 D InputReader: Input event: device=13 type=0x0000 code=0x0000 value=0x00000000 when=12109695056000
Line 6429: 03-23 12:16:42.198 455 556 D InputReader: Input event: device=13 type=0x0004 code=0x0004 value=0x00070026 when=12109695878000
Line 6430: 03-23 12:16:42.198 455 556 D InputReader: Input event: device=13 type=0x0001 code=0x000a value=0x00000000 when=12109695878000
通过查表,进行解析,
如:type=0x0001 code=0x000a value=0x00000001
type=0x0001 表示EV_KEY
code=0x000a 翻译成10进制是10 ,对应KEY_9
value=0x00000001 表示DOWN
结果应该是和adb shell getevent -l /dev/input/evnetX结果一致
EV_MSC MSC_SCAN 00070026
EV_KEY KEY_9 DOWN
EV_SYN SYN_REPORT 00000000
EV_MSC MSC_SCAN 00070026
EV_KEY KEY_9 UP
key值十进制查表如下
70#define EV_SYN 0x00
71#define EV_KEY 0x01
72#define EV_REL 0x02
73#define EV_ABS 0x03
74#define EV_MSC 0x04
75#define EV_SW 0x05
76#define EV_LED 0x11
77#define EV_SND 0x12
78#define EV_REP 0x14
79#define EV_FF 0x15
80#define EV_PWR 0x16
81#define EV_FF_STATUS 0x17
82#define EV_MAX 0x1f
83
84#define SYN_REPORT 0
85#define SYN_CONFIG 1
86
87#define KEY_RESERVED 0
88#define KEY_ESC 1
89#define KEY_1 2
90#define KEY_2 3
91#define KEY_3 4
92#define KEY_4 5
93#define KEY_5 6
94#define KEY_6 7
95#define KEY_7 8
96#define KEY_8 9
97#define KEY_9 10
98#define KEY_0 11
99#define KEY_MINUS 12
100#define KEY_EQUAL 13
101#define KEY_BACKSPACE 14
102#define KEY_TAB 15
103#define KEY_Q 16
104#define KEY_W 17
105#define KEY_E 18
106#define KEY_R 19
107#define KEY_T 20
108#define KEY_Y 21
109#define KEY_U 22
110#define KEY_I 23
111#define KEY_O 24
112#define KEY_P 25
113#define KEY_LEFTBRACE 26
114#define KEY_RIGHTBRACE 27
115#define KEY_ENTER 28
116#define KEY_LEFTCTRL 29
117#define KEY_A 30
118#define KEY_S 31
119#define KEY_D 32
120#define KEY_F 33
121#define KEY_G 34
122#define KEY_H 35
123#define KEY_J 36
124#define KEY_K 37
125#define KEY_L 38
126#define KEY_SEMICOLON 39
127#define KEY_APOSTROPHE 40
128#define KEY_GRAVE 41
129#define KEY_LEFTSHIFT 42
130#define KEY_BACKSLASH 43
131#define KEY_Z 44
132#define KEY_X 45
133#define KEY_C 46
134#define KEY_V 47
135#define KEY_B 48
136#define KEY_N 49
137#define KEY_M 50
138#define KEY_COMMA 51
139#define KEY_DOT 52
140#define KEY_SLASH 53
141#define KEY_RIGHTSHIFT 54
142#define KEY_KPASTERISK 55
143#define KEY_LEFTALT 56
144#define KEY_SPACE 57
145#define KEY_CAPSLOCK 58
146#define KEY_F1 59
147#define KEY_F2 60
148#define KEY_F3 61
149#define KEY_F4 62
150#define KEY_F5 63
151#define KEY_F6 64
152#define KEY_F7 65
153#define KEY_F8 66
154#define KEY_F9 67
155#define KEY_F10 68
156#define KEY_NUMLOCK 69
157#define KEY_SCROLLLOCK 70
158#define KEY_KP7 71
159#define KEY_KP8 72
160#define KEY_KP9 73
161#define KEY_KPMINUS 74
162#define KEY_KP4 75
163#define KEY_KP5 76
164#define KEY_KP6 77
165#define KEY_KPPLUS 78
166#define KEY_KP1 79
167#define KEY_KP2 80
168#define KEY_KP3 81
169#define KEY_KP0 82
170#define KEY_KPDOT 83
171
172#define KEY_ZENKAKUHANKAKU 85
173#define KEY_102ND 86
174#define KEY_F11 87
175#define KEY_F12 88
176#define KEY_RO 89
177#define KEY_KATAKANA 90
178#define KEY_HIRAGANA 91
179#define KEY_HENKAN 92
180#define KEY_KATAKANAHIRAGANA 93
181#define KEY_MUHENKAN 94
182#define KEY_KPJPCOMMA 95
183#define KEY_KPENTER 96
184#define KEY_RIGHTCTRL 97
185#define KEY_KPSLASH 98
186#define KEY_SYSRQ 99
187#define KEY_RIGHTALT 100
188#define KEY_LINEFEED 101
189#define KEY_HOME 102
190#define KEY_UP 103
191#define KEY_PAGEUP 104
192#define KEY_LEFT 105
193#define KEY_RIGHT 106
194#define KEY_END 107
195#define KEY_DOWN 108
196#define KEY_PAGEDOWN 109
197#define KEY_INSERT 110
198#define KEY_DELETE 111
199#define KEY_MACRO 112
200#define KEY_MUTE 113
201#define KEY_VOLUMEDOWN 114
202#define KEY_VOLUMEUP 115
203#define KEY_POWER 116
204#define KEY_KPEQUAL 117
205#define KEY_KPPLUSMINUS 118
206#define KEY_PAUSE 119
207
208#define KEY_KPCOMMA 121
209#define KEY_HANGEUL 122
210#define KEY_HANGUEL KEY_HANGEUL
211#define KEY_HANJA 123
212#define KEY_YEN 124
213#define KEY_LEFTMETA 125
214#define KEY_RIGHTMETA 126
215#define KEY_COMPOSE 127
216
217#define KEY_STOP 128
218#define KEY_AGAIN 129
219#define KEY_PROPS 130
220#define KEY_UNDO 131
221#define KEY_FRONT 132
222#define KEY_COPY 133
223#define KEY_OPEN 134
224#define KEY_PASTE 135
225#define KEY_FIND 136
226#define KEY_CUT 137
227#define KEY_HELP 138
228#define KEY_MENU 139
229#define KEY_CALC 140
230#define KEY_SETUP 141
231#define KEY_SLEEP 142
232#define KEY_WAKEUP 143
233#define KEY_FILE 144
234#define KEY_SENDFILE 145
235#define KEY_DELETEFILE 146
236#define KEY_XFER 147
237#define KEY_PROG1 148
238#define KEY_PROG2 149
239#define KEY_WWW 150
240#define KEY_MSDOS 151
241#define KEY_COFFEE 152
242#define KEY_DIRECTION 153
243#define KEY_CYCLEWINDOWS 154
244#define KEY_MAIL 155
245#define KEY_BOOKMARKS 156
246#define KEY_COMPUTER 157
247#define KEY_BACK 158
248#define KEY_FORWARD 159
249#define KEY_CLOSECD 160
250#define KEY_EJECTCD 161
251#define KEY_EJECTCLOSECD 162
252#define KEY_NEXTSONG 163
253#define KEY_PLAYPAUSE 164
254#define KEY_PREVIOUSSONG 165
255#define KEY_STOPCD 166
256#define KEY_RECORD 167
257#define KEY_REWIND 168
258#define KEY_PHONE 169
259#define KEY_ISO 170
260#define KEY_CONFIG 171
261#define KEY_HOMEPAGE 172
262#define KEY_REFRESH 173
263#define KEY_EXIT 174
264#define KEY_MOVE 175
265#define KEY_EDIT 176
266#define KEY_SCROLLUP 177
267#define KEY_SCROLLDOWN 178
268#define KEY_KPLEFTPAREN 179
269#define KEY_KPRIGHTPAREN 180
270#define KEY_NEW 181
271#define KEY_REDO 182
272
273#define KEY_F13 183
274#define KEY_F14 184
275#define KEY_F15 185
276#define KEY_F16 186
277#define KEY_F17 187
278#define KEY_F18 188
279#define KEY_F19 189
280#define KEY_F20 190
281#define KEY_F21 191
282#define KEY_F22 192
283#define KEY_F23 193
284#define KEY_F24 194
285
286#define KEY_PLAYCD 200
287#define KEY_PAUSECD 201
288#define KEY_PROG3 202
289#define KEY_PROG4 203
290#define KEY_SUSPEND 205
291#define KEY_CLOSE 206
292#define KEY_PLAY 207
293#define KEY_FASTFORWARD 208
294#define KEY_BASSBOOST 209
295#define KEY_PRINT 210
296#define KEY_HP 211
297#define KEY_CAMERA 212
298#define KEY_SOUND 213
299#define KEY_QUESTION 214
300#define KEY_EMAIL 215
301#define KEY_CHAT 216
302#define KEY_SEARCH 217
303#define KEY_CONNECT 218
304#define KEY_FINANCE 219
305#define KEY_SPORT 220
306#define KEY_SHOP 221
307#define KEY_ALTERASE 222
308#define KEY_CANCEL 223
309#define KEY_BRIGHTNESSDOWN 224
310#define KEY_BRIGHTNESSUP 225
311#define KEY_MEDIA 226
312
313#define KEY_STAR 227
314#define KEY_SHARP 228
315#define KEY_SOFT1 229
316#define KEY_SOFT2 230
317#define KEY_SEND 231
318#define KEY_CENTER 232
319#define KEY_HEADSETHOOK 233
320#define KEY_0_5 234
321#define KEY_2_5 235
322
323#define KEY_SWITCHVIDEOMODE 236
324#define KEY_KBDILLUMTOGGLE 237
325#define KEY_KBDILLUMDOWN 238
326#define KEY_KBDILLUMUP 239
327
328#define KEY_SEND 231
329#define KEY_REPLY 232
330#define KEY_FORWARDMAIL 233
331#define KEY_SAVE 234
332#define KEY_DOCUMENTS 235
333
334#define KEY_BATTERY 236
335
336#define KEY_UNKNOWN 240
337
338#define BTN_MISC 0x100
339#define BTN_0 0x100
340#define BTN_1 0x101
341#define BTN_2 0x102
342#define BTN_3 0x103
343#define BTN_4 0x104
344#define BTN_5 0x105
345#define BTN_6 0x106
346#define BTN_7 0x107
347#define BTN_8 0x108
348#define BTN_9 0x109
349
350#define BTN_MOUSE 0x110
351#define BTN_LEFT 0x110
352#define BTN_RIGHT 0x111
353#define BTN_MIDDLE 0x112
354#define BTN_SIDE 0x113
355#define BTN_EXTRA 0x114
356#define BTN_FORWARD 0x115
357#define BTN_BACK 0x116
358#define BTN_TASK 0x117
359
360#define BTN_JOYSTICK 0x120
361#define BTN_TRIGGER 0x120
362#define BTN_THUMB 0x121
363#define BTN_THUMB2 0x122
364#define BTN_TOP 0x123
365#define BTN_TOP2 0x124
366#define BTN_PINKIE 0x125
367#define BTN_BASE 0x126
368#define BTN_BASE2 0x127
369#define BTN_BASE3 0x128
370#define BTN_BASE4 0x129
371#define BTN_BASE5 0x12a
372#define BTN_BASE6 0x12b
373#define BTN_DEAD 0x12f
374
375#define BTN_GAMEPAD 0x130
376#define BTN_A 0x130
377#define BTN_B 0x131
378#define BTN_C 0x132
379#define BTN_X 0x133
380#define BTN_Y 0x134
381#define BTN_Z 0x135
382#define BTN_TL 0x136
383#define BTN_TR 0x137
384#define BTN_TL2 0x138
385#define BTN_TR2 0x139
386#define BTN_SELECT 0x13a
387#define BTN_START 0x13b
388#define BTN_MODE 0x13c
389#define BTN_THUMBL 0x13d
390#define BTN_THUMBR 0x13e
391
392#define BTN_DIGI 0x140
393#define BTN_TOOL_PEN 0x140
394#define BTN_TOOL_RUBBER 0x141
395#define BTN_TOOL_BRUSH 0x142
396#define BTN_TOOL_PENCIL 0x143
397#define BTN_TOOL_AIRBRUSH 0x144
398#define BTN_TOOL_FINGER 0x145
399#define BTN_TOOL_MOUSE 0x146
400#define BTN_TOOL_LENS 0x147
401#define BTN_TOUCH 0x14a
402#define BTN_STYLUS 0x14b
403#define BTN_STYLUS2 0x14c
404#define BTN_TOOL_DOUBLETAP 0x14d
405#define BTN_TOOL_TRIPLETAP 0x14e
406
407#define BTN_WHEEL 0x150
408#define BTN_GEAR_DOWN 0x150
409#define BTN_GEAR_UP 0x151
410
411#define KEY_OK 0x160
412#define KEY_SELECT 0x161
413#define KEY_GOTO 0x162
414#define KEY_CLEAR 0x163
415#define KEY_POWER2 0x164
416#define KEY_OPTION 0x165
417#define KEY_INFO 0x166
418#define KEY_TIME 0x167
419#define KEY_VENDOR 0x168
420#define KEY_ARCHIVE 0x169
421#define KEY_PROGRAM 0x16a
422#define KEY_CHANNEL 0x16b
423#define KEY_FAVORITES 0x16c
424#define KEY_EPG 0x16d
425#define KEY_PVR 0x16e
426#define KEY_MHP 0x16f
427#define KEY_LANGUAGE 0x170
428#define KEY_TITLE 0x171
429#define KEY_SUBTITLE 0x172
430#define KEY_ANGLE 0x173
431#define KEY_ZOOM 0x174
432#define KEY_MODE 0x175
433#define KEY_KEYBOARD 0x176
434#define KEY_SCREEN 0x177
435#define KEY_PC 0x178
436#define KEY_TV 0x179
437#define KEY_TV2 0x17a
438#define KEY_VCR 0x17b
439#define KEY_VCR2 0x17c
440#define KEY_SAT 0x17d
441#define KEY_SAT2 0x17e
442#define KEY_CD 0x17f
443#define KEY_TAPE 0x180
444#define KEY_RADIO 0x181
445#define KEY_TUNER 0x182
446#define KEY_PLAYER 0x183
447#define KEY_TEXT 0x184
448#define KEY_DVD 0x185
449#define KEY_AUX 0x186
450#define KEY_MP3 0x187
451#define KEY_AUDIO 0x188
452#define KEY_VIDEO 0x189
453#define KEY_DIRECTORY 0x18a
454#define KEY_LIST 0x18b
455#define KEY_MEMO 0x18c
456#define KEY_CALENDAR 0x18d
457#define KEY_RED 0x18e
458#define KEY_GREEN 0x18f
459#define KEY_YELLOW 0x190
460#define KEY_BLUE 0x191
461#define KEY_CHANNELUP 0x192
462#define KEY_CHANNELDOWN 0x193
463#define KEY_FIRST 0x194
464#define KEY_LAST 0x195
465#define KEY_AB 0x196
466#define KEY_NEXT 0x197
467#define KEY_RESTART 0x198
468#define KEY_SLOW 0x199
469#define KEY_SHUFFLE 0x19a
470#define KEY_BREAK 0x19b
471#define KEY_PREVIOUS 0x19c
472#define KEY_DIGITS 0x19d
473#define KEY_TEEN 0x19e
474#define KEY_TWEN 0x19f
475
476#define KEY_DEL_EOL 0x1c0
477#define KEY_DEL_EOS 0x1c1
478#define KEY_INS_LINE 0x1c2
479#define KEY_DEL_LINE 0x1c3
480
481#define KEY_FN 0x1d0
482#define KEY_FN_ESC 0x1d1
483#define KEY_FN_F1 0x1d2
484#define KEY_FN_F2 0x1d3
485#define KEY_FN_F3 0x1d4
486#define KEY_FN_F4 0x1d5
487#define KEY_FN_F5 0x1d6
488#define KEY_FN_F6 0x1d7
489#define KEY_FN_F7 0x1d8
490#define KEY_FN_F8 0x1d9
491#define KEY_FN_F9 0x1da
492#define KEY_FN_F10 0x1db
493#define KEY_FN_F11 0x1dc
494#define KEY_FN_F12 0x1dd
495#define KEY_FN_1 0x1de
496#define KEY_FN_2 0x1df
497#define KEY_FN_D 0x1e0
498#define KEY_FN_E 0x1e1
499#define KEY_FN_F 0x1e2
500#define KEY_FN_S 0x1e3
501#define KEY_FN_B 0x1e4
502
503#define KEY_BRL_DOT1 0x1f1
504#define KEY_BRL_DOT2 0x1f2
505#define KEY_BRL_DOT3 0x1f3
506#define KEY_BRL_DOT4 0x1f4
507#define KEY_BRL_DOT5 0x1f5
508#define KEY_BRL_DOT6 0x1f6
509#define KEY_BRL_DOT7 0x1f7
510#define KEY_BRL_DOT8 0x1f8
511
512#define KEY_MIN_INTERESTING KEY_MUTE
513#define KEY_MAX 0x1ff
514
515#define REL_X 0x00
516#define REL_Y 0x01
517#define REL_Z 0x02
518#define REL_RX 0x03
519#define REL_RY 0x04
520#define REL_RZ 0x05
521#define REL_HWHEEL 0x06
522#define REL_DIAL 0x07
523#define REL_WHEEL 0x08
524#define REL_MISC 0x09
525#define REL_MAX 0x0f
526
527#define ABS_X 0x00
528#define ABS_Y 0x01
529#define ABS_Z 0x02
530#define ABS_RX 0x03
531#define ABS_RY 0x04
532#define ABS_RZ 0x05
533#define ABS_THROTTLE 0x06
534#define ABS_RUDDER 0x07
535#define ABS_WHEEL 0x08
536#define ABS_GAS 0x09
537#define ABS_BRAKE 0x0a
538#define ABS_HAT0X 0x10
539#define ABS_HAT0Y 0x11
540#define ABS_HAT1X 0x12
541#define ABS_HAT1Y 0x13
542#define ABS_HAT2X 0x14
543#define ABS_HAT2Y 0x15
544#define ABS_HAT3X 0x16
545#define ABS_HAT3Y 0x17
546#define ABS_PRESSURE 0x18
547#define ABS_DISTANCE 0x19
548#define ABS_TILT_X 0x1a
549#define ABS_TILT_Y 0x1b
550#define ABS_TOOL_WIDTH 0x1c
551#define ABS_VOLUME 0x20
552#define ABS_MISC 0x28
553#define ABS_MAX 0x3f
554
555#define SW_LID 0x00
556#define SW_TABLET_MODE 0x01
557#define SW_HEADPHONE_INSERT 0x02
558#define SW_MAX 0x0f
559
560#define MSC_SERIAL 0x00
561#define MSC_PULSELED 0x01
562#define MSC_GESTURE 0x02
563#define MSC_RAW 0x03
564#define MSC_SCAN 0x04
565#define MSC_MAX 0x07
566
567#define LED_NUML 0x00
568#define LED_CAPSL 0x01
569#define LED_SCROLLL 0x02
570#define LED_COMPOSE 0x03
571#define LED_KANA 0x04
572#define LED_SLEEP 0x05
573#define LED_SUSPEND 0x06
574#define LED_MUTE 0x07
575#define LED_MISC 0x08
576#define LED_MAIL 0x09
577#define LED_CHARGING 0x0a
578#define LED_MAX 0x0f
579
580#define REP_DELAY 0x00
581#define REP_PERIOD 0x01
582#define REP_MAX 0x01
583
584#define SND_CLICK 0x00
585#define SND_BELL 0x01
586#define SND_TONE 0x02
587#define SND_MAX 0x07
588
589#define ID_BUS 0
590#define ID_VENDOR 1
591#define ID_PRODUCT 2
592#define ID_VERSION 3
593
594#define BUS_PCI 0x01
595#define BUS_ISAPNP 0x02
596#define BUS_USB 0x03
597#define BUS_HIL 0x04
598#define BUS_BLUETOOTH 0x05
599
600#define BUS_ISA 0x10
601#define BUS_I8042 0x11
602#define BUS_XTKBD 0x12
603#define BUS_RS232 0x13
604#define BUS_GAMEPORT 0x14
605#define BUS_PARPORT 0x15
606#define BUS_AMIGA 0x16
607#define BUS_ADB 0x17
608#define BUS_I2C 0x18
609#define BUS_HOST 0x19
610#define BUS_GSC 0x1A
611
612#define FF_STATUS_STOPPED 0x00
613#define FF_STATUS_PLAYING 0x01
614#define FF_STATUS_MAX 0x01