Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f3af3e3c authored by Brad Hinegardner's avatar Brad Hinegardner
Browse files

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
parent 57b293ef
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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))
+3 −0
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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 =
+5 −0
Original line number Diff line number Diff line
@@ -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")
    }

+14 −0
Original line number Diff line number Diff line
@@ -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) })
Loading