From c86f2affc87273eac7fddcdf7cf006be29c9fde7 Mon Sep 17 00:00:00 2001 From: Peter Kalauskas Date: Thu, 6 Apr 2023 19:18:14 +0000 Subject: [PATCH] Revert "Fix jank in CUJ_SCREEN_OFF_SHOW_AOD" This reverts commit 1e3ee3375d219999462fc8dd25fe7194b0261a3e. Reason for revert: b/277237119 Change-Id: Ieefd81511ce6cba407a1113e24214916af75a3ad --- .../keyguard/KeyguardVisibilityHelper.java | 10 +--- .../phone/ScreenOffAnimationController.kt | 22 +++------ .../UnlockedScreenOffAnimationController.kt | 46 ++++++------------- 3 files changed, 23 insertions(+), 55 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardVisibilityHelper.java b/packages/SystemUI/src/com/android/keyguard/KeyguardVisibilityHelper.java index ac0a3fd8dbc4a..a678edc0eb06e 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardVisibilityHelper.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardVisibilityHelper.java @@ -28,7 +28,6 @@ import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.notification.AnimatableProperty; import com.android.systemui.statusbar.notification.PropertyAnimator; import com.android.systemui.statusbar.notification.stack.AnimationProperties; -import com.android.systemui.statusbar.phone.AnimatorHandle; import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.statusbar.phone.ScreenOffAnimationController; import com.android.systemui.statusbar.policy.KeyguardStateController; @@ -48,7 +47,6 @@ public class KeyguardVisibilityHelper { private final ScreenOffAnimationController mScreenOffAnimationController; private boolean mAnimateYPos; private boolean mKeyguardViewVisibilityAnimating; - private AnimatorHandle mKeyguardAnimatorHandle; private boolean mLastOccludedState = false; private final AnimationProperties mAnimationProperties = new AnimationProperties(); private final LogBuffer mLogBuffer; @@ -85,10 +83,6 @@ public class KeyguardVisibilityHelper { boolean keyguardFadingAway, boolean goingToFullShade, int oldStatusBarState) { - if (mKeyguardAnimatorHandle != null) { - mKeyguardAnimatorHandle.cancel(); - mKeyguardAnimatorHandle = null; - } mView.animate().cancel(); boolean isOccluded = mKeyguardStateController.isOccluded(); mKeyguardViewVisibilityAnimating = false; @@ -122,7 +116,7 @@ public class KeyguardVisibilityHelper { .setDuration(320) .setInterpolator(Interpolators.ALPHA_IN) .withEndAction(mAnimateKeyguardStatusViewVisibleEndRunnable); - log("keyguardFadingAway transition w/ Y Animation"); + log("keyguardFadingAway transition w/ Y Aniamtion"); } else if (statusBarState == KEYGUARD) { if (keyguardFadingAway) { mKeyguardViewVisibilityAnimating = true; @@ -154,7 +148,7 @@ public class KeyguardVisibilityHelper { // Ask the screen off animation controller to animate the keyguard visibility for us // since it may need to be cancelled due to keyguard lifecycle events. - mKeyguardAnimatorHandle = mScreenOffAnimationController.animateInKeyguard( + mScreenOffAnimationController.animateInKeyguard( mView, mAnimateKeyguardStatusViewVisibleEndRunnable); } else { log("Direct set Visibility to VISIBLE"); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScreenOffAnimationController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScreenOffAnimationController.kt index b3031515ae9d2..c8174669cc653 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScreenOffAnimationController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScreenOffAnimationController.kt @@ -85,17 +85,16 @@ class ScreenOffAnimationController @Inject constructor( /** * Called when keyguard is about to be displayed and allows to perform custom animation - * - * @return A handle that can be used for cancelling the animation, if necessary */ - fun animateInKeyguard(keyguardView: View, after: Runnable): AnimatorHandle? { - animations.forEach { + fun animateInKeyguard(keyguardView: View, after: Runnable) = + animations.firstOrNull { if (it.shouldAnimateInKeyguard()) { - return@animateInKeyguard it.animateInKeyguard(keyguardView, after) + it.animateInKeyguard(keyguardView, after) + true + } else { + false } } - return null - } /** * If returns true it will disable propagating touches to apps and keyguard @@ -212,10 +211,7 @@ interface ScreenOffAnimation { fun onAlwaysOnChanged(alwaysOn: Boolean) {} fun shouldAnimateInKeyguard(): Boolean = false - fun animateInKeyguard(keyguardView: View, after: Runnable): AnimatorHandle? { - after.run() - return null - } + fun animateInKeyguard(keyguardView: View, after: Runnable) = after.run() fun shouldDelayKeyguardShow(): Boolean = false fun isKeyguardShowDelayed(): Boolean = false @@ -228,7 +224,3 @@ interface ScreenOffAnimation { fun shouldAnimateDozingChange(): Boolean = true fun shouldAnimateClockChange(): Boolean = true } - -interface AnimatorHandle { - fun cancel() -} \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt index deb041454da4d..118bfc55dd4c7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt @@ -160,7 +160,7 @@ class UnlockedScreenOffAnimationController @Inject constructor( * Animates in the provided keyguard view, ending in the same position that it will be in on * AOD. */ - override fun animateInKeyguard(keyguardView: View, after: Runnable): AnimatorHandle { + override fun animateInKeyguard(keyguardView: View, after: Runnable) { shouldAnimateInKeyguard = false keyguardView.alpha = 0f keyguardView.visibility = View.VISIBLE @@ -175,36 +175,11 @@ class UnlockedScreenOffAnimationController @Inject constructor( // We animate the Y properly separately using the PropertyAnimator, as the panel // view also needs to update the end position. PropertyAnimator.cancelAnimation(keyguardView, AnimatableProperty.Y) + PropertyAnimator.setProperty(keyguardView, AnimatableProperty.Y, currentY, + AnimationProperties().setDuration(duration.toLong()), + true /* animate */) - // Start the animation on the next frame using Choreographer APIs. animateInKeyguard() is - // called while the system is busy processing lots of requests, so delaying the animation a - // frame will mitigate jank. In the event the animation is cancelled before the next frame - // is called, this callback will be removed - val keyguardAnimator = keyguardView.animate() - val nextFrameCallback = TraceUtils.namedRunnable("startAnimateInKeyguard") { - PropertyAnimator.setProperty(keyguardView, AnimatableProperty.Y, currentY, - AnimationProperties().setDuration(duration.toLong()), - true /* animate */) - keyguardAnimator.start() - } - DejankUtils.postAfterTraversal(nextFrameCallback) - val animatorHandle = object : AnimatorHandle { - private var hasCancelled = false - override fun cancel() { - if (!hasCancelled) { - DejankUtils.removeCallbacks(nextFrameCallback) - // If we're cancelled, reset state flags/listeners. The end action above - // will not be called, which is what we want since that will finish the - // screen off animation and show the lockscreen, which we don't want if we - // were cancelled. - aodUiAnimationPlaying = false - decidedToAnimateGoingToSleep = null - keyguardView.animate().setListener(null) - hasCancelled = true - } - } - } - keyguardAnimator + keyguardView.animate() .setDuration(duration.toLong()) .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) .alpha(1f) @@ -230,7 +205,14 @@ class UnlockedScreenOffAnimationController @Inject constructor( } .setListener(object : AnimatorListenerAdapter() { override fun onAnimationCancel(animation: Animator?) { - animatorHandle.cancel() + // If we're cancelled, reset state flags/listeners. The end action above + // will not be called, which is what we want since that will finish the + // screen off animation and show the lockscreen, which we don't want if we + // were cancelled. + aodUiAnimationPlaying = false + decidedToAnimateGoingToSleep = null + keyguardView.animate().setListener(null) + interactionJankMonitor.cancel(CUJ_SCREEN_OFF_SHOW_AOD) } @@ -240,7 +222,7 @@ class UnlockedScreenOffAnimationController @Inject constructor( CUJ_SCREEN_OFF_SHOW_AOD) } }) - return animatorHandle + .start() } override fun onStartedWakingUp() {