From a4208e619dad57c54fe83d4cbd28a66da8bd04ac Mon Sep 17 00:00:00 2001 From: Beverly Date: Thu, 12 May 2022 16:19:14 +0000 Subject: [PATCH] Update lock icon location onConfigurationChange So the location will update on orientation change. Test: manually rotate lock screen Test: atest LockIconViewControllerTest Fixes: 231903658 Change-Id: I50984988ae785de3c7829afca28ad821c8502d1d --- .../keyguard/LockIconViewController.java | 5 +-- .../keyguard/LockIconViewControllerTest.java | 39 +++++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java b/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java index ab831be0f8e0a..680b8bd708371 100644 --- a/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java @@ -188,7 +188,6 @@ public class LockIconViewController extends ViewController impleme protected void onViewAttached() { updateIsUdfpsEnrolled(); updateConfiguration(); - updateLockIconLocation(); updateKeyguardShowing(); mUserUnlockedWithBiometric = false; @@ -347,6 +346,7 @@ public class LockIconViewController extends ViewController impleme R.string.accessibility_unlock_button); mLockedLabel = mView.getContext() .getResources().getString(R.string.accessibility_lock_icon); + updateLockIconLocation(); } private void updateLockIconLocation() { @@ -691,7 +691,6 @@ public class LockIconViewController extends ViewController impleme mExecutor.execute(() -> { updateIsUdfpsEnrolled(); updateConfiguration(); - updateLockIconLocation(); }); } @@ -708,7 +707,7 @@ public class LockIconViewController extends ViewController impleme @Override public void onUdfpsLocationChanged() { - updateLockIconLocation(); + updateUdfpsConfig(); } }; diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java index c532ed5ab651f..24d051508fde4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java @@ -135,8 +135,7 @@ public class LockIconViewControllerTest extends SysuiTestCase { .startMocking(); MockitoAnnotations.initMocks(this); - when(mLockIconView.getResources()).thenReturn(mResources); - when(mLockIconView.getContext()).thenReturn(mContext); + setupLockIconViewMocks(); when(mContext.getResources()).thenReturn(mResources); when(mContext.getSystemService(WindowManager.class)).thenReturn(mWindowManager); Rect windowBounds = new Rect(0, 0, 800, 1200); @@ -206,13 +205,14 @@ public class LockIconViewControllerTest extends SysuiTestCase { } @Test - public void testUpdateFingerprintLocationOnAuthenticatorsRegistered() { + public void testUpdateLockIconLocationOnAuthenticatorsRegistered() { // GIVEN fp sensor location is not available pre-init when(mKeyguardUpdateMonitor.isUdfpsSupported()).thenReturn(false); when(mAuthController.getFingerprintSensorLocation()).thenReturn(null); mLockIconViewController.init(); captureAttachListener(); mAttachListener.onViewAttachedToWindow(mLockIconView); + resetLockIconView(); // reset any method call counts for when we verify method calls later // GIVEN fp sensor location is available post-attached captureAuthControllerCallback(); @@ -227,6 +227,29 @@ public class LockIconViewControllerTest extends SysuiTestCase { eq(PADDING)); } + @Test + public void testUpdateLockIconLocationOnUdfpsLocationChanged() { + // GIVEN fp sensor location is not available pre-init + when(mKeyguardUpdateMonitor.isUdfpsSupported()).thenReturn(false); + when(mAuthController.getFingerprintSensorLocation()).thenReturn(null); + mLockIconViewController.init(); + captureAttachListener(); + mAttachListener.onViewAttachedToWindow(mLockIconView); + resetLockIconView(); // reset any method call counts for when we verify method calls later + + // GIVEN fp sensor location is available post-attached + captureAuthControllerCallback(); + Pair udfps = setupUdfps(); + + // WHEN udfps location changes + mAuthControllerCallback.onUdfpsLocationChanged(); + mDelayableExecutor.runAllReady(); + + // THEN lock icon view location is updated with the same coordinates as auth controller vals + verify(mLockIconView).setCenterLocation(eq(udfps.second), eq(udfps.first), + eq(PADDING)); + } + @Test public void testLockIconViewBackgroundEnabledWhenUdfpsIsSupported() { // GIVEN Udpfs sensor location is available @@ -440,4 +463,14 @@ public class LockIconViewControllerTest extends SysuiTestCase { mKeyguardUpdateMonitorCallbackCaptor.capture()); mKeyguardUpdateMonitorCallback = mKeyguardUpdateMonitorCallbackCaptor.getValue(); } + + private void setupLockIconViewMocks() { + when(mLockIconView.getResources()).thenReturn(mResources); + when(mLockIconView.getContext()).thenReturn(mContext); + } + + private void resetLockIconView() { + reset(mLockIconView); + setupLockIconViewMocks(); + } }