Android Keyevent test

发送key (system/core/toolbox/sendevent.c)

发送长按POWER键:(long press)

input keyevent --longpress POWER

or

sendevent /dev/input/event0 1 116 1
sendevent /dev/input/event0 0 0 0
sleep 1
sendevent /dev/input/event0 1 116 0
sendevent /dev/input/event0 0 0 0
sleep 1

KEY_DOWN

sendevent /dev/input/event0 1 108 1
sendevent /dev/input/event0 0 0 0
sendevent /dev/input/event0 1 108 0
sendevent /dev/input/event0 0 0 0

KEY_UP

sendevent /dev/input/event0 1 103 1
sendevent /dev/input/event0 0 0 0
sendevent /dev/input/event0 1 103 0
sendevent /dev/input/event0 0 0 0

发送Power+KeyUp,切换RecoveryUI

sendevent /dev/input/event0 1 116 1
sendevent /dev/input/event0 0 0 0
sendevent /dev/input/event0 1 115 1
sendevent /dev/input/event0 0 0 0
sendevent /dev/input/event0 1 115 0
sendevent /dev/input/event0 0 0 0
sendevent /dev/input/event0 1 116 0
sendevent /dev/input/event0 0 0 0

读取keyevent:

getevent
[    1688.811239] /dev/input/event1: 0004 0004 0007004f
[    1688.811239] /dev/input/event1: 0001 006a 00000001
[    1688.811239] /dev/input/event1: 0000 0000 00000000

[    1688.827260] /dev/input/event1: 0004 0004 0007004f
[    1688.827260] /dev/input/event1: 0001 006a 00000000
[    1688.827260] /dev/input/event1: 0000 0000 00000000

InputDispatcherThread

InputDispatcherThread::threadLoop()
- InputDispatcher::dispatchOnce()
- - InputDispatcher::dispatchOnceInnerLocked()
- - - InputDispatcher::dispatchKeyLocked()
- - - - - InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible()
- - - - - - mPolicy->interceptKeyBeforeDispatching()

按键输入

KeyboardInputMapper::processKey()
- QueuedInputListener::flush()
- - NotifyKeyArgs::notify()
- - - QueuedInputListener::notifyKey()
InputDispatcher::notifyKey()
- mPolicy->interceptKeyBeforeQueueing()

CLI输入

(java)InputManagerService.injectInputEvent()
- (java)InputManagerService.injectInputEventInternal()
- - (java/c)nativeInjectInputEvent()
- - - (c)InputDispatcher::injectInputEvent()
- - - - (c/java)mPolicy->interceptKeyBeforeQueueing()

input flinger测试代码
frameworks/native/services/inputflinger/tests

java input keyevent: jni
frameworks/base/services/core/jni/com_android_server_input_InputManagerService.cpp
调用(jint) im->getInputManager()->getDispatcher()->injectInputEvent()
实现于
frameworks/native/services/inputflinger/InputDispatcher.cpp
打包于
libinputflinger.so

KeyEvent.java定义了keycode,键码
linux/include/uapi/linux/input.h定义了sendevent中的键值