Shift "Add guest" button in User switcher for tablets
Bug: 246918225 Test: atest UserInteractorTest Change-Id: I4f090dbd7852cb5988c537ff60b4eaa7778aeeb8
This commit is contained in:
@@ -156,42 +156,64 @@ constructor(
|
||||
keyguardInteractor.isKeyguardShowing,
|
||||
) { _, userInfos, settings, isDeviceLocked ->
|
||||
buildList {
|
||||
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.
|
||||
// from the lock-screen is not enabled. We can finish building the list
|
||||
// here.
|
||||
val isFullScreen = featureFlags.isEnabled(Flags.FULL_SCREEN_USER_SWITCHER)
|
||||
|
||||
val canCreateUsers =
|
||||
UserActionsUtil.canCreateUser(
|
||||
manager,
|
||||
repository,
|
||||
settings.isUserSwitcherEnabled,
|
||||
settings.isAddUsersFromLockscreen,
|
||||
)
|
||||
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)
|
||||
}
|
||||
}
|
||||
UserActionModel.ADD_USER -> {
|
||||
val canCreateUsers =
|
||||
UserActionsUtil.canCreateUser(
|
||||
manager,
|
||||
repository,
|
||||
settings.isUserSwitcherEnabled,
|
||||
settings.isAddUsersFromLockscreen,
|
||||
)
|
||||
|
||||
if (canCreateUsers) {
|
||||
add(UserActionModel.ADD_USER)
|
||||
}
|
||||
|
||||
if (
|
||||
UserActionsUtil.canCreateSupervisedUser(
|
||||
manager,
|
||||
repository,
|
||||
settings.isUserSwitcherEnabled,
|
||||
settings.isAddUsersFromLockscreen,
|
||||
supervisedUserPackageName,
|
||||
)
|
||||
) {
|
||||
add(UserActionModel.ADD_SUPERVISED_USER)
|
||||
if (canCreateUsers) {
|
||||
add(UserActionModel.ADD_USER)
|
||||
}
|
||||
}
|
||||
UserActionModel.ADD_SUPERVISED_USER -> {
|
||||
if (
|
||||
UserActionsUtil.canCreateSupervisedUser(
|
||||
manager,
|
||||
repository,
|
||||
settings.isUserSwitcherEnabled,
|
||||
settings.isAddUsersFromLockscreen,
|
||||
supervisedUserPackageName,
|
||||
)
|
||||
) {
|
||||
add(UserActionModel.ADD_SUPERVISED_USER)
|
||||
}
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
UserActionsUtil.canManageUsers(
|
||||
repository,
|
||||
|
||||
@@ -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,7 +400,37 @@ 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,
|
||||
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,
|
||||
)
|
||||
)
|
||||
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `actions - device locked - only manage user is shown`() =
|
||||
runBlocking(IMMEDIATE) {
|
||||
val userInfos = createUserInfos(count = 2, includeGuest = false)
|
||||
userRepository.setUserInfos(userInfos)
|
||||
@@ -383,13 +440,7 @@ class UserInteractorTest : SysuiTestCase() {
|
||||
var value: List<UserActionModel>? = null
|
||||
val job = underTest.actions.onEach { value = it }.launchIn(this)
|
||||
|
||||
assertThat(value)
|
||||
.isEqualTo(
|
||||
listOf(
|
||||
UserActionModel.ENTER_GUEST_MODE,
|
||||
UserActionModel.NAVIGATE_TO_USER_MANAGEMENT
|
||||
)
|
||||
)
|
||||
assertThat(value).isEqualTo(listOf(UserActionModel.NAVIGATE_TO_USER_MANAGEMENT))
|
||||
|
||||
job.cancel()
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user