Android InputReader 输入事件处理流程

Android系统输入事件产生的底层主要是输入子系统,Android 中的输入设备有很多,例如屏幕,鼠标,键盘等都是输入设备,对于应用开发者,接触最多的也就是屏幕了。

1. 当输入设备可用时,Linux会在 /dev/input 中创建对应的设备节点。

2. 用户操作输入设备就会产生各种事件,这些事件的原始信息就会被 Linux内核中的输入子系统采集,原始信息由 Kernel space 的驱动层一直传递到设备结点。

3. InputReader读取设备节点数据并对输入事件信息进行加工处理,加工处理后的事件会交给 InputDispatcher 来处理。

以下是InputReader创建InputDevice设备、读取事件和交给InputDispatcher事件的调用流程

@frameworks/native/services/inputflinger/reader/InputReader.cpp
InputReader::start
    loopOnce()
        processEventsLocked(mEventBuffer, count);
            case EventHubInterface::DEVICE_ADDED: addDeviceLocked(rawEvent->when, rawEvent->deviceId);  //添加设备
                InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId);
                if(identifier.vendor == 8183 && identifier.product == 4084) { return; }  //根据keyboard设备类型判断,不添加设备,以免vd启动异常
                std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier)
@frameworks/native/services/inputflinger/reader/InputDevice.cpp                
                    device->addEventHubDevice(eventHubId);  //添加触摸光标设备
                        if (classes.test(InputDeviceClass::BATTERY) || classes.test(InputDeviceClass::LIGHT)) {  mController = std::make_unique<PeripheralController>(*contextPtr); }
                        if (classes.test(InputDeviceClass::CURSOR)) { mappers.push_back(std::make_unique<CursorInputMapper>(*contextPtr)); }
                        //addDeviceLocked Device added: id=3, eventHubId=8, name='hyn_ts', descriptor='dd768709fe8e1221a31cd1cbe2fb6da013ae6c46',sources=0x00002002
                        mDevices.insert({eventHubId, std::make_pair(std::move(contextPtr), std::move(mappers))});            
            processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
                auto deviceIt = mDevices.find(eventHubId);
                device->process(rawEvents, count);
@frameworks/native/services/inputflinger/reader/InputDevice.cpp
                    for_each_mapper_in_subdevice(rawEvent->deviceId, [rawEvent](InputMapper& mapper)
                        auto deviceIt = mDevices.find(eventHubDevice);   //eventHubDevice=8
@frameworks/native/services/inputflinger/reader/mapper/CursorInputMapper.cpp                        
                        mapper.process(rawEvent);  //CursorInputMapper::process
                            mCursorButtonAccumulator.process(rawEvent);
                            mCursorMotionAccumulator.process(rawEvent);
                            mCursorScrollAccumulator.process(rawEvent);
                                sync(rawEvent->when, rawEvent->readTime);
                                    getListener()->notifyMotion(&args);
                                        InputDispatcher::notifyMotion
                                            mPolicy->interceptMotionBeforeQueueing(args->displayId, args->eventTime, /*byref*/ policyFlags);
                                                needWake = enqueueInboundEventLocked(std::move(newEntry));
                                                    mInboundQueue.push_back(std::move(newEntry)); //放入mInboundQueue队列

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛文旺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值