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

Commit 5f72ed3e authored by Lucas Silva's avatar Lucas Silva
Browse files

Avoid opening hub when we transitioned to occluded from dream

When hubV2 is enabled, avoid transitioning to the hub if we opened an
app from the dream. In this case, the user should return to the
lockscreen.

Fixes: 411577003
Test: atest CommunalInteractorTest
Flag: com.android.systemui.glanceable_hub_v2
Change-Id: I05013d3746a1a662428fa571dc7ab0f81863e216
parent 6e14ced4
Loading
Loading
Loading
Loading
+21 −11
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.systemui.Flags.FLAG_COMMUNAL_HUB
import com.android.systemui.Flags.FLAG_COMMUNAL_RESPONSIVE_GRID
import com.android.systemui.Flags.FLAG_COMMUNAL_WIDGET_RESIZING
import com.android.systemui.Flags.FLAG_GLANCEABLE_HUB_V2
import com.android.systemui.Flags.glanceableHubV2
import com.android.systemui.SysuiTestCase
import com.android.systemui.broadcast.broadcastDispatcher
import com.android.systemui.communal.data.model.CommunalSmartspaceTimer
@@ -52,8 +53,6 @@ import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.EditModeState
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.flags.Flags
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
@@ -81,21 +80,29 @@ import kotlinx.coroutines.test.advanceTimeBy
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.stub
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters

@SmallTest
@RunWith(ParameterizedAndroidJunit4::class)
@EnableFlags(FLAG_COMMUNAL_HUB)
class CommunalInteractorTest(flags: FlagsParameterization) : SysuiTestCase() {
    private val mainUser =
        UserInfo(/* id= */ 0, /* name= */ "primary user", /* flags= */ UserInfo.FLAG_MAIN)
    private val secondaryUser = UserInfo(/* id= */ 1, /* name= */ "secondary user", /* flags= */ 0)

    private val kosmos = testKosmos().useUnconfinedTestDispatcher()
    private val kosmos =
        testKosmos().useUnconfinedTestDispatcher().apply {
            userManager.stub {
                on { isQuietModeEnabled(any()) } doReturn false
                on { isManagedProfile(any()) } doReturn false
            }
        }

    private val Kosmos.underTest by Kosmos.Fixture { communalInteractor }

@@ -105,12 +112,8 @@ class CommunalInteractorTest(flags: FlagsParameterization) : SysuiTestCase() {

    @Before
    fun setUp() {
        whenever(kosmos.userManager.isQuietModeEnabled(any<UserHandle>())).thenReturn(false)
        whenever(kosmos.userManager.isManagedProfile(anyInt())).thenReturn(false)
        kosmos.fakeUserRepository.setUserInfos(listOf(mainUser, secondaryUser))

        kosmos.fakeFeatureFlagsClassic.set(Flags.COMMUNAL_SERVICE_ENABLED, true)
        mSetFlagsRule.enableFlags(FLAG_COMMUNAL_HUB)
        kosmos.setCommunalV2Enabled(true)
    }

    @Test
@@ -841,8 +844,12 @@ class CommunalInteractorTest(flags: FlagsParameterization) : SysuiTestCase() {
                testScope,
            )

            if (glanceableHubV2()) {
                assertThat(showCommunalFromOccluded).isFalse()
            } else {
                assertThat(showCommunalFromOccluded).isTrue()
            }
        }

    private fun smartspaceTimer(id: String, timestamp: Long = 0L): CommunalSmartspaceTimer {
        return CommunalSmartspaceTimer(
@@ -1112,7 +1119,10 @@ class CommunalInteractorTest(flags: FlagsParameterization) : SysuiTestCase() {
        @JvmStatic
        @Parameters(name = "{0}")
        fun getParams(): List<FlagsParameterization> {
            return FlagsParameterization.allCombinationsOf(FLAG_COMMUNAL_RESPONSIVE_GRID)
            return FlagsParameterization.allCombinationsOf(
                FLAG_COMMUNAL_RESPONSIVE_GRID,
                FLAG_GLANCEABLE_HUB_V2,
            )
        }

        private val MAIN_USER_INFO = UserInfo(0, "primary", UserInfo.FLAG_MAIN)
+8 −3
Original line number Diff line number Diff line
@@ -189,9 +189,11 @@ constructor(
            .filter { step -> step.to == KeyguardState.OCCLUDED }
            .combine(isCommunalAvailable, ::Pair)
            .map { (step, available) ->
                available &&
                    (step.from == KeyguardState.GLANCEABLE_HUB ||
                        step.from == KeyguardState.DREAMING)
                val enteredFromHub = step.from == KeyguardState.GLANCEABLE_HUB
                val enteredFromDream =
                    step.from == KeyguardState.DREAMING &&
                        !communalSettingsInteractor.isV2FlagEnabled()
                available && (enteredFromHub || enteredFromDream)
            }
            .flowOn(bgDispatcher)
            .stateIn(
@@ -467,6 +469,7 @@ constructor(
                            size = CommunalContentSize.toSize(widget.spanY),
                        )
                    }

                    is CommunalWidgetContentModel.Pending -> {
                        WidgetContent.PendingWidget(
                            appWidgetId = widget.appWidgetId,
@@ -493,6 +496,7 @@ constructor(
                    when (model) {
                        is CommunalWidgetContentModel.Available ->
                            model.providerInfo.profile.identifier

                        is CommunalWidgetContentModel.Pending -> model.user.identifier
                    }
                uid != disallowedByDevicePolicyUser.id
@@ -576,6 +580,7 @@ constructor(
            when (widget) {
                is CommunalWidgetContentModel.Available ->
                    currentUserIds.contains(widget.providerInfo.profile?.identifier)

                is CommunalWidgetContentModel.Pending -> true
            }
        }