From 294e8a1efc67505ae8ecad3f2f8e866b22dcbe9a Mon Sep 17 00:00:00 2001 From: Beverly Date: Wed, 14 Jul 2021 16:01:50 -0400 Subject: [PATCH] For devices with udfps, always show bg on udfps Also show background on lock icon and unlock icons if the device supports udfps. This is to help indicate the affordance is tappable. Test: manually test with and w/o udfps - AOD <=> Lock screen - gpay wallet affordance on LS that requests udfps - slowly swipe up to show bouncer => udfps fades - slowly swipe down to expand notification shade => udfps fades - tap notification on ls, no bg animation - tap notification on locked shade, there is a bg animation - toggle on/off dark mode from lock screen Fixes: 192403524 Change-Id: I5a19d3cd45c51af78a49d46126fc0678a3df6d6c --- .../SystemUI/res/drawable/fingerprint_bg.xml | 3 +- packages/SystemUI/res/drawable/ic_unlock.xml | 42 +++++ .../res/layout/status_bar_expanded.xml | 20 ++- .../res/layout/udfps_keyguard_view.xml | 3 +- .../com/android/keyguard/LockIconView.java | 39 +++- .../keyguard/LockIconViewController.java | 20 +-- .../systemui/biometrics/UdfpsController.java | 7 +- .../biometrics/UdfpsKeyguardView.java | 169 +++--------------- .../UdfpsKeyguardViewController.java | 44 ++++- .../biometrics/UdfpsControllerTest.java | 6 +- .../UdfpsKeyguardViewControllerTest.java | 4 + 11 files changed, 185 insertions(+), 172 deletions(-) create mode 100644 packages/SystemUI/res/drawable/ic_unlock.xml diff --git a/packages/SystemUI/res/drawable/fingerprint_bg.xml b/packages/SystemUI/res/drawable/fingerprint_bg.xml index 2b0ab6f9a8d24..558ec08b2ceb9 100644 --- a/packages/SystemUI/res/drawable/fingerprint_bg.xml +++ b/packages/SystemUI/res/drawable/fingerprint_bg.xml @@ -14,10 +14,11 @@ --> + android:color="?androidprv:attr/colorSurface"/> + + + + + + + + + + + + diff --git a/packages/SystemUI/res/layout/status_bar_expanded.xml b/packages/SystemUI/res/layout/status_bar_expanded.xml index 1a912023e33ce..b0f1f487b2609 100644 --- a/packages/SystemUI/res/layout/status_bar_expanded.xml +++ b/packages/SystemUI/res/layout/status_bar_expanded.xml @@ -55,9 +55,23 @@ android:id="@+id/lock_icon_view" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:padding="48px" - android:layout_gravity="center" - android:scaleType="centerCrop"/> + android:layout_gravity="center"> + + + + + + android:src="@drawable/fingerprint_bg"/> diff --git a/packages/SystemUI/src/com/android/keyguard/LockIconView.java b/packages/SystemUI/src/com/android/keyguard/LockIconView.java index c1d448db1e637..42777ffcc9cfa 100644 --- a/packages/SystemUI/src/com/android/keyguard/LockIconView.java +++ b/packages/SystemUI/src/com/android/keyguard/LockIconView.java @@ -17,15 +17,20 @@ package com.android.keyguard; import android.content.Context; +import android.content.res.ColorStateList; import android.graphics.PointF; import android.graphics.RectF; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; +import android.view.View; import android.widget.FrameLayout; import android.widget.ImageView; import androidx.annotation.NonNull; +import com.android.settingslib.Utils; import com.android.systemui.Dumpable; +import com.android.systemui.R; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -33,16 +38,47 @@ import java.io.PrintWriter; /** * A view positioned under the notification shade. */ -public class LockIconView extends ImageView implements Dumpable { +public class LockIconView extends FrameLayout implements Dumpable { @NonNull private final RectF mSensorRect; @NonNull private PointF mLockIconCenter = new PointF(0f, 0f); private int mRadius; + private ImageView mLockIcon; + private ImageView mUnlockBgView; + + private int mLockIconColor; + public LockIconView(Context context, AttributeSet attrs) { super(context, attrs); mSensorRect = new RectF(); } + @Override + public void onFinishInflate() { + super.onFinishInflate(); + mLockIcon = findViewById(R.id.lock_icon); + mUnlockBgView = findViewById(R.id.lock_icon_bg); + } + + void updateColorAndBackgroundVisibility(boolean useBackground) { + if (useBackground) { + mLockIconColor = Utils.getColorAttrDefaultColor(getContext(), + android.R.attr.textColorPrimary); + mUnlockBgView.setBackground(getContext().getDrawable(R.drawable.fingerprint_bg)); + mUnlockBgView.setVisibility(View.VISIBLE); + } else { + mLockIconColor = Utils.getColorAttrDefaultColor(getContext(), + R.attr.wallpaperTextColorAccent); + mUnlockBgView.setVisibility(View.GONE); + } + + mLockIcon.setImageTintList(ColorStateList.valueOf(mLockIconColor)); + } + + void setImageDrawable(Drawable drawable) { + mLockIcon.setImageDrawable(drawable); + } + void setCenterLocation(@NonNull PointF center, int radius) { mLockIconCenter = center; mRadius = radius; @@ -70,7 +106,6 @@ public class LockIconView extends ImageView implements Dumpable { return mLockIconCenter.y - mRadius; } - @Override public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) { pw.println("Center in px (x, y)= (" + mLockIconCenter.x + ", " + mLockIconCenter.y + ")"); diff --git a/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java b/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java index 9c8582fa334d4..9beb4cce0ca76 100644 --- a/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/LockIconViewController.java @@ -43,7 +43,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; -import com.android.settingslib.Utils; import com.android.systemui.Dumpable; import com.android.systemui.R; import com.android.systemui.biometrics.AuthController; @@ -111,7 +110,7 @@ public class LockIconViewController extends ViewController impleme private boolean mUserUnlockedWithBiometric; private Runnable mCancelDelayedUpdateVisibilityRunnable; - private boolean mHasUdfps; + private boolean mUdfpsSupported; private float mHeightPixels; private float mWidthPixels; private int mBottomPadding; // in pixels @@ -152,9 +151,8 @@ public class LockIconViewController extends ViewController impleme final Context context = view.getContext(); mUnlockIcon = mView.getContext().getResources().getDrawable( - R.anim.lock_to_unlock, + R.drawable.ic_unlock, mView.getContext().getTheme()); - ((AnimatedVectorDrawable) mUnlockIcon).start(); mLockIcon = mView.getContext().getResources().getDrawable( R.anim.lock_to_unlock, mView.getContext().getTheme()); @@ -177,7 +175,7 @@ public class LockIconViewController extends ViewController impleme protected void onViewAttached() { // we check this here instead of onInit since the FingerprintManager + FaceManager may not // have started up yet onInit - mHasUdfps = mAuthController.getUdfpsSensorLocation() != null; + mUdfpsSupported = mAuthController.getUdfpsSensorLocation() != null; updateConfiguration(); updateKeyguardShowing(); @@ -307,12 +305,7 @@ public class LockIconViewController extends ViewController impleme } private void updateColors() { - final int color = Utils.getColorAttrDefaultColor(mView.getContext(), - R.attr.wallpaperTextColorAccent); - mFpToUnlockIcon.setTint(color); - mLockToUnlockIcon.setTint(color); - mLockIcon.setTint(color); - mUnlockIcon.setTint(color); + mView.updateColorAndBackgroundVisibility(mUdfpsSupported); } private void updateConfiguration() { @@ -325,7 +318,7 @@ public class LockIconViewController extends ViewController impleme } private void updateLockIconLocation() { - if (mHasUdfps) { + if (mUdfpsSupported) { FingerprintSensorPropertiesInternal props = mAuthController.getUdfpsProps().get(0); mView.setCenterLocation(new PointF(props.sensorLocationX, props.sensorLocationY), props.sensorRadius); @@ -467,6 +460,7 @@ public class LockIconViewController extends ViewController impleme @Override public void onConfigChanged(Configuration newConfig) { updateConfiguration(); + updateColors(); } }; @@ -560,7 +554,7 @@ public class LockIconViewController extends ViewController impleme } private boolean isClickable() { - return mUdfpsEnrolled || mShowUnlockIcon; + return mUdfpsSupported || mShowUnlockIcon; } /** diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java index 594dcff2644d2..3c3f1f44d0c28 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsController.java @@ -72,6 +72,7 @@ import com.android.systemui.statusbar.LockscreenShadeTransitionController; import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; +import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.concurrency.DelayableExecutor; import com.android.systemui.util.concurrency.Execution; @@ -123,6 +124,7 @@ public class UdfpsController implements DozeReceiver { @NonNull private final LockscreenShadeTransitionController mLockscreenShadeTransitionController; @Nullable private final UdfpsHbmProvider mHbmProvider; @NonNull private final KeyguardBypassController mKeyguardBypassController; + @NonNull private final ConfigurationController mConfigurationController; @VisibleForTesting @NonNull final BiometricOrientationEventListener mOrientationListener; // Currently the UdfpsController supports a single UDFPS sensor. If devices have multiple // sensors, this, in addition to a lot of the code here, will be updated. @@ -522,7 +524,8 @@ public class UdfpsController implements DozeReceiver { @NonNull KeyguardStateController keyguardStateController, @NonNull KeyguardBypassController keyguardBypassController, @NonNull DisplayManager displayManager, - @Main Handler mainHandler) { + @Main Handler mainHandler, + @NonNull ConfigurationController configurationController) { mContext = context; mExecution = execution; // TODO (b/185124905): inject main handler and vibrator once done prototyping @@ -557,6 +560,7 @@ public class UdfpsController implements DozeReceiver { displayManager, mainHandler); mKeyguardBypassController = keyguardBypassController; + mConfigurationController = configurationController; mSensorProps = findFirstUdfps(); // At least one UDFPS sensor exists @@ -776,6 +780,7 @@ public class UdfpsController implements DozeReceiver { mDumpManager, mKeyguardViewMediator, mLockscreenShadeTransitionController, + mConfigurationController, this ); case IUdfpsOverlayController.REASON_AUTH_BP: diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardView.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardView.java index eb02aa0d9cdfe..d122610c395df 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardView.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardView.java @@ -22,7 +22,6 @@ import static com.android.systemui.doze.util.BurnInHelperKt.getBurnInProgressOff import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; -import android.animation.ArgbEvaluator; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.content.Context; @@ -51,17 +50,14 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { private UdfpsDrawable mFingerprintDrawable; // placeholder private LottieAnimationView mAodFp; private LottieAnimationView mLockScreenFp; - private int mUdfpsBouncerColor; - private int mWallpaperTextColor; private int mStatusBarState; // used when highlighting fp icon: private int mTextColorPrimary; private ImageView mBgProtection; boolean mUdfpsRequested; - int mUdfpsRequestedColor; - private AnimatorSet mAnimatorSet; + private AnimatorSet mBackgroundInAnimator = new AnimatorSet(); private int mAlpha; // 0-255 // AOD anti-burn-in offsets @@ -89,20 +85,15 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { super.onFinishInflate(); mAodFp = findViewById(R.id.udfps_aod_fp); mLockScreenFp = findViewById(R.id.udfps_lockscreen_fp); - mBgProtection = findViewById(R.id.udfps_keyguard_fp_bg); - mWallpaperTextColor = Utils.getColorAttrDefaultColor(mContext, - R.attr.wallpaperTextColorAccent); - mTextColorPrimary = Utils.getColorAttrDefaultColor(mContext, - android.R.attr.textColorPrimary); + updateColor(); - // requires call to invalidate to update the color (see #updateColor) + // requires call to invalidate to update the color mLockScreenFp.addValueCallback( new KeyPath("**"), LottieProperty.COLOR_FILTER, - frameInfo -> new PorterDuffColorFilter(getColor(), PorterDuff.Mode.SRC_ATOP) + frameInfo -> new PorterDuffColorFilter(mTextColorPrimary, PorterDuff.Mode.SRC_ATOP) ); - mUdfpsRequested = false; mHintAnimator = ObjectAnimator.ofFloat(mLockScreenFp, "progress", 1f, 0f, 1f); mHintAnimator.setDuration(4000); @@ -148,13 +139,7 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { } void requestUdfps(boolean request, int color) { - if (request) { - mUdfpsRequestedColor = color; - } else { - mUdfpsRequestedColor = -1; - } mUdfpsRequested = request; - updateColor(); } void setStatusBarState(int statusBarState) { @@ -162,31 +147,10 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { } void updateColor() { - mWallpaperTextColor = Utils.getColorAttrDefaultColor(mContext, - R.attr.wallpaperTextColorAccent); mTextColorPrimary = Utils.getColorAttrDefaultColor(mContext, android.R.attr.textColorPrimary); - mLockScreenFp.invalidate(); - mBgProtection.setBackground(getContext().getDrawable(R.drawable.fingerprint_bg)); - } - - private boolean showingUdfpsBouncer() { - return mBgProtection.getVisibility() == View.VISIBLE; - } - - - private int getColor() { - if (isUdfpsColorRequested()) { - return mUdfpsRequestedColor; - } else if (showingUdfpsBouncer()) { - return mUdfpsBouncerColor; - } else { - return mWallpaperTextColor; - } - } - - private boolean isUdfpsColorRequested() { - return mUdfpsRequested && mUdfpsRequestedColor != -1; + mBgProtection.setImageDrawable(getContext().getDrawable(R.drawable.fingerprint_bg)); + mLockScreenFp.invalidate(); // updated with a valueCallback } /** @@ -200,7 +164,13 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { @Override protected int updateAlpha() { int alpha = super.updateAlpha(); - mLockScreenFp.setImageAlpha(alpha); + mLockScreenFp.setAlpha(alpha / 255f); + if (mInterpolatedDarkAmount != 0f) { + mBgProtection.setAlpha(1f - mInterpolatedDarkAmount); + } else { + mBgProtection.setAlpha(alpha / 255f); + } + return alpha; } @@ -215,6 +185,7 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { void onDozeAmountChanged(float linear, float eased) { mHintAnimator.cancel(); mInterpolatedDarkAmount = eased; + updateAlpha(); updateBurnInOffsets(); } @@ -228,52 +199,21 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { /** * Animates in the bg protection circle behind the fp icon to highlight the icon. */ - void animateUdfpsBouncer(Runnable onEndAnimation) { - if (showingUdfpsBouncer() && mBgProtection.getAlpha() == 1f) { - // already fully highlighted, don't re-animate + void animateInUdfpsBouncer(Runnable onEndAnimation) { + if (mBackgroundInAnimator.isRunning()) { + // already animating in return; } - if (mAnimatorSet != null) { - mAnimatorSet.cancel(); - } - - mAnimatorSet = new AnimatorSet(); - mAnimatorSet.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); - mAnimatorSet.setDuration(500); - mAnimatorSet.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationStart(Animator animation) { - mBgProtection.setVisibility(View.VISIBLE); - } - }); - - ValueAnimator fpIconColorAnim; - if (isShadeLocked()) { - // set color and fade in since we weren't showing before - mUdfpsBouncerColor = mTextColorPrimary; - fpIconColorAnim = ValueAnimator.ofInt(0, 255); - fpIconColorAnim.addUpdateListener(valueAnimator -> - mLockScreenFp.setImageAlpha((int) valueAnimator.getAnimatedValue())); - } else { - // update icon color - fpIconColorAnim = new ValueAnimator(); - fpIconColorAnim.setIntValues( - isUdfpsColorRequested() ? mUdfpsRequestedColor : mWallpaperTextColor, - mTextColorPrimary); - fpIconColorAnim.setEvaluator(ArgbEvaluator.getInstance()); - fpIconColorAnim.addUpdateListener(valueAnimator -> { - mUdfpsBouncerColor = (int) valueAnimator.getAnimatedValue(); - updateColor(); - }); - } - - mAnimatorSet.playTogether( + // fade in and scale up + mBackgroundInAnimator = new AnimatorSet(); + mBackgroundInAnimator.playTogether( ObjectAnimator.ofFloat(mBgProtection, View.ALPHA, 0f, 1f), ObjectAnimator.ofFloat(mBgProtection, View.SCALE_X, 0f, 1f), - ObjectAnimator.ofFloat(mBgProtection, View.SCALE_Y, 0f, 1f), - fpIconColorAnim); - mAnimatorSet.addListener(new AnimatorListenerAdapter() { + ObjectAnimator.ofFloat(mBgProtection, View.SCALE_Y, 0f, 1f)); + mBackgroundInAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); + mBackgroundInAnimator.setDuration(500); + mBackgroundInAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (onEndAnimation != null) { @@ -281,66 +221,7 @@ public class UdfpsKeyguardView extends UdfpsAnimationView { } } }); - mAnimatorSet.start(); - } - - /** - * Animates out the bg protection circle behind the fp icon to unhighlight the icon. - */ - void animateAwayUdfpsBouncer(@Nullable Runnable onEndAnimation) { - if (!showingUdfpsBouncer()) { - // already hidden - return; - } - - if (mAnimatorSet != null) { - mAnimatorSet.cancel(); - } - - ValueAnimator fpIconColorAnim; - if (isShadeLocked()) { - // fade out - mUdfpsBouncerColor = mTextColorPrimary; - fpIconColorAnim = ValueAnimator.ofInt(255, 0); - fpIconColorAnim.addUpdateListener(valueAnimator -> - mLockScreenFp.setImageAlpha((int) valueAnimator.getAnimatedValue())); - } else { - // update icon color - fpIconColorAnim = new ValueAnimator(); - fpIconColorAnim.setIntValues( - mTextColorPrimary, - isUdfpsColorRequested() ? mUdfpsRequestedColor : mWallpaperTextColor); - fpIconColorAnim.setEvaluator(ArgbEvaluator.getInstance()); - fpIconColorAnim.addUpdateListener(valueAnimator -> { - mUdfpsBouncerColor = (int) valueAnimator.getAnimatedValue(); - updateColor(); - }); - } - - mAnimatorSet = new AnimatorSet(); - mAnimatorSet.playTogether( - ObjectAnimator.ofFloat(mBgProtection, View.ALPHA, 1f, 0f), - ObjectAnimator.ofFloat(mBgProtection, View.SCALE_X, 1f, 0f), - ObjectAnimator.ofFloat(mBgProtection, View.SCALE_Y, 1f, 0f), - fpIconColorAnim); - mAnimatorSet.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); - mAnimatorSet.setDuration(500); - - mAnimatorSet.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - mBgProtection.setVisibility(View.GONE); - if (onEndAnimation != null) { - onEndAnimation.run(); - } - } - }); - - mAnimatorSet.start(); - } - - boolean isAnimating() { - return mAnimatorSet != null && mAnimatorSet.isRunning(); + mBackgroundInAnimator.start(); } private boolean isShadeLocked() { diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.java b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.java index 6435bdd698725..58f1254da5638 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.java +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsKeyguardViewController.java @@ -19,6 +19,7 @@ package com.android.systemui.biometrics; import static com.android.systemui.statusbar.StatusBarState.KEYGUARD; import android.annotation.NonNull; +import android.content.res.Configuration; import android.hardware.biometrics.BiometricSourceType; import android.util.MathUtils; import android.view.MotionEvent; @@ -36,6 +37,7 @@ import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.phone.KeyguardBouncer; import com.android.systemui.statusbar.phone.StatusBar; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; +import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.util.concurrency.DelayableExecutor; import java.io.FileDescriptor; @@ -57,6 +59,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController