OSDN Git Service

Lockscreen: Restrict double taps to prevent falsing
authorAdrian Roos <roosa@google.com>
Wed, 9 Nov 2016 23:56:50 +0000 (15:56 -0800)
committerAdrian Roos <roosa@google.com>
Thu, 10 Nov 2016 16:35:34 +0000 (16:35 +0000)
Further restricts the second tap on ActivateableNotificationView
such that it must occur no further than 0.2in from the first tap.

Bug: 32766052
Change-Id: I033c1abc64c815d519153ced23ac9751471b1d05
Test: Tap notification on lockscreen. Verify that second touch is only accepted near the first tap

packages/SystemUI/res/values/dimens.xml
packages/SystemUI/src/com/android/systemui/classifier/FalsingManager.java
packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java

index fe67808..3041a73 100644 (file)
     <!-- TrustDrawable: Thickness of the circle -->
     <dimen name="trust_circle_thickness">2dp</dimen>
 
+    <!-- How much two taps can be apart to still be recognized as a double tap on the lockscreen -->
+    <dimen name="double_tap_slop">32dp</dimen>
+
     <!-- Margin on the right side of the system icon group on Keyguard. -->
     <fraction name="battery_button_height_fraction">10.5%</fraction>
 
index 664e886..8fc555f 100644 (file)
@@ -313,7 +313,11 @@ public class FalsingManager implements SensorEventListener {
         mDataCollector.onNotificationActive();
     }
 
-    public void onNotificationDoubleTap() {
+    public void onNotificationDoubleTap(boolean accepted, float dx, float dy) {
+        if (FalsingLog.ENABLED) {
+            FalsingLog.i("onNotificationDoubleTap", "accepted=" + accepted
+                    + " dx=" + dx + " dy=" + dy + " (px)");
+        }
         mDataCollector.onNotificationDoubleTap();
     }
 
index bc46548..6b30c0c 100644 (file)
@@ -110,6 +110,10 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
     private float mDownY;
     private final float mTouchSlop;
 
+    private float mActivationX;
+    private float mActivationY;
+    private final float mDoubleTapSlop;
+
     private OnActivatedListener mOnActivatedListener;
 
     private final Interpolator mSlowOutFastInInterpolator;
@@ -171,6 +175,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
     public ActivatableNotificationView(Context context, AttributeSet attrs) {
         super(context, attrs);
         mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
+        mDoubleTapSlop = context.getResources().getDimension(R.dimen.double_tap_slop);
         mSlowOutFastInInterpolator = new PathInterpolator(0.8f, 0.0f, 0.6f, 1.0f);
         mSlowOutLinearInInterpolator = new PathInterpolator(0.8f, 0.0f, 1.0f, 1.0f);
         setClipChildren(false);
@@ -232,7 +237,6 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
             boolean wasActivated = mActivated;
             result = handleTouchEventDimmed(event);
             if (wasActivated && result && event.getAction() == MotionEvent.ACTION_UP) {
-                mFalsingManager.onNotificationDoubleTap();
                 removeCallbacks(mTapTimeoutRunnable);
             }
         } else {
@@ -283,9 +287,21 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
                     if (!mActivated) {
                         makeActive();
                         postDelayed(mTapTimeoutRunnable, DOUBLETAP_TIMEOUT_MS);
+                        mActivationX = event.getX();
+                        mActivationY = event.getY();
                     } else {
-                        if (!performClick()) {
-                            return false;
+                        boolean withinDoubleTapSlop = isWithinDoubleTapSlop(event);
+                        mFalsingManager.onNotificationDoubleTap(
+                                withinDoubleTapSlop,
+                                event.getX() - mActivationX,
+                                event.getY() - mActivationY);
+                        if (withinDoubleTapSlop) {
+                            if (!performClick()) {
+                                return false;
+                            }
+                        } else {
+                            makeInactive(true /* animate */);
+                            mTrackTouch = false;
                         }
                     }
                 } else {
@@ -393,6 +409,16 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
                 && Math.abs(event.getY() - mDownY) < mTouchSlop;
     }
 
+    private boolean isWithinDoubleTapSlop(MotionEvent event) {
+        if (!mActivated) {
+            // If we're not activated there's no double tap slop to satisfy.
+            return true;
+        }
+
+        return Math.abs(event.getX() - mActivationX) < mDoubleTapSlop
+                && Math.abs(event.getY() - mActivationY) < mDoubleTapSlop;
+    }
+
     public void setDimmed(boolean dimmed, boolean fade) {
         if (mDimmed != dimmed) {
             mDimmed = dimmed;