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

Commit abc8f82a authored by Tetiana Meronyk's avatar Tetiana Meronyk
Browse files

Shift "Add guest" button in User switcher for tablets

Bug: 246918225
Test: atest UserInteractorTest
Change-Id: I4f090dbd7852cb5988c537ff60b4eaa7778aeeb8
parent bcd596c6
Loading
Loading
Loading
Loading
+54 −32
Original line number Diff line number Diff line
@@ -156,17 +156,35 @@ constructor(
                keyguardInteractor.isKeyguardShowing,
            ) { _, userInfos, settings, isDeviceLocked ->
                buildList {
                    if (!isDeviceLocked || settings.isAddUsersFromLockscreen) {
                        // The device is locked and our setting to allow actions that add users
                        // from the lock-screen is not enabled. We can finish building the list
                        // here.
                        val isFullScreen = featureFlags.isEnabled(Flags.FULL_SCREEN_USER_SWITCHER)

                        val actionList: List<UserActionModel> =
                            if (isFullScreen) {
                                listOf(
                                    UserActionModel.ADD_USER,
                                    UserActionModel.ADD_SUPERVISED_USER,
                                    UserActionModel.ENTER_GUEST_MODE,
                                )
                            } else {
                                listOf(
                                    UserActionModel.ENTER_GUEST_MODE,
                                    UserActionModel.ADD_USER,
                                    UserActionModel.ADD_SUPERVISED_USER,
                                )
                            }
                        actionList.map {
                            when (it) {
                                UserActionModel.ENTER_GUEST_MODE -> {
                                    val hasGuestUser = userInfos.any { it.isGuest }
                                    if (!hasGuestUser && canCreateGuestUser(settings)) {
                                        add(UserActionModel.ENTER_GUEST_MODE)
                                    }

                    if (!isDeviceLocked || settings.isAddUsersFromLockscreen) {
                        // The device is locked and our setting to allow actions that add users
                        // from the lock-screen is not enabled. The guest action from above is
                        // always allowed, even when the device is locked, but the various "add
                        // user" actions below are not. We can finish building the list here.

                                }
                                UserActionModel.ADD_USER -> {
                                    val canCreateUsers =
                                        UserActionsUtil.canCreateUser(
                                            manager,
@@ -178,7 +196,8 @@ constructor(
                                    if (canCreateUsers) {
                                        add(UserActionModel.ADD_USER)
                                    }

                                }
                                UserActionModel.ADD_SUPERVISED_USER -> {
                                    if (
                                        UserActionsUtil.canCreateSupervisedUser(
                                            manager,
@@ -191,7 +210,10 @@ constructor(
                                        add(UserActionModel.ADD_SUPERVISED_USER)
                                    }
                                }

                                else -> Unit
                            }
                        }
                    }
                    if (
                        UserActionsUtil.canManageUsers(
                            repository,
+82 −6
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ class UserInteractorTest : SysuiTestCase() {
        )

        featureFlags = FakeFeatureFlags()
        featureFlags.set(Flags.FULL_SCREEN_USER_SWITCHER, false)
        userRepository = FakeUserRepository()
        keyguardRepository = FakeKeyguardRepository()
        telephonyRepository = FakeTelephonyRepository()
@@ -310,6 +311,32 @@ class UserInteractorTest : SysuiTestCase() {
            job.cancel()
        }

    @Test
    fun `actions - device unlocked - full screen`() =
        runBlocking(IMMEDIATE) {
            featureFlags.set(Flags.FULL_SCREEN_USER_SWITCHER, true)
            val userInfos = createUserInfos(count = 2, includeGuest = false)

            userRepository.setUserInfos(userInfos)
            userRepository.setSelectedUserInfo(userInfos[0])
            userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = true))
            keyguardRepository.setKeyguardShowing(false)
            var value: List<UserActionModel>? = null
            val job = underTest.actions.onEach { value = it }.launchIn(this)

            assertThat(value)
                .isEqualTo(
                    listOf(
                        UserActionModel.ADD_USER,
                        UserActionModel.ADD_SUPERVISED_USER,
                        UserActionModel.ENTER_GUEST_MODE,
                        UserActionModel.NAVIGATE_TO_USER_MANAGEMENT,
                    )
                )

            job.cancel()
        }

    @Test
    fun `actions - device unlocked user not primary - empty list`() =
        runBlocking(IMMEDIATE) {
@@ -373,27 +400,51 @@ class UserInteractorTest : SysuiTestCase() {
        }

    @Test
    fun `actions - device locked - only guest action and manage user is shown`() =
    fun `actions - device locked add from lockscreen set - full list - full screen`() =
        runBlocking(IMMEDIATE) {
            featureFlags.set(Flags.FULL_SCREEN_USER_SWITCHER, true)
            val userInfos = createUserInfos(count = 2, includeGuest = false)
            userRepository.setUserInfos(userInfos)
            userRepository.setSelectedUserInfo(userInfos[0])
            userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = true))
            keyguardRepository.setKeyguardShowing(true)
            userRepository.setSettings(
                UserSwitcherSettingsModel(
                    isUserSwitcherEnabled = true,
                    isAddUsersFromLockscreen = true,
                )
            )
            keyguardRepository.setKeyguardShowing(false)
            var value: List<UserActionModel>? = null
            val job = underTest.actions.onEach { value = it }.launchIn(this)

            assertThat(value)
                .isEqualTo(
                    listOf(
                        UserActionModel.ADD_USER,
                        UserActionModel.ADD_SUPERVISED_USER,
                        UserActionModel.ENTER_GUEST_MODE,
                        UserActionModel.NAVIGATE_TO_USER_MANAGEMENT
                        UserActionModel.NAVIGATE_TO_USER_MANAGEMENT,
                    )
                )

            job.cancel()
        }

    @Test
    fun `actions - device locked - only  manage user is shown`() =
        runBlocking(IMMEDIATE) {
            val userInfos = createUserInfos(count = 2, includeGuest = false)
            userRepository.setUserInfos(userInfos)
            userRepository.setSelectedUserInfo(userInfos[0])
            userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = true))
            keyguardRepository.setKeyguardShowing(true)
            var value: List<UserActionModel>? = null
            val job = underTest.actions.onEach { value = it }.launchIn(this)

            assertThat(value).isEqualTo(listOf(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT))

            job.cancel()
        }

    @Test
    fun `executeAction - add user - dialog shown`() =
        runBlocking(IMMEDIATE) {
@@ -664,6 +715,33 @@ class UserInteractorTest : SysuiTestCase() {
            )
        }

    @Test
    fun userRecordsFullScreen() =
        runBlocking(IMMEDIATE) {
            featureFlags.set(Flags.FULL_SCREEN_USER_SWITCHER, true)
            val userInfos = createUserInfos(count = 3, includeGuest = false)
            userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = true))
            userRepository.setUserInfos(userInfos)
            userRepository.setSelectedUserInfo(userInfos[0])
            keyguardRepository.setKeyguardShowing(false)

            testCoroutineScope.advanceUntilIdle()

            assertRecords(
                records = underTest.userRecords.value,
                userIds = listOf(0, 1, 2),
                selectedUserIndex = 0,
                includeGuest = false,
                expectedActions =
                    listOf(
                        UserActionModel.ADD_USER,
                        UserActionModel.ADD_SUPERVISED_USER,
                        UserActionModel.ENTER_GUEST_MODE,
                        UserActionModel.NAVIGATE_TO_USER_MANAGEMENT,
                    ),
            )
        }

    @Test
    fun selectedUserRecord() =
        runBlocking(IMMEDIATE) {
@@ -728,8 +806,6 @@ class UserInteractorTest : SysuiTestCase() {
    @Test
    fun `show user switcher - full screen disabled - shows dialog switcher`() =
        runBlocking(IMMEDIATE) {
            featureFlags.set(Flags.FULL_SCREEN_USER_SWITCHER, false)

            var dialogRequest: ShowDialogRequestModel? = null
            val expandable = mock<Expandable>()
            underTest.showUserSwitcher(context, expandable)
+3 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.GuestResumeSessionReceiver
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.shared.model.Text
import com.android.systemui.flags.FakeFeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.plugins.ActivityStarter
@@ -241,7 +242,8 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
                        KeyguardInteractor(
                            repository = keyguardRepository,
                        ),
                    featureFlags = featureFlags,
                    featureFlags =
                        FakeFeatureFlags().apply { set(Flags.FULL_SCREEN_USER_SWITCHER, false) },
                    manager = manager,
                    applicationScope = testScope.backgroundScope,
                    telephonyInteractor =
+5 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.systemui.GuestResumeSessionReceiver
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.shared.model.Text
import com.android.systemui.flags.FakeFeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.plugins.ActivityStarter
@@ -148,7 +149,10 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
                                KeyguardInteractor(
                                    repository = keyguardRepository,
                                ),
                            featureFlags = FakeFeatureFlags(),
                            featureFlags =
                                FakeFeatureFlags().apply {
                                    set(Flags.FULL_SCREEN_USER_SWITCHER, false)
                                },
                            manager = manager,
                            applicationScope = injectedScope,
                            telephonyInteractor =