关于linux input device输入子系统架构及android中的框架

关于linux input device输入子系统架构及android中的框架

关于linux input device输入子系统架构及android中的框架

应用app和windowmanagerservice的input event通信方式

在Native层的InputChannel就是一个通道,仅仅是一个通道,仅仅具有通信功能,不包含其他的。至于从数据流动方向,与InputChannel无关。数据流向是由InputPublisher和InputConsumer在组合了InputChannel后决定的。
把InputChannel由应用程序传递到WindowManageService的过程,涉及到的是Binder通信,不是文章的重点,不多说。需要知道的是,mWindowSession.addToDisplay最后会传递到WindowManagerService的addWindow方法。通过代码看看InputChannel是如何使用的,代码如下:
1 public int addWindow(Session session, IWindow client, int seq,
2 WindowManager.LayoutParams attrs, int viewVisibility, int displayId,
3 Rect outContentInsets, InputChannel outInputChannel) {
4 …
5 if (outInputChannel != null && (attrs.inputFeatures
6 & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) {
7 //这个名字是根据对象的hashcode和窗口的一些属性转化为字符串后建立的。
8 String name = win.makeInputChannelName();
9 InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
10 win.setInputChannel(inputChannels[0]);
11 inputChannels[1].transferTo(outInputChannel);
12 mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
13 }
14 …
15 }

需要注意的是,InputDispatcher.cpp除了会向PhoneWindowManager.java传递KeyEvent外,例如SW_LID.
正方向传递,还会反方向查询policy。PhoneWindowManager.java作为android.policy的一分子。参见PhoneWindowManager.java:: interceptKeyBeforeDispatching() 和PhoneWindowManager.java:: interceptKeyBeforeQueueing()。 通过返回的ACTION_PASS_TO_USER等来判断是否需要发给app,另外还会查找有无focus app,然后发给它。在SW_LID为LID_CLOSE时屏幕变黑,此时一般按键是不会传到Application的,如果想传特定按键,那么需要更改InputDispatcher::dispatchKeyLocked()函数的逻辑,见dropReason 。

关于linux input device输入子系统架构及android中的框架

EVIOCGRAB功能

关于linux input device输入子系统架构及android中的框架

关于linux input device输入子系统架构及android中的框架

具体请参考我的免费的linux各种驱动开发课程如下:
https://edu.51cto.com/course/17138.html

另外我的相关培训视频请看:
欢迎观看我发布的各个课程: https://edu.51cto.com/lecturer/8896847.html

猜你喜欢

转载自blog.51cto.com/8906847/2367984