Merge "[User Switcher] filter for only full userinfos." into tm-qpr-dev

This commit is contained in:
Aaron Liu
2022-11-18 15:27:55 +00:00
committed by Android (Google) Code Review
4 changed files with 33 additions and 11 deletions

View File

@@ -117,7 +117,7 @@ constructor(
private val callbacks = mutableSetOf<UserCallback>() private val callbacks = mutableSetOf<UserCallback>()
private val userInfos = private val userInfos =
combine(repository.userSwitcherSettings, repository.userInfos) { settings, userInfos -> combine(repository.userSwitcherSettings, repository.userInfos) { settings, userInfos ->
userInfos.filter { !it.isGuest || canCreateGuestUser(settings) } userInfos.filter { !it.isGuest || canCreateGuestUser(settings) }.filter { it.isFull }
} }
/** List of current on-device users to select from. */ /** List of current on-device users to select from. */

View File

@@ -771,6 +771,28 @@ class UserInteractorTest : SysuiTestCase() {
) )
} }
@Test
fun `users - secondary user - managed profile is not included`() =
runBlocking(IMMEDIATE) {
var userInfos = createUserInfos(count = 3, includeGuest = false).toMutableList()
userInfos.add(
UserInfo(
50,
"Work Profile",
/* iconPath= */ "",
/* flags= */ UserInfo.FLAG_MANAGED_PROFILE
)
)
userRepository.setUserInfos(userInfos)
userRepository.setSelectedUserInfo(userInfos[1])
userRepository.setSettings(UserSwitcherSettingsModel(isUserSwitcherEnabled = true))
var res: List<UserModel>? = null
val job = underTest.users.onEach { res = it }.launchIn(this)
assertThat(res?.size == 3).isTrue()
job.cancel()
}
private fun assertUsers( private fun assertUsers(
models: List<UserModel>?, models: List<UserModel>?,
count: Int, count: Int,
@@ -893,9 +915,9 @@ class UserInteractorTest : SysuiTestCase() {
name, name,
/* iconPath= */ "", /* iconPath= */ "",
/* flags= */ if (isPrimary) { /* flags= */ if (isPrimary) {
UserInfo.FLAG_PRIMARY or UserInfo.FLAG_ADMIN UserInfo.FLAG_PRIMARY or UserInfo.FLAG_ADMIN or UserInfo.FLAG_FULL
} else { } else {
0 UserInfo.FLAG_FULL
}, },
if (isGuest) { if (isGuest) {
UserManager.USER_TYPE_FULL_GUEST UserManager.USER_TYPE_FULL_GUEST

View File

@@ -281,7 +281,7 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
USER_ID_0, USER_ID_0,
USER_NAME_0.text!!, USER_NAME_0.text!!,
/* iconPath */ "", /* iconPath */ "",
/* flags */ 0, /* flags */ UserInfo.FLAG_FULL,
/* userType */ UserManager.USER_TYPE_FULL_SYSTEM /* userType */ UserManager.USER_TYPE_FULL_SYSTEM
) )
@@ -290,7 +290,7 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
USER_ID_1, USER_ID_1,
USER_NAME_1.text!!, USER_NAME_1.text!!,
/* iconPath */ "", /* iconPath */ "",
/* flags */ 0, /* flags */ UserInfo.FLAG_FULL,
/* userType */ UserManager.USER_TYPE_FULL_SYSTEM /* userType */ UserManager.USER_TYPE_FULL_SYSTEM
) )
@@ -299,7 +299,7 @@ class StatusBarUserChipViewModelTest : SysuiTestCase() {
USER_ID_2, USER_ID_2,
USER_NAME_2.text!!, USER_NAME_2.text!!,
/* iconPath */ "", /* iconPath */ "",
/* flags */ 0, /* flags */ UserInfo.FLAG_FULL,
/* userType */ UserManager.USER_TYPE_FULL_SYSTEM /* userType */ UserManager.USER_TYPE_FULL_SYSTEM
) )
} }

View File

@@ -178,21 +178,21 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
/* id= */ 0, /* id= */ 0,
/* name= */ "zero", /* name= */ "zero",
/* iconPath= */ "", /* iconPath= */ "",
/* flags= */ UserInfo.FLAG_PRIMARY or UserInfo.FLAG_ADMIN, /* flags= */ UserInfo.FLAG_PRIMARY or UserInfo.FLAG_ADMIN or UserInfo.FLAG_FULL,
UserManager.USER_TYPE_FULL_SYSTEM, UserManager.USER_TYPE_FULL_SYSTEM,
), ),
UserInfo( UserInfo(
/* id= */ 1, /* id= */ 1,
/* name= */ "one", /* name= */ "one",
/* iconPath= */ "", /* iconPath= */ "",
/* flags= */ 0, /* flags= */ UserInfo.FLAG_FULL,
UserManager.USER_TYPE_FULL_SYSTEM, UserManager.USER_TYPE_FULL_SYSTEM,
), ),
UserInfo( UserInfo(
/* id= */ 2, /* id= */ 2,
/* name= */ "two", /* name= */ "two",
/* iconPath= */ "", /* iconPath= */ "",
/* flags= */ 0, /* flags= */ UserInfo.FLAG_FULL,
UserManager.USER_TYPE_FULL_SYSTEM, UserManager.USER_TYPE_FULL_SYSTEM,
), ),
) )
@@ -361,10 +361,10 @@ class UserSwitcherViewModelTest : SysuiTestCase() {
/* iconPath= */ "", /* iconPath= */ "",
/* flags= */ if (index == 0) { /* flags= */ if (index == 0) {
// This is the primary user. // This is the primary user.
UserInfo.FLAG_PRIMARY or UserInfo.FLAG_ADMIN UserInfo.FLAG_PRIMARY or UserInfo.FLAG_ADMIN or UserInfo.FLAG_FULL
} else { } else {
// This isn't the primary user. // This isn't the primary user.
0 UserInfo.FLAG_FULL
}, },
UserManager.USER_TYPE_FULL_SYSTEM, UserManager.USER_TYPE_FULL_SYSTEM,
) )