Android应用程序的消息处理机制学习心得(一)
InputManager类处理过程:
InputManager 先创建InputDispatcher 和InputReader对象,并把InputReader和InputDispatcher对象为参数再创建两个线程对象,InputReaderThread 以及InputDispatcherThread。InputManager::start()启动两个线程。
InputReader类处理过程:
InputReader::loopOnce()--->EventHub::getEvents()--->InputReader::processEventsLocked()---
--->InputReader::processEventsForDeviceLocked()--->InputDevice::process()--->TouchInputMapper::process()--
--->TouchInputMapper::sync()--->TouchInputMapper::dispatchTouches()
EventHub类处理过程:
getEvents()函数负责处理事件,可以处理不止一个事件,这个之前版本源码不同,scanDirLock()负责扫描设备,openDeviceLock()负责生成设备相关信息,新版函数都在后面加了Lock。
读过一些源码之后,我思考了两个问题
1.有些文章说InputReaderThread 和InputDispatcherThread都会在没有事件时进入睡眠状态。研读源码发现InputDispatcher::dispatchOnce()以及mLooper->pollOnce()确实在没有事件需要处理时进行睡眠,但研读InputRedaer源码时,没有了解其如何睡眠。
2.InputReader是如何和InputDispatcher交互的?因为老版本源码,InputReader有getDispatcher()函数,但新版本替换为getListener()。
继续研读代码发现答案:
1.InputReaderThread::loopOnce会休眠到EventHub::getEvents()中的epoll_wait(),epoll_wait()是系统调用,负责轮询IO的。
2.getListener()是一个队列 ,队列里面是一个Inputdispatcher对象。
明天继续研读,写写笔记免得自己忘掉。
- 01-11全球最受赞誉公司揭晓:苹果连续九年第一
- 12-09罗伯特·莫里斯:让黑客真正变黑
- 12-09谁闯入了中国网络?揭秘美国绝密黑客小组TA
- 12-09警示:iOS6 惊现“闪退”BUG
- 03-08消息称微软开发内部AI推理模型,或将成为Op
- 03-08美国法院驳回马斯克请求,未阻止OpenAI转型
- 03-08饿了么成立即时配送算法专家委员会 持续全局
- 03-08长安汽车:预计今年底长安飞行汽车将完成试
- 03-08谷歌推出虚拟试穿、AR美妆新功能