NSSL: Smooth transition from shade->lockscreen

The current animation is rather abrupt. Have it fade in with the rest
of lockscreen.

Also, remove flatmaps from bounds and max notification
calculations. This was causing a slight delay in updating those
values. Use a straightforward combine instead.

To ensure a smooth transition, make sure the legacy finger tracking
stops properly.

Fixes: 310993802
Test: atest SharedNotificationContainerViewModelTest
Flag: ACONFIG com.android.systemui.keyguard_shade_migration_nssl
DEVELOPMENT

Change-Id: Icff993a5622290f98ee699220a4010eb1fbba015
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultNotificationStackScrollLayoutSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultNotificationStackScrollLayoutSection.kt
index 0588857..108f2a3 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultNotificationStackScrollLayoutSection.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultNotificationStackScrollLayoutSection.kt
@@ -24,6 +24,7 @@
 import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID
 import androidx.constraintlayout.widget.ConstraintSet.START
 import androidx.constraintlayout.widget.ConstraintSet.TOP
+import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.deviceentry.shared.DeviceEntryUdfpsRefactor
 import com.android.systemui.flags.FeatureFlags
 import com.android.systemui.flags.Flags
@@ -39,6 +40,7 @@
 import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationStackAppearanceViewModel
 import com.android.systemui.statusbar.notification.stack.ui.viewmodel.SharedNotificationContainerViewModel
 import javax.inject.Inject
+import kotlinx.coroutines.CoroutineDispatcher
 
 /** Single column format for notifications (default for phones) */
 class DefaultNotificationStackScrollLayoutSection
@@ -55,6 +57,7 @@
     controller: NotificationStackScrollLayoutController,
     notificationStackSizeCalculator: NotificationStackSizeCalculator,
     private val smartspaceViewModel: KeyguardSmartspaceViewModel,
