正文
NotifyKeyArgs
:
public
NotifyArgs {
nsecs_t
eventTime;
int32_t
deviceId;
uint32_t
source;
uint32_t
policyFlags;
int32_t
action;
int32_t
flags;
int32_t
keyCode;
int32_t
scanCode;
int32_t
metaState;
nsecs_t
downTime;
inline
NotifyKeyArgs
()
{ }
NotifyKeyArgs(
nsecs_t
eventTime,
int32_t
deviceId,
uint32_t
source,
uint32_t
policyFlags,
int32_t
action,
int32_t
flags,
int32_t
keyCode,
int32_t
scanCode,
int32_t
metaState,
nsecs_t
downTime);
NotifyKeyArgs(
const
NotifyKeyArgs& other);
virtual
~NotifyKeyArgs() { }
virtual
void
notify
(
const
sp<InputListenerInterface>& listener)
const
;
};
复制代码
可以看到,NotifyKeyArgs结构体继承自NotifyArgs结构体,如下图所示。
NotifyArgs有三个子类,分别是NotifyKeyArgs、NotifyMotionArgs和NotifySwichArgs,这说明InputReader对原始输入事件加工后,最终会得出三种事件类型,分别是key事件、Motion事件和Swich事件,这些事件会交由InputDispatcher来进行分发,如下图所示。
2.InputDispatcher的分发过程
不同的事件类型有着不同的分发过程,其中Swich事件的处理是没有派发过程的,在InputDispatcher的notifySwitch函数中会将Swich事件交由InputDispatcherPolicy来处理。本系列文章一直讲解key事件相关,这次换一下,以Motion事件的分发过程来进行举例,对key事件分发事件有兴趣的可以自行去看源码,本质上都差不多。
2.1 唤醒InputDispatcherThread
InputDispatcher的notifyMotion函数用来唤醒InputDispatcherThread。
frameworks/native/services/inputflinger/InputDispatcher.cpp
void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) {
#if DEBUG_INBOUND_EVENT_DETAILS
...
#endif
if (!validateMotionEvent(args->action, args->actionButton,
args->pointerCount, args->pointerProperties)) {
return;
}
uint32_t policyFlags = args->policyFlags;
policyFlags |= POLICY_FLAG_TRUSTED;
mPolicy->interceptMotionBeforeQueueing(args->eventTime,