Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12dcc650 authored by Sherry Zhou's avatar Sherry Zhou
Browse files

Fix notification bottom sent from SysUI is inaccurate and refactor

Bug: 374382849
Test: atest SharedNotificationContainerViewModelTest
Flag: com.android.systemui.magic_portrait_wallpapers

Change-Id: I97ca05d891cd0bc00a16778657306d5fd8912e23
parent d7e89209
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
@@ -1229,6 +1229,75 @@ class SharedNotificationContainerViewModelTest(flags: FlagsParameterization) : S
            assertThat(alpha).isEqualTo(1f)
        }

    @Test
    @DisableSceneContainer
    fun notificationAbsoluteBottom() =
        testScope.runTest {
            var notificationCount = 2
            val calculateSpace = { _: Float, _: Boolean -> notificationCount }
            val shelfHeight = 10F
            val heightForNotification = 20F
            val calculateHeight = { count: Int -> count * heightForNotification + shelfHeight }
            val stackAbsoluteBottom by
                collectLastValue(
                    underTest.getNotificationStackAbsoluteBottom(
                        calculateSpace,
                        calculateHeight,
                        shelfHeight,
                    )
                )
            advanceTimeBy(50L)
            showLockscreen()

            shadeTestUtil.setSplitShade(false)
            keyguardInteractor.setNotificationContainerBounds(
                NotificationContainerBounds(top = 100F, bottom = 300F)
            )
            configurationRepository.onAnyConfigurationChange()

            assertThat(stackAbsoluteBottom).isEqualTo(150F)

            // Also updates when directly requested (as it would from NotificationStackScrollLayout)
            notificationCount = 3
            sharedNotificationContainerInteractor.notificationStackChanged()
            advanceTimeBy(50L)
            assertThat(stackAbsoluteBottom).isEqualTo(170F)
        }

    @Test
    @DisableSceneContainer
    fun notificationAbsoluteBottom_maxNotificationIsZero_noShelfHeight() =
        testScope.runTest {
            var notificationCount = 2
            val calculateSpace = { _: Float, _: Boolean -> notificationCount }
            val shelfHeight = 10F
            val heightForNotification = 20F
            val calculateHeight = { count: Int -> count * heightForNotification + shelfHeight }
            val stackAbsoluteBottom by
                collectLastValue(
                    underTest.getNotificationStackAbsoluteBottom(
                        calculateSpace,
                        calculateHeight,
                        shelfHeight,
                    )
                )
            advanceTimeBy(50L)
            showLockscreen()

            shadeTestUtil.setSplitShade(false)
            keyguardInteractor.setNotificationContainerBounds(
                NotificationContainerBounds(top = 100F, bottom = 300F)
            )
            configurationRepository.onAnyConfigurationChange()

            assertThat(stackAbsoluteBottom).isEqualTo(150F)

            notificationCount = 0
            sharedNotificationContainerInteractor.notificationStackChanged()
            advanceTimeBy(50L)
            assertThat(stackAbsoluteBottom).isEqualTo(100F)
        }

    private suspend fun TestScope.showLockscreen() {
        shadeTestUtil.setQsExpansion(0f)
        shadeTestUtil.setLockscreenShadeExpansion(0f)
+0 −5
Original line number Diff line number Diff line
@@ -25,9 +25,4 @@ class FakeWallpaperRepository : WallpaperRepository {
    override val wallpaperInfo = MutableStateFlow<WallpaperInfo?>(null)
    override val wallpaperSupportsAmbientMode = MutableStateFlow(false)
    override var rootView: View? = null
    private val _notificationStackAbsoluteBottom = MutableStateFlow(0F)

    override fun setNotificationStackAbsoluteBottom(bottom: Float) {
        _notificationStackAbsoluteBottom.value = bottom
    }
}
+15 −0
Original line number Diff line number Diff line
@@ -269,6 +269,8 @@ interface KeyguardRepository {
    /** The top of shortcut in screen, used by wallpaper to find remaining space in lockscreen */
    val shortcutAbsoluteTop: StateFlow<Float>

    val notificationStackAbsoluteBottom: StateFlow<Float>

    /**
     * Returns `true` if the keyguard is showing; `false` otherwise.
     *
@@ -339,6 +341,12 @@ interface KeyguardRepository {
    fun isShowKeyguardWhenReenabled(): Boolean

    fun setShortcutAbsoluteTop(top: Float)

    /**
     * Set bottom of notifications from notification stack, and Magic Portrait will layout base on
     * this value
     */
    fun setNotificationStackAbsoluteBottom(bottom: Float)
}

/** Encapsulates application state for the keyguard. */
@@ -635,6 +643,9 @@ constructor(
    private val _shortcutAbsoluteTop = MutableStateFlow(0F)
    override val shortcutAbsoluteTop = _shortcutAbsoluteTop.asStateFlow()

    private val _notificationStackAbsoluteBottom = MutableStateFlow(0F)
    override val notificationStackAbsoluteBottom = _notificationStackAbsoluteBottom.asStateFlow()

    init {
        val callback =
            object : KeyguardStateController.Callback {
@@ -717,6 +728,10 @@ constructor(
        _shortcutAbsoluteTop.value = top
    }

    override fun setNotificationStackAbsoluteBottom(bottom: Float) {
        _notificationStackAbsoluteBottom.value = bottom
    }

    private fun dozeMachineStateToModel(state: DozeMachine.State): DozeStateModel {
        return when (state) {
            DozeMachine.State.UNINITIALIZED -> DozeStateModel.UNINITIALIZED
+4 −0
Original line number Diff line number Diff line
@@ -545,6 +545,10 @@ constructor(
        repository.isKeyguardGoingAway.value = isGoingAway
    }

    fun setNotificationStackAbsoluteBottom(bottom: Float) {
        repository.setNotificationStackAbsoluteBottom(bottom)
    }

    companion object {
        private const val TAG = "KeyguardInteractor"
    }
+1 −2
Original line number Diff line number Diff line
@@ -1200,7 +1200,6 @@ public class NotificationStackScrollLayout
        if (!SceneContainerFlag.isEnabled()) {
            setMaxLayoutHeight(getHeight());
            updateContentHeight();
            mWallpaperInteractor.setNotificationStackAbsoluteBottom(mContentHeight);
        }
        clampScrollPosition();
        requestChildrenUpdate();
@@ -1278,7 +1277,6 @@ public class NotificationStackScrollLayout
        if (mAmbientState.getStackTop() != stackTop) {
            mAmbientState.setStackTop(stackTop);
            onTopPaddingChanged(/* animate = */ isAddOrRemoveAnimationPending());
            mWallpaperInteractor.setNotificationStackAbsoluteBottom((int) stackTop);
        }
    }

@@ -2648,6 +2646,7 @@ public class NotificationStackScrollLayout

        // The topPadding can be bigger than the regular padding when qs is expanded, in that
        // state the maxPanelHeight and the contentHeight should be bigger

        mContentHeight =
                (int) (height + Math.max(getIntrinsicPadding(), getTopPadding()) + mBottomPadding);
        updateScrollability();
Loading