Don't allow users to be switched on keyguard when multiple users is disabled

Currently, if there is only one user, and "add users from lockscreen" is  disabled, the Keyguard user-switcher dropdown sticks around to display the current user.

The changes here will maintain visual parity with that user experience when "multiple users" is disabled.

Bug: b/269399217
Test: atest BaseUserSwitcherAdapterTest
Change-Id: Id808e3ecd34de57f19976101eb1a9c37831f26b9
This commit is contained in:
Brad Hinegardner
2023-06-08 19:40:33 +00:00
parent 57b293ef31
commit f3af3e3c6a
7 changed files with 39 additions and 1 deletions

View File

@@ -35,7 +35,10 @@ protected constructor(
) : BaseAdapter() {
protected open val users: List<UserRecord>
get() = controller.users.filter { !controller.isKeyguardShowing || !it.isRestricted }
get() = controller.users.filter {
(!controller.isKeyguardShowing || !it.isRestricted) &&
(controller.isUserSwitcherEnabled || it.isCurrent)
}
init {
controller.addAdapter(WeakReference(this))

View File

@@ -67,6 +67,9 @@ constructor(
val isSimpleUserSwitcher: Boolean
get() = userInteractor.isSimpleUserSwitcher
val isUserSwitcherEnabled: Boolean
get() = userInteractor.isUserSwitcherEnabled
/** The [UserRecord] of the current user or `null` when none. */
val currentUserRecord: UserRecord?
get() = userInteractor.selectedUserRecord.value

View File

@@ -105,6 +105,8 @@ interface UserRepository {
fun getSelectedUserInfo(): UserInfo
fun isSimpleUserSwitcher(): Boolean
fun isUserSwitcherEnabled(): Boolean
}
@SysUISingleton
@@ -206,6 +208,10 @@ constructor(
return _userSwitcherSettings.value.isSimpleUserSwitcher
}
override fun isUserSwitcherEnabled(): Boolean {
return _userSwitcherSettings.value.isUserSwitcherEnabled
}
private fun observeUserSwitching() {
conflatedCallbackFlow {
val callback =

View File

@@ -294,6 +294,10 @@ constructor(
val isSimpleUserSwitcher: Boolean
get() = repository.isSimpleUserSwitcher()
val isUserSwitcherEnabled: Boolean
get() = repository.isUserSwitcherEnabled()
val keyguardUpdateMonitorCallback =
object : KeyguardUpdateMonitorCallback() {
override fun onKeyguardGoingAway() {
@@ -370,6 +374,7 @@ constructor(
}
pw.println("isSimpleUserSwitcher=$isSimpleUserSwitcher")
pw.println("isUserSwitcherEnabled=$isUserSwitcherEnabled")
pw.println("isGuestUserAutoCreated=$isGuestUserAutoCreated")
}

View File

@@ -77,6 +77,7 @@ class BaseUserSwitcherAdapterTest : SysuiTestCase() {
)
whenever(controller.users).thenAnswer { users }
whenever(controller.isUserSwitcherEnabled).thenReturn(true)
underTest =
object : BaseUserSwitcherAdapter(controller) {
@@ -161,6 +162,19 @@ class BaseUserSwitcherAdapterTest : SysuiTestCase() {
assertThat(underTest.count).isEqualTo(users.size)
}
@Test
fun count_onlyShowsCurrentUserWhenMultiUserDisabled() {
whenever(controller.isUserSwitcherEnabled).thenReturn(false)
assertThat(underTest.count).isEqualTo(1)
assertThat(underTest.getItem(0).isCurrent).isTrue()
}
@Test
fun count_doesNotIgnoreAllOtherUsersWhenMultiUserEnabled() {
whenever(controller.isUserSwitcherEnabled).thenReturn(true)
assertThat(underTest.count).isEqualTo(users.size)
}
@Test
fun getItem() {
assertThat((0 until underTest.count).map { position -> underTest.getItem(position) })

View File

@@ -29,6 +29,7 @@ import com.android.systemui.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.qs.tiles.UserDetailItemView
import com.android.systemui.user.data.source.UserRecord
import com.android.systemui.util.mockito.whenever
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
@@ -68,6 +69,8 @@ class KeyguardUserSwitcherAdapterTest : SysuiTestCase() {
fun setUp() {
MockitoAnnotations.initMocks(this)
whenever(userSwitcherController.isUserSwitcherEnabled).thenReturn(true)
mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE, layoutInflater)
`when`(layoutInflater.inflate(anyInt(), any(ViewGroup::class.java), anyBoolean()))
.thenReturn(inflatedUserDetailItemView)

View File

@@ -79,6 +79,10 @@ class FakeUserRepository : UserRepository {
return _userSwitcherSettings.value.isSimpleUserSwitcher
}
override fun isUserSwitcherEnabled(): Boolean {
return _userSwitcherSettings.value.isUserSwitcherEnabled
}
fun setUserInfos(infos: List<UserInfo>) {
_userInfos.value = infos
}