在input事件分发的时候,会调用到
int32_t InputDispatcher::findTouchedWindowTargetsLocked
这个地方写的比较复杂,在点击后,滑动手指,可以查看log发现,这个方法会不断的被调用。
一些点击事件被drop,也是这里处理的,
点击的时候,newGesture 为true
1204 bool newGesture = (maskedAction == AMOTION_EVENT_ACTION_DOWN 1205 || maskedAction == AMOTION_EVENT_ACTION_SCROLL 1206 || isHoverAction);
而滑动和up手指的时候,newGesture 为false,newGesture 影响后面的处理逻辑
1237 if (newGesture || (isSplit && maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN)) { 1238 /* Case 1: New splittable pointer going down, or need target for hover or scroll. */
1323 } else { 1324 /* Case 2: Pointer move, up, cancel or non-splittable pointer down. */ 1325 1326 // If the pointer is not currently down, then ignore the event. 1327 if (! mTempTouchState.down) { 1328#if DEBUG_FOCUS 1329 ALOGD("Dropping event because the pointer is not down or we previously " 1330 "dropped the pointer down event."); 1331#endif 1332 injectionResult = INPUT_EVENT_INJECTION_FAILED; 1333 goto Failed; 1334 }
这里mTempTouchState.down又影响到处理流程。
mTempTouchState的代码逻辑比较混乱,
可以添加log查看
mTempTouchState.down值的变化过程。
在多点点击,input事件注入的时候,mTempTouchState.down值是怎么变化的呢?
1513 // Update final pieces of touch state if the injector had permission. 1514 if (injectionPermission == INJECTION_PERMISSION_GRANTED) { 1515 if (!wrongDevice) { 1516 if (switchedDevice) { 1517#if DEBUG_FOCUS 1518 ALOGD("Conflicting pointer actions: Switched to a different device."); 1519#endif 1520 *outConflictingPointerActions = true; 1521 } 1522 1523 if (isHoverAction) {
1538 } else if (maskedAction == AMOTION_EVENT_ACTION_UP 1539 || maskedAction == AMOTION_EVENT_ACTION_CANCEL) { 1540 // All pointers up or canceled. 1541 mTempTouchState.reset();
这里可以重点关注下
reset方法会把down设置为false
4519void InputDispatcher::TouchState::reset() { 4520 down = false; 4521 split = false; 4522 deviceId = -1; 4523 source = 0; 4524 displayId = -1; 4525 windows.clear(); 4526}