diff options
| author | 2021-09-23 10:18:41 -0400 | |
|---|---|---|
| committer | 2021-09-23 19:41:54 +0000 | |
| commit | 0f6491dce5fbcb071330e431426f4a563e8a9d93 (patch) | |
| tree | c202f348db8908a17bc05e268990467346cb0324 | |
| parent | e84c7c6393fe1f84d3812d000614dcebe58a6b50 (diff) | |
[DO NOT MERGE] Only show lock icon background with UDFPS
Otherwise the background should remain hidden (View.GONE) for devices
without the UDFPS sensor.
Fixes: 200813382
Test: atest LockIconViewControllerTest
Change-Id: I1ef3cef37de60e6968432869f4c946b6de414db4
(cherry picked from commit ddfb4df1a83d6e51e23177790f0b0ecae207f764)
3 files changed, 63 insertions, 25 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/LockIconView.java b/packages/SystemUI/src/com/android/keyguard/LockIconView.java index 371564a98aad..ef4353b93179 100644 --- a/packages/SystemUI/src/com/android/keyguard/LockIconView.java +++ b/packages/SystemUI/src/com/android/keyguard/LockIconView.java @@ -48,6 +48,7 @@ public class LockIconView extends FrameLayout implements Dumpable { private ImageView mBgView; private int mLockIconColor; + private boolean mUseBackground = false; public LockIconView(Context context, AttributeSet attrs) { super(context, attrs); @@ -61,8 +62,8 @@ public class LockIconView extends FrameLayout implements Dumpable { mBgView = findViewById(R.id.lock_icon_bg); } - void updateColorAndBackgroundVisibility(boolean useBackground) { - if (useBackground && mLockIcon.getDrawable() != null) { + void updateColorAndBackgroundVisibility() { + if (mUseBackground && mLockIcon.getDrawable() != null) { mLockIconColor = Utils.getColorAttrDefaultColor(getContext(), android.R.attr.textColorPrimary); mBgView.setBackground(getContext().getDrawable(R.drawable.fingerprint_bg)); @@ -78,6 +79,9 @@ public class LockIconView extends FrameLayout implements Dumpable { void setImageDrawable(Drawable drawable) { mLockIcon.setImageDrawable(drawable); + + if (!mUseBackground) return; + if (drawable == null) { mBgView.setVisibility(View.INVISIBLE); } else { @@ -86,6 +90,14 @@ public class LockIconView extends FrameLayout implements Dumpable { } /** + * Whether or not to render the lock icon background. Mainly used for UDPFS. + */ + public void setUseBackground(boolean useBackground) { + mUseBackground = useBackground; + updateColorAndBackgroundVisibility(); + } + + /** * Set the location of the lock icon. */ @VisibleForTesting diff --git a/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java b/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java index 28e19acce506..8cfd225fc4df 100644 --- a/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java @@ -346,7 +346,7 @@ public class LockIconViewController extends ViewController<LockIconView> impleme } private void updateColors() { - mView.updateColorAndBackgroundVisibility(mUdfpsSupported); + mView.updateColorAndBackgroundVisibility(); } private void updateConfiguration() { @@ -427,6 +427,8 @@ public class LockIconViewController extends ViewController<LockIconView> impleme boolean wasUdfpsEnrolled = mUdfpsEnrolled; mUdfpsSupported = mAuthController.getUdfpsSensorLocation() != null; + mView.setUseBackground(mUdfpsSupported); + mUdfpsEnrolled = mKeyguardUpdateMonitor.isUdfpsEnrolled(); if (wasUdfpsSupported != mUdfpsSupported || wasUdfpsEnrolled != mUdfpsEnrolled) { updateVisibility(); 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 af6dee76139e..c464cad3e0b2 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java @@ -32,6 +32,7 @@ import android.os.Vibrator; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.util.DisplayMetrics; +import android.util.Pair; import android.view.View; import android.view.accessibility.AccessibilityManager; @@ -128,20 +129,7 @@ public class LockIconViewControllerTest extends SysuiTestCase { @Test public void testUpdateFingerprintLocationOnInit() { // GIVEN fp sensor location is available pre-attached - final PointF udfpsLocation = new PointF(50, 75); - final int radius = 33; - final FingerprintSensorPropertiesInternal fpProps = - new FingerprintSensorPropertiesInternal( - /* sensorId */ 0, - /* strength */ 0, - /* max enrollments per user */ 5, - /* component info */ new ArrayList<>(), - /* sensorType */ 3, - /* resetLockoutRequiresHwToken */ false, - List.of(new SensorLocationInternal("" /* displayId */, - (int) udfpsLocation.x, (int) udfpsLocation.y, radius))); - when(mAuthController.getUdfpsSensorLocation()).thenReturn(udfpsLocation); - when(mAuthController.getUdfpsProps()).thenReturn(List.of(fpProps)); + Pair<Integer, PointF> udfps = setupUdfps(); // WHEN lock icon view controller is initialized and attached mLockIconViewController.init(); @@ -149,8 +137,8 @@ public class LockIconViewControllerTest extends SysuiTestCase { mAttachListener.onViewAttachedToWindow(mLockIconView); // THEN lock icon view location is updated with the same coordinates as fpProps - verify(mLockIconView).setCenterLocation(mPointCaptor.capture(), eq(radius)); - assertEquals(udfpsLocation, mPointCaptor.getValue()); + verify(mLockIconView).setCenterLocation(mPointCaptor.capture(), eq(udfps.first)); + assertEquals(udfps.second, mPointCaptor.getValue()); } @Test @@ -164,6 +152,47 @@ public class LockIconViewControllerTest extends SysuiTestCase { // GIVEN fp sensor location is available post-atttached captureAuthControllerCallback(); + Pair<Integer, PointF> udfps = setupUdfps(); + + // WHEN all authenticators are registered + mAuthControllerCallback.onAllAuthenticatorsRegistered(); + + // THEN lock icon view location is updated with the same coordinates as fpProps + verify(mLockIconView).setCenterLocation(mPointCaptor.capture(), eq(udfps.first)); + assertEquals(udfps.second, mPointCaptor.getValue()); + } + + @Test + public void testLockIconViewBackgroundEnabledWhenUdfpsIsAvailable() { + // GIVEN Udpfs sensor location is available + setupUdfps(); + + mLockIconViewController.init(); + captureAttachListener(); + + // WHEN the view is attached + mAttachListener.onViewAttachedToWindow(mLockIconView); + + // THEN the lock icon view background should be enabled + verify(mLockIconView).setUseBackground(true); + } + + @Test + public void testLockIconViewBackgroundDisabledWhenUdfpsIsUnavailable() { + // GIVEN Udfps sensor location is not available + when(mAuthController.getUdfpsSensorLocation()).thenReturn(null); + + mLockIconViewController.init(); + captureAttachListener(); + + // WHEN the view is attached + mAttachListener.onViewAttachedToWindow(mLockIconView); + + // THEN the lock icon view background should be disabled + verify(mLockIconView).setUseBackground(false); + } + + private Pair<Integer, PointF> setupUdfps() { final PointF udfpsLocation = new PointF(50, 75); final int radius = 33; final FingerprintSensorPropertiesInternal fpProps = @@ -179,12 +208,7 @@ public class LockIconViewControllerTest extends SysuiTestCase { when(mAuthController.getUdfpsSensorLocation()).thenReturn(udfpsLocation); when(mAuthController.getUdfpsProps()).thenReturn(List.of(fpProps)); - // WHEN all authenticators are registered - mAuthControllerCallback.onAllAuthenticatorsRegistered(); - - // THEN lock icon view location is updated with the same coordinates as fpProps - verify(mLockIconView).setCenterLocation(mPointCaptor.capture(), eq(radius)); - assertEquals(udfpsLocation, mPointCaptor.getValue()); + return new Pair(radius, udfpsLocation); } private void captureAuthControllerCallback() { |