+    @Main mainDispatcher: CoroutineDispatcher,
 ) :
     NotificationStackScrollLayoutSection(
         context,
@@ -66,6 +69,7 @@
         ambientState,
         controller,
         notificationStackSizeCalculator,
+        mainDispatcher,
     ) {
     override fun applyConstraints(constraintSet: ConstraintSet) {
         if (!KeyguardShadeMigrationNssl.isEnabled) {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/NotificationStackScrollLayoutSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/NotificationStackScrollLayoutSection.kt
index a9e766e..a25471c 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/NotificationStackScrollLayoutSection.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/NotificationStackScrollLayoutSection.kt
@@ -35,6 +35,7 @@
 import com.android.systemui.statusbar.notification.stack.ui.viewbinder.SharedNotificationContainerBinder
 import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationStackAppearanceViewModel
 import com.android.systemui.statusbar.notification.stack.ui.viewmodel.SharedNotificationContainerViewModel
+import kotlinx.coroutines.CoroutineDispatcher
 import kotlinx.coroutines.DisposableHandle
 
 abstract class NotificationStackScrollLayoutSection
@@ -48,6 +49,7 @@
     private val ambientState: AmbientState,
     private val controller: NotificationStackScrollLayoutController,
     private val notificationStackSizeCalculator: NotificationStackSizeCalculator,
+    private val mainDispatcher: CoroutineDispatcher,
 ) : KeyguardSection() {
     private val placeHolderId = R.id.nssl_placeholder
     private var disposableHandle: DisposableHandle? = null
@@ -79,6 +81,7 @@
                 sceneContainerFlags,
                 controller,
                 notificationStackSizeCalculator,
+                mainDispatcher,
             )
         if (sceneContainerFlags.flexiNotifsEnabled()) {
             NotificationStackAppearanceViewBinder.bind(
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeNotificationStackScrollLayoutSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeNotificationStackScrollLayoutSection.kt
index 05ef5c3..8640e00 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeNotificationStackScrollLayoutSection.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeNotificationStackScrollLayoutSection.kt
@@ -24,6 +24,7 @@
 import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID
 import androidx.constraintlayout.widget.ConstraintSet.START
 import androidx.constraintlayout.widget.ConstraintSet.TOP
+import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.deviceentry.shared.DeviceEntryUdfpsRefactor
 import com.android.systemui.flags.FeatureFlags
 import com.android.systemui.flags.Flags
@@ -39,6 +40,7 @@
 import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationStackAppearanceViewModel
 import com.android.systemui.statusbar.notification.stack.ui.viewmodel.SharedNotificationContainerViewModel
 import javax.inject.Inject
+import kotlinx.coroutines.CoroutineDispatcher
 
 /** Large-screen format for notifications, shown as two columns on the device */
 class SplitShadeNotificationStackScrollLayoutSection
@@ -55,6 +57,7 @@
     controller: NotificationStackScrollLayoutController,
     notificationStackSizeCalculator: NotificationStackSizeCalculator,
     private val smartspaceViewModel: KeyguardSmartspaceViewModel,
+    @Main mainDispatcher: CoroutineDispatcher,
 ) :
     NotificationStackScrollLayoutSection(
         context,
@@ -66,6 +69,7 @@
         ambientState,
         controller,
         notificationStackSizeCalculator,
+        mainDispatcher,
     ) {
     override fun applyConstraints(constraintSet: ConstraintSet) {
         if (!KeyguardShadeMigrationNssl.isEnabled) {
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
index 8e98d89..61ff9a5 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java
@@ -2677,17 +2677,20 @@
         if (mIsOcclusionTransitionRunning) {
             return;
         }
-        float alpha = 1f;
-        if (mClosingWithAlphaFadeOut && !mExpandingFromHeadsUp
+
+        if (!KeyguardShadeMigrationNssl.isEnabled()) {
+            float alpha = 1f;
+            if (mClosingWithAlphaFadeOut && !mExpandingFromHeadsUp
                 && !mHeadsUpManager.hasPinnedHeadsUp()) {
-            alpha = getFadeoutAlpha();
-        }
-        if (mBarState == KEYGUARD
+                alpha = getFadeoutAlpha();
+            }
+            if (mBarState == KEYGUARD
                 && !mKeyguardBypassController.getBypassEnabled()
                 && !mQsController.getFullyExpanded()) {
-            alpha *= mClockPositionResult.clockAlpha;
+                alpha *= mClockPositionResult.clockAlpha;
+            }
+            mNotificationStackScrollLayoutController.setMaxAlphaForExpansion(alpha);
         }
-        mNotificationStackScrollLayoutController.setMaxAlphaForExpansion(alpha);
     }
 
     private float getFadeoutAlpha() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/LockscreenShadeTransitionController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/LockscreenShadeTransitionController.kt
index 49c729e..2438298 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/LockscreenShadeTransitionController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/LockscreenShadeTransitionController.kt
@@ -351,7 +351,6 @@
         )
         nsslController.resetScrollPosition()
         nsslController.resetCheckSnoozeLeavebehind()
-        shadeRepository.setLegacyLockscreenShadeTracking(false)
         setDragDownAmountAnimated(0f)
     }
 
@@ -378,7 +377,6 @@
                 cancel()
             }
         }
-        shadeRepository.setLegacyLockscreenShadeTracking(true)
     }
 
     /** Do we need a falsing check currently? */
@@ -836,7 +834,12 @@
                     initialTouchX = x
                     dragDownCallback.onDragDownStarted(startingChild)
                     dragDownAmountOnStart = dragDownCallback.dragDownAmount
-                    return startingChild != null || dragDownCallback.isDragDownAnywhereEnabled
+                    val intercepted =
+                        startingChild != null || dragDownCallback.isDragDownAnywhereEnabled
+                    if (intercepted) {
+                        shadeRepository.setLegacyLockscreenShadeTracking(true)
+                    }
+                    return intercepted
                 }
             }
         }
@@ -964,6 +967,7 @@
         }
         isDraggingDown = false
         isTrackpadReverseScroll = false
+        shadeRepository.setLegacyLockscreenShadeTracking(false)
         dragDownCallback.onDragDownReset()
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/SharedNotificationContainerBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/SharedNotificationContainerBinder.kt
index 7b2caea..af56a3f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/SharedNotificationContainerBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/SharedNotificationContainerBinder.kt
@@ -16,8 +16,12 @@
 
 package com.android.systemui.statusbar.notification.stack.ui.viewbinder
 
+import android.animation.Animator
+import android.animation.AnimatorListenerAdapter
+import android.animation.ValueAnimator
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.repeatOnLifecycle
+import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.lifecycle.repeatWhenAttached
 import com.android.systemui.scene.shared.flag.SceneContainerFlags
 import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController
@@ -25,6 +29,7 @@
 import com.android.systemui.statusbar.notification.stack.shared.flexiNotifsEnabled
 import com.android.systemui.statusbar.notification.stack.ui.view.SharedNotificationContainer
 import com.android.systemui.statusbar.notification.stack.ui.viewmodel.SharedNotificationContainerViewModel
