From caf8a9bfe446d3ed7cfa8e368ad68ba5c31c8693 Mon Sep 17 00:00:00 2001 From: Jamie Garside Date: Fri, 19 Mar 2021 16:15:48 +0000 Subject: [PATCH] Ensure bouncer in correct position on swipe. Remove orientationlistener. This adds a hook to onLayout to move the bouncer to the correct screen side on large format devices. KeyguardBouncer already calls updateLayoutForSecurityMode() when the security mode is created, but this can happen before the bouncer has actually been attached to the screen (hence width = 0, so the bouncer gets left-aligned). It's also done in onResume(), but this is only called when the bouncer is at the correct place after swipe (hence causing the "jump" when swiping up). Also, removes orientationlistener from KeyguardBouncer, and replaces it with a proxied "updateResources" call. I messed up; I thought that orientationlistener worked like deviceorientationlistener, which notifies on screen rotation. Instead, it notifies on _every_ angle change, which would have led to a lot of layout passes as it'd update the bouncer gravity whenever the device moved. Oops. Test: atest SystemUITests: com.android.keyguard.KeyguardSecurityContainerControllerTest Bug: 177303121 Change-Id: I6d68e553c3114e043bcc126ba7b6910f98ce6694 --- .../keyguard/KeyguardHostViewController.java | 4 ++++ .../keyguard/KeyguardSecurityContainer.java | 20 ++++++++-------- .../KeyguardSecurityContainerController.java | 17 ++++++++++++++ ...yguardSecurityContainerControllerTest.java | 23 +++++++++++++++++++ 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java index 72dd72eb1676b..02a8958ef6574 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardHostViewController.java @@ -487,5 +487,9 @@ public class KeyguardHostViewController extends ViewController mView.setLayoutParams(lp); } } + + if (mKeyguardSecurityContainerController != null) { + mKeyguardSecurityContainerController.updateResources(); + } } } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java index 4887767b99224..708b2d55b75aa 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java @@ -33,7 +33,6 @@ import android.util.MathUtils; import android.util.TypedValue; import android.view.Gravity; import android.view.MotionEvent; -import android.view.OrientationEventListener; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; @@ -107,7 +106,6 @@ public class KeyguardSecurityContainer extends FrameLayout { private boolean mOneHandedMode = false; private SecurityMode mSecurityMode = SecurityMode.Invalid; private ViewPropertyAnimator mRunningOneHandedAnimator; - private final OrientationEventListener mOrientationEventListener; private final WindowInsetsAnimation.Callback mWindowInsetsAnimationCallback = new WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) { @@ -247,13 +245,6 @@ public class KeyguardSecurityContainer extends FrameLayout { super(context, attrs, defStyle); mSpringAnimation = new SpringAnimation(this, DynamicAnimation.Y); mViewConfiguration = ViewConfiguration.get(context); - - mOrientationEventListener = new OrientationEventListener(context) { - @Override - public void onOrientationChanged(int orientation) { - updateLayoutForSecurityMode(mSecurityMode); - } - }; } void onResume(SecurityMode securityMode, boolean faceAuthEnabled) { @@ -262,7 +253,6 @@ public class KeyguardSecurityContainer extends FrameLayout { updateBiometricRetry(securityMode, faceAuthEnabled); updateLayoutForSecurityMode(securityMode); - mOrientationEventListener.enable(); } void updateLayoutForSecurityMode(SecurityMode securityMode) { @@ -385,7 +375,6 @@ public class KeyguardSecurityContainer extends FrameLayout { mAlertDialog = null; } mSecurityViewFlipper.setWindowInsetsAnimationCallback(null); - mOrientationEventListener.disable(); } @Override @@ -663,6 +652,15 @@ public class KeyguardSecurityContainer extends FrameLayout { childState << MEASURED_HEIGHT_STATE_SHIFT)); } + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + + // After a layout pass, we need to re-place the inner bouncer, as our bounds may have + // changed. + updateSecurityViewLocation(/* animate= */false); + } + void showAlmostAtWipeDialog(int attempts, int remaining, int userType) { String message = null; switch (userType) { diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java index ccba1d59c8d02..760eaecae2471 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java @@ -29,6 +29,7 @@ import static com.android.systemui.DejankUtils.whitelistIpcs; import android.app.admin.DevicePolicyManager; import android.content.Intent; import android.content.res.ColorStateList; +import android.content.res.Configuration; import android.metrics.LogMaker; import android.os.UserHandle; import android.util.Log; @@ -74,6 +75,8 @@ public class KeyguardSecurityContainerController extends ViewController