https://blog.csdn.net/qq_34211365/article/details/103243723
看了上篇的文章觉得写的挺好, 简单做个笔记:
- ActivityThread.handleResumeActivity负责将Activity对应的DecorView通过wm.addView(decor, l);放入WMS中
- WindowManagerGlobal.addView中负责root = new ViewRootImpl(view.getContext(), display);并且将DecorView和ViewRootImpl关联起来root.setView(view, wparams, panelParentView);
- ViewRootImpl.setView就会负责mInputChannel = new InputChannel();并且将mInputChannel放入WMS中,同时通过mInputEventReceiver = new WindowInputEventReceiver(mInputChannel, Looper.myLooper());构造一个事件处理,通过ViewRootImple.enqueueInputEvent()把事件分发下去
- mWindowSession.addToDisplay(..., mInputChannel,...);会走入WMS.addWindow
- WMS.addWindow负责final WindowState win = new WindowState(this, session,...);之后win.openInputChannel(outInputChannel);
- 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());
}