专栏名称: 刘望舒
腾讯云最具价值专家
目录
相关文章推荐
鸿洋  ·  务必立即拿下软考证(政策红利) ·  21 小时前  
复利大王  ·  冷暴力女王,翻车了 ·  22 小时前  
复利大王  ·  520怀孕事件? ·  22 小时前  
复利大王  ·  卷疯了:食堂档口末位淘汰 ·  昨天  
复利大王  ·  王石最新朋友圈 ·  昨天  
51好读  ›  专栏  ›  刘望舒

Android输入系统(三)InputReader的加工类型和InputDispatcher的分发过...

刘望舒  · 掘金  · android  · 2018-12-16 23:19

正文

请到「今天看啥」查看全文


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
    //检查Motion事件的参数是否有效
    if (!validateMotionEvent(args->action, args->actionButton,
                args->pointerCount, args->pointerProperties)) {//1
        return;
    }
    uint32_t policyFlags = args->policyFlags;
    policyFlags |= POLICY_FLAG_TRUSTED;
    mPolicy->interceptMotionBeforeQueueing(args->eventTime, /*byref*/






请到「今天看啥」查看全文


推荐文章
复利大王  ·  冷暴力女王,翻车了
22 小时前
复利大王  ·  520怀孕事件?
22 小时前
复利大王  ·  卷疯了:食堂档口末位淘汰
昨天
复利大王  ·  王石最新朋友圈
昨天
EC观察  ·  负债48亿,他想到了自杀
7 年前