12. 输入系统_APP跟输入系统建立联系_InputChannel和Connection
核心: socketpair // 第9课第3节_输入系统_必备Linux编程知识_任意进程双向通信(scoketpair+binder)

对于每个APP在WindowManagerService中都有个WindowState与之对应,当新建一个APP的时候通过binder系统调用addToDisplay把自己告诉给WindowManagerService,同时会导致addWindow被调用,其会创建WindowState来表示这个应用程序,并创建一个socketpair得到两个文件句柄fd0和fd1,同时把fd1返回给应用程序,把fd0封装成Inputchannel,这个Inputchannel会放入到WindowState中,也会通过registerInputchannel注册给InputDispatcher,在InputDispatcher中会根据Inputchannel来构造一个Connection,把这个创建出来的Connection放入KeyedVector(KeyedVector<int,sp<Connection>>  mConnectionsByFd),这个InputDispatcher得到数据后放入某个Connection.Inputchannel.fd0中,APP端从fd1取得数据;APP在收到返回的fd1后,把其封装成Inputchannel,在把其封装成WindowInputEventReceiver,最后把fd1放入Looper中,使用epoll来查询等待。

对于每个能接受输入事件的应用程序,其在InputDispatcher中都有对应的connection,InputDispatcher需要把数据发送给应用程序的时候,需要找出当前在屏幕最前面的是哪个应用程序,然后找到他的connection,把数据输入他的fd就可以

InputReader线程、InputDispatcher线程、WindowManagerService线程都属于SystemServer进程中,线程可以直接通讯,不需要binder

应用程序调用:

handleResumeActivity

  ViewManager wm =a.getWindowManager()//这个WindowManager和上面说的WindowManagerService不是一个东西

  wm.addView(decor,l);

    mGlobal.addView()

      root = new ViewRootlmpl()

      root.setView()

        mWindowSession.addToDisplay(...,mInputChannel)//该函数是分界线,下面的内容是在WindowManagerService线程中执行,前面的都是在应用程序中执行的,mWindowSession是一个远程服务的引用,mInputChannel包含有返回的文件句柄fd1

          mRemote.transact(Stub.TRANSACTION_addToDisplay,...)

            onTransact

              addToDisplay  

                addWindow

                  InputChannel[] inputChannels = InputChannel.openInputChannelPair(name)//得到fd0和fd1

                    nativeOpenInputChannelPair

                      android_view_InputChannel_nativeOpenInputChannelPair

                        openInputChannelPair

                          socketpair

                  win.setInputChannel(inputChannels[0])

                  inputChannels[1].transferTo(outInputChannel)

                  mInputManager.registerInputChannel //把inputChannels[1]告诉InputDispatcher,WindowManagerService与InputDispatcher同属一个进程,所有可以直接调用 

                    nativeRegisterInputChannel

                      im->registerInputChannel

                        registerInputChannel

                          connection = new Connection(inputChannel,inputWindowHandle,monitor)

                            int fd = inputChannel->getFd()

                            mConnectionByFd.add(fd,connection);

                            mLooker->addFd(fd,0,ALOOPER_EVENT_INPUT,....)

              _arg6.writeToParcel

                parcel->writeDupFileDescriptor(inputChannel->getFd())//把fd1写入binder驱动

          outInputChannel.readFromParcel(_reply)

            int rawFd = parcel->readFileDescriptor();//binder驱动中读到fd1
            int dupFd = dup(rawFd);
            InputChannel* inputChannel = new InputChannel(name, dupFd);
            NativeInputChannel* nativeInputChannel = new NativeInputChannel(inputChannel);
            android_view_InputChannel_setNativeInputChannel(env, obj, nativeInputChannel);

        mInputEventReceiver = new WindowInputEventReceiver()

          InputEventReceiver  

            nativeInit

              receiver = new NativeInputEventReceiver

              receiver->initialize()

                setFdEvents

                  mMessageQueue->getLooper()->addFd(fd,0,events,this,NULL)                  

13. 输入系统_Dispatcher线程_分发dispatch

dispatch线程中有mConnectionsByFd,其中有一些列的connection,connection中有inputchannel.fd0,通过socketpair与APP的fd1通讯

分发的步骤(具体情景分析见uml图中的dispatch_input_event)

(1)查找目标

  向WindowManagerService查询当前Window获得对应的Connection

(2)把输入事件放入Connection的队列outboundQueue

(3)从队列中取出事件构造为InputMessage发送

