diff options
| author | 2024-04-15 15:11:56 +0000 | |
|---|---|---|
| committer | 2024-04-16 21:19:00 +0000 | |
| commit | 6019e9d8b0cf7ecb5f6293c1d74d27afb030d8a0 (patch) | |
| tree | 8d962754dce292598f869f8f75860de8dab71110 | |
| parent | 21f8ea372bc6db5c063104c8ad4515b7414b40e5 (diff) | |
Get user switcher actions on the background flow.
Bug: 332061190
Test: UserSwitcherInteractorTest
Flag: NONE
Change-Id: Ic430195499aa1b5d6b465baec88b36e9dee0936b
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt | 141 |
1 files changed, 74 insertions, 67 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt index 382bc03daca8..93396516add7 100644 --- a/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/user/domain/interactor/UserSwitcherInteractor.kt @@ -76,6 +76,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach @@ -164,81 +165,87 @@ constructor( val actions: Flow<List<UserActionModel>> get() = combine( - repository.selectedUserInfo, - userInfos, - repository.userSwitcherSettings, - keyguardInteractor.isKeyguardShowing, - ) { _, userInfos, settings, isDeviceLocked -> - buildList { - val canAccessUserSwitcher = !isDeviceLocked || settings.isAddUsersFromLockscreen - if (canAccessUserSwitcher) { - // 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, canAccessUserSwitcher) - ) { - add(UserActionModel.ENTER_GUEST_MODE) - } + repository.selectedUserInfo, + userInfos, + repository.userSwitcherSettings, + keyguardInteractor.isKeyguardShowing, + ) { _, userInfos, settings, isDeviceLocked -> + buildList { + val canAccessUserSwitcher = + !isDeviceLocked || settings.isAddUsersFromLockscreen + if (canAccessUserSwitcher) { + // 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, + ) } - UserActionModel.ADD_USER -> { - val canCreateUsers = - UserActionsUtil.canCreateUser( - manager, - repository, - settings.isUserSwitcherEnabled, - canAccessUserSwitcher - ) - - if (canCreateUsers) { - add(UserActionModel.ADD_USER) + actionList.map { + when (it) { + UserActionModel.ENTER_GUEST_MODE -> { + val hasGuestUser = userInfos.any { it.isGuest } + if ( + !hasGuestUser && + canCreateGuestUser(settings, canAccessUserSwitcher) + ) { + add(UserActionModel.ENTER_GUEST_MODE) + } } - } - UserActionModel.ADD_SUPERVISED_USER -> { - if ( - UserActionsUtil.canCreateSupervisedUser( - manager, - repository, - settings.isUserSwitcherEnabled, - canAccessUserSwitcher, - supervisedUserPackageName, - ) - ) { - add(UserActionModel.ADD_SUPERVISED_USER) + UserActionModel.ADD_USER -> { + val canCreateUsers = + UserActionsUtil.canCreateUser( + manager, + repository, + settings.isUserSwitcherEnabled, + canAccessUserSwitcher + ) + + if (canCreateUsers) { + add(UserActionModel.ADD_USER) + } } + UserActionModel.ADD_SUPERVISED_USER -> { + if ( + UserActionsUtil.canCreateSupervisedUser( + manager, + repository, + settings.isUserSwitcherEnabled, + canAccessUserSwitcher, + supervisedUserPackageName, + ) + ) { + add(UserActionModel.ADD_SUPERVISED_USER) + } + } + else -> Unit } - else -> Unit } } - } - if ( - UserActionsUtil.canManageUsers(repository, settings.isUserSwitcherEnabled) - ) { - add(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT) + if ( + UserActionsUtil.canManageUsers( + repository, + settings.isUserSwitcherEnabled + ) + ) { + add(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT) + } } } - } + .flowOn(backgroundDispatcher) val userRecords: StateFlow<ArrayList<UserRecord>> = combine( |