Loading include/input/Input.h +7 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,13 @@ constexpr int32_t VERIFIED_KEY_EVENT_FLAGS = AKEY_EVENT_FLAG_CANCELED; constexpr int32_t VERIFIED_MOTION_EVENT_FLAGS = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED; /** * This flag indicates that the point up event has been canceled. * Typically this is used for palm event when the user has accidental touches. * TODO: Adjust flag to public api */ constexpr int32_t AMOTION_EVENT_FLAG_CANCELED = 0x20; enum { /* Used when a motion event is not associated with any display. * Typically used for non-pointer events. */ Loading services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp +17 −4 Original line number Diff line number Diff line Loading @@ -236,6 +236,20 @@ void MultiTouchInputMapper::process(const RawEvent* rawEvent) { mMultiTouchMotionAccumulator.process(rawEvent); } std::optional<int32_t> MultiTouchInputMapper::getActiveBitId( const MultiTouchMotionAccumulator::Slot& inSlot) { if (mHavePointerIds) { int32_t trackingId = inSlot.getTrackingId(); for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty();) { int32_t n = idBits.clearFirstMarkedBit(); if (mPointerTrackingIdMap[n] == trackingId) { return std::make_optional(n); } } } return std::nullopt; } void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { size_t inCount = mMultiTouchMotionAccumulator.getSlotCount(); size_t outCount = 0; Loading @@ -250,10 +264,9 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { } if (inSlot->getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM) { if (!mCurrentMotionAborted) { ALOGI("Canceling touch gesture from device %s because the palm event was detected", getDeviceName().c_str()); cancelTouch(when); std::optional<int32_t> id = getActiveBitId(*inSlot); if (id) { outState->rawPointerData.canceledIdBits.markBit(id.value()); } continue; } Loading services/inputflinger/reader/mapper/MultiTouchInputMapper.h +2 −0 Original line number Diff line number Diff line Loading @@ -103,6 +103,8 @@ protected: bool hasStylus() const override; private: // If the slot is in use, return the bit id. Return std::nullopt otherwise. std::optional<int32_t> getActiveBitId(const MultiTouchMotionAccumulator::Slot& inSlot); MultiTouchMotionAccumulator mMultiTouchMotionAccumulator; // Specifies the pointer id bits that are in use, and their associated tracking id. Loading services/inputflinger/reader/mapper/TouchInputMapper.cpp +16 −6 Original line number Diff line number Diff line Loading @@ -104,6 +104,7 @@ void RawPointerData::copyFrom(const RawPointerData& other) { pointerCount = other.pointerCount; hoveringIdBits = other.hoveringIdBits; touchingIdBits = other.touchingIdBits; canceledIdBits = other.canceledIdBits; for (uint32_t i = 0; i < pointerCount; i++) { pointers[i] = other.pointers[i]; Loading Loading @@ -140,6 +141,7 @@ void CookedPointerData::clear() { pointerCount = 0; hoveringIdBits.clear(); touchingIdBits.clear(); canceledIdBits.clear(); } void CookedPointerData::copyFrom(const CookedPointerData& other) { Loading Loading @@ -1444,10 +1446,11 @@ void TouchInputMapper::sync(nsecs_t when) { #if DEBUG_RAW_EVENTS ALOGD("syncTouch: pointerCount %d -> %d, touching ids 0x%08x -> 0x%08x, " "hovering ids 0x%08x -> 0x%08x", "hovering ids 0x%08x -> 0x%08x, canceled ids 0x%08x", last->rawPointerData.pointerCount, next->rawPointerData.pointerCount, last->rawPointerData.touchingIdBits.value, next->rawPointerData.touchingIdBits.value, last->rawPointerData.hoveringIdBits.value, next->rawPointerData.hoveringIdBits.value); last->rawPointerData.hoveringIdBits.value, next->rawPointerData.hoveringIdBits.value, next->rawPointerData.canceledIdBits.value); #endif processRawTouches(false /*timeout*/); Loading Loading @@ -1892,14 +1895,15 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { // Dispatch pointer up events. while (!upIdBits.isEmpty()) { uint32_t upId = upIdBits.clearFirstMarkedBit(); dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_UP, 0, 0, metaState, buttonState, 0, bool isCanceled = mCurrentCookedState.cookedPointerData.canceledIdBits.hasBit(upId); dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_UP, 0, isCanceled ? AMOTION_EVENT_FLAG_CANCELED : 0, metaState, buttonState, 0, mLastCookedState.cookedPointerData.pointerProperties, mLastCookedState.cookedPointerData.pointerCoords, mLastCookedState.cookedPointerData.idToIndex, dispatchedIdBits, upId, mOrientedXPrecision, mOrientedYPrecision, mDownTime); dispatchedIdBits.clearBit(upId); mCurrentCookedState.cookedPointerData.canceledIdBits.clearBit(upId); } // Dispatch move events if any of the remaining pointers moved from their old locations. Loading Loading @@ -2025,6 +2029,8 @@ void TouchInputMapper::cookPointerData() { mCurrentRawState.rawPointerData.hoveringIdBits; mCurrentCookedState.cookedPointerData.touchingIdBits = mCurrentRawState.rawPointerData.touchingIdBits; mCurrentCookedState.cookedPointerData.canceledIdBits = mCurrentRawState.rawPointerData.canceledIdBits; if (mCurrentCookedState.cookedPointerData.pointerCount == 0) { mCurrentCookedState.buttonState = 0; Loading Loading @@ -3563,7 +3569,11 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32 if (action == AMOTION_EVENT_ACTION_POINTER_DOWN) { action = AMOTION_EVENT_ACTION_DOWN; } else if (action == AMOTION_EVENT_ACTION_POINTER_UP) { if ((flags & AMOTION_EVENT_FLAG_CANCELED) != 0) { action = AMOTION_EVENT_ACTION_CANCEL; } else { action = AMOTION_EVENT_ACTION_UP; } } else { // Can't happen. ALOG_ASSERT(false); Loading services/inputflinger/reader/mapper/TouchInputMapper.h +3 −2 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ struct RawPointerData { uint32_t pointerCount; Pointer pointers[MAX_POINTERS]; BitSet32 hoveringIdBits, touchingIdBits; BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits; uint32_t idToIndex[MAX_POINTER_ID + 1]; RawPointerData(); Loading @@ -90,6 +90,7 @@ struct RawPointerData { inline void clearIdBits() { hoveringIdBits.clear(); touchingIdBits.clear(); canceledIdBits.clear(); } inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; } Loading @@ -102,7 +103,7 @@ struct CookedPointerData { uint32_t pointerCount; PointerProperties pointerProperties[MAX_POINTERS]; PointerCoords pointerCoords[MAX_POINTERS]; BitSet32 hoveringIdBits, touchingIdBits; BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits; uint32_t idToIndex[MAX_POINTER_ID + 1]; CookedPointerData(); Loading Loading
include/input/Input.h +7 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,13 @@ constexpr int32_t VERIFIED_KEY_EVENT_FLAGS = AKEY_EVENT_FLAG_CANCELED; constexpr int32_t VERIFIED_MOTION_EVENT_FLAGS = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED; /** * This flag indicates that the point up event has been canceled. * Typically this is used for palm event when the user has accidental touches. * TODO: Adjust flag to public api */ constexpr int32_t AMOTION_EVENT_FLAG_CANCELED = 0x20; enum { /* Used when a motion event is not associated with any display. * Typically used for non-pointer events. */ Loading
services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp +17 −4 Original line number Diff line number Diff line Loading @@ -236,6 +236,20 @@ void MultiTouchInputMapper::process(const RawEvent* rawEvent) { mMultiTouchMotionAccumulator.process(rawEvent); } std::optional<int32_t> MultiTouchInputMapper::getActiveBitId( const MultiTouchMotionAccumulator::Slot& inSlot) { if (mHavePointerIds) { int32_t trackingId = inSlot.getTrackingId(); for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty();) { int32_t n = idBits.clearFirstMarkedBit(); if (mPointerTrackingIdMap[n] == trackingId) { return std::make_optional(n); } } } return std::nullopt; } void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { size_t inCount = mMultiTouchMotionAccumulator.getSlotCount(); size_t outCount = 0; Loading @@ -250,10 +264,9 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { } if (inSlot->getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM) { if (!mCurrentMotionAborted) { ALOGI("Canceling touch gesture from device %s because the palm event was detected", getDeviceName().c_str()); cancelTouch(when); std::optional<int32_t> id = getActiveBitId(*inSlot); if (id) { outState->rawPointerData.canceledIdBits.markBit(id.value()); } continue; } Loading
services/inputflinger/reader/mapper/MultiTouchInputMapper.h +2 −0 Original line number Diff line number Diff line Loading @@ -103,6 +103,8 @@ protected: bool hasStylus() const override; private: // If the slot is in use, return the bit id. Return std::nullopt otherwise. std::optional<int32_t> getActiveBitId(const MultiTouchMotionAccumulator::Slot& inSlot); MultiTouchMotionAccumulator mMultiTouchMotionAccumulator; // Specifies the pointer id bits that are in use, and their associated tracking id. Loading
services/inputflinger/reader/mapper/TouchInputMapper.cpp +16 −6 Original line number Diff line number Diff line Loading @@ -104,6 +104,7 @@ void RawPointerData::copyFrom(const RawPointerData& other) { pointerCount = other.pointerCount; hoveringIdBits = other.hoveringIdBits; touchingIdBits = other.touchingIdBits; canceledIdBits = other.canceledIdBits; for (uint32_t i = 0; i < pointerCount; i++) { pointers[i] = other.pointers[i]; Loading Loading @@ -140,6 +141,7 @@ void CookedPointerData::clear() { pointerCount = 0; hoveringIdBits.clear(); touchingIdBits.clear(); canceledIdBits.clear(); } void CookedPointerData::copyFrom(const CookedPointerData& other) { Loading Loading @@ -1444,10 +1446,11 @@ void TouchInputMapper::sync(nsecs_t when) { #if DEBUG_RAW_EVENTS ALOGD("syncTouch: pointerCount %d -> %d, touching ids 0x%08x -> 0x%08x, " "hovering ids 0x%08x -> 0x%08x", "hovering ids 0x%08x -> 0x%08x, canceled ids 0x%08x", last->rawPointerData.pointerCount, next->rawPointerData.pointerCount, last->rawPointerData.touchingIdBits.value, next->rawPointerData.touchingIdBits.value, last->rawPointerData.hoveringIdBits.value, next->rawPointerData.hoveringIdBits.value); last->rawPointerData.hoveringIdBits.value, next->rawPointerData.hoveringIdBits.value, next->rawPointerData.canceledIdBits.value); #endif processRawTouches(false /*timeout*/); Loading Loading @@ -1892,14 +1895,15 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { // Dispatch pointer up events. while (!upIdBits.isEmpty()) { uint32_t upId = upIdBits.clearFirstMarkedBit(); dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_UP, 0, 0, metaState, buttonState, 0, bool isCanceled = mCurrentCookedState.cookedPointerData.canceledIdBits.hasBit(upId); dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_UP, 0, isCanceled ? AMOTION_EVENT_FLAG_CANCELED : 0, metaState, buttonState, 0, mLastCookedState.cookedPointerData.pointerProperties, mLastCookedState.cookedPointerData.pointerCoords, mLastCookedState.cookedPointerData.idToIndex, dispatchedIdBits, upId, mOrientedXPrecision, mOrientedYPrecision, mDownTime); dispatchedIdBits.clearBit(upId); mCurrentCookedState.cookedPointerData.canceledIdBits.clearBit(upId); } // Dispatch move events if any of the remaining pointers moved from their old locations. Loading Loading @@ -2025,6 +2029,8 @@ void TouchInputMapper::cookPointerData() { mCurrentRawState.rawPointerData.hoveringIdBits; mCurrentCookedState.cookedPointerData.touchingIdBits = mCurrentRawState.rawPointerData.touchingIdBits; mCurrentCookedState.cookedPointerData.canceledIdBits = mCurrentRawState.rawPointerData.canceledIdBits; if (mCurrentCookedState.cookedPointerData.pointerCount == 0) { mCurrentCookedState.buttonState = 0; Loading Loading @@ -3563,7 +3569,11 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32 if (action == AMOTION_EVENT_ACTION_POINTER_DOWN) { action = AMOTION_EVENT_ACTION_DOWN; } else if (action == AMOTION_EVENT_ACTION_POINTER_UP) { if ((flags & AMOTION_EVENT_FLAG_CANCELED) != 0) { action = AMOTION_EVENT_ACTION_CANCEL; } else { action = AMOTION_EVENT_ACTION_UP; } } else { // Can't happen. ALOG_ASSERT(false); Loading
services/inputflinger/reader/mapper/TouchInputMapper.h +3 −2 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ struct RawPointerData { uint32_t pointerCount; Pointer pointers[MAX_POINTERS]; BitSet32 hoveringIdBits, touchingIdBits; BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits; uint32_t idToIndex[MAX_POINTER_ID + 1]; RawPointerData(); Loading @@ -90,6 +90,7 @@ struct RawPointerData { inline void clearIdBits() { hoveringIdBits.clear(); touchingIdBits.clear(); canceledIdBits.clear(); } inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; } Loading @@ -102,7 +103,7 @@ struct CookedPointerData { uint32_t pointerCount; PointerProperties pointerProperties[MAX_POINTERS]; PointerCoords pointerCoords[MAX_POINTERS]; BitSet32 hoveringIdBits, touchingIdBits; BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits; uint32_t idToIndex[MAX_POINTER_ID + 1]; CookedPointerData(); Loading