| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 移动开发 -> Input系统学习-----injectInputEvent注入事件调用流程 -> 正文阅读 |
|
[移动开发]Input系统学习-----injectInputEvent注入事件调用流程 |
input命令可以用来注入事件,代码在frameworks/base/cmds/input/src/com/android/commands/input/Input.java 注入点击等触碰事件时,在Android 10版本后还可以通过-d来指定displayId,这个对多屏手机具有测试参考作用。 InputManager的injectInputEvent方法最终调用到InputDispatcher::injectInputEvent int32_t InputDispatcher::injectInputEvent(const InputEvent* event, int32_t displayId, ??????? int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis, ??????? uint32_t policyFlags) { enqueueInboundEventLocked(entry); ------? mInboundQueue.enqueueAtTail(entry); 这里调用到enqueueInboundEventLocked,屏幕的触碰事件也是调用到enqueueInboundEventLocked,是通过TouchInputMapper::dispatchMotion调用到的 void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source, ??????? int32_t action, int32_t flags, int32_t metaState, int32_t buttonState, int32_t edgeFlags, ??????? const PointerProperties* properties, const PointerCoords* coords, ??????? const uint32_t* idToIndex, BitSet32 idBits, ??????? int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime) { ??? NotifyMotionArgs args(when, getDeviceId(), source, policyFlags, ??????????? action, flags, metaState, buttonState, edgeFlags, ??????????? mViewport.displayId, pointerCount, pointerProperties, pointerCoords, ??????????? xPrecision, yPrecision, downTime); ??? getListener()->notifyMotion(&args); } void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) { … ??????? if (shouldSendMotionToInputFilterLocked(args)) { ??????????? mLock.unlock(); ??????????? MotionEvent event; ??????????? event.initialize(args->deviceId, args->source, args->action, args->flags, ???? ???????????????args->edgeFlags, args->metaState, args->buttonState, 0, 0, ??????????????????? args->xPrecision, args->yPrecision, ??????????????????? args->downTime, args->eventTime, ??????????????????? args->pointerCount, args->pointerProperties, args->pointerCoords); ??????????? policyFlags |= POLICY_FLAG_FILTERED; ??????????? if (!mPolicy->filterInputEvent(&event, policyFlags)) { ??????????????? return; // event was consumed by the filter ??????????? } ??????????? mLock.lock(); ??????? } ??????? // Just enqueue a new motion event. ??????? MotionEntry* newEntry = new MotionEntry(args->eventTime, ??????????????? args->deviceId, args->source, policyFlags, ??????????????? args->action, args->flags, args->metaState, args->buttonState, ???????? ???????args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime, ??????????????? args->displayId, ??????????????? args->pointerCount, args->pointerProperties, args->pointerCoords, 0, 0); ??????? needWake = enqueueInboundEventLocked(newEntry); ??????? mLock.unlock(); ??? } // release lock 都有enqueueInboundEventLocked调用, enqueueInboundEventLocked会触发dispatchOnce中的调用 loop流程 bool InputDispatcherThread::threadLoop() { ??? mDispatcher->dispatchOnce(); ??? return true; } void InputDispatcher::dispatchOnce() 有指令时调用 ??????? if (!haveCommandsLocked()) { ??????????? dispatchOnceInnerLocked(&nextWakeupTime); ??????? } bool InputDispatcher::haveCommandsLocked() const { ??? return !mCommandQueue.isEmpty(); } dispatchOnceInnerLocked void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) { dispatchMotionLocked event是从mPendingEvent里面获取的 bool InputDispatcher::dispatchMotionLocked( ??????? nsecs_t currentTime, MotionEntry* entry, DropReason* dropReason, nsecs_t* nextWakeupTime) { findTouchedWindowTargetsLocked 获取 inputTargets 然后,dispatchEventLocked(currentTime, entry, inputTargets); ??? 里面调用connect进行了分发 void InputDispatcher::dispatchEventLocked(nsecs_t currentTime, ??????? EventEntry* eventEntry, const Vector& inputTargets) { #if DEBUG_DISPATCH_CYCLE ??? ALOGD("dispatchEventToCurrentInputTargets"); #endif ??? ALOG_ASSERT(eventEntry->dispatchInProgress); // should already have been set to true ??? pokeUserActivityLocked(eventEntry); ??? for (size_t i = 0; i < inputTargets.size(); i++) { ??????? const InputTarget& inputTarget = inputTargets.itemAt(i); ??????? ssize_t connectionIndex = getConnectionIndexLocked(inputTarget.inputChannel); ??????? if (connectionIndex >= 0) { ??????????? sp connection = mConnectionsByFd.valueAt(connectionIndex); ??????????? prepareDispatchCycleLocked(currentTime, connection, eventEntry, &inputTarget); ??????? } else { #if DEBUG_FOCUS ??????????? ALOGD("Dropping event delivery to target with channel '%s' because it " ??????????????????? "is no longer registered with the input dispatcher.", ??????????????????? inputTarget.inputChannel->getName().string()); #endif ??????? } ??? } } 参考资料 InputManagerService分析一:IMS的启动与事件传递 |
|
移动开发 最新文章 |
Vue3装载axios和element-ui |
android adb cmd |
【xcode】Xcode常用快捷键与技巧 |
Android开发中的线程池使用 |
Java 和 Android 的 Base64 |
Android 测试文字编码格式 |
微信小程序支付 |
安卓权限记录 |
知乎之自动养号 |
【Android Jetpack】DataStore |
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/25 4:26:16- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |