From 547a06b50fa97cd079851f80d0d5aa5297cbb040 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Thu, 27 Nov 2014 14:06:04 +0100 Subject: Added more anti-falsing logic We now discard unlock attempts with multiple pointers. Bug: 18544191 Change-Id: Id2e7bca0353b3f85aa193f6a5c793b93ca0776e3 --- .../systemui/statusbar/phone/PanelView.java | 109 +++++++++++++-------- 1 file changed, 69 insertions(+), 40 deletions(-) (limited to 'packages') diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java index 47034e2..4bbf690 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java @@ -73,6 +73,7 @@ public abstract class PanelView extends FrameLayout { private boolean mTouchAboveFalsingThreshold; private int mUnlockFalsingThreshold; private boolean mTouchStartedInEmptyArea; + private boolean mMotionAborted; private ValueAnimator mHeightAnimator; private ObjectAnimator mPeekAnimator; @@ -208,7 +209,8 @@ public abstract class PanelView extends FrameLayout { @Override public boolean onTouchEvent(MotionEvent event) { - if (mInstantExpanding || mTouchDisabled) { + if (mInstantExpanding || mTouchDisabled + || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) { return false; } @@ -226,8 +228,8 @@ public abstract class PanelView extends FrameLayout { pointerIndex = 0; mTrackingPointer = event.getPointerId(pointerIndex); } - final float y = event.getY(pointerIndex); final float x = event.getX(pointerIndex); + final float y = event.getY(pointerIndex); if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { mGestureWaitForTouchSlop = mExpandedHeight == 0f; @@ -244,6 +246,7 @@ public abstract class PanelView extends FrameLayout { mPanelClosedOnDown = mExpandedHeight == 0.0f; mHasLayoutedSinceDown = false; mUpdateFlingOnLayout = false; + mMotionAborted = false; mPeekTouching = mPanelClosedOnDown; mTouchAboveFalsingThreshold = false; if (mVelocityTracker == null) { @@ -276,7 +279,13 @@ public abstract class PanelView extends FrameLayout { mInitialTouchX = newX; } break; - + case MotionEvent.ACTION_POINTER_DOWN: + if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) { + mMotionAborted = true; + endMotionEvent(event, x, y, true /* forceCancel */); + return false; + } + break; case MotionEvent.ACTION_MOVE: float h = y - mInitialTouchY; @@ -318,26 +327,35 @@ public abstract class PanelView extends FrameLayout { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: - mTrackingPointer = -1; trackMovement(event); - if ((mTracking && mTouchSlopExceeded) - || Math.abs(x - mInitialTouchX) > mTouchSlop - || Math.abs(y - mInitialTouchY) > mTouchSlop - || event.getActionMasked() == MotionEvent.ACTION_CANCEL) { - float vel = 0f; - float vectorVel = 0f; - if (mVelocityTracker != null) { - mVelocityTracker.computeCurrentVelocity(1000); - vel = mVelocityTracker.getYVelocity(); - vectorVel = (float) Math.hypot( - mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity()); - } - boolean expand = flingExpands(vel, vectorVel) - || event.getActionMasked() == MotionEvent.ACTION_CANCEL; - onTrackingStopped(expand); - DozeLog.traceFling(expand, mTouchAboveFalsingThreshold, - mStatusBar.isFalsingThresholdNeeded(), - mStatusBar.isScreenOnComingFromTouch()); + endMotionEvent(event, x, y, false /* forceCancel */); + break; + } + return !waitForTouchSlop || mTracking; + } + + private void endMotionEvent(MotionEvent event, float x, float y, boolean forceCancel) { + mTrackingPointer = -1; + if ((mTracking && mTouchSlopExceeded) + || Math.abs(x - mInitialTouchX) > mTouchSlop + || Math.abs(y - mInitialTouchY) > mTouchSlop + || event.getActionMasked() == MotionEvent.ACTION_CANCEL + || forceCancel) { + float vel = 0f; + float vectorVel = 0f; + if (mVelocityTracker != null) { + mVelocityTracker.computeCurrentVelocity(1000); + vel = mVelocityTracker.getYVelocity(); + vectorVel = (float) Math.hypot( + mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity()); + } + boolean expand = flingExpands(vel, vectorVel) + || event.getActionMasked() == MotionEvent.ACTION_CANCEL + || forceCancel; + onTrackingStopped(expand); + DozeLog.traceFling(expand, mTouchAboveFalsingThreshold, + mStatusBar.isFalsingThresholdNeeded(), + mStatusBar.isScreenOnComingFromTouch()); // Log collapse gesture if on lock screen. if (!expand && mStatusBar.getBarState() == StatusBarState.KEYGUARD) { float displayDensity = mStatusBar.getDisplayDensity(); @@ -347,24 +365,21 @@ public abstract class PanelView extends FrameLayout { EventLogConstants.SYSUI_LOCKSCREEN_GESTURE_SWIPE_UP_UNLOCK, heightDp, velocityDp); } - fling(vel, expand); - mUpdateFlingOnLayout = expand && mPanelClosedOnDown && !mHasLayoutedSinceDown; - if (mUpdateFlingOnLayout) { - mUpdateFlingVelocity = vel; - } - } else { - boolean expands = onEmptySpaceClick(mInitialTouchX); - onTrackingStopped(expands); - } + fling(vel, expand); + mUpdateFlingOnLayout = expand && mPanelClosedOnDown && !mHasLayoutedSinceDown; + if (mUpdateFlingOnLayout) { + mUpdateFlingVelocity = vel; + } + } else { + boolean expands = onEmptySpaceClick(mInitialTouchX); + onTrackingStopped(expands); + } - if (mVelocityTracker != null) { - mVelocityTracker.recycle(); - mVelocityTracker = null; - } - mPeekTouching = false; - break; + if (mVelocityTracker != null) { + mVelocityTracker.recycle(); + mVelocityTracker = null; } - return !waitForTouchSlop || mTracking; + mPeekTouching = false; } private int getFalsingThreshold() { @@ -389,7 +404,8 @@ public abstract class PanelView extends FrameLayout { @Override public boolean onInterceptTouchEvent(MotionEvent event) { - if (mInstantExpanding) { + if (mInstantExpanding + || (mMotionAborted && event.getActionMasked() != MotionEvent.ACTION_DOWN)) { return false; } @@ -425,6 +441,7 @@ public abstract class PanelView extends FrameLayout { mTouchStartedInEmptyArea = !isInContentBounds(x, y); mTouchSlopExceeded = false; mJustPeeked = false; + mMotionAborted = false; mPanelClosedOnDown = mExpandedHeight == 0.0f; mHasLayoutedSinceDown = false; mUpdateFlingOnLayout = false; @@ -442,7 +459,15 @@ public abstract class PanelView extends FrameLayout { mInitialTouchY = event.getY(newIndex); } break; - + case MotionEvent.ACTION_POINTER_DOWN: + if (mStatusBar.getBarState() == StatusBarState.KEYGUARD) { + mMotionAborted = true; + if (mVelocityTracker != null) { + mVelocityTracker.recycle(); + mVelocityTracker = null; + } + } + break; case MotionEvent.ACTION_MOVE: final float h = y - mInitialTouchY; trackMovement(event); @@ -461,6 +486,10 @@ public abstract class PanelView extends FrameLayout { break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: + if (mVelocityTracker != null) { + mVelocityTracker.recycle(); + mVelocityTracker = null; + } break; } return false; -- cgit v1.1