1 /*
2  * Copyright (C) 2020 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.media.dagger;
18 
19 import com.android.systemui.dagger.SysUISingleton;
20 import com.android.systemui.log.LogBuffer;
21 import com.android.systemui.log.LogBufferFactory;
22 import com.android.systemui.media.controls.domain.MediaDomainModule;
23 import com.android.systemui.media.controls.domain.pipeline.MediaDataManager;
24 import com.android.systemui.media.controls.ui.controller.MediaCarouselController;
25 import com.android.systemui.media.controls.ui.controller.MediaHierarchyManager;
26 import com.android.systemui.media.controls.ui.controller.MediaHostStatesManager;
27 import com.android.systemui.media.controls.ui.view.MediaHost;
28 import com.android.systemui.media.dream.dagger.MediaComplicationComponent;
29 import com.android.systemui.media.taptotransfer.MediaTttCommandLineHelper;
30 import com.android.systemui.media.taptotransfer.MediaTttFlags;
31 import com.android.systemui.media.taptotransfer.receiver.MediaTttReceiverLogBuffer;
32 import com.android.systemui.media.taptotransfer.sender.MediaTttSenderLogBuffer;
33 
34 import dagger.Lazy;
35 import dagger.Module;
36 import dagger.Provides;
37 
38 import java.util.Optional;
39 
40 import javax.inject.Named;
41 
42 /** Dagger module for the media package. */
43 @Module(
44         includes = {
45             MediaDomainModule.class
46         },
47         subcomponents = {
48         MediaComplicationComponent.class,
49 })
50 public interface MediaModule {
51     String QS_PANEL = "media_qs_panel";
52     String QUICK_QS_PANEL = "media_quick_qs_panel";
53     String KEYGUARD = "media_keyguard";
54     String DREAM = "dream";
55     String COMMUNAL_HUB = "communal_Hub";
56 
57     /** */
58     @Provides
59     @SysUISingleton
60     @Named(QS_PANEL)
providesQSMediaHost(MediaHost.MediaHostStateHolder stateHolder, MediaHierarchyManager hierarchyManager, MediaDataManager dataManager, MediaHostStatesManager statesManager, MediaCarouselController carouselController)61     static MediaHost providesQSMediaHost(MediaHost.MediaHostStateHolder stateHolder,
62             MediaHierarchyManager hierarchyManager, MediaDataManager dataManager,
63             MediaHostStatesManager statesManager, MediaCarouselController carouselController) {
64         return new MediaHost(stateHolder, hierarchyManager, dataManager, statesManager,
65                 carouselController);
66     }
67 
68     /** */
69     @Provides
70     @SysUISingleton
71     @Named(QUICK_QS_PANEL)
providesQuickQSMediaHost(MediaHost.MediaHostStateHolder stateHolder, MediaHierarchyManager hierarchyManager, MediaDataManager dataManager, MediaHostStatesManager statesManager, MediaCarouselController carouselController)72     static MediaHost providesQuickQSMediaHost(MediaHost.MediaHostStateHolder stateHolder,
73             MediaHierarchyManager hierarchyManager, MediaDataManager dataManager,
74             MediaHostStatesManager statesManager, MediaCarouselController carouselController) {
75         return new MediaHost(stateHolder, hierarchyManager, dataManager, statesManager,
76                 carouselController);
77     }
78 
79     /** */
80     @Provides
81     @SysUISingleton
82     @Named(KEYGUARD)
providesKeyguardMediaHost(MediaHost.MediaHostStateHolder stateHolder, MediaHierarchyManager hierarchyManager, MediaDataManager dataManager, MediaHostStatesManager statesManager, MediaCarouselController carouselController)83     static MediaHost providesKeyguardMediaHost(MediaHost.MediaHostStateHolder stateHolder,
84             MediaHierarchyManager hierarchyManager, MediaDataManager dataManager,
85             MediaHostStatesManager statesManager, MediaCarouselController carouselController) {
86         return new MediaHost(stateHolder, hierarchyManager, dataManager, statesManager,
87                 carouselController);
88     }
89 
90     /** */
91     @Provides
92     @SysUISingleton
93     @Named(DREAM)
providesDreamMediaHost(MediaHost.MediaHostStateHolder stateHolder, MediaHierarchyManager hierarchyManager, MediaDataManager dataManager, MediaHostStatesManager statesManager, MediaCarouselController carouselController)94     static MediaHost providesDreamMediaHost(MediaHost.MediaHostStateHolder stateHolder,
95             MediaHierarchyManager hierarchyManager, MediaDataManager dataManager,
96             MediaHostStatesManager statesManager, MediaCarouselController carouselController) {
97         return new MediaHost(stateHolder, hierarchyManager, dataManager, statesManager,
98                 carouselController);
99     }
100 
101     /** */
102     @Provides
103     @SysUISingleton
104     @Named(COMMUNAL_HUB)
providesCommunalMediaHost(MediaHost.MediaHostStateHolder stateHolder, MediaHierarchyManager hierarchyManager, MediaDataManager dataManager, MediaHostStatesManager statesManager, MediaCarouselController carouselController)105     static MediaHost providesCommunalMediaHost(MediaHost.MediaHostStateHolder stateHolder,
106             MediaHierarchyManager hierarchyManager, MediaDataManager dataManager,
107             MediaHostStatesManager statesManager, MediaCarouselController carouselController) {
108         return new MediaHost(stateHolder, hierarchyManager, dataManager, statesManager,
109                 carouselController);
110     }
111 
112     /** Provides a logging buffer related to the media tap-to-transfer chip on the sender device. */
113     @Provides
114     @SysUISingleton
115     @MediaTttSenderLogBuffer
provideMediaTttSenderLogBuffer(LogBufferFactory factory)116     static LogBuffer provideMediaTttSenderLogBuffer(LogBufferFactory factory) {
117         return factory.create("MediaTttSender", 30);
118     }
119 
120     /**
121      * Provides a logging buffer related to the media tap-to-transfer chip on the receiver device.
122      */
123     @Provides
124     @SysUISingleton
125     @MediaTttReceiverLogBuffer
provideMediaTttReceiverLogBuffer(LogBufferFactory factory)126     static LogBuffer provideMediaTttReceiverLogBuffer(LogBufferFactory factory) {
127         return factory.create("MediaTttReceiver", 20);
128     }
129 
130     /** */
131     @Provides
132     @SysUISingleton
providesMediaTttCommandLineHelper( MediaTttFlags mediaTttFlags, Lazy<MediaTttCommandLineHelper> helperLazy)133     static Optional<MediaTttCommandLineHelper> providesMediaTttCommandLineHelper(
134             MediaTttFlags mediaTttFlags,
135             Lazy<MediaTttCommandLineHelper> helperLazy) {
136         if (!mediaTttFlags.isMediaTttEnabled()) {
137             return Optional.empty();
138         }
139         return Optional.of(helperLazy.get());
140     }
141 }
142