InputChannel 用于窗口与InputDispatcher通信

https://blog.csdn.net/qq_34211365/article/details/103243723

 

看了上篇的文章觉得写的挺好, 简单做个笔记:

  1. ActivityThread.handleResumeActivity负责将Activity对应的DecorView通过wm.addView(decor, l);放入WMS中
  2. WindowManagerGlobal.addView中负责root = new ViewRootImpl(view.getContext(), display);并且将DecorView和ViewRootImpl关联起来root.setView(view, wparams, panelParentView);
  3. ViewRootImpl.setView就会负责mInputChannel = new InputChannel();并且将mInputChannel放入WMS中,同时通过mInputEventReceiver = new WindowInputEventReceiver(mInputChannel, Looper.myLooper());构造一个事件处理,通过ViewRootImple.enqueueInputEvent()把事件分发下去
  4. mWindowSession.addToDisplay(..., mInputChannel,...);会走入WMS.addWindow
  5. WMS.addWindow负责final WindowState win = new WindowState(this, session,...);之后win.openInputChannel(outInputChannel);
  6. WindowState.openInputChannel()负责,mClientChannel重定向给步骤3的mInputChannel,而server端通知InputManager最后给到InputDispatcher

 


    void openInputChannel(InputChannel outInputChannel) {
        if (mInputChannel != null) {
            throw new IllegalStateException("Window already has an input channel.");
        }
        String name = getName();
        //创建InputChannelPair
        InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
        //服务端InputChannel
        mInputChannel = inputChannels[0];
        //客户端InputChannel
        mClientChannel = inputChannels[1];
        mInputWindowHandle.token = mClient.asBinder();
        if (outInputChannel != null) {
            //将客户端InputChannel发送回ViewRootImpl
            mClientChannel.transferTo(outInputChannel);
            mClientChannel.dispose();
            mClientChannel = null;
        } else {
            // If the window died visible, we setup a dummy input channel, so that taps
            // can still detected by input monitor channel, and we can relaunch the app.
            // Create dummy event receiver that simply reports all events as handled.
            mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
        }
        //将服务端InputChannel注册到InputDispatcher
        mWmService.mInputManager.registerInputChannel(mInputChannel, mClient.asBinder());
    }

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值