Android Input事件处理

Android Input事件处理

Input UML 图表

系统启动SystemServer时创建其他服务,初始话Input管理服务,创建InputManager、InputReader对象
对于InputReader在初始化成功之后,start启动时,创建InputTread loop工作线程
framework/native/services/inputflinger/reader/InputReader.cpp

InputReader.h
private:
    std::unique_ptr<InputThread> mThread;

InputReader.cpp
status_t InputReader::start() {
    if (mThread) {
        return ALREADY_EXISTS;
    }
    mThread = std::make_unique<InputThread>(
            "InputReader", [this]() { loopOnce(); }, [this]() { mEventHub->wake(); });
    return OK;
}

如下图是系统启动input服务时序图:

SystemServer InputManagerService com_android_server_input_InputManagerService NativeInputManager InputManager InputReader InputThread EventBug run startOtherServices new InputManagerService nativeInit(JNI) new NativeInutManager new InputManager createInputReader start nativeStart start start new InputThread() loop线程会 循环不断的 从EventBug中 读取Input事件 threadloop loopOnce getEvents 返回Input事件 SystemServer InputManagerService com_android_server_input_InputManagerService NativeInputManager InputManager InputReader InputThread EventBug

如图可知,inputThread这个线程的工作就是通过EventHub的getEvents监听读取Input事件。
获取到事件Input事件之后,通知InputDispatcher派发InputEvent事件
在InputReader中loopOnce方法最后一句是flush

    // Flush queued events out to the listener.
    // This must happen outside of the lock because the listener could potentially call
    // back into the InputReader's methods, such as getScanCodeState, or become blocked
    // on another thread similarly waiting to acquire the InputReader lock thereby
    // resulting in a deadlock.  This situation is actually quite plausible because the
    // listener is actually the input dispatcher, which calls into the window manager,
    // which occasionally calls into the input reader.
    mQueuedListener->flush();

如下图是flush动作的时序图

InputReader InputListener InputDispather loopOnce mQueuedListener->>flush() notify notifyMotion interceptMotionBeforeQueueing filterInputEvent queueInboundEventLocked wake ->>dispatchOnce dispatchMotionLocked findTouchedWindowTargetsLocked dispatchEventLocked InputReader InputListener InputDispather
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值