diff --git a/packages/SystemUI/res/layout/status_bar_expanded.xml b/packages/SystemUI/res/layout/status_bar_expanded.xml index 18315f1dff423..cc1af873ce2be 100644 --- a/packages/SystemUI/res/layout/status_bar_expanded.xml +++ b/packages/SystemUI/res/layout/status_bar_expanded.xml @@ -65,18 +65,6 @@ android:layout_gravity="center" android:scaleType="centerCrop"/> - - - + \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java b/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java index ed0bbafd0bc84..321c1a309cb51 100644 --- a/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java @@ -22,8 +22,8 @@ import static com.android.systemui.classifier.Classifier.LOCK_ICON; import static com.android.systemui.doze.util.BurnInHelperKt.getBurnInOffset; import static com.android.systemui.doze.util.BurnInHelperKt.getBurnInProgressOffset; -import android.content.Context; import android.content.res.Configuration; +import android.content.res.Resources; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.drawable.AnimatedVectorDrawable; @@ -38,6 +38,7 @@ import android.util.DisplayMetrics; import android.util.MathUtils; import android.view.GestureDetector; import android.view.GestureDetector.SimpleOnGestureListener; +import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.accessibility.AccessibilityManager; @@ -98,9 +99,10 @@ public class LockIconViewController extends ViewController impleme @NonNull private final AccessibilityManager mAccessibilityManager; @NonNull private final ConfigurationController mConfigurationController; @NonNull private final DelayableExecutor mExecutor; + @NonNull private final LayoutInflater mLayoutInflater; private boolean mUdfpsEnrolled; - @NonNull private LottieAnimationView mAodFp; + @Nullable private LottieAnimationView mAodFp; @NonNull private final AnimatedVectorDrawable mFpToUnlockIcon; @NonNull private final AnimatedVectorDrawable mLockToUnlockIcon; @@ -154,7 +156,9 @@ public class LockIconViewController extends ViewController impleme @NonNull ConfigurationController configurationController, @NonNull @Main DelayableExecutor executor, @Nullable Vibrator vibrator, - @Nullable AuthRippleController authRippleController + @Nullable AuthRippleController authRippleController, + @NonNull @Main Resources resources, + @NonNull LayoutInflater inflater ) { super(view); mStatusBarStateController = statusBarStateController; @@ -168,27 +172,19 @@ public class LockIconViewController extends ViewController impleme mExecutor = executor; mVibrator = vibrator; mAuthRippleController = authRippleController; + mLayoutInflater = inflater; - final Context context = view.getContext(); - mAodFp = mView.findViewById(R.id.lock_udfps_aod_fp); - mMaxBurnInOffsetX = context.getResources() - .getDimensionPixelSize(R.dimen.udfps_burn_in_offset_x); - mMaxBurnInOffsetY = context.getResources() - .getDimensionPixelSize(R.dimen.udfps_burn_in_offset_y); + mMaxBurnInOffsetX = resources.getDimensionPixelSize(R.dimen.udfps_burn_in_offset_x); + mMaxBurnInOffsetY = resources.getDimensionPixelSize(R.dimen.udfps_burn_in_offset_y); - mUnlockIcon = mView.getContext().getResources().getDrawable( - R.drawable.ic_unlock, - mView.getContext().getTheme()); - mLockIcon = mView.getContext().getResources().getDrawable( - R.anim.lock_to_unlock, - mView.getContext().getTheme()); - mFpToUnlockIcon = (AnimatedVectorDrawable) mView.getContext().getResources().getDrawable( + mUnlockIcon = resources.getDrawable(R.drawable.ic_unlock, mView.getContext().getTheme()); + mLockIcon = resources.getDrawable(R.anim.lock_to_unlock, mView.getContext().getTheme()); + mFpToUnlockIcon = (AnimatedVectorDrawable) resources.getDrawable( R.anim.fp_to_unlock, mView.getContext().getTheme()); - mLockToUnlockIcon = (AnimatedVectorDrawable) mView.getContext().getResources().getDrawable( - R.anim.lock_to_unlock, + mLockToUnlockIcon = (AnimatedVectorDrawable) resources.getDrawable(R.anim.lock_to_unlock, mView.getContext().getTheme()); - mUnlockedLabel = context.getResources().getString(R.string.accessibility_unlock_button); - mLockedLabel = context.getResources().getString(R.string.accessibility_lock_icon); + mUnlockedLabel = resources.getString(R.string.accessibility_unlock_button); + mLockedLabel = resources.getString(R.string.accessibility_lock_icon); dumpManager.registerDumpable("LockIconViewController", this); } @@ -264,7 +260,7 @@ public class LockIconViewController extends ViewController impleme boolean wasShowingLockIcon = mShowLockIcon; boolean wasShowingUnlockIcon = mShowUnlockIcon; mShowLockIcon = !mCanDismissLockScreen && !mUserUnlockedWithBiometric && isLockScreen() - && (!mUdfpsEnrolled || !mRunningFPS); + && (!mUdfpsEnrolled || !mRunningFPS); mShowUnlockIcon = (mCanDismissLockScreen || mUserUnlockedWithBiometric) && isLockScreen(); mShowAODFpIcon = mIsDozing && mUdfpsEnrolled && !mRunningFPS; @@ -300,7 +296,7 @@ public class LockIconViewController extends ViewController impleme mView.setContentDescription(null); } - if (!mShowAODFpIcon) { + if (!mShowAODFpIcon && mAodFp != null) { mAodFp.setVisibility(View.INVISIBLE); mAodFp.setContentDescription(null); } @@ -416,10 +412,12 @@ public class LockIconViewController extends ViewController impleme - mMaxBurnInOffsetY, mInterpolatedDarkAmount); float progress = MathUtils.lerp(0f, getBurnInProgressOffset(), mInterpolatedDarkAmount); - mAodFp.setTranslationX(offsetX); - mAodFp.setTranslationY(offsetY); - mAodFp.setProgress(progress); - mAodFp.setAlpha(255 * mInterpolatedDarkAmount); + if (mAodFp != null) { + mAodFp.setTranslationX(offsetX); + mAodFp.setTranslationY(offsetY); + mAodFp.setProgress(progress); + mAodFp.setAlpha(255 * mInterpolatedDarkAmount); + } } private void updateIsUdfpsEnrolled() { @@ -430,6 +428,10 @@ public class LockIconViewController extends ViewController impleme mView.setUseBackground(mUdfpsSupported); mUdfpsEnrolled = mKeyguardUpdateMonitor.isUdfpsEnrolled(); + if (!wasUdfpsEnrolled && mUdfpsEnrolled && mAodFp == null) { + mLayoutInflater.inflate(R.layout.udfps_aod_lock_icon, mView); + mAodFp = mView.findViewById(R.id.lock_udfps_aod_fp); + } if (wasUdfpsSupported != mUdfpsSupported || wasUdfpsEnrolled != mUdfpsEnrolled) { updateVisibility(); } @@ -651,7 +653,7 @@ public class LockIconViewController extends ViewController impleme public boolean onTouchEvent(MotionEvent event, Runnable onGestureDetectedRunnable) { if (mSensorTouchLocation.contains((int) event.getX(), (int) event.getY()) && (mView.getVisibility() == View.VISIBLE - || mAodFp.getVisibility() == View.VISIBLE)) { + || (mAodFp != null && mAodFp.getVisibility() == View.VISIBLE))) { mOnGestureDetectedRunnable = onGestureDetectedRunnable; mGestureDetector.onTouchEvent(event); } 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 ddf1d7033b825..90e3db7750bcf 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/LockIconViewControllerTest.java @@ -18,9 +18,10 @@ package com.android.systemui.keyguard; import static junit.framework.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -37,6 +38,7 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.util.DisplayMetrics; import android.util.Pair; +import android.view.LayoutInflater; import android.view.View; import android.view.accessibility.AccessibilityManager; @@ -96,6 +98,7 @@ public class LockIconViewControllerTest extends SysuiTestCase { private @Mock Vibrator mVibrator; private @Mock AuthRippleController mAuthRippleController; private @Mock LottieAnimationView mAodFp; + private @Mock LayoutInflater mLayoutInflater; private LockIconViewController mLockIconViewController; @@ -120,11 +123,11 @@ public class LockIconViewControllerTest extends SysuiTestCase { when(mLockIconView.getResources()).thenReturn(mResources); when(mLockIconView.getContext()).thenReturn(mContext); + when(mLockIconView.findViewById(R.layout.udfps_aod_lock_icon)).thenReturn(mAodFp); when(mContext.getResources()).thenReturn(mResources); when(mResources.getDisplayMetrics()).thenReturn(mDisplayMetrics); - when(mLockIconView.findViewById(anyInt())).thenReturn(mAodFp); when(mResources.getString(R.string.accessibility_unlock_button)).thenReturn(UNLOCKED_LABEL); - when(mResources.getDrawable(anyInt(), anyObject())).thenReturn(mIconDrawable); + when(mResources.getDrawable(anyInt(), any())).thenReturn(mIconDrawable); when(mKeyguardStateController.isShowing()).thenReturn(true); when(mKeyguardStateController.isKeyguardGoingAway()).thenReturn(false); @@ -144,10 +147,41 @@ public class LockIconViewControllerTest extends SysuiTestCase { mConfigurationController, mDelayableExecutor, mVibrator, - mAuthRippleController + mAuthRippleController, + mResources, + mLayoutInflater ); } + @Test + public void testIgnoreUdfpsWhenNotSupported() { + // GIVEN Udpfs sensor is NOT available + mLockIconViewController.init(); + captureAttachListener(); + + // WHEN the view is attached + mAttachListener.onViewAttachedToWindow(mLockIconView); + + // THEN lottie animation should NOT be inflated + verify(mLayoutInflater, never()).inflate(eq(R.layout.udfps_aod_lock_icon), any()); + } + + @Test + public void testInflateUdfpsWhenSupported() { + // GIVEN Udpfs sensor is available + setupUdfps(); + when(mKeyguardUpdateMonitor.isUdfpsEnrolled()).thenReturn(true); + + mLockIconViewController.init(); + captureAttachListener(); + + // WHEN the view is attached + mAttachListener.onViewAttachedToWindow(mLockIconView); + + // THEN lottie animation should be inflated + verify(mLayoutInflater).inflate(eq(R.layout.udfps_aod_lock_icon), any()); + } + @Test public void testUpdateFingerprintLocationOnInit() { // GIVEN fp sensor location is available pre-attached