From fd49d593feced2288db6e982209eb21d215f976c Mon Sep 17 00:00:00 2001 From: Josh Tsuji Date: Tue, 14 Mar 2023 17:30:45 -0400 Subject: [PATCH] Don't animate scrim changes to UNLOCKED if we're occluding. The occlude animation suppresses the notification scrim alpha to 0f so that the animation can play over the lockscreen contents. When we finish that animation, we are currently animating from 1f to 0f, despite the current alpha being 0f already (due to the suppression). We can simply not animate this change to fix this, which is already done for activity launches. Fixes: 251275444 Test: launch timer from assistant on tablet Test: atest ScrimControllerTest Change-Id: Iccbe0124381a6cf1d813e8c1edb6c44b46cbd3fb --- .../statusbar/phone/ScrimController.java | 6 +++++- .../systemui/statusbar/phone/ScrimState.java | 12 ++++++++++- .../statusbar/phone/ScrimControllerTest.java | 21 +++++++++++++------ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java index f5d2eee35c933..00f26beb64785 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java @@ -796,6 +796,11 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump public void setOccludeAnimationPlaying(boolean occludeAnimationPlaying) { mOccludeAnimationPlaying = occludeAnimationPlaying; + + for (ScrimState state : ScrimState.values()) { + state.setOccludeAnimationPlaying(occludeAnimationPlaying); + } + applyAndDispatchState(); } @@ -840,7 +845,6 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump if (mState == ScrimState.UNLOCKED || mState == ScrimState.DREAMING) { final boolean occluding = mOccludeAnimationPlaying || mState.mLaunchingAffordanceWithPreview; - // Darken scrim as it's pulled down while unlocked. If we're unlocked but playing the // screen off/occlusion animations, ignore expansion changes while those animations // play. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimState.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimState.java index 0e9d3ce33d5b1..7b2028310a84e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimState.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimState.java @@ -243,7 +243,12 @@ public enum ScrimState { : CentralSurfaces.FADE_KEYGUARD_DURATION; boolean fromAod = previousState == AOD || previousState == PULSING; - mAnimateChange = !mLaunchingAffordanceWithPreview && !fromAod; + // If launch/occlude animations were playing, they already animated the scrim + // alpha to 0f as part of the animation. If we animate it now, we'll set it back + // to 1f and animate it back to 0f, causing an unwanted scrim flash. + mAnimateChange = !mLaunchingAffordanceWithPreview + && !mOccludeAnimationPlaying + && !fromAod; mFrontTint = Color.TRANSPARENT; mBehindTint = Color.BLACK; @@ -308,6 +313,7 @@ public enum ScrimState { boolean mWallpaperSupportsAmbientMode; boolean mHasBackdrop; boolean mLaunchingAffordanceWithPreview; + boolean mOccludeAnimationPlaying; boolean mWakeLockScreenSensorActive; boolean mKeyguardFadingAway; long mKeyguardFadingAwayDuration; @@ -411,6 +417,10 @@ public enum ScrimState { mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview; } + public void setOccludeAnimationPlaying(boolean occludeAnimationPlaying) { + mOccludeAnimationPlaying = occludeAnimationPlaying; + } + public boolean isLowPowerState() { return false; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java index 7a1270f3521d2..a9ed175319265 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java @@ -25,6 +25,7 @@ import static com.android.systemui.statusbar.phone.ScrimState.SHADE_LOCKED; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyFloat; import static org.mockito.ArgumentMatchers.anyInt; @@ -1163,8 +1164,8 @@ public class ScrimControllerTest extends SysuiTestCase { @Test public void testScrimFocus() { mScrimController.transitionTo(ScrimState.AOD); - Assert.assertFalse("Should not be focusable on AOD", mScrimBehind.isFocusable()); - Assert.assertFalse("Should not be focusable on AOD", mScrimInFront.isFocusable()); + assertFalse("Should not be focusable on AOD", mScrimBehind.isFocusable()); + assertFalse("Should not be focusable on AOD", mScrimInFront.isFocusable()); mScrimController.transitionTo(ScrimState.KEYGUARD); Assert.assertTrue("Should be focusable on keyguard", mScrimBehind.isFocusable()); @@ -1224,7 +1225,7 @@ public class ScrimControllerTest extends SysuiTestCase { public void testAnimatesTransitionToAod() { when(mDozeParameters.shouldControlScreenOff()).thenReturn(false); ScrimState.AOD.prepare(ScrimState.KEYGUARD); - Assert.assertFalse("No animation when ColorFade kicks in", + assertFalse("No animation when ColorFade kicks in", ScrimState.AOD.getAnimateChange()); reset(mDozeParameters); @@ -1236,9 +1237,9 @@ public class ScrimControllerTest extends SysuiTestCase { @Test public void testViewsDontHaveFocusHighlight() { - Assert.assertFalse("Scrim shouldn't have focus highlight", + assertFalse("Scrim shouldn't have focus highlight", mScrimInFront.getDefaultFocusHighlightEnabled()); - Assert.assertFalse("Scrim shouldn't have focus highlight", + assertFalse("Scrim shouldn't have focus highlight", mScrimBehind.getDefaultFocusHighlightEnabled()); } @@ -1738,7 +1739,7 @@ public class ScrimControllerTest extends SysuiTestCase { @Test public void aodStateSetsFrontScrimToNotBlend() { mScrimController.transitionTo(ScrimState.AOD); - Assert.assertFalse("Front scrim should not blend with main color", + assertFalse("Front scrim should not blend with main color", mScrimInFront.shouldBlendWithMainColor()); } @@ -1773,6 +1774,14 @@ public class ScrimControllerTest extends SysuiTestCase { verify(mStatusBarKeyguardViewManager).onKeyguardFadedAway(); } + @Test + public void testDoNotAnimateChangeIfOccludeAnimationPlaying() { + mScrimController.setOccludeAnimationPlaying(true); + mScrimController.transitionTo(ScrimState.UNLOCKED); + + assertFalse(ScrimState.UNLOCKED.mAnimateChange); + } + private void assertAlphaAfterExpansion(ScrimView scrim, float expectedAlpha, float expansion) { mScrimController.setRawPanelExpansionFraction(expansion); finishAnimationsImmediately();