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 package com.android.systemui.tv.dagger
17 
18 import android.app.Activity
19 import android.content.Context
20 import android.hardware.SensorPrivacyManager
21 import com.android.internal.logging.UiEventLogger
22 import com.android.keyguard.KeyguardViewController
23 import com.android.systemui.Dependency
24 import com.android.systemui.animation.DialogTransitionAnimator
25 import com.android.systemui.broadcast.BroadcastSender
26 import com.android.systemui.dagger.ReferenceSystemUIModule
27 import com.android.systemui.dagger.SysUISingleton
28 import com.android.systemui.display.ui.viewmodel.ConnectingDisplayViewModel
29 import com.android.systemui.dock.DockManager
30 import com.android.systemui.dock.DockManagerImpl
31 import com.android.systemui.doze.DozeHost
32 import com.android.systemui.media.dialog.MediaOutputController
33 import com.android.systemui.media.dialog.MediaOutputDialogManager
34 import com.android.systemui.media.muteawait.MediaMuteAwaitConnectionCli
35 import com.android.systemui.media.nearby.NearbyMediaDevicesManager
36 import com.android.systemui.navigationbar.gestural.GestureModule
37 import com.android.systemui.plugins.qs.QSFactory
38 import com.android.systemui.power.dagger.PowerModule
39 import com.android.systemui.privacy.MediaProjectionPrivacyItemMonitor
40 import com.android.systemui.privacy.PrivacyItemMonitor
41 import com.android.systemui.qs.dagger.QSModule
42 import com.android.systemui.qs.tileimpl.QSFactoryImpl
43 import com.android.systemui.screenshot.ReferenceScreenshotModule
44 import com.android.systemui.settings.MultiUserUtilsModule
45 import com.android.systemui.shade.ShadeEmptyImplModule
46 import com.android.systemui.statusbar.KeyboardShortcutsModule
47 import com.android.systemui.statusbar.NotificationListener
48 import com.android.systemui.statusbar.NotificationLockscreenUserManager
49 import com.android.systemui.statusbar.NotificationLockscreenUserManagerImpl
50 import com.android.systemui.statusbar.NotificationShadeWindowController
51 import com.android.systemui.statusbar.events.StatusBarEventsModule
52 import com.android.systemui.statusbar.phone.DozeServiceHost
53 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager
54 import com.android.systemui.statusbar.policy.AospPolicyModule
55 import com.android.systemui.statusbar.policy.DeviceProvisionedController
56 import com.android.systemui.statusbar.policy.DeviceProvisionedControllerImpl
57 import com.android.systemui.statusbar.policy.HeadsUpEmptyImplModule
58 import com.android.systemui.statusbar.policy.IndividualSensorPrivacyController
59 import com.android.systemui.statusbar.policy.IndividualSensorPrivacyControllerImpl
60 import com.android.systemui.statusbar.policy.SensorPrivacyController
61 import com.android.systemui.statusbar.policy.SensorPrivacyControllerImpl
62 import com.android.systemui.tv.hdmi.HdmiModule
63 import com.android.systemui.tv.media.TvMediaOutputDialogActivity
64 import com.android.systemui.tv.media.TvMediaOutputDialogManager
65 import com.android.systemui.tv.notifications.TvNotificationHandler
66 import com.android.systemui.tv.notifications.TvNotificationsModule
67 import com.android.systemui.tv.privacy.PrivacyModule
68 import com.android.systemui.tv.sensorprivacy.TvSensorPrivacyModule
69 import com.android.systemui.tv.shade.TvNotificationShadeWindowController
70 import com.android.systemui.unfold.SysUIUnfoldStartableModule
71 import com.android.systemui.volume.dagger.VolumeModule
72 import dagger.Binds
73 import dagger.Module
74 import dagger.Provides
75 import dagger.multibindings.ClassKey
76 import dagger.multibindings.IntoMap
77 import dagger.multibindings.IntoSet
78 import kotlinx.coroutines.ExperimentalCoroutinesApi
79 import javax.inject.Named
80 
81 /**
82  * A TV specific version of [ReferenceSystemUIModule].
83  *
84  * Code here should be specific to the TV variant of SystemUI and will not be included in other
85  * variants of SystemUI.
86  */
87 @Module(
88     includes = [
89     AospPolicyModule::class,
90     ConnectingDisplayViewModel.StartableModule::class,
91     GestureModule::class,
92     HdmiModule::class,
93     HeadsUpEmptyImplModule::class,
94     KeyboardShortcutsModule::class,
95     MediaMuteAwaitConnectionCli.StartableModule::class,
96     MultiUserUtilsModule::class,
97     NearbyMediaDevicesManager.StartableModule::class,
98     PowerModule::class,
99     PrivacyModule::class,
100     QSModule::class,
101     ReferenceScreenshotModule::class,
102     ShadeEmptyImplModule::class,
103     StatusBarEventsModule::class,
104     SysUIUnfoldStartableModule::class,
105     TvNotificationsModule::class,
106     TvSensorPrivacyModule::class,
107     VolumeModule::class,
108 ]
109 )
110 abstract class TvSystemUIModule {
111     @Binds
bindNotificationLockscreenUserManagernull112     abstract fun bindNotificationLockscreenUserManager(
113             notificationLockscreenUserManager: NotificationLockscreenUserManagerImpl
114     ): NotificationLockscreenUserManager
115 
116     @Binds
117     @SysUISingleton
118     abstract fun bindQSFactory(qsFactoryImpl: QSFactoryImpl): QSFactory
119 
120     @Binds
121     abstract fun bindDockManager(dockManager: DockManagerImpl): DockManager
122 
123     @Binds
124     abstract fun bindKeyguardViewController(
125             statusBarKeyguardViewManager: StatusBarKeyguardViewManager
126     ): KeyguardViewController
127 
128     @Binds
129     abstract fun bindNotificationShadeController(
130             notificationShadeWindowController: TvNotificationShadeWindowController
131     ): NotificationShadeWindowController
132 
133     @OptIn(ExperimentalCoroutinesApi::class)
134     @Binds
135     abstract fun provideDozeHost(dozeServiceHost: DozeServiceHost): DozeHost
136 
137     /**
138      * Binds [MediaProjectionPrivacyItemMonitor] into the set of [PrivacyItemMonitor].
139      */
140     @Binds
141     @IntoSet
142     abstract fun bindMediaProjectionPrivacyItemMonitor(
143             mediaProjectionPrivacyItemMonitor: MediaProjectionPrivacyItemMonitor
144     ): PrivacyItemMonitor
145 
146     @Binds
147     @IntoMap
148     @ClassKey(TvMediaOutputDialogActivity::class)
149     abstract fun provideTvMediaOutputDialogActivity(
150             tvMediaOutputDialogActivity: TvMediaOutputDialogActivity
151     ): Activity
152 
153     companion object {
154         @SysUISingleton
155         @Provides
156         @Named(Dependency.LEAK_REPORT_EMAIL_NAME)
157         fun provideLeakReportEmail(): String = ""
158 
159         @Provides
160         @SysUISingleton
161         fun provideSensorPrivacyController(
162                 sensorPrivacyManager: SensorPrivacyManager
163         ): SensorPrivacyController =
164                 SensorPrivacyControllerImpl(sensorPrivacyManager).apply { init() }
165 
166         @Provides
167         @SysUISingleton
168         fun provideIndividualSensorPrivacyController(
169                 sensorPrivacyManager: SensorPrivacyManager
170         ): IndividualSensorPrivacyController =
171                 IndividualSensorPrivacyControllerImpl(sensorPrivacyManager).apply { init() }
172 
173         @SysUISingleton
174         @Provides
175         @Named(Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME)
176         fun provideAllowNotificationLongPress(): Boolean = true
177 
178         @SysUISingleton
179         @Provides
180         fun providesDeviceProvisionedController(
181                 deviceProvisionedController: DeviceProvisionedControllerImpl
182         ): DeviceProvisionedController {
183             deviceProvisionedController.init()
184             return deviceProvisionedController
185         }
186 
187         @Provides
188         @SysUISingleton
189         fun provideTvNotificationHandler(
190                 notificationListener: NotificationListener
191         ): TvNotificationHandler = TvNotificationHandler(notificationListener)
192 
193         @Provides
194         fun provideMediaOutputDialogFactory(
195                 context: Context,
196                 broadcastSender: BroadcastSender,
197                 uiEventLogger: UiEventLogger,
198                 dialogTransitionAnimator: DialogTransitionAnimator,
199                 mediaOutputControllerFactory: MediaOutputController.Factory,
200             ): MediaOutputDialogManager =
201                 TvMediaOutputDialogManager(context, broadcastSender, uiEventLogger,
202                         dialogTransitionAnimator, mediaOutputControllerFactory)
203     }
204 }
205