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