From 0d4b8acf0c8913c8ff53e3a87bbd9f8e6fde0765 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Wed, 23 Mar 2022 14:09:10 -0400 Subject: [PATCH] Bouncer - Ensure one-handed mode bouncer side The bouncer should appear (and remain) on the side the user swipes up. From then on, it needs to move to the left/right side, depending on touch. Fixes: 224170485 Test: atest KeyguardSecurityContainerTest Change-Id: Idd6f29e4591eacad74480e7928a6c8b82e73f206 --- .../keyguard/KeyguardSecurityContainer.java | 20 +++++++++++-------- .../KeyguardSecurityContainerTest.java | 5 +++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java index 46a883194e25f..3103219d89781 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java @@ -307,8 +307,6 @@ public class KeyguardSecurityContainer extends FrameLayout { void onResume(SecurityMode securityMode, boolean faceAuthEnabled) { mSecurityViewFlipper.setWindowInsetsAnimationCallback(mWindowInsetsAnimationCallback); updateBiometricRetry(securityMode, faceAuthEnabled); - - setupViewMode(); } void initMode(@Mode int mode, GlobalSettings globalSettings, FalsingManager falsingManager, @@ -1044,11 +1042,13 @@ public class KeyguardSecurityContainer extends FrameLayout { /** * Moves the bouncer to align with a tap (most likely in the shade), so the bouncer - * appears on the same side as a touch. Will not update the user-preference. + * appears on the same side as a touch. */ @Override public void updatePositionByTouchX(float x) { - updateSecurityViewLocation(x <= mView.getWidth() / 2f, /* animate= */false); + boolean isTouchOnLeft = x <= mView.getWidth() / 2f; + updateSideSetting(isTouchOnLeft); + updateSecurityViewLocation(isTouchOnLeft, /* animate= */false); } boolean isLeftAligned() { @@ -1057,6 +1057,13 @@ public class KeyguardSecurityContainer extends FrameLayout { == Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT; } + private void updateSideSetting(boolean leftAligned) { + mGlobalSettings.putInt( + Settings.Global.ONE_HANDED_KEYGUARD_SIDE, + leftAligned ? Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT + : Settings.Global.ONE_HANDED_KEYGUARD_SIDE_RIGHT); + } + /** * Determine if a tap on this view is on the other side. If so, will animate positions * and record the preference to always show on this side. @@ -1070,10 +1077,7 @@ public class KeyguardSecurityContainer extends FrameLayout { || (!currentlyLeftAligned && (x < mView.getWidth() / 2f))) { boolean willBeLeftAligned = !currentlyLeftAligned; - mGlobalSettings.putInt( - Settings.Global.ONE_HANDED_KEYGUARD_SIDE, - willBeLeftAligned ? Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT - : Settings.Global.ONE_HANDED_KEYGUARD_SIDE_RIGHT); + updateSideSetting(willBeLeftAligned); int keyguardState = willBeLeftAligned ? SysUiStatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__SWITCH_LEFT diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerTest.java index 6736bfd217404..14c903c86b627 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardSecurityContainerTest.java @@ -34,6 +34,7 @@ import static org.mockito.Mockito.when; import android.content.pm.UserInfo; import android.content.res.Configuration; import android.graphics.Insets; +import android.provider.Settings; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.view.Gravity; @@ -204,10 +205,14 @@ public class KeyguardSecurityContainerTest extends SysuiTestCase { mKeyguardSecurityContainer.updatePositionByTouchX( mKeyguardSecurityContainer.getWidth() - 1f); + verify(mGlobalSettings).putInt(Settings.Global.ONE_HANDED_KEYGUARD_SIDE, + Settings.Global.ONE_HANDED_KEYGUARD_SIDE_RIGHT); verify(mSecurityViewFlipper).setTranslationX( mKeyguardSecurityContainer.getWidth() - mSecurityViewFlipper.getWidth()); mKeyguardSecurityContainer.updatePositionByTouchX(1f); + verify(mGlobalSettings).putInt(Settings.Global.ONE_HANDED_KEYGUARD_SIDE, + Settings.Global.ONE_HANDED_KEYGUARD_SIDE_LEFT); verify(mSecurityViewFlipper).setTranslationX(0.0f); }