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

Commit 4d41e127 authored by Denis Kuznetsov's avatar Denis Kuznetsov
Browse files

Disable user switching in SysUI for desktop

This is a temporary solution, until proper handling of desktop
switching restrictions are implemented at the framework level.

For now use config_userSwitchingMustGoThroughLoginScreen to
override visibility of user switching UI.

Test: tested manually
Test: atest UserRepositoryImplTest
Flag: EXEMPT Desktop-only change
Bug:375394047
Bug:378068979
Change-Id: Ife7b8ffff8352d6421ef7c385bf30f83fad932bc
parent 3404a179
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.broadcast.broadcastDispatcher
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.res.R
import com.android.systemui.settings.FakeUserTracker
import com.android.systemui.testKosmos
import com.android.systemui.user.data.model.SelectedUserModel
@@ -74,6 +75,10 @@ class UserRepositoryImplTest : SysuiTestCase() {
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        tracker = FakeUserTracker()
        context.orCreateTestableResources.addOverride(
            R.bool.config_userSwitchingMustGoThroughLoginScreen,
            false,
        )
    }

    @Test
+47 −36
Original line number Diff line number Diff line
@@ -348,6 +348,17 @@ constructor(

    private suspend fun getSettings(): UserSwitcherSettingsModel {
        return withContext(backgroundDispatcher) {
            if (
                // TODO(b/378068979): remove once login screen-specific logic
                // is implemented at framework level.
                appContext.resources.getBoolean(R.bool.config_userSwitchingMustGoThroughLoginScreen)
            ) {
                UserSwitcherSettingsModel(
                    isSimpleUserSwitcher = false,
                    isAddUsersFromLockscreen = false,
                    isUserSwitcherEnabled = false,
                )
            } else {
                val isSimpleUserSwitcher =
                    globalSettings.getInt(
                        SETTING_SIMPLE_USER_SWITCHER,
@@ -378,7 +389,6 @@ constructor(
                            0
                        },
                    ) != 0

                UserSwitcherSettingsModel(
                    isSimpleUserSwitcher = isSimpleUserSwitcher,
                    isAddUsersFromLockscreen = isAddUsersFromLockscreen,
@@ -386,6 +396,7 @@ constructor(
                )
            }
        }
    }

    companion object {
        private const val TAG = "UserRepository"
+11 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.graphics.drawable.Drawable
import android.os.Handler
import android.os.UserManager
import android.provider.Settings.Global.USER_SWITCHER_ENABLED
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
@@ -40,7 +41,6 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import com.android.app.tracing.coroutines.launchTraced as launch
import kotlinx.coroutines.withContext

interface UserSwitcherRepository {
@@ -67,6 +67,9 @@ constructor(
    private val showUserSwitcherForSingleUser =
        context.resources.getBoolean(R.bool.qs_show_user_switcher_for_single_user)

    private val userSwitchingMustGoThroughLoginScreen =
        context.resources.getBoolean(R.bool.config_userSwitchingMustGoThroughLoginScreen)

    override val isEnabled: Flow<Boolean> = conflatedCallbackFlow {
        suspend fun updateState() {
            trySendWithFailureLogging(isUserSwitcherEnabled(), TAG)
@@ -135,9 +138,15 @@ constructor(

    private suspend fun isUserSwitcherEnabled(): Boolean {
        return withContext(bgDispatcher) {
            // TODO(b/378068979): remove once login screen-specific logic
            // is implemented at framework level.
            if (userSwitchingMustGoThroughLoginScreen) {
                false
            } else {
                userManager.isUserSwitcherEnabled(showUserSwitcherForSingleUser)
            }
        }
    }

    private suspend fun getCurrentUser(): String? {
        return withContext(bgDispatcher) { userSwitcherController.currentUserName }