1 /*
2  * Copyright (C) 2022 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.connectivity
18 
19 import android.os.UserManager
20 import com.android.systemui.flags.FeatureFlags
21 import com.android.systemui.flags.Flags.SIGNAL_CALLBACK_DEPRECATION
22 import com.android.systemui.qs.QsEventLogger
23 import com.android.systemui.qs.pipeline.shared.TileSpec
24 import com.android.systemui.qs.tileimpl.QSTileImpl
25 import com.android.systemui.qs.tiles.AirplaneModeTile
26 import com.android.systemui.qs.tiles.BluetoothTile
27 import com.android.systemui.qs.tiles.CastTile
28 import com.android.systemui.qs.tiles.DataSaverTile
29 import com.android.systemui.qs.tiles.HotspotTile
30 import com.android.systemui.qs.tiles.InternetTile
31 import com.android.systemui.qs.tiles.InternetTileNewImpl
32 import com.android.systemui.qs.tiles.NfcTile
33 import com.android.systemui.qs.tiles.base.interactor.QSTileAvailabilityInteractor
34 import com.android.systemui.qs.tiles.base.viewmodel.QSTileViewModelFactory
35 import com.android.systemui.qs.tiles.impl.airplane.domain.AirplaneModeMapper
36 import com.android.systemui.qs.tiles.impl.airplane.domain.interactor.AirplaneModeTileDataInteractor
37 import com.android.systemui.qs.tiles.impl.airplane.domain.interactor.AirplaneModeTileUserActionInteractor
38 import com.android.systemui.qs.tiles.impl.airplane.domain.model.AirplaneModeTileModel
39 import com.android.systemui.qs.tiles.impl.internet.domain.InternetTileMapper
40 import com.android.systemui.qs.tiles.impl.internet.domain.interactor.InternetTileDataInteractor
41 import com.android.systemui.qs.tiles.impl.internet.domain.interactor.InternetTileUserActionInteractor
42 import com.android.systemui.qs.tiles.impl.internet.domain.model.InternetTileModel
43 import com.android.systemui.qs.tiles.impl.saver.domain.DataSaverTileMapper
44 import com.android.systemui.qs.tiles.impl.saver.domain.interactor.DataSaverTileDataInteractor
45 import com.android.systemui.qs.tiles.impl.saver.domain.interactor.DataSaverTileUserActionInteractor
46 import com.android.systemui.qs.tiles.impl.saver.domain.model.DataSaverTileModel
47 import com.android.systemui.qs.tiles.viewmodel.QSTileConfig
48 import com.android.systemui.qs.tiles.viewmodel.QSTilePolicy
49 import com.android.systemui.qs.tiles.viewmodel.QSTileUIConfig
50 import com.android.systemui.qs.tiles.viewmodel.QSTileViewModel
51 import com.android.systemui.res.R
52 import dagger.Binds
53 import dagger.Module
54 import dagger.Provides
55 import dagger.multibindings.IntoMap
56 import dagger.multibindings.StringKey
57 
58 @Module
59 interface ConnectivityModule {
60 
61     /** Inject BluetoothTile into tileMap in QSModule */
62     @Binds
63     @IntoMap
64     @StringKey(BluetoothTile.TILE_SPEC)
bindBluetoothTilenull65     fun bindBluetoothTile(bluetoothTile: BluetoothTile): QSTileImpl<*>
66 
67     /** Inject CastTile into tileMap in QSModule */
68     @Binds
69     @IntoMap
70     @StringKey(CastTile.TILE_SPEC)
71     fun bindCastTile(castTile: CastTile): QSTileImpl<*>
72 
73     /** Inject HotspotTile into tileMap in QSModule */
74     @Binds
75     @IntoMap
76     @StringKey(HotspotTile.TILE_SPEC)
77     fun bindHotspotTile(hotspotTile: HotspotTile): QSTileImpl<*>
78 
79     /** Inject AirplaneModeTile into tileMap in QSModule */
80     @Binds
81     @IntoMap
82     @StringKey(AirplaneModeTile.TILE_SPEC)
83     fun bindAirplaneModeTile(airplaneModeTile: AirplaneModeTile): QSTileImpl<*>
84 
85     /** Inject DataSaverTile into tileMap in QSModule */
86     @Binds
87     @IntoMap
88     @StringKey(DataSaverTile.TILE_SPEC)
89     fun bindDataSaverTile(dataSaverTile: DataSaverTile): QSTileImpl<*>
90 
91     /** Inject NfcTile into tileMap in QSModule */
92     @Binds @IntoMap @StringKey(NfcTile.TILE_SPEC) fun bindNfcTile(nfcTile: NfcTile): QSTileImpl<*>
93 
94     @Binds
95     @IntoMap
96     @StringKey(AIRPLANE_MODE_TILE_SPEC)
97     fun provideAirplaneModeAvailabilityInteractor(
98             impl: AirplaneModeTileDataInteractor
99     ): QSTileAvailabilityInteractor
100 
101     @Binds
102     @IntoMap
103     @StringKey(DATA_SAVER_TILE_SPEC)
104     fun provideDataSaverAvailabilityInteractor(
105             impl: DataSaverTileDataInteractor
106     ): QSTileAvailabilityInteractor
107 
108     @Binds
109     @IntoMap
110     @StringKey(INTERNET_TILE_SPEC)
111     fun provideInternetAvailabilityInteractor(
112             impl: InternetTileDataInteractor
113     ): QSTileAvailabilityInteractor
114 
115     companion object {
116 
117         const val AIRPLANE_MODE_TILE_SPEC = "airplane"
118         const val DATA_SAVER_TILE_SPEC = "saver"
119         const val INTERNET_TILE_SPEC = "internet"
120         const val HOTSPOT_TILE_SPEC = "hotspot"
121         const val CAST_TILE_SPEC = "cast"
122         const val BLUETOOTH_TILE_SPEC = "bt"
123 
124         /** Inject InternetTile or InternetTileNewImpl into tileMap in QSModule */
125         @Provides
126         @IntoMap
127         @StringKey(InternetTile.TILE_SPEC)
128         fun bindInternetTile(
129             internetTile: InternetTile,
130             newInternetTile: InternetTileNewImpl,
131             featureFlags: FeatureFlags,
132         ): QSTileImpl<*> =
133             if (featureFlags.isEnabled(SIGNAL_CALLBACK_DEPRECATION)) {
134                 newInternetTile
135             } else {
136                 internetTile
137             }
138 
139         @Provides
140         @IntoMap
141         @StringKey(AIRPLANE_MODE_TILE_SPEC)
142         fun provideAirplaneModeTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
143             QSTileConfig(
144                 tileSpec = TileSpec.create(AIRPLANE_MODE_TILE_SPEC),
145                 uiConfig =
146                     QSTileUIConfig.Resource(
147                         iconRes = R.drawable.qs_airplane_icon_off,
148                         labelRes = R.string.airplane_mode,
149                     ),
150                 instanceId = uiEventLogger.getNewInstanceId(),
151                 policy = QSTilePolicy.Restricted(listOf(UserManager.DISALLOW_AIRPLANE_MODE)),
152             )
153 
154         /** Inject AirplaneModeTile into tileViewModelMap in QSModule */
155         @Provides
156         @IntoMap
157         @StringKey(AIRPLANE_MODE_TILE_SPEC)
158         fun provideAirplaneModeTileViewModel(
159             factory: QSTileViewModelFactory.Static<AirplaneModeTileModel>,
160             mapper: AirplaneModeMapper,
161             stateInteractor: AirplaneModeTileDataInteractor,
162             userActionInteractor: AirplaneModeTileUserActionInteractor
163         ): QSTileViewModel =
164             factory.create(
165                 TileSpec.create(AIRPLANE_MODE_TILE_SPEC),
166                 userActionInteractor,
167                 stateInteractor,
168                 mapper,
169             )
170 
171         @Provides
172         @IntoMap
173         @StringKey(DATA_SAVER_TILE_SPEC)
174         fun provideDataSaverTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
175             QSTileConfig(
176                 tileSpec = TileSpec.create(DATA_SAVER_TILE_SPEC),
177                 uiConfig =
178                     QSTileUIConfig.Resource(
179                         iconRes = R.drawable.qs_data_saver_icon_off,
180                         labelRes = R.string.data_saver,
181                     ),
182                 instanceId = uiEventLogger.getNewInstanceId(),
183             )
184 
185         /** Inject DataSaverTile into tileViewModelMap in QSModule */
186         @Provides
187         @IntoMap
188         @StringKey(DATA_SAVER_TILE_SPEC)
189         fun provideDataSaverTileViewModel(
190             factory: QSTileViewModelFactory.Static<DataSaverTileModel>,
191             mapper: DataSaverTileMapper,
192             stateInteractor: DataSaverTileDataInteractor,
193             userActionInteractor: DataSaverTileUserActionInteractor
194         ): QSTileViewModel =
195             factory.create(
196                 TileSpec.create(DATA_SAVER_TILE_SPEC),
197                 userActionInteractor,
198                 stateInteractor,
199                 mapper,
200             )
201 
202         @Provides
203         @IntoMap
204         @StringKey(INTERNET_TILE_SPEC)
205         fun provideInternetTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
206             QSTileConfig(
207                 tileSpec = TileSpec.create(INTERNET_TILE_SPEC),
208                 uiConfig =
209                     QSTileUIConfig.Resource(
210                         iconRes = R.drawable.ic_qs_no_internet_available,
211                         labelRes = R.string.quick_settings_internet_label,
212                     ),
213                 instanceId = uiEventLogger.getNewInstanceId(),
214             )
215 
216         /** Inject InternetTile into tileViewModelMap in QSModule */
217         @Provides
218         @IntoMap
219         @StringKey(INTERNET_TILE_SPEC)
220         fun provideInternetTileViewModel(
221             factory: QSTileViewModelFactory.Static<InternetTileModel>,
222             mapper: InternetTileMapper,
223             stateInteractor: InternetTileDataInteractor,
224             userActionInteractor: InternetTileUserActionInteractor
225         ): QSTileViewModel =
226             factory.create(
227                 TileSpec.create(INTERNET_TILE_SPEC),
228                 userActionInteractor,
229                 stateInteractor,
230                 mapper,
231             )
232 
233         @Provides
234         @IntoMap
235         @StringKey(HOTSPOT_TILE_SPEC)
236         fun provideHotspotTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
237             QSTileConfig(
238                 tileSpec = TileSpec.create(HOTSPOT_TILE_SPEC),
239                 uiConfig =
240                     QSTileUIConfig.Resource(
241                         iconRes = R.drawable.ic_hotspot,
242                         labelRes = R.string.quick_settings_hotspot_label,
243                     ),
244                 instanceId = uiEventLogger.getNewInstanceId(),
245             )
246 
247         @Provides
248         @IntoMap
249         @StringKey(CAST_TILE_SPEC)
250         fun provideCastTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
251             QSTileConfig(
252                 tileSpec = TileSpec.create(CAST_TILE_SPEC),
253                 uiConfig =
254                     QSTileUIConfig.Resource(
255                         iconRes = R.drawable.ic_cast,
256                         labelRes = R.string.quick_settings_cast_title,
257                     ),
258                 instanceId = uiEventLogger.getNewInstanceId(),
259             )
260 
261         @Provides
262         @IntoMap
263         @StringKey(BLUETOOTH_TILE_SPEC)
264         fun provideBluetoothTileConfig(uiEventLogger: QsEventLogger): QSTileConfig =
265             QSTileConfig(
266                 tileSpec = TileSpec.create(BLUETOOTH_TILE_SPEC),
267                 uiConfig =
268                     QSTileUIConfig.Resource(
269                         iconRes = R.drawable.qs_bluetooth_icon_off,
270                         labelRes = R.string.quick_settings_bluetooth_label,
271                     ),
272                 instanceId = uiEventLogger.getNewInstanceId(),
273             )
274     }
275 }
276