Merge "Don't allow users to be switched on keyguard when multiple users is disabled" into udc-dev

This commit is contained in:
Brad Hinegardner
2023-06-14 17:54:28 +00:00
committed by Android (Google) Code Review
7 changed files with 39 additions and 1 deletions

View File

@@ -35,7 +35,10 @@ protected constructor(
) : BaseAdapter() { ) : BaseAdapter() {
protected open val users: List<UserRecord> 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 { init {
controller.addAdapter(WeakReference(this)) controller.addAdapter(WeakReference(this))

View File

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

View File

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

View File

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

View File

@@ -77,6 +77,7 @@ class BaseUserSwitcherAdapterTest : SysuiTestCase() {
) )
whenever(controller.users).thenAnswer { users } whenever(controller.users).thenAnswer { users }
whenever(controller.isUserSwitcherEnabled).thenReturn(true)
underTest = underTest =
object : BaseUserSwitcherAdapter(controller) { object : BaseUserSwitcherAdapter(controller) {
@@ -161,6 +162,19 @@ class BaseUserSwitcherAdapterTest : SysuiTestCase() {
assertThat(underTest.count).isEqualTo(users.size) 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 @Test
fun getItem() { fun getItem() {
assertThat((0 until underTest.count).map { position -> underTest.getItem(position) }) 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.SysuiTestCase
import com.android.systemui.qs.tiles.UserDetailItemView import com.android.systemui.qs.tiles.UserDetailItemView
import com.android.systemui.user.data.source.UserRecord import com.android.systemui.user.data.source.UserRecord
import com.android.systemui.util.mockito.whenever
import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
@@ -68,6 +69,8 @@ class KeyguardUserSwitcherAdapterTest : SysuiTestCase() {
fun setUp() { fun setUp() {
MockitoAnnotations.initMocks(this) MockitoAnnotations.initMocks(this)
whenever(userSwitcherController.isUserSwitcherEnabled).thenReturn(true)
mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE, layoutInflater) mContext.addMockSystemService(Context.LAYOUT_INFLATER_SERVICE, layoutInflater)
`when`(layoutInflater.inflate(anyInt(), any(ViewGroup::class.java), anyBoolean())) `when`(layoutInflater.inflate(anyInt(), any(ViewGroup::class.java), anyBoolean()))
.thenReturn(inflatedUserDetailItemView) .thenReturn(inflatedUserDetailItemView)

View File

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