Sync wallpaper animation with unlock animation

Fix: 281859780
Test: atest --iterations 40 CameraMicIndicatorsPermissionTest
Test: atest --iterations 20 KeyguardUnlockAnimationControllerTest
Change-Id: I7bc350689affde76f9d3427ea94ff31f56bb75f0
This commit is contained in:
Robin Lee
2023-05-13 13:31:36 +02:00
parent 0ce5c2dca6
commit 0ed572b2a7
3 changed files with 41 additions and 78 deletions

View File

@@ -258,12 +258,10 @@ class KeyguardUnlockAnimationController @Inject constructor(
*/
private var surfaceBehindAlpha = 1f
private var wallpaperAlpha = 1f
@VisibleForTesting
var surfaceBehindAlphaAnimator = ValueAnimator.ofFloat(0f, 1f)
var wallpaperAlphaAnimator = ValueAnimator.ofFloat(0f, 1f)
var wallpaperCannedUnlockAnimator = ValueAnimator.ofFloat(0f, 1f)
/**
* Matrix applied to [surfaceBehindRemoteAnimationTarget], which is the surface of the
@@ -330,6 +328,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
if (surfaceBehindAlpha == 0f) {
Log.d(TAG, "surfaceBehindAlphaAnimator#onAnimationEnd")
surfaceBehindRemoteAnimationTargets = null
wallpaperTargets = null
keyguardViewMediator.get().finishSurfaceBehindRemoteAnimation(
false /* cancelled */)
} else {
@@ -340,23 +339,17 @@ class KeyguardUnlockAnimationController @Inject constructor(
})
}
with(wallpaperAlphaAnimator) {
with(wallpaperCannedUnlockAnimator) {
duration = LAUNCHER_ICONS_ANIMATION_DURATION_MS
interpolator = Interpolators.ALPHA_OUT
addUpdateListener { valueAnimator: ValueAnimator ->
wallpaperAlpha = valueAnimator.animatedValue as Float
setWallpaperAppearAmount(wallpaperAlpha)
setWallpaperAppearAmount(valueAnimator.animatedValue as Float)
}
addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
Log.d(TAG, "wallpaperAlphaAnimator#onAnimationEnd, animation ended ")
if (wallpaperAlpha == 1f) {
wallpaperTargets = null
keyguardViewMediator.get().finishExitRemoteAnimation()
} else {
Log.d(TAG, "wallpaperAlphaAnimator#onAnimationEnd, " +
"animation was cancelled: skipping finishAnimation()")
}
Log.d(TAG, "wallpaperCannedUnlockAnimator#onAnimationEnd")
keyguardViewMediator.get().exitKeyguardAndFinishSurfaceBehindRemoteAnimation(
false /* cancelled */)
}
})
}
@@ -387,11 +380,6 @@ class KeyguardUnlockAnimationController @Inject constructor(
context.resources.getDimensionPixelSize(R.dimen.rounded_corner_radius).toFloat()
}
fun isAnyKeyguyardAnimatorPlaying(): Boolean {
return surfaceBehindAlphaAnimator.isStarted ||
wallpaperAlphaAnimator.isStarted || surfaceBehindEntryAnimator.isStarted
}
/**
* Add a listener to be notified of various stages of the unlock animation.
*/
@@ -536,8 +524,6 @@ class KeyguardUnlockAnimationController @Inject constructor(
wallpaperTargets = wallpapers
surfaceBehindRemoteAnimationStartTime = startTime
fadeInWallpaper()
// If we specifically requested that the surface behind be made visible (vs. it being made
// visible because we're unlocking), then we're in the middle of a swipe-to-unlock touch
// gesture and the surface behind the keyguard should be made visible so that we can animate
@@ -599,7 +585,9 @@ class KeyguardUnlockAnimationController @Inject constructor(
// Finish the keyguard remote animation if the dismiss amount has crossed the threshold.
// Check it here in case there is no more change to the dismiss amount after the last change
// that starts the keyguard animation. @see #updateKeyguardViewMediatorIfThresholdsReached()
finishKeyguardExitRemoteAnimationIfReachThreshold()
if (!playingCannedUnlockAnimation) {
finishKeyguardExitRemoteAnimationIfReachThreshold()
}
}
/**
@@ -650,7 +638,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
* transition if possible.
*/
private fun unlockToLauncherWithInWindowAnimations() {
setSurfaceBehindAppearAmount(1f)
setSurfaceBehindAppearAmount(1f, wallpapers = false)
try {
// Begin the animation, waiting for the shade to animate out.
@@ -676,19 +664,8 @@ class KeyguardUnlockAnimationController @Inject constructor(
// visible, hide our smartspace.
lockscreenSmartspace?.visibility = View.INVISIBLE
// As soon as the shade has animated out of the way, finish the keyguard exit animation. The
// in-window animations in the Launcher window will end on their own.
handler.postDelayed({
if (keyguardViewMediator.get().isShowingAndNotOccluded &&
!keyguardStateController.isKeyguardGoingAway) {
Log.e(TAG, "Finish keyguard exit animation delayed Runnable ran, but we are " +
"showing and not going away.")
return@postDelayed
}
keyguardViewMediator.get().exitKeyguardAndFinishSurfaceBehindRemoteAnimation(
false /* cancelled */)
}, CANNED_UNLOCK_START_DELAY)
// Start an animation for the wallpaper, which will finish keyguard exit when it completes.
fadeInWallpaper()
}
/**
@@ -809,7 +786,16 @@ class KeyguardUnlockAnimationController @Inject constructor(
* animations and swipe gestures to animate the surface's entry (and exit, if the swipe is
* cancelled).
*/
fun setSurfaceBehindAppearAmount(amount: Float) {
fun setSurfaceBehindAppearAmount(amount: Float, wallpapers: Boolean = true) {
val animationAlpha = when {
// If we're snapping the keyguard back, immediately begin fading it out.
keyguardStateController.isSnappingKeyguardBackAfterSwipe -> amount
// If the screen has turned back off, the unlock animation is going to be cancelled,
// so set the surface alpha to 0f so it's no longer visible.
!powerManager.isInteractive -> 0f
else -> surfaceBehindAlpha
}
surfaceBehindRemoteAnimationTargets?.forEach { surfaceBehindRemoteAnimationTarget ->
val surfaceHeight: Int = surfaceBehindRemoteAnimationTarget.screenSpaceBounds.height()
@@ -839,16 +825,6 @@ class KeyguardUnlockAnimationController @Inject constructor(
surfaceHeight * SURFACE_BEHIND_SCALE_PIVOT_Y
)
val animationAlpha = when {
// If we're snapping the keyguard back, immediately begin fading it out.
keyguardStateController.isSnappingKeyguardBackAfterSwipe -> amount
// If the screen has turned back off, the unlock animation is going to be cancelled,
// so set the surface alpha to 0f so it's no longer visible.
!powerManager.isInteractive -> 0f
else -> surfaceBehindAlpha
}
// SyncRtSurfaceTransactionApplier cannot apply transaction when the target view is
// unable to draw
val sc: SurfaceControl? = surfaceBehindRemoteAnimationTarget.leash
@@ -863,28 +839,27 @@ class KeyguardUnlockAnimationController @Inject constructor(
} else {
applyParamsToSurface(
SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(
surfaceBehindRemoteAnimationTarget.leash)
.withMatrix(surfaceBehindMatrix)
.withCornerRadius(roundedCornerRadius)
.withAlpha(animationAlpha)
.build()
surfaceBehindRemoteAnimationTarget.leash)
.withMatrix(surfaceBehindMatrix)
.withCornerRadius(roundedCornerRadius)
.withAlpha(animationAlpha)
.build()
)
}
}
if (wallpapers) {
setWallpaperAppearAmount(amount)
}
}
/**
* Modify the opacity of a wallpaper window.
*/
fun setWallpaperAppearAmount(amount: Float) {
wallpaperTargets?.forEach { wallpaper ->
val animationAlpha = when {
// If the screen has turned back off, the unlock animation is going to be cancelled,
// so set the surface alpha to 0f so it's no longer visible.
!powerManager.isInteractive -> 0f
else -> amount
}
val animationAlpha = when {
!powerManager.isInteractive -> 0f
else -> amount
}
wallpaperTargets?.forEach { wallpaper ->
// SyncRtSurfaceTransactionApplier cannot apply transaction when the target view is
// unable to draw
val sc: SurfaceControl? = wallpaper.leash
@@ -923,6 +898,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
setSurfaceBehindAppearAmount(1f)
surfaceBehindAlphaAnimator.cancel()
surfaceBehindEntryAnimator.cancel()
wallpaperCannedUnlockAnimator.cancel()
try {
launcherUnlockController?.setUnlockAmount(1f, false /* forceIfAnimating */)
} catch (e: RemoteException) {
@@ -931,6 +907,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
// That target is no longer valid since the animation finished, null it out.
surfaceBehindRemoteAnimationTargets = null
wallpaperTargets = null
playingCannedUnlockAnimation = false
willUnlockWithInWindowLauncherAnimations = false
@@ -972,8 +949,8 @@ class KeyguardUnlockAnimationController @Inject constructor(
private fun fadeInWallpaper() {
Log.d(TAG, "fadeInWallpaper")
wallpaperAlphaAnimator.cancel()
wallpaperAlphaAnimator.start()
wallpaperCannedUnlockAnimator.cancel()
wallpaperCannedUnlockAnimator.start()
}
private fun fadeOutSurfaceBehind() {

View File

@@ -3009,19 +3009,6 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
mSurfaceBehindRemoteAnimationRequested = false;
mSurfaceBehindRemoteAnimationRunning = false;
mKeyguardStateController.notifyKeyguardGoingAway(false);
finishExitRemoteAnimation();
}
void finishExitRemoteAnimation() {
if (mKeyguardUnlockAnimationControllerLazy.get().isAnyKeyguyardAnimatorPlaying()
|| mKeyguardStateController.isDismissingFromSwipe()) {
// If the animation is ongoing, or we are not done with the swipe gesture,
// it's too early to terminate the animation
Log.d(TAG, "finishAnimation not executing now because "
+ "not all animations have finished");
return;
}
Log.d(TAG, "finishAnimation executing");
if (mSurfaceBehindRemoteAnimationFinishedCallback != null) {
try {

View File

@@ -114,7 +114,6 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
@After
fun tearDown() {
keyguardUnlockAnimationController.notifyFinishedKeyguardExitAnimation(true)
keyguardUnlockAnimationController.wallpaperAlphaAnimator.cancel()
}
/**