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

Commit 0cb579cc authored by Lucas Silva's avatar Lucas Silva
Browse files

Only allow swiping to the hub from the lockscreen

This prevents swiping to the hub from other states, such as AOD

Bug: 399910239
Test: atest CommunalViewModelTest
Test: no longer able to swipe into hub from AOD
Flag: com.android.systemui.glanceable_hub_v2
Change-Id: I45db712b8df29b9ac3f571c15b3446896e5b9ad1
parent 33746bcb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ fun CommunalContainer(
        viewModel.communalBackground.collectAsStateWithLifecycle(
            initialValue = CommunalBackgroundType.ANIMATED
        )
    val swipeToHubEnabled by viewModel.swipeToHubEnabled.collectAsStateWithLifecycle()
    val swipeToHubEnabled by viewModel.swipeToHubEnabled.collectAsStateWithLifecycle(false)
    val state: MutableSceneTransitionLayoutState =
        rememberMutableSceneTransitionLayoutState(
            initialScene = currentSceneKey,
+36 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import com.android.systemui.Flags.FLAG_GLANCEABLE_HUB_DIRECT_EDIT_MODE
import com.android.systemui.Flags.FLAG_GLANCEABLE_HUB_V2
import com.android.systemui.SysuiTestCase
import com.android.systemui.bouncer.data.repository.fakeKeyguardBouncerRepository
import com.android.systemui.common.data.repository.batteryRepository
import com.android.systemui.common.data.repository.fake
import com.android.systemui.communal.data.model.CommunalSmartspaceTimer
import com.android.systemui.communal.data.repository.FakeCommunalMediaRepository
import com.android.systemui.communal.data.repository.FakeCommunalSceneRepository
@@ -48,6 +50,7 @@ import com.android.systemui.communal.domain.interactor.communalInteractor
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.communal.domain.interactor.communalSettingsInteractor
import com.android.systemui.communal.domain.interactor.communalTutorialInteractor
import com.android.systemui.communal.domain.interactor.setCommunalV2ConfigEnabled
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.shared.log.CommunalMetricsLogger
import com.android.systemui.communal.shared.model.CommunalContentSize
@@ -73,6 +76,8 @@ import com.android.systemui.keyguard.shared.model.StatusBarState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.keyguard.ui.transitions.blurConfig
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.log.logcatLogBuffer
@@ -96,6 +101,7 @@ import com.android.systemui.statusbar.KeyguardIndicationController
import com.android.systemui.testKosmos
import com.android.systemui.user.data.repository.FakeUserRepository
import com.android.systemui.user.data.repository.fakeUserRepository
import com.android.systemui.util.settings.fakeSettings
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.advanceTimeBy
@@ -940,6 +946,36 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
            assertThat(isUiBlurred).isFalse()
        }

    @Test
    @EnableFlags(FLAG_GLANCEABLE_HUB_V2)
    fun swipeToCommunal() =
        kosmos.runTest {
            setCommunalV2ConfigEnabled(true)
            val mainUser = fakeUserRepository.asMainUser()
            fakeKeyguardRepository.setKeyguardShowing(true)
            fakeUserRepository.setUserUnlocked(mainUser.id, true)
            fakeUserTracker.set(userInfos = listOf(mainUser), selectedUserIndex = 0)
            fakeSettings.putIntForUser(
                Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
                1,
                mainUser.id,
            )

            val viewModel = createViewModel()
            val swipeToHubEnabled by collectLastValue(viewModel.swipeToHubEnabled)
            assertThat(swipeToHubEnabled).isFalse()

            batteryRepository.fake.setDevicePluggedIn(true)
            assertThat(swipeToHubEnabled).isTrue()

            keyguardTransitionRepository.sendTransitionStep(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.AOD,
                transitionState = TransitionState.STARTED,
            )
            assertThat(swipeToHubEnabled).isFalse()
        }

    private suspend fun setIsMainUser(isMainUser: Boolean) {
        val user = if (isMainUser) MAIN_USER_INFO else SECONDARY_USER_INFO
        with(userRepository) {
+16 −6
Original line number Diff line number Diff line
@@ -367,12 +367,22 @@ constructor(
    /** See [CommunalSettingsInteractor.isV2FlagEnabled] */
    fun v2FlagEnabled(): Boolean = communalSettingsInteractor.isV2FlagEnabled()

    val swipeToHubEnabled: StateFlow<Boolean> by lazy {
        if (v2FlagEnabled()) {
    val swipeToHubEnabled: Flow<Boolean> by lazy {
        val inAllowedDeviceState =
            if (swipeToHub) {
                MutableStateFlow(true)
            } else if (v2FlagEnabled()) {
                communalInteractor.shouldShowCommunal
            } else {
            MutableStateFlow(swipeToHub)
                MutableStateFlow(false)
            }

        val inAllowedKeyguardState =
            keyguardTransitionInteractor.startedKeyguardTransitionStep.map {
                it.to == KeyguardState.LOCKSCREEN || it.to == KeyguardState.GLANCEABLE_HUB
            }

        allOf(inAllowedDeviceState, inAllowedKeyguardState)
    }

    companion object {