From 6019e9d8b0cf7ecb5f6293c1d74d27afb030d8a0 Mon Sep 17 00:00:00 2001 From: Riley Campillo Date: Mon, 15 Apr 2024 15:11:56 +0000 Subject: Get user switcher actions on the background flow. Bug: 332061190 Test: UserSwitcherInteractorTest Flag: NONE Change-Id: Ic430195499aa1b5d6b465baec88b36e9dee0936b --- .../domain/interactor/UserSwitcherInteractor.kt | 141 +++++++++++---------- 1 file 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> 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 = - 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 = + 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> = combine( -- cgit v1.2.3-59-g8ed1b