• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * 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.communal.dagger
18 
19 import android.content.Context
20 import android.content.res.Resources
21 import com.android.systemui.CoreStartable
22 import com.android.systemui.communal.data.backup.CommunalBackupUtils
23 import com.android.systemui.communal.data.db.CommunalDatabaseModule
24 import com.android.systemui.communal.data.repository.CommunalMediaRepositoryModule
25 import com.android.systemui.communal.data.repository.CommunalPrefsRepositoryModule
26 import com.android.systemui.communal.data.repository.CommunalRepositoryModule
27 import com.android.systemui.communal.data.repository.CommunalSettingsRepositoryModule
28 import com.android.systemui.communal.data.repository.CommunalSmartspaceRepositoryModule
29 import com.android.systemui.communal.data.repository.CommunalTutorialRepositoryModule
30 import com.android.systemui.communal.data.repository.CommunalWidgetRepositoryModule
31 import com.android.systemui.communal.domain.interactor.CommunalSceneTransitionInteractor
32 import com.android.systemui.communal.domain.suppression.dagger.CommunalSuppressionModule
33 import com.android.systemui.communal.shared.log.CommunalMetricsLogger
34 import com.android.systemui.communal.shared.log.CommunalStatsLogProxyImpl
35 import com.android.systemui.communal.shared.model.CommunalScenes
36 import com.android.systemui.communal.shared.model.GlanceableHubMultiUserHelper
37 import com.android.systemui.communal.shared.model.GlanceableHubMultiUserHelperImpl
38 import com.android.systemui.communal.ui.compose.sceneTransitions
39 import com.android.systemui.communal.util.CommunalColors
40 import com.android.systemui.communal.util.CommunalColorsImpl
41 import com.android.systemui.communal.widgets.CommunalWidgetModule
42 import com.android.systemui.communal.widgets.EditWidgetsActivityStarter
43 import com.android.systemui.communal.widgets.EditWidgetsActivityStarterImpl
44 import com.android.systemui.dagger.SysUISingleton
45 import com.android.systemui.dagger.qualifiers.Application
46 import com.android.systemui.dagger.qualifiers.Main
47 import com.android.systemui.res.R
48 import com.android.systemui.scene.shared.model.SceneContainerConfig
49 import com.android.systemui.scene.shared.model.SceneDataSource
50 import com.android.systemui.scene.shared.model.SceneDataSourceDelegator
51 import com.android.systemui.scene.ui.composable.ConstantSceneContainerTransitionsBuilder
52 import dagger.Binds
53 import dagger.Module
54 import dagger.Provides
55 import dagger.multibindings.ClassKey
56 import dagger.multibindings.IntoMap
57 import javax.inject.Named
58 import kotlinx.coroutines.CoroutineScope
59 
60 @Module(
61     includes =
62         [
63             CommunalRepositoryModule::class,
64             CommunalMediaRepositoryModule::class,
65             CommunalTutorialRepositoryModule::class,
66             CommunalWidgetRepositoryModule::class,
67             CommunalDatabaseModule::class,
68             CommunalWidgetModule::class,
69             CommunalPrefsRepositoryModule::class,
70             CommunalSettingsRepositoryModule::class,
71             CommunalSmartspaceRepositoryModule::class,
72             CommunalStartableModule::class,
73             GlanceableHubWidgetManagerModule::class,
74             CommunalSuppressionModule::class,
75         ]
76 )
77 interface CommunalModule {
78     @Binds
bindEditWidgetsActivityStarternull79     fun bindEditWidgetsActivityStarter(
80         starter: EditWidgetsActivityStarterImpl
81     ): EditWidgetsActivityStarter
82 
83     @Binds
84     @Communal
85     fun bindCommunalSceneDataSource(@Communal delegator: SceneDataSourceDelegator): SceneDataSource
86 
87     @Binds fun bindCommunalColors(impl: CommunalColorsImpl): CommunalColors
88 
89     @Binds
90     fun bindCommunalStatsLogProxy(
91         impl: CommunalStatsLogProxyImpl
92     ): CommunalMetricsLogger.StatsLogProxy
93 
94     @Binds
95     @IntoMap
96     @ClassKey(CommunalSceneTransitionInteractor::class)
97     abstract fun bindCommunalSceneTransitionInteractor(
98         impl: CommunalSceneTransitionInteractor
99     ): CoreStartable
100 
101     @Binds
102     fun bindGlanceableHubMultiUserHelper(
103         impl: GlanceableHubMultiUserHelperImpl
104     ): GlanceableHubMultiUserHelper
105 
106     companion object {
107         const val LOGGABLE_PREFIXES = "loggable_prefixes"
108         const val LAUNCHER_PACKAGE = "launcher_package"
109         const val SWIPE_TO_HUB = "swipe_to_hub"
110         const val SHOW_UMO = "show_umo"
111         const val TOUCH_NOTIFICATION_RATE_LIMIT = "TOUCH_NOTIFICATION_RATE_LIMIT"
112 
113         const val TOUCH_NOTIFIFCATION_RATE_LIMIT_MS = 100
114 
115         @Provides
116         @Communal
117         @SysUISingleton
118         fun providesCommunalSceneDataSourceDelegator(
119             @Application applicationScope: CoroutineScope
120         ): SceneDataSourceDelegator {
121             val config =
122                 SceneContainerConfig(
123                     sceneKeys = listOf(CommunalScenes.Blank, CommunalScenes.Communal),
124                     initialSceneKey = CommunalScenes.Blank,
125                     navigationDistances =
126                         mapOf(CommunalScenes.Blank to 0, CommunalScenes.Communal to 1),
127                     transitionsBuilder = ConstantSceneContainerTransitionsBuilder(sceneTransitions),
128                 )
129             return SceneDataSourceDelegator(applicationScope, config)
130         }
131 
132         @Provides
133         @SysUISingleton
134         fun providesCommunalBackupUtils(@Application context: Context): CommunalBackupUtils {
135             return CommunalBackupUtils(context)
136         }
137 
138         /** The prefixes of widgets packages names that are considered loggable. */
139         @Provides
140         @Named(LOGGABLE_PREFIXES)
141         fun provideLoggablePrefixes(@Application context: Context): List<String> {
142             return context.resources
143                 .getStringArray(com.android.internal.R.array.config_loggable_dream_prefixes)
144                 .toList()
145         }
146 
147         /** The package name of the launcher */
148         @Provides
149         @Named(LAUNCHER_PACKAGE)
150         fun provideLauncherPackage(@Main resources: Resources): String {
151             return resources.getString(R.string.launcher_overlayable_package)
152         }
153 
154         @Provides
155         @Named(SWIPE_TO_HUB)
156         fun provideSwipeToHub(@Main resources: Resources): Boolean {
157             return resources.getBoolean(R.bool.config_swipeToOpenGlanceableHub)
158         }
159 
160         @Provides
161         @Named(SHOW_UMO)
162         fun provideShowUmo(@Main resources: Resources): Boolean {
163             return resources.getBoolean(R.bool.config_showUmoOnHub)
164         }
165 
166         @Provides
167         @Named(TOUCH_NOTIFICATION_RATE_LIMIT)
168         fun providesRateLimit(): Int {
169             return TOUCH_NOTIFIFCATION_RATE_LIMIT_MS
170         }
171     }
172 }
173