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

Commit b1eaa3f6 authored by Sherry Zhou's avatar Sherry Zhou
Browse files

Fix shape effects not reacting to bcsmartspace visibility

Bug: 405421277
Test: atest WallpaperFocalAreaInteactorTest
Flag: com.android.systemui.shared.extended_wallpaper_effects

Change-Id: I8c152d2aa1f426af76ef242a4df61111a212150c
parent 07ec9119
Loading
Loading
Loading
Loading
+55 −1
Original line number Diff line number Diff line
@@ -21,10 +21,12 @@ import android.content.res.Resources
import android.graphics.PointF
import android.graphics.RectF
import android.util.DisplayMetrics
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.domain.interactor.keyguardSmartspaceInteractor
import com.android.systemui.kosmos.currentValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.res.R
@@ -52,13 +54,19 @@ class WallpaperFocalAreaInteractorTest : SysuiTestCase() {
    private val testScope = kosmos.testScope
    lateinit var shadeRepository: ShadeRepository
    private lateinit var mockedResources: Resources
    lateinit var underTest: WallpaperFocalAreaInteractor
    private var underTest = kosmos.wallpaperFocalAreaInteractor

    @Before
    fun setup() {
        MockitoAnnotations.initMocks(this)
        mockedResources = mock<Resources>()
        whenever(kosmos.mockedContext.resources).thenReturn(mockedResources)
        whenever(
                kosmos.mockedContext.resources.getDimensionPixelSize(
                    com.android.systemui.customization.clocks.R.dimen.enhanced_smartspace_height
                )
            )
            .thenReturn(200)
        whenever(
                mockedResources.getFloat(
                    Resources.getSystem()
@@ -75,6 +83,7 @@ class WallpaperFocalAreaInteractorTest : SysuiTestCase() {
                context = kosmos.mockedContext,
                wallpaperFocalAreaRepository = kosmos.wallpaperFocalAreaRepository,
                shadeRepository = kosmos.shadeRepository,
                smartspaceInteractor = kosmos.keyguardSmartspaceInteractor,
            )
    }

@@ -253,6 +262,51 @@ class WallpaperFocalAreaInteractorTest : SysuiTestCase() {
                .isEqualTo(PointF(0F, 0F))
        }

    @Test
    fun onBcSmartspaceVisible_boundsUnderBcSmartspace() =
        testScope.runTest {
            overrideMockedResources(
                mockedResources,
                OverrideResources(
                    screenWidth = 1000,
                    screenHeight = 2000,
                    centerAlignFocalArea = false,
                ),
            )
            val bounds by collectLastValue(underTest.wallpaperFocalAreaBounds)
            kosmos.shadeRepository.setShadeLayoutWide(false)
            kosmos.wallpaperFocalAreaRepository.setShortcutAbsoluteTop(1800F)
            kosmos.wallpaperFocalAreaRepository.setNotificationDefaultTop(400F)
            kosmos.wallpaperFocalAreaRepository.setNotificationStackAbsoluteBottom(400F)
            kosmos.keyguardSmartspaceInteractor.setBcSmartspaceVisibility(View.VISIBLE)

            assertThat(bounds?.top).isEqualTo(800F)
            assertThat(bounds?.bottom).isEqualTo(1400F)
        }

    @Test
    fun onBcSmartspaceNotVisible_boundsNotUnderBcSmartspace() =
        testScope.runTest {
            overrideMockedResources(
                mockedResources,
                OverrideResources(
                    screenWidth = 1000,
                    screenHeight = 2000,
                    centerAlignFocalArea = false,
                ),
            )
            val bounds by collectLastValue(underTest.wallpaperFocalAreaBounds)
            kosmos.shadeRepository.setShadeLayoutWide(false)

            kosmos.wallpaperFocalAreaRepository.setShortcutAbsoluteTop(1800F)
            kosmos.wallpaperFocalAreaRepository.setNotificationDefaultTop(400F)
            kosmos.wallpaperFocalAreaRepository.setNotificationStackAbsoluteBottom(400F)
            kosmos.keyguardSmartspaceInteractor.setBcSmartspaceVisibility(View.INVISIBLE)

            assertThat(bounds?.top).isEqualTo(700F)
            assertThat(bounds?.bottom).isEqualTo(1400F)
        }

    data class OverrideResources(
        val screenWidth: Int,
        val screenHeight: Int,
+2 −7
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import com.android.systemui.statusbar.notification.data.repository.activeNotific
import com.android.systemui.statusbar.notification.data.repository.setActiveNotifs
import com.android.systemui.testKosmos
import com.android.systemui.wallpapers.data.repository.wallpaperFocalAreaRepository
import com.android.systemui.wallpapers.domain.interactor.WallpaperFocalAreaInteractor
import com.android.systemui.wallpapers.domain.interactor.WallpaperFocalAreaInteractorTest.Companion.overrideMockedResources
import com.android.systemui.wallpapers.domain.interactor.WallpaperFocalAreaInteractorTest.OverrideResources
import com.android.systemui.wallpapers.domain.interactor.wallpaperFocalAreaInteractor
@@ -67,6 +66,7 @@ class WallpaperFocalAreaViewModelTest : SysuiTestCase() {
            mockedResources,
            OverrideResources(screenWidth = 1000, screenHeight = 2000, centerAlignFocalArea = false),
        )

        whenever(kosmos.mockedContext.resources).thenReturn(mockedResources)
        whenever(
                mockedResources.getFloat(
@@ -79,12 +79,7 @@ class WallpaperFocalAreaViewModelTest : SysuiTestCase() {
                )
            )
            .thenReturn(1f)
        kosmos.wallpaperFocalAreaInteractor =
            WallpaperFocalAreaInteractor(
                context = kosmos.mockedContext,
                wallpaperFocalAreaRepository = kosmos.wallpaperFocalAreaRepository,
                shadeRepository = kosmos.shadeRepository,
            )
        kosmos.wallpaperFocalAreaInteractor.context = kosmos.mockedContext
        underTest =
            WallpaperFocalAreaViewModel(
                wallpaperFocalAreaInteractor = kosmos.wallpaperFocalAreaInteractor,
+30 −5
Original line number Diff line number Diff line
@@ -21,8 +21,11 @@ import android.content.res.Resources
import android.graphics.PointF
import android.graphics.RectF
import android.util.Log
import android.view.View
import com.android.app.animation.MathUtils
import com.android.systemui.customization.clocks.R as customR
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.domain.interactor.KeyguardSmartspaceInteractor
import com.android.systemui.res.R
import com.android.systemui.shade.data.repository.ShadeRepository
import com.android.systemui.wallpapers.data.repository.WallpaperFocalAreaRepository
@@ -31,28 +34,50 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map

@SysUISingleton
class WallpaperFocalAreaInteractor
@Inject
constructor(
    private val context: Context,
    var context: Context,
    private val wallpaperFocalAreaRepository: WallpaperFocalAreaRepository,
    shadeRepository: ShadeRepository,
    smartspaceInteractor: KeyguardSmartspaceInteractor,
) {
    val hasFocalArea = wallpaperFocalAreaRepository.hasFocalArea

    val smartspaceBottom =
        combine(
                wallpaperFocalAreaRepository.notificationDefaultTop,
                smartspaceInteractor.bcSmartspaceVisibility,
                ::Pair,
            )
            .map { (notificationDefaultTop, bcSmartspaceVisibility) ->
                when (bcSmartspaceVisibility) {
                    View.VISIBLE -> {
                        notificationDefaultTop +
                            context.resources
                                .getDimensionPixelSize(customR.dimen.enhanced_smartspace_height)
                                .toFloat()
                    }
                    else -> {
                        notificationDefaultTop
                    }
                }
            }

    val wallpaperFocalAreaBounds: Flow<RectF> =
        combine(
                shadeRepository.isShadeLayoutWide,
                wallpaperFocalAreaRepository.notificationStackAbsoluteBottom,
                wallpaperFocalAreaRepository.shortcutAbsoluteTop,
                wallpaperFocalAreaRepository.notificationDefaultTop,
                smartspaceBottom,
            ) {
                isShadeLayoutWide,
                notificationStackAbsoluteBottom,
                shortcutAbsoluteTop,
                notificationDefaultTop ->
                smartspaceBottom ->
                // Wallpaper will be zoomed in with config_wallpaperMaxScale in lockscreen
                // so we need to give a bounds taking this scale in consideration
                val wallpaperZoomedInScale = getSystemWallpaperMaximumScale(context)
@@ -91,11 +116,11 @@ constructor(
                    // unfold foldable landscape
                    else if (isShadeLayoutWide) {
                        // For all landscape, we should use bottom of smartspace to constrain
                        scaledBounds.top + notificationDefaultTop / wallpaperZoomedInScale
                        scaledBounds.top + smartspaceBottom / wallpaperZoomedInScale
                        // handheld / portrait
                    } else {
                        scaledBounds.top +
                            MathUtils.max(notificationDefaultTop, notificationStackAbsoluteBottom) /
                            MathUtils.max(smartspaceBottom, notificationStackAbsoluteBottom) /
                                wallpaperZoomedInScale
                    }
                val bottom = scaledBounds.bottom - scaledBottomMargin
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.wallpapers.domain.interactor

import android.content.applicationContext
import com.android.systemui.keyguard.domain.interactor.keyguardSmartspaceInteractor
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.shade.data.repository.shadeRepository
import com.android.systemui.wallpapers.data.repository.wallpaperFocalAreaRepository
@@ -27,5 +28,6 @@ var Kosmos.wallpaperFocalAreaInteractor by
            context = applicationContext,
            wallpaperFocalAreaRepository = wallpaperFocalAreaRepository,
            shadeRepository = shadeRepository,
            smartspaceInteractor = keyguardSmartspaceInteractor,
        )
    }