From e6f6ad04ed1e0e73fc260a0100d5759a0456fdd6 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Mon, 22 Jun 2015 16:18:21 +0100 Subject: [PATCH] DO NOT MERGE. Cancel touches as well as pointer gestures. Bug: 19264992 Change-Id: If48e0953b972c9d69f516906adf7c6faf67e3eb8 --- services/inputflinger/InputReader.cpp | 29 ++++++++++++++++++++++++--- services/inputflinger/InputReader.h | 4 ++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index ccf8ced55..006ec6bb8 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -3721,6 +3721,7 @@ void TouchInputMapper::reset(nsecs_t when) { mLastMouseIdBits.clear(); mPointerUsage = POINTER_USAGE_NONE; mSentHoverEnter = false; + mCurrentMotionAborted = false; mDownTime = 0; mCurrentVirtualKey.down = false; @@ -3874,10 +3875,15 @@ void TouchInputMapper::sync(nsecs_t when) { mCurrentCookedPointerData.idToIndex, mCurrentCookedPointerData.touchingIdBits); } + if (!mCurrentMotionAborted) { + dispatchHoverExit(when, policyFlags); + dispatchTouches(when, policyFlags); + dispatchHoverEnterAndMove(when, policyFlags); + } - dispatchHoverExit(when, policyFlags); - dispatchTouches(when, policyFlags); - dispatchHoverEnterAndMove(when, policyFlags); + if (mCurrentCookedPointerData.pointerCount == 0) { + mCurrentMotionAborted = false; + } } // Synthesize key up from raw buttons if needed. @@ -4018,6 +4024,22 @@ void TouchInputMapper::dispatchVirtualKey(nsecs_t when, uint32_t policyFlags, getListener()->notifyKey(&args); } +void TouchInputMapper::abortTouches(nsecs_t when, uint32_t policyFlags) { + BitSet32 currentIdBits = mCurrentCookedPointerData.touchingIdBits; + if (!currentIdBits.isEmpty()) { + int32_t metaState = getContext()->getGlobalMetaState(); + int32_t buttonState = mCurrentButtonState; + dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_CANCEL, 0, + metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE, + mCurrentCookedPointerData.pointerProperties, + mCurrentCookedPointerData.pointerCoords, + mCurrentCookedPointerData.idToIndex, + currentIdBits, -1, + mOrientedXPrecision, mOrientedYPrecision, mDownTime); + mCurrentMotionAborted = true; + } +} + void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) { BitSet32 currentIdBits = mCurrentCookedPointerData.touchingIdBits; BitSet32 lastIdBits = mLastCookedPointerData.touchingIdBits; @@ -5733,6 +5755,7 @@ void TouchInputMapper::fadePointer() { void TouchInputMapper::cancelTouch(nsecs_t when) { abortPointerUsage(when, 0 /*policyFlags*/); + abortTouches(when, 0 /* policyFlags*/); } bool TouchInputMapper::isPointInsideSurface(int32_t x, int32_t y) { diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/InputReader.h index 34f20af47..62cd36a57 100644 --- a/services/inputflinger/InputReader.h +++ b/services/inputflinger/InputReader.h @@ -1364,6 +1364,9 @@ protected: // True if we sent a HOVER_ENTER event. bool mSentHoverEnter; + // Is the current stream of direct touch events aborted + bool mCurrentMotionAborted; + // The time the primary pointer last went down. nsecs_t mDownTime; @@ -1688,6 +1691,7 @@ private: void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage); void abortPointerUsage(nsecs_t when, uint32_t policyFlags); + void abortTouches(nsecs_t when, uint32_t policyFlags); void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout); void abortPointerGestures(nsecs_t when, uint32_t policyFlags);