+import kotlinx.coroutines.CoroutineDispatcher
 import kotlinx.coroutines.DisposableHandle
 import kotlinx.coroutines.launch
 
@@ -38,6 +43,7 @@
         sceneContainerFlags: SceneContainerFlags,
         controller: NotificationStackScrollLayoutController,
         notificationStackSizeCalculator: NotificationStackSizeCalculator,
+        @Main mainImmediateDispatcher: CoroutineDispatcher,
     ): DisposableHandle {
         val disposableHandle =
             view.repeatWhenAttached {
@@ -57,6 +63,41 @@
                             controller.updateFooter()
                         }
                     }
+                }
+            }
+
+        /*
+         * For animation sensitive coroutines, immediately run just like applicationScope does
+         * instead of doing a post() to the main thread. This extra delay can cause visible jitter.
+         */
+        val disposableHandleMainImmediate =
+            view.repeatWhenAttached(mainImmediateDispatcher) {
+                repeatOnLifecycle(Lifecycle.State.CREATED) {
+                    if (!sceneContainerFlags.flexiNotifsEnabled()) {
+                        launch {
+                            // Only temporarily needed, until flexi notifs go live
+                            viewModel.shadeCollpaseFadeIn.collect { fadeIn ->
+                                if (fadeIn) {
+                                    android.animation.ValueAnimator.ofFloat(0f, 1f).apply {
+                                        duration = 350
+                                        addUpdateListener { animation ->
+                                            controller.setMaxAlphaForExpansion(
+                                                animation.getAnimatedFraction()
+                                            )
+                                        }
+                                        addListener(
+                                            object : AnimatorListenerAdapter() {
+                                                override fun onAnimationEnd(animation: Animator) {
+                                                    viewModel.setShadeCollapseFadeInComplete(true)
+                                                }
+                                            }
+                                        )
+                                        start()
+                                    }
+                                }
+                            }
+                        }
+                    }
 
                     launch {
                         viewModel
@@ -92,6 +133,7 @@
         return object : DisposableHandle {
             override fun dispose() {
                 disposableHandle.dispose()
+                disposableHandleMainImmediate.dispose()
                 controller.setOnHeightChangedRunnable(null)
             }
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt
index da847c0..b0f1038 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt
@@ -24,24 +24,31 @@
 import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
 import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
 import com.android.systemui.keyguard.shared.model.KeyguardState
+import com.android.systemui.keyguard.shared.model.StatusBarState.SHADE_LOCKED
+import com.android.systemui.keyguard.ui.viewmodel.LockscreenToOccludedTransitionViewModel
 import com.android.systemui.keyguard.ui.viewmodel.OccludedToLockscreenTransitionViewModel
 import com.android.systemui.shade.domain.interactor.ShadeInteractor
 import com.android.systemui.statusbar.notification.stack.domain.interactor.SharedNotificationContainerInteractor
-import com.android.systemui.util.kotlin.sample
+import com.android.systemui.util.kotlin.Utils.Companion.sample as sampleCombine
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.currentCoroutineContext
 import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.SharingStarted
 import kotlinx.coroutines.flow.StateFlow
 import kotlinx.coroutines.flow.combine
 import kotlinx.coroutines.flow.combineTransform
 import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.first
 import kotlinx.coroutines.flow.flatMapLatest
+import kotlinx.coroutines.flow.flow
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.merge
 import kotlinx.coroutines.flow.onStart
 import kotlinx.coroutines.flow.stateIn
+import kotlinx.coroutines.isActive
 
 /** View-model for the shared notification container, used by both the shade and keyguard spaces */
 class SharedNotificationContainerViewModel
@@ -49,10 +56,11 @@
 constructor(
     private val interactor: SharedNotificationContainerInteractor,
     @Application applicationScope: CoroutineScope,
-    keyguardInteractor: KeyguardInteractor,
+    private val keyguardInteractor: KeyguardInteractor,
     keyguardTransitionInteractor: KeyguardTransitionInteractor,
     private val shadeInteractor: ShadeInteractor,
     occludedToLockscreenTransitionViewModel: OccludedToLockscreenTransitionViewModel,
+    lockscreenToOccludedTransitionViewModel: LockscreenToOccludedTransitionViewModel,
 ) {
     private val statesForConstrainedNotifications =
         setOf(
@@ -63,6 +71,8 @@
             KeyguardState.PRIMARY_BOUNCER
         )
 
+    val shadeCollapseFadeInComplete = MutableStateFlow(false)
+
     val configurationBasedDimensions: Flow<ConfigurationBasedDimensions> =
         interactor.configurationBasedDimensions
             .map {
@@ -106,6 +116,27 @@
             }
             .distinctUntilChanged()
 
+    /** Fade in only for use after the shade collapses */
+    val shadeCollpaseFadeIn: Flow<Boolean> =
+        flow {
+                while (currentCoroutineContext().isActive) {
+                    emit(false)
+                    // Wait for shade to be fully expanded
+                    keyguardInteractor.statusBarState.first { it == SHADE_LOCKED }
+                    // ... and then for it to be collapsed
+                    isOnLockscreenWithoutShade.first { it }
+                    emit(true)
+                    // ... and then for the animation to complete
+                    shadeCollapseFadeInComplete.first { it }
+                    shadeCollapseFadeInComplete.value = false
+                }
+            }
+            .stateIn(
+                scope = applicationScope,
+                started = SharingStarted.WhileSubscribed(),
+                initialValue = false,
+            )
+
     /**
      * The container occupies the entire screen, and must be positioned relative to other elements.
      *
@@ -115,30 +146,29 @@
      * When the shade is expanding, the position is controlled by... the shade.
      */
     val bounds: StateFlow<NotificationContainerBounds> =
-        isOnLockscreenWithoutShade
-            .flatMapLatest { onLockscreen ->
+        combine(
+                isOnLockscreenWithoutShade,
+                keyguardInteractor.notificationContainerBounds,
+                configurationBasedDimensions,
+                interactor.topPosition.sampleCombine(
+                    keyguardTransitionInteractor.isInTransitionToAnyState,
+                    shadeInteractor.qsExpansion,
+                ),
+            ) { onLockscreen, bounds, config, (top, isInTransitionToAnyState, qsExpansion) ->
                 if (onLockscreen) {
-                    combine(
-                        keyguardInteractor.notificationContainerBounds,
-                        configurationBasedDimensions
-                    ) { bounds, config ->
-                        if (config.useSplitShade) {
-                            bounds.copy(top = 0f)
-                        } else {
-                            bounds
-                        }
+                    if (config.useSplitShade) {
+                        bounds.copy(top = 0f)
+                    } else {
+                        bounds
                     }
                 } else {
-                    interactor.topPosition.sample(shadeInteractor.qsExpansion, ::Pair).map {
-                        (top, qsExpansion) ->
-                        // When QS expansion > 0, it should directly set the top padding so do not
-                        // animate it
-                        val animate = qsExpansion == 0f
-                        keyguardInteractor.notificationContainerBounds.value.copy(
-                            top = top,
-                            isAnimated = animate
-                        )
-                    }
+                    // When QS expansion > 0, it should directly set the top padding so do not
+                    // animate it
+                    val animate = qsExpansion == 0f && !isInTransitionToAnyState
+                    keyguardInteractor.notificationContainerBounds.value.copy(
+                        top = top,
+                        isAnimated = animate,
+                    )
                 }
             }
             .stateIn(
@@ -147,7 +177,27 @@
                 initialValue = NotificationContainerBounds(0f, 0f),
             )
 
-    val alpha: Flow<Float> = occludedToLockscreenTransitionViewModel.lockscreenAlpha
+    val alpha: Flow<Float> =
+        isOnLockscreenWithoutShade
+            .flatMapLatest { isOnLockscreenWithoutShade ->
+                combineTransform(
+                    merge(
+                        occludedToLockscreenTransitionViewModel.lockscreenAlpha,
+                        lockscreenToOccludedTransitionViewModel.lockscreenAlpha,
+                        keyguardInteractor.keyguardAlpha,
+                    ),
+                    shadeCollpaseFadeIn,
+                ) { alpha, shadeCollpaseFadeIn ->
+                    if (isOnLockscreenWithoutShade) {
+                        if (!shadeCollpaseFadeIn) {
+                            emit(alpha)
+                        }
+                    } else {
+                        emit(1f)
+                    }
+                }
+            }
+            .distinctUntilChanged()
 
     /**
      * Under certain scenarios, such as swiping up on the lockscreen, the container will need to be
@@ -176,33 +226,29 @@
      * emit a value.
      */
     fun getMaxNotifications(calculateSpace: (Float) -> Int): Flow<Int> {
-        // When to limit notifications: on lockscreen with an unexpanded shade. Also, recalculate
-        // when the notification stack has changed internally
-        val limitedNotifications =
+        val showLimitedNotifications = isOnLockscreenWithoutShade
+        val showUnlimitedNotifications =
             combine(
-                bounds,
-                interactor.notificationStackChanged.onStart { emit(Unit) },
-            ) { position, _ ->
-                calculateSpace(position.bottom - position.top)
+                isOnLockscreen,
+                keyguardInteractor.statusBarState,
+            ) { isOnLockscreen, statusBarState ->
+                statusBarState == SHADE_LOCKED || !isOnLockscreen
             }
 
-        // When to show unlimited notifications: When the shade is fully expanded and the user is
-        // not actively dragging the shade
-        val unlimitedNotifications =
-            combineTransform(
-                shadeInteractor.shadeExpansion,
+        return combineTransform(
+                showLimitedNotifications,
+                showUnlimitedNotifications,
                 shadeInteractor.isUserInteracting,
-            ) { shadeExpansion, isUserInteracting ->
-                if (shadeExpansion == 1f && !isUserInteracting) {
-                    emit(-1)
-                }
-            }
-        return isOnLockscreenWithoutShade
-            .flatMapLatest { isOnLockscreenWithoutShade ->
-                if (isOnLockscreenWithoutShade) {
-                    limitedNotifications
-                } else {
-                    unlimitedNotifications
+                bounds,
+                interactor.notificationStackChanged.onStart { emit(Unit) },
+            ) { showLimitedNotifications, showUnlimitedNotifications, isUserInteracting, bounds, _
+                ->
+                if (!isUserInteracting) {
+                    if (showLimitedNotifications) {
+                        emit(calculateSpace(bounds.bottom - bounds.top))
+                    } else if (showUnlimitedNotifications) {
+                        emit(-1)
+                    }
                 }
             }
             .distinctUntilChanged()
@@ -212,6 +258,10 @@
         interactor.notificationStackChanged()
     }
 
+    fun setShadeCollapseFadeInComplete(complete: Boolean) {
+        shadeCollapseFadeInComplete.value = complete
+    }
+
     data class ConfigurationBasedDimensions(
         val marginStart: Int,
         val marginTop: Int,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt
index ac7c2aa..b4f7b20 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt
@@ -32,6 +32,7 @@
 import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
 import com.android.systemui.keyguard.shared.model.KeyguardState
 import com.android.systemui.keyguard.shared.model.StatusBarState
+import com.android.systemui.keyguard.shared.model.StatusBarState.SHADE_LOCKED
 import com.android.systemui.keyguard.shared.model.TransitionState
 import com.android.systemui.keyguard.shared.model.TransitionStep
 import com.android.systemui.keyguard.ui.viewmodel.keyguardRootViewModel
@@ -384,6 +385,29 @@
             assertThat(bounds).isEqualTo(NotificationContainerBounds(top, bottom))
         }
 
+    @Test
+    fun shadeCollpaseFadeIn() =
+        testScope.runTest {
+            // Start on lockscreen without the shade
+            underTest.setShadeCollapseFadeInComplete(false)
+            showLockscreen()
+
+            val fadeIn by collectLastValue(underTest.shadeCollpaseFadeIn)
+            assertThat(fadeIn).isEqualTo(false)
+
+            // ... then the shade expands
+            showLockscreenWithShadeExpanded()
+            assertThat(fadeIn).isEqualTo(false)
+
+            // ... it collapses
+            showLockscreen()
+            assertThat(fadeIn).isEqualTo(true)
+
+            // ... now send animation complete signal
+            underTest.setShadeCollapseFadeInComplete(true)
+            assertThat(fadeIn).isEqualTo(false)
+        }
+
     private suspend fun showLockscreen() {
         shadeRepository.setLockscreenShadeExpansion(0f)
         shadeRepository.setQsExpansion(0f)
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt
index e2479fe..5ef9a8e 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt
@@ -18,6 +18,7 @@
 
 import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
 import com.android.systemui.keyguard.domain.interactor.keyguardTransitionInteractor
+import com.android.systemui.keyguard.ui.viewmodel.lockscreenToOccludedTransitionViewModel
 import com.android.systemui.keyguard.ui.viewmodel.occludedToLockscreenTransitionViewModel
 import com.android.systemui.kosmos.Kosmos
 import com.android.systemui.kosmos.Kosmos.Fixture
@@ -33,5 +34,6 @@
         keyguardTransitionInteractor = keyguardTransitionInteractor,
         shadeInteractor = shadeInteractor,
         occludedToLockscreenTransitionViewModel = occludedToLockscreenTransitionViewModel,
+        lockscreenToOccludedTransitionViewModel = lockscreenToOccludedTransitionViewModel,
     )
 }