From 72eadbad8031cdcf8236d34eb0df2c11c4ed1c35 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 19 Apr 2019 14:30:36 -0700 Subject: [PATCH] Add touch slop before sending home intent from DeviceLockedInputConsumer Bug: 128808922 Change-Id: I4eaa5ba627f123022310c23663b6711c0eb62518 --- .../quickstep/DeviceLockedInputConsumer.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/DeviceLockedInputConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/DeviceLockedInputConsumer.java index d919a3e711..7fd09f7dee 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/DeviceLockedInputConsumer.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/DeviceLockedInputConsumer.java @@ -17,7 +17,9 @@ package com.android.quickstep; import android.content.Context; import android.content.Intent; +import android.graphics.PointF; import android.view.MotionEvent; +import android.view.ViewConfiguration; /** * A dummy input consumer used when the device is still locked, e.g. from secure camera. @@ -25,9 +27,13 @@ import android.view.MotionEvent; public class DeviceLockedInputConsumer implements InputConsumer { private final Context mContext; + private final float mTouchSlopSquared; + private final PointF mTouchDown = new PointF(); public DeviceLockedInputConsumer(Context context) { mContext = context; + float touchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); + mTouchSlopSquared = touchSlop * touchSlop; } @Override @@ -37,11 +43,19 @@ public class DeviceLockedInputConsumer implements InputConsumer { @Override public void onMotionEvent(MotionEvent ev) { - // For now, just start the home intent so user is prompted to unlock the device. + float x = ev.getX(); + float y = ev.getY(); if (ev.getAction() == MotionEvent.ACTION_DOWN) { - mContext.startActivity(new Intent(Intent.ACTION_MAIN) - .addCategory(Intent.CATEGORY_HOME) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + mTouchDown.set(x, y); + } else if (ev.getAction() == MotionEvent.ACTION_MOVE) { + float xSquared = (x - mTouchDown.x) * (x - mTouchDown.x); + float ySquared = (y - mTouchDown.y) * (y - mTouchDown.y); + if (xSquared + ySquared > mTouchSlopSquared) { + // For now, just start the home intent so user is prompted to unlock the device. + mContext.startActivity(new Intent(Intent.ACTION_MAIN) + .addCategory(Intent.CATEGORY_HOME) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + } } } }