1 /*
<lambda>null2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.statusbar.data.repository
18 
19 import android.content.Context
20 import com.android.internal.R
21 import com.android.systemui.common.coroutine.ConflatedCallbackFlow
22 import com.android.systemui.dagger.SysUISingleton
23 import com.android.systemui.statusbar.policy.ConfigurationController
24 import com.android.systemui.user.data.repository.UserSwitcherRepository
25 import dagger.Binds
26 import dagger.Module
27 import javax.inject.Inject
28 import kotlinx.coroutines.channels.awaitClose
29 import kotlinx.coroutines.flow.Flow
30 import kotlinx.coroutines.flow.combine
31 import kotlinx.coroutines.flow.map
32 import kotlinx.coroutines.flow.merge
33 
34 /**
35  * Repository for data that's specific to the status bar **on keyguard**. For data that applies to
36  * all status bars, use [StatusBarModeRepositoryStore].
37  */
38 interface KeyguardStatusBarRepository {
39     /** True if we can show the user switcher on keyguard and false otherwise. */
40     val isKeyguardUserSwitcherEnabled: Flow<Boolean>
41 }
42 
43 @SysUISingleton
44 class KeyguardStatusBarRepositoryImpl
45 @Inject
46 constructor(
47     context: Context,
48     configurationController: ConfigurationController,
49     userSwitcherRepository: UserSwitcherRepository,
50 ) : KeyguardStatusBarRepository {
51     private val relevantConfigChanges: Flow<Unit> =
<lambda>null52         ConflatedCallbackFlow.conflatedCallbackFlow {
53             val callback =
54                 object : ConfigurationController.ConfigurationListener {
55                     override fun onSmallestScreenWidthChanged() {
56                         trySend(Unit)
57                     }
58 
59                     override fun onDensityOrFontScaleChanged() {
60                         trySend(Unit)
61                     }
62                 }
63             configurationController.addCallback(callback)
64             awaitClose { configurationController.removeCallback(callback) }
65         }
66 
67     private val isKeyguardUserSwitcherConfigEnabled: Flow<Boolean> =
68         // The config depends on screen size and user enabled settings, so re-fetch whenever any of
69         // those change.
<lambda>null70         merge(userSwitcherRepository.isEnabled.map {}, relevantConfigChanges).map {
71             context.resources.getBoolean(R.bool.config_keyguardUserSwitcher)
72         }
73 
74     /** True if we can show the user switcher on keyguard and false otherwise. */
75     override val isKeyguardUserSwitcherEnabled: Flow<Boolean> =
76         combine(
77             userSwitcherRepository.isEnabled,
78             isKeyguardUserSwitcherConfigEnabled,
isKeyguardEnablednull79         ) { isEnabled, isKeyguardEnabled ->
80             isEnabled && isKeyguardEnabled
81         }
82 }
83 
84 @Module
85 interface KeyguardStatusBarRepositoryModule {
bindImplnull86     @Binds fun bindImpl(impl: KeyguardStatusBarRepositoryImpl): KeyguardStatusBarRepository
87 }
88