Animate panel to transparent if profile is managed
For managed profiles, we need to show the managed device background with
the device admin color theme during credential UI. Since it's shown on
the "background" view behind the panel, we can animate/fade the biometric
view down, and slide in the credential UI on the "background" layer.
Bug: 140127687
Test: manual test with device admin
Test: atest com.android.systemui.biometrics
Change-Id: I2d0a1b4367912e4bf6ddf701ad68fc387501f048
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricView.java
index 6914973..d20cd72 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricView.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthBiometricView.java
@@ -46,6 +46,8 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.List;
/**
* Contains the Biometric views (title, subtitle, icon, buttons, etc) and its controllers.
@@ -376,8 +378,17 @@
0 /* animateDurationMs */);
mSize = newSize;
} else if (newSize == AuthDialog.SIZE_LARGE) {
- final float translationY = getResources().getDimension(
- R.dimen.biometric_dialog_medium_to_large_translation_offset);
+ final boolean isManagedProfile = Utils.isManagedProfile(mContext, mUserId);
+
+ // If it's a managed profile, animate the contents and panel down, since the credential
+ // contents will be shown on the same "layer" as the background. If it's not a managed
+ // profile, animate the contents up and expand the panel to full-screen - the credential
+ // contents will be shown on the same "layer" as the panel.
+ final float translationY = isManagedProfile ?
+ -getResources().getDimension(
+ R.dimen.biometric_dialog_animation_translation_offset)
+ : getResources().getDimension(
+ R.dimen.biometric_dialog_medium_to_large_translation_offset);
final AuthBiometricView biometricView = this;
// Translate at full duration
@@ -407,13 +418,26 @@
biometricView.setAlpha(opacity);
});
- mPanelController.setUseFullScreen(true);
- mPanelController.updateForContentDimensions(
- mPanelController.getContainerWidth(),
- mPanelController.getContainerHeight(),
- mInjector.getMediumToLargeAnimationDurationMs());
+ if (!isManagedProfile) {
+ mPanelController.setUseFullScreen(true);
+ mPanelController.updateForContentDimensions(
+ mPanelController.getContainerWidth(),
+ mPanelController.getContainerHeight(),
+ mInjector.getMediumToLargeAnimationDurationMs());
+ }
+
+ // Start the animations together
AnimatorSet as = new AnimatorSet();
- as.play(translationAnimator).with(opacityAnimator);
+ List<Animator> animators = new ArrayList<>();
+ animators.add(translationAnimator);
+ animators.add(opacityAnimator);
+ if (isManagedProfile) {
+ animators.add(mPanelController.getTranslationAnimator(translationY));
+ animators.add(mPanelController.getAlphaAnimator(0));
+ }
+ as.playTogether(animators);
+ as.setDuration(isManagedProfile ? mInjector.getMediumToLargeAnimationDurationMs()
+ : mInjector.getMediumToLargeAnimationDurationMs() * 2 / 3);
as.start();
} else {
Log.e(TAG, "Unknown transition from: " + mSize + " to: " + newSize);
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java
index ced910f..a9359d4 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java
@@ -165,8 +165,9 @@
R.layout.auth_container_view, root, false /* attachToRoot */);
}
- AuthPanelController getPanelController(Context context, View panelView) {
- return new AuthPanelController(context, panelView);
+ AuthPanelController getPanelController(Context context, View panelView,
+ boolean isManagedProfile) {
+ return new AuthPanelController(context, panelView, isManagedProfile);
}
ImageView getBackgroundView(FrameLayout parent) {
@@ -234,8 +235,10 @@
final LayoutInflater factory = LayoutInflater.from(mContext);
mFrameLayout = mInjector.inflateContainerView(factory, this);
+ final boolean isManagedProfile = Utils.isManagedProfile(mContext, mConfig.mUserId);
+
mPanelView = mInjector.getPanelView(mFrameLayout);
- mPanelController = mInjector.getPanelController(mContext, mPanelView);
+ mPanelController = mInjector.getPanelController(mContext, mPanelView, isManagedProfile);
// Inflate biometric view only if necessary.
if (Utils.isBiometricAllowed(mConfig.mBiometricPromptBundle)) {
@@ -257,11 +260,11 @@
mBiometricScrollView = mInjector.getBiometricScrollView(mFrameLayout);
mBackgroundView = mInjector.getBackgroundView(mFrameLayout);
- UserManager userManager = mContext.getSystemService(UserManager.class);
- DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
- if (userManager.isManagedProfile(mConfig.mUserId)) {
+
+ if (isManagedProfile) {
final Drawable image = getResources().getDrawable(R.drawable.work_challenge_background,
mContext.getTheme());
+ final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
image.setColorFilter(dpm.getOrganizationColorForUser(mConfig.mUserId),
PorterDuff.Mode.DARKEN);
mBackgroundView.setScaleType(ImageView.ScaleType.CENTER_CROP);
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthPanelController.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthPanelController.java
index 18c1b4b..2b8b586 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthPanelController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthPanelController.java
@@ -19,10 +19,12 @@
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.content.Context;
+import android.graphics.Color;
import android.graphics.Outline;
import android.util.Log;
import android.view.View;
import android.view.ViewOutlineProvider;
+import android.view.animation.AccelerateDecelerateInterpolator;
import com.android.systemui.R;
@@ -36,6 +38,7 @@
private final Context mContext;
private final View mPanelView;
+ private final boolean mIsManagedProfile;
private boolean mUseFullScreen;
@@ -77,6 +80,24 @@
mUseFullScreen = fullScreen;
}
+ public ValueAnimator getTranslationAnimator(float relativeTranslationY) {
+ final ValueAnimator animator = ValueAnimator.ofFloat(
+ mPanelView.getY(), mPanelView.getY() - relativeTranslationY);
+ animator.addUpdateListener(animation -> {
+ final float translation = (float) animation.getAnimatedValue();
+ mPanelView.setTranslationY(translation);
+ });
+ return animator;
+ }
+
+ public ValueAnimator getAlphaAnimator(float alpha) {
+ final ValueAnimator animator = ValueAnimator.ofFloat(mPanelView.getAlpha(), alpha);
+ animator.addUpdateListener(animation -> {
+ mPanelView.setAlpha((float) animation.getAnimatedValue());
+ });
+ return animator;
+ }
+
public void updateForContentDimensions(int contentWidth, int contentHeight,
int animateDurationMs) {
if (DEBUG) {
@@ -95,6 +116,13 @@
final float cornerRadius = mUseFullScreen ? 0 : mContext.getResources()
.getDimension(R.dimen.biometric_dialog_corner_size);
+ // When going to full-screen for managed profiles, fade away so the managed profile
+ // background behind this view becomes visible.
+ final boolean shouldFadeAway = mUseFullScreen && mIsManagedProfile;
+ final int alpha = shouldFadeAway ? 0 : 255;
+ final float elevation = shouldFadeAway ? 0 :
+ mContext.getResources().getDimension(R.dimen.biometric_dialog_elevation);
+
if (animateDurationMs > 0) {
// Animate margin
ValueAnimator marginAnimator = ValueAnimator.ofInt(mMargin, margin);
@@ -122,16 +150,28 @@
mContentWidth = (int) animation.getAnimatedValue();
});
+ // Animate background
+ ValueAnimator alphaAnimator = ValueAnimator.ofInt(
+ mPanelView.getBackground().getAlpha(), alpha);
+ alphaAnimator.addUpdateListener((animation) -> {
+ if (shouldFadeAway) {
+ mPanelView.getBackground().setAlpha((int) animation.getAnimatedValue());
+ }
+ });
+
// Play together
AnimatorSet as = new AnimatorSet();
as.setDuration(animateDurationMs);
- as.playTogether(cornerAnimator, heightAnimator, widthAnimator, marginAnimator);
+ as.setInterpolator(new AccelerateDecelerateInterpolator());
+ as.playTogether(cornerAnimator, widthAnimator, marginAnimator, alphaAnimator);
as.start();
+
} else {
mMargin = margin;
mCornerRadius = cornerRadius;
mContentWidth = contentWidth;
mContentHeight = contentHeight;
+ mPanelView.getBackground().setAlpha(alpha);
mPanelView.invalidateOutline();
}
}
@@ -144,9 +184,10 @@
return mContainerHeight;
}
- AuthPanelController(Context context, View panelView) {
+ AuthPanelController(Context context, View panelView, boolean isManagedProfile) {
mContext = context;
mPanelView = panelView;
+ mIsManagedProfile = isManagedProfile;
mCornerRadius = context.getResources()
.getDimension(R.dimen.biometric_dialog_corner_size);
mMargin = (int) context.getResources()
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/Utils.java b/packages/SystemUI/src/com/android/systemui/biometrics/Utils.java
index b78a9ad..d6f830d 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/Utils.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/Utils.java
@@ -24,6 +24,7 @@
import android.hardware.biometrics.Authenticator;
import android.hardware.biometrics.BiometricPrompt;
import android.os.Bundle;
+import android.os.UserManager;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
@@ -99,4 +100,9 @@
return CREDENTIAL_PASSWORD;
}
}
+
+ static boolean isManagedProfile(Context context, int userId) {
+ final UserManager userManager = context.getSystemService(UserManager.class);
+ return userManager.isManagedProfile(userId);
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java
index 8550390..990f74a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java
@@ -192,7 +192,8 @@
}
@Override
- public AuthPanelController getPanelController(Context context, View view) {
+ public AuthPanelController getPanelController(Context context, View view,
+ boolean isManagedProfile) {
return mock(AuthPanelController.class);
}