Merge "Don't allow users to be switched on keyguard when multiple users is disabled" into udc-dev am: aa792b8d6b
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23620497 Change-Id: Ibb5cbaf034b9108ea750af644bd34383e38e71e6 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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))
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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 =
|
||||||
|
|||||||
@@ -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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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) })
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user