1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
mInputManager =
new
InputManager(context,
this
);
mInputManager.start();
InputManager是WindowManagerService的成员变量,主要实现了读取RawEvent,分发事件给WindowManagerService;
InputManager.java的
native
代码InputManager.cpp实现了读取和事件分发,他初始化两个线程
void
InputManager::initialize() {
mReaderThread =
new
InputReaderThread(mReader);
//不断地从/dev/input/目录下面的设备文件读取事件
mDispatcherThread =
new
InputDispatcherThread(mDispatcher);
//事件分发
}
InputManager通过InputManager.Callbacks类响应回调,在回调里再调用 WindowManagerService.InputMonitor来接收事件。并在 WindowManagerService.InputMonitor.interceptKeyBeforeQueueing()和 interceptKeyBeforeDispatching()进行消息拦截处理。处理的代码如下:
WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
/* Provides an opportunity for the window manager policy to intercept early key
* processing as soon as the key has been read from the device. */
public
int
interceptKeyBeforeQueueing(
long
whenNanos,
int
keyCode,
boolean
down,
int
policyFlags,
boolean
isScreenOn) {
return
mPolicy.interceptKeyBeforeQueueing(whenNanos,
keyCode, down, policyFlags, isScreenOn);
}
|
/frameworks/base/libs/ui/EventHub.cpp(键码与键值转换)
参考文档:
Android按键事件处理流程 -- KeyEvent