10.9 android输入系统_APP跟输入系统建立联系和Dispatcher线程_分发dispatch的更多相关文章

  1. Android系统--输入系统(十七)Dispatcher线程_分发dispatch

    Android系统--输入系统(十七)Dispatcher线程_分发dispatch 1. 回顾 InputRead线程从输入设备当中得到输入事件 对于读到输入事件稍作处理,比如紧急事件,来电时候按下 ...

  2. 10.4 android输入系统_框架、编写一个万能模拟输入驱动程序、reader/dispatcher线程启动过程源码分析

    1. 输入系统框架 android输入系统官方文档 // 需FQhttp://source.android.com/devices/input/index.html <深入理解Android 卷 ...

  3. 10.13 android输入系统_多点触摸驱动理论与框架

    1.多点触摸驱动理论 驱动程序仅上报多个触点的位置就可以,是放大还是缩小由应用程序控制 对于多点触摸驱动在linux系统中有个输入子系统,其已经实现了open/read/write等接口 我们只需要实 ...

  4. 10.7 android输入系统_Dispatcher线程情景分析_Reader线程传递事件和dispatch前处理

    android输入系统C++最上层文件是com_android_serve_input_InputManagerService.cpp global key:按下按键,启动某个APP可以自己指定,修改 ...

  5. 10.6 android输入系统_Dispatcher线程_总体框架

    图解Android - Android GUI 系统 (5) - Android的Event Input System - 漫天尘沙 - 博客园.htm // 关注里面的Dispatcher处理流程h ...

  6. 10.5 android输入系统_Reader线程_使用EventHub读取事件和核心类及配置文件_实验_分析

    4. Reader线程_使用EventHub读取事件 使用inotify监测/dev/input下文件的创建和删除 使用epoll监测有无数据上报 细节: a.fd1 = inotify_init(& ...

  7. Android底层开发之Linux输入子系统要不要推断系统休眠状态上报键值

    Android底层开发之Linux输入子系统要不要推断系统休眠状态上报键值 题外话:一个问题研究到最后,那边记录文档的前半部分基本上都是没用的,甚至是错误的. 重点在最后,前边不过一些假想猜測. ht ...

  8. Android系统--输入系统(八)Reader线程_使用EventHub读取事件

    Android系统--输入系统(八)Reader线程_使用EventHub读取事件 1. Reader线程工作流程 获得事件 size_t count = mEventHub->getEvent ...

  9. Android系统--输入系统(九)Reader线程_核心类及配置文件

    Android系统--输入系统(九)Reader线程_核心类及配置文件 1. Reader线程核心类--EventHub 1.1 Reader线程核心结构体 实例化对象:mEventHub--表示多个 ...

随机推荐

  1. [ Java ] [ Eclipse ] 加速 Eclipse 載入速度-轉載

    加速 Eclipse 載入速度-轉載 https://read01.com/NJjNOB.html

  2. MVC和MTV设计模式

    1.MVC MVC最初是由施乐公司旗下的帕罗奥多研究中心中的一位研究人员给 smalltalk语言发明的一中软件设计模式. MVC概述:MVC全名是ModelViewController,是模型(mo ...

  3. ABAP调用外部WebService

    TCode:se80 选择 Package,输入我们自己的开发包,后回车 右击 开发包名称,选择菜单 出现创建向导窗体 选择"Service Consumer",点击 继续 选择& ...

  4. 动态库dll使用module.def文件导出函数(像静态库一样使用)

    1.新建文件module.def. 2.动态库工程上右键->属性->链接器->输入->模块定义文件编辑它写入module.def 3.下面为module.def实例(smart ...

  5. 暴力破解FTP服务器技术探讨与防范措施

    暴力破解FTP服务器技术探讨与防范措施 随着Internet的发展出现了由于大量傻瓜化黑客工具任何一种黑客攻击手段的门槛都降低了很多但是暴力破解法的工具制作都已经非常容易大家通常会认为暴力破解攻击只是 ...

  6. Linux架设Jsp环境

    本文已发表在2010年<网管员世界> 650) this.width=650;" onclick="window.open("http://blog.51ct ...

  7. Winform 获取相对路径 C#

    ///获取相对路径 ///例如:System.Windows.Forms.Application.StartupPath = "E:\App\CheckingMachine\QueryMac ...

  8. C# 异步延时执行

    https://blog.csdn.net/xiawu1990/article/details/78350253?utm_source=blogxgwz7 var t = Task.Run(async ...

  9. 【AIM Tech Round 4 (Div. 2) C】Sorting by Subsequences

    [链接]http://codeforces.com/contest/844/problem/C [题意] 水题,没有记录意义 [题解] 排序之后,记录每个数字原来在哪里就好. 可以形成环的. 环的个数 ...

  10. libiconv 支持的编码

    libiconv 支持的编码 php 中的 iconv() 函数常用来作编码转换用.作一些不同编码的动态数据的转换时常遇到一些未知编码的数据,这时 iconv() 支持那些编码转换就很重要. 刚开始, ...