From 3b6a94202950f0b67c448b69465464199785b545 Mon Sep 17 00:00:00 2001 From: Jamie Garside Date: Fri, 14 May 2021 18:55:25 +0100 Subject: [PATCH] Make one-handed bouncer properly inhibit falsing. Previously, the falsing manager would take all taps that weren't on the bouncer (ish) as potential false taps, eventually dismissing the bouncer. This causes issues for the one-handed bouncer; taps on the "other" side were registered as false taps, so in many cases, tapping to move the bouncer would cause the falsing to kick in. To fix, this CL inhibits falsing for gestures that begin on the "opposite" bouncer side. This also refactors a bunch of the code to decide whether to use a one handed bouncer, to move a lot of logic into the ContainerController. The animations on change, and tap to change are still handled in the View, but the decision of whether to enter one-handed mode, and which side to open on, are now handled in the Controller. FYI - this CL still attempts to load from settings; that will be cleaned up in a follow-up CL. Bug: 182982037 Bug: 170858298 Test: Tests updated and pass. Change-Id: Icb36a3b88032c4bcad8530d518a97a8d8717244e --- .../keyguard/KeyguardSecurityContainer.java | 99 ++++------- .../KeyguardSecurityContainerController.java | 73 +++++++- ...yguardSecurityContainerControllerTest.java | 157 +++++++++++++++++- .../KeyguardSecurityContainerTest.java | 111 +++---------- 4 files changed, 269 insertions(+), 171 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java index ca4d73b6de5df..840e8c8cba585 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java @@ -42,7 +42,6 @@ import android.view.WindowInsetsAnimation; import android.view.WindowManager; import android.widget.FrameLayout; -import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.dynamicanimation.animation.DynamicAnimation; import androidx.dynamicanimation.animation.SpringAnimation; @@ -104,7 +103,6 @@ public class KeyguardSecurityContainer extends FrameLayout { private boolean mIsSecurityViewLeftAligned = true; private boolean mOneHandedMode = false; - private SecurityMode mSecurityMode = SecurityMode.Invalid; private ViewPropertyAnimator mRunningOneHandedAnimator; private final WindowInsetsAnimation.Callback mWindowInsetsAnimationCallback = @@ -248,66 +246,47 @@ public class KeyguardSecurityContainer extends FrameLayout { } void onResume(SecurityMode securityMode, boolean faceAuthEnabled) { - mSecurityMode = securityMode; mSecurityViewFlipper.setWindowInsetsAnimationCallback(mWindowInsetsAnimationCallback); updateBiometricRetry(securityMode, faceAuthEnabled); - - updateLayoutForSecurityMode(securityMode); } - void updateLayoutForSecurityMode(SecurityMode securityMode) { - mSecurityMode = securityMode; - mOneHandedMode = canUseOneHandedBouncer(); - - if (mOneHandedMode) { - mIsSecurityViewLeftAligned = isOneHandedKeyguardLeftAligned(mContext); - } - + /** + * Sets whether this security container is in one handed mode. If so, it will measure its + * child SecurityViewFlipper in one half of the screen, and move it when tapping on the opposite + * side of the screen. + */ + public void setOneHandedMode(boolean oneHandedMode) { + mOneHandedMode = oneHandedMode; updateSecurityViewGravity(); updateSecurityViewLocation(false); } - /** Update keyguard position based on a tapped X coordinate. */ - public void updateKeyguardPosition(float x) { - if (mOneHandedMode) { - moveBouncerForXCoordinate(x, /* animate= */false); - } + /** Returns whether this security container is in one-handed mode. */ + public boolean isOneHandedMode() { + return mOneHandedMode; } - /** Return whether the one-handed keyguard should be enabled. */ - private boolean canUseOneHandedBouncer() { - // Is it enabled? - if (!getResources().getBoolean( - com.android.internal.R.bool.config_enableDynamicKeyguardPositioning)) { - return false; - } - - if (!KeyguardSecurityModel.isSecurityViewOneHanded(mSecurityMode)) { - return false; - } - - return getResources().getBoolean(R.bool.can_use_one_handed_bouncer); + /** + * When in one-handed mode, sets if the inner SecurityViewFlipper should be aligned to the + * left-hand side of the screen or not, and whether to animate when moving between the two. + */ + public void setOneHandedModeLeftAligned(boolean leftAligned, boolean animate) { + mIsSecurityViewLeftAligned = leftAligned; + updateSecurityViewLocation(animate); } - /** Read whether the one-handed keyguard should be on the left/right from settings. */ - private boolean isOneHandedKeyguardLeftAligned(Context context) { - try { - return Settings.Global.getInt(context.getContentResolver(), - Settings.Global.ONE_HANDED_KEYGUARD_SIDE) - == Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT; - } catch (Settings.SettingNotFoundException ex) { - return true; - } + /** Returns whether the inner SecurityViewFlipper is left-aligned when in one-handed mode. */ + public boolean isOneHandedModeLeftAligned() { + return mIsSecurityViewLeftAligned; } private void updateSecurityViewGravity() { - View securityView = findKeyguardSecurityView(); - - if (securityView == null) { + if (mSecurityViewFlipper == null) { return; } - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) securityView.getLayoutParams(); + FrameLayout.LayoutParams lp = + (FrameLayout.LayoutParams) mSecurityViewFlipper.getLayoutParams(); if (mOneHandedMode) { lp.gravity = Gravity.LEFT | Gravity.BOTTOM; @@ -315,7 +294,7 @@ public class KeyguardSecurityContainer extends FrameLayout { lp.gravity = Gravity.CENTER_HORIZONTAL; } - securityView.setLayoutParams(lp); + mSecurityViewFlipper.setLayoutParams(lp); } /** @@ -324,14 +303,12 @@ public class KeyguardSecurityContainer extends FrameLayout { * by the security view . */ private void updateSecurityViewLocation(boolean animate) { - View securityView = findKeyguardSecurityView(); - - if (securityView == null) { + if (mSecurityViewFlipper == null) { return; } if (!mOneHandedMode) { - securityView.setTranslationX(0); + mSecurityViewFlipper.setTranslationX(0); return; } @@ -343,7 +320,8 @@ public class KeyguardSecurityContainer extends FrameLayout { int targetTranslation = mIsSecurityViewLeftAligned ? 0 : (int) (getMeasuredWidth() / 2f); if (animate) { - mRunningOneHandedAnimator = securityView.animate().translationX(targetTranslation); + mRunningOneHandedAnimator = + mSecurityViewFlipper.animate().translationX(targetTranslation); mRunningOneHandedAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); mRunningOneHandedAnimator.setListener(new AnimatorListenerAdapter() { @Override @@ -355,27 +333,10 @@ public class KeyguardSecurityContainer extends FrameLayout { mRunningOneHandedAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); mRunningOneHandedAnimator.start(); } else { - securityView.setTranslationX(targetTranslation); + mSecurityViewFlipper.setTranslationX(targetTranslation); } } - @Nullable - private KeyguardSecurityViewFlipper findKeyguardSecurityView() { - for (int i = 0; i < getChildCount(); i++) { - View child = getChildAt(i); - - if (isKeyguardSecurityView(child)) { - return (KeyguardSecurityViewFlipper) child; - } - } - - return null; - } - - private boolean isKeyguardSecurityView(View view) { - return view instanceof KeyguardSecurityViewFlipper; - } - public void onPause() { if (mAlertDialog != null) { mAlertDialog.dismiss(); @@ -635,7 +596,7 @@ public class KeyguardSecurityContainer extends FrameLayout { for (int i = 0; i < getChildCount(); i++) { final View view = getChildAt(i); if (view.getVisibility() != GONE) { - if (mOneHandedMode && isKeyguardSecurityView(view)) { + if (mOneHandedMode && view == mSecurityViewFlipper) { measureChildWithMargins(view, halfWidthMeasureSpec, 0, heightMeasureSpec, 0); } else { diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java index 4827cab3b5c01..6826e7b8ac94f 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java @@ -32,6 +32,7 @@ import android.content.res.ColorStateList; import android.content.res.Configuration; import android.metrics.LogMaker; import android.os.UserHandle; +import android.provider.Settings; import android.util.Log; import android.util.Slog; import android.view.MotionEvent; @@ -49,6 +50,8 @@ import com.android.keyguard.KeyguardSecurityModel.SecurityMode; import com.android.keyguard.dagger.KeyguardBouncerScope; import com.android.settingslib.utils.ThreadUtils; import com.android.systemui.Gefingerpoken; +import com.android.systemui.R; +import com.android.systemui.classifier.FalsingCollector; import com.android.systemui.shared.system.SysUiStatsLog; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.KeyguardStateController; @@ -74,12 +77,14 @@ public class KeyguardSecurityContainerController extends ViewController mView.getWidth() / 2f) + || (!mView.isOneHandedModeLeftAligned() + && ev.getX() <= mView.getWidth() / 2f)) { + mFalsingCollector.avoidGesture(); + } + } + if (mTouchDown != null) { mTouchDown.recycle(); mTouchDown = null; @@ -202,7 +218,8 @@ public class KeyguardSecurityContainerController extends ViewController