diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index fef2f0624..271b5d4d3 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -5843,6 +5843,7 @@ void TouchInputMapper::dispatchPointerStylus(nsecs_t when, uint32_t policyFlags) mPointerSimple.currentProperties.id = 0; mPointerSimple.currentProperties.toolType = mCurrentCookedState.cookedPointerData.pointerProperties[index].toolType; + mLastStylusTime = when; } else { down = false; hovering = false; @@ -5924,6 +5925,11 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL); } } + + if (rejectPalm(when)) { // stylus is currently active + mPointerSimple.reset(); + return; + } if (mPointerSimple.down && !down) { mPointerSimple.down = false; @@ -6045,6 +6051,9 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32 const PointerProperties* properties, const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits, int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime) { + + if (rejectPalm(when)) return; + PointerCoords pointerCoords[MAX_POINTERS]; PointerProperties pointerProperties[MAX_POINTERS]; uint32_t pointerCount = 0; @@ -6118,6 +6127,13 @@ void TouchInputMapper::fadePointer() { } } +nsecs_t TouchInputMapper::mLastStylusTime = 0; + +bool TouchInputMapper::rejectPalm(nsecs_t when) { + return (when - mLastStylusTime < mConfig.stylusPalmRejectionTime) && + mPointerSimple.currentProperties.toolType != AMOTION_EVENT_TOOL_TYPE_STYLUS; +} + void TouchInputMapper::cancelTouch(nsecs_t when) { abortPointerUsage(when, 0 /*policyFlags*/); abortTouches(when, 0 /* policyFlags*/); diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/InputReader.h index b73fe61e2..3b783c1e9 100644 --- a/services/inputflinger/InputReader.h +++ b/services/inputflinger/InputReader.h @@ -230,6 +230,9 @@ struct InputReaderConfiguration { // True to show the location of touches on the touch screen as spots. bool showTouches; + + // Ignore finger touches this long after the stylus has been used (including hover) + nsecs_t stylusPalmRejectionTime; InputReaderConfiguration() : virtualKeyQuietTime(0), @@ -247,6 +250,7 @@ struct InputReaderConfiguration { pointerGestureSwipeMaxWidthRatio(0.25f), pointerGestureMovementSpeedRatio(0.8f), pointerGestureZoomSpeedRatio(0.3f), + stylusPalmRejectionTime(50 * 10000000LL), // 50 ms showTouches(false) { } bool getDisplayInfo(bool external, DisplayViewport* outViewport) const; @@ -1787,6 +1791,9 @@ private: VelocityControl mPointerVelocityControl; VelocityControl mWheelXVelocityControl; VelocityControl mWheelYVelocityControl; + + // The time the stylus event was processed by any TouchInputMapper + static nsecs_t mLastStylusTime; void resetExternalStylus(); void clearStylusDataPendingFlags(); @@ -1853,6 +1860,8 @@ private: const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y); static void assignPointerIds(const RawState* last, RawState* current); + + bool rejectPalm(nsecs_t when); };