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

Commit 8f9c2b72 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Scene] Decide when to show user switcher on keyguard in repos.

NPVC has a lot of logic in a lot of different methods about when to show
the user switcher. After reading and re-reading, I think it distills
down to config_keyguardUserSwitcher &&
userManager.isUserSwitcherEnabled(qs_show_user_switcher_for_single_user).
This CL adds a flow to that effect and listens to it.

Bug: 300484307
Test: On phone, verify user switcher is never shown (only user avatar if
there are multiple users, nothing if single user)
Test: On tablet, verify user switcher chip is shown if there are multiple
users (or user & guest), not shown if single user
Test: atest KeyguardStatusBarRepositoryImplTest

Change-Id: I5ec9a8a964219fdea3f7addf95f03469585113f2
parent f860443c
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.systemui.qs.footer.dagger

import com.android.systemui.qs.footer.data.repository.ForegroundServicesRepository
import com.android.systemui.qs.footer.data.repository.ForegroundServicesRepositoryImpl
import com.android.systemui.qs.footer.data.repository.UserSwitcherRepository
import com.android.systemui.qs.footer.data.repository.UserSwitcherRepositoryImpl
import com.android.systemui.qs.footer.domain.interactor.FooterActionsInteractor
import com.android.systemui.qs.footer.domain.interactor.FooterActionsInteractorImpl
import dagger.Binds
@@ -28,7 +26,6 @@ import dagger.Module
/** Dagger module to provide/bind footer actions singletons. */
@Module
interface FooterActionsModule {
    @Binds fun userSwitcherRepository(impl: UserSwitcherRepositoryImpl): UserSwitcherRepository

    @Binds
    fun foregroundServicesRepository(
+1 −1
Original line number Diff line number Diff line
@@ -38,10 +38,10 @@ import com.android.systemui.qs.FgsManagerController
import com.android.systemui.qs.QSSecurityFooterUtils
import com.android.systemui.qs.footer.data.model.UserSwitcherStatusModel
import com.android.systemui.qs.footer.data.repository.ForegroundServicesRepository
import com.android.systemui.qs.footer.data.repository.UserSwitcherRepository
import com.android.systemui.qs.footer.domain.model.SecurityButtonConfig
import com.android.systemui.security.data.repository.SecurityRepository
import com.android.systemui.statusbar.policy.DeviceProvisionedController
import com.android.systemui.user.data.repository.UserSwitcherRepository
import com.android.systemui.user.domain.interactor.UserInteractor
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
+7 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.systemui.statusbar.dagger

import com.android.systemui.CoreStartable
import com.android.systemui.statusbar.core.StatusBarInitializer
import com.android.systemui.statusbar.data.repository.KeyguardStatusBarRepository
import com.android.systemui.statusbar.data.repository.KeyguardStatusBarRepositoryImpl
import com.android.systemui.statusbar.data.repository.StatusBarModeRepository
import com.android.systemui.statusbar.data.repository.StatusBarModeRepositoryImpl
import com.android.systemui.statusbar.phone.LightBarController
@@ -48,6 +50,11 @@ abstract class StatusBarModule {
    @ClassKey(StatusBarModeRepositoryImpl::class)
    abstract fun bindStatusBarModeRepositoryStart(impl: StatusBarModeRepositoryImpl): CoreStartable

    @Binds
    abstract fun bindKeyguardStatusBarRepository(
        impl: KeyguardStatusBarRepositoryImpl
    ): KeyguardStatusBarRepository

    @Binds
    @IntoMap
    @ClassKey(OngoingCallController::class)
+80 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.data.repository

import android.content.Context
import com.android.internal.R
import com.android.systemui.common.coroutine.ConflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.user.data.repository.UserSwitcherRepository
import javax.inject.Inject
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge

/**
 * Repository for data that's specific to the status bar **on keyguard**. For data that applies to
 * all status bars, use [StatusBarModeRepository].
 */
interface KeyguardStatusBarRepository {
    /** True if we can show the user switcher on keyguard and false otherwise. */
    val isKeyguardUserSwitcherEnabled: Flow<Boolean>
}

@SysUISingleton
class KeyguardStatusBarRepositoryImpl
@Inject
constructor(
    context: Context,
    configurationController: ConfigurationController,
    userSwitcherRepository: UserSwitcherRepository,
) : KeyguardStatusBarRepository {
    private val relevantConfigChanges: Flow<Unit> =
        ConflatedCallbackFlow.conflatedCallbackFlow {
            val callback =
                object : ConfigurationController.ConfigurationListener {
                    override fun onSmallestScreenWidthChanged() {
                        trySend(Unit)
                    }

                    override fun onDensityOrFontScaleChanged() {
                        trySend(Unit)
                    }
                }
            configurationController.addCallback(callback)
            awaitClose { configurationController.removeCallback(callback) }
        }

    private val isKeyguardUserSwitcherConfigEnabled: Flow<Boolean> =
        // The config depends on screen size and user enabled settings, so re-fetch whenever any of
        // those change.
        merge(userSwitcherRepository.isEnabled.map {}, relevantConfigChanges).map {
            context.resources.getBoolean(R.bool.config_keyguardUserSwitcher)
        }

    /** True if we can show the user switcher on keyguard and false otherwise. */
    override val isKeyguardUserSwitcherEnabled: Flow<Boolean> =
        combine(
            userSwitcherRepository.isEnabled,
            isKeyguardUserSwitcherConfigEnabled,
        ) { isEnabled, isKeyguardEnabled ->
            isEnabled && isKeyguardEnabled
        }
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.data.repository.KeyguardStatusBarRepository
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow

@SysUISingleton
class KeyguardStatusBarInteractor
@Inject
constructor(
    keyguardStatusBarRepository: KeyguardStatusBarRepository,
) {
    /** True if we can show the user switcher on keyguard and false otherwise. */
    val isKeyguardUserSwitcherEnabled: Flow<Boolean> =
        keyguardStatusBarRepository.isKeyguardUserSwitcherEnabled
}
Loading