diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt index c882f8adceb6c..c3bd5d96590e9 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayAnimationsController.kt @@ -182,6 +182,18 @@ constructor( } } + /** + * Ends the dream content and dream overlay animations, if they're currently running. + * @see [AnimatorSet.end] + */ + fun endAnimations() { + mAnimator = + mAnimator?.let { + it.end() + null + } + } + private fun blurAnimator( view: View, fromBlurRadius: Float, diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java index 539d2cad836d1..50cfb6a905c97 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayContainerViewController.java @@ -142,6 +142,23 @@ public class DreamOverlayContainerViewController extends ViewController callbackCaptor = + ArgumentCaptor.forClass(DreamOverlayStateController.Callback.class); + when(mStateController.isLowLightActive()).thenReturn(false); + + // Call onInit so that the callback is added. + mController.onInit(); + verify(mStateController).addCallback(callbackCaptor.capture()); + + // Send the signal that low light is exiting + callbackCaptor.getValue().onExitLowLight(); + + // View is attached to trigger animations. + mController.onViewAttached(); + + // Entry animations should be started then immediately ended to skip to the end. + verify(mAnimationsController).startEntryAnimations(); + verify(mAnimationsController).endAnimations(); + } + @Test public void testCancelDreamEntryAnimationsOnDetached() { mController.onViewAttached(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java index ee989d1ddab68..b7d0f294ecd44 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayStateControllerTest.java @@ -250,6 +250,30 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase { assertThat(stateController.isLowLightActive()).isTrue(); } + @Test + public void testNotifyLowLightExit() { + final DreamOverlayStateController stateController = + new DreamOverlayStateController(mExecutor, true); + + stateController.addCallback(mCallback); + mExecutor.runAllReady(); + assertThat(stateController.isLowLightActive()).isFalse(); + + // Turn low light on then off to trigger the exiting callback. + stateController.setLowLightActive(true); + stateController.setLowLightActive(false); + + // Callback was only called once, when + mExecutor.runAllReady(); + verify(mCallback, times(1)).onExitLowLight(); + assertThat(stateController.isLowLightActive()).isFalse(); + + // Set with false again, which should not cause the callback to trigger again. + stateController.setLowLightActive(false); + mExecutor.runAllReady(); + verify(mCallback, times(1)).onExitLowLight(); + } + @Test public void testNotifyEntryAnimationsFinishedChanged() { final DreamOverlayStateController stateController =