1 /* 2 * Copyright (C) 2019 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.controls.dagger 18 19 import android.app.Activity 20 import android.content.pm.PackageManager 21 import com.android.systemui.controls.ControlsMetricsLogger 22 import com.android.systemui.controls.ControlsMetricsLoggerImpl 23 import com.android.systemui.controls.controller.ControlsBindingController 24 import com.android.systemui.controls.controller.ControlsBindingControllerImpl 25 import com.android.systemui.controls.controller.ControlsController 26 import com.android.systemui.controls.controller.ControlsControllerImpl 27 import com.android.systemui.controls.controller.ControlsFavoritePersistenceWrapper 28 import com.android.systemui.controls.controller.ControlsTileResourceConfiguration 29 import com.android.systemui.controls.management.ControlsEditingActivity 30 import com.android.systemui.controls.management.ControlsFavoritingActivity 31 import com.android.systemui.controls.management.ControlsListingController 32 import com.android.systemui.controls.management.ControlsListingControllerImpl 33 import com.android.systemui.controls.management.ControlsProviderSelectorActivity 34 import com.android.systemui.controls.management.ControlsRequestDialog 35 import com.android.systemui.controls.panels.AuthorizedPanelsRepository 36 import com.android.systemui.controls.panels.AuthorizedPanelsRepositoryImpl 37 import com.android.systemui.controls.panels.SelectedComponentRepository 38 import com.android.systemui.controls.panels.SelectedComponentRepositoryImpl 39 import com.android.systemui.controls.settings.ControlsSettingsDialogManager 40 import com.android.systemui.controls.settings.ControlsSettingsDialogManagerImpl 41 import com.android.systemui.controls.settings.ControlsSettingsRepository 42 import com.android.systemui.controls.settings.ControlsSettingsRepositoryImpl 43 import com.android.systemui.controls.ui.ControlActionCoordinator 44 import com.android.systemui.controls.ui.ControlActionCoordinatorImpl 45 import com.android.systemui.controls.ui.ControlsActivity 46 import com.android.systemui.controls.ui.ControlsUiController 47 import com.android.systemui.controls.ui.ControlsUiControllerImpl 48 import com.android.systemui.dagger.SysUISingleton 49 import com.android.systemui.qs.QsEventLogger 50 import com.android.systemui.qs.pipeline.shared.TileSpec 51 import com.android.systemui.qs.tileimpl.QSTileImpl 52 import com.android.systemui.qs.tiles.DeviceControlsTile 53 import com.android.systemui.qs.tiles.viewmodel.QSTileConfig 54 import com.android.systemui.qs.tiles.viewmodel.QSTileUIConfig 55 import dagger.Binds 56 import dagger.BindsOptionalOf 57 import dagger.Module 58 import dagger.Provides 59 import dagger.multibindings.ClassKey 60 import dagger.multibindings.IntoMap 61 import dagger.multibindings.StringKey 62 63 /** 64 * Module for injecting classes in `com.android.systemui.controls`- 65 * 66 * Classes provided by this module should only be injected directly into other classes in this 67 * module. For injecting outside of this module (for example, [GlobalActionsDialog], inject 68 * [ControlsComponent] and obtain the corresponding optionals from it. 69 */ 70 @Module 71 abstract class ControlsModule { 72 73 @Module 74 companion object { 75 @JvmStatic 76 @Provides 77 @SysUISingleton 78 @ControlsFeatureEnabled providesControlsFeatureEnablednull79 fun providesControlsFeatureEnabled(pm: PackageManager): Boolean { 80 return pm.hasSystemFeature(PackageManager.FEATURE_CONTROLS) 81 } 82 83 const val DEVICE_CONTROLS_SPEC = "controls" 84 85 @Provides 86 @IntoMap 87 @StringKey(DEVICE_CONTROLS_SPEC) provideDeviceControlsTileConfignull88 fun provideDeviceControlsTileConfig(uiEventLogger: QsEventLogger): QSTileConfig = 89 QSTileConfig( 90 tileSpec = TileSpec.create(DEVICE_CONTROLS_SPEC), 91 uiConfig = 92 QSTileUIConfig.Resource( 93 iconRes = com.android.systemui.res.R.drawable.controls_icon, 94 labelRes = com.android.systemui.res.R.string.quick_controls_title 95 ), 96 instanceId = uiEventLogger.getNewInstanceId(), 97 ) 98 } 99 100 @Binds 101 abstract fun provideControlsListingController( 102 controller: ControlsListingControllerImpl 103 ): ControlsListingController 104 105 @Binds 106 abstract fun provideControlsController(controller: ControlsControllerImpl): ControlsController 107 108 @Binds 109 abstract fun provideControlsBindingController( 110 controller: ControlsBindingControllerImpl 111 ): ControlsBindingController 112 113 @Binds 114 abstract fun provideUiController(controller: ControlsUiControllerImpl): ControlsUiController 115 116 @Binds 117 abstract fun provideSettingsManager( 118 manager: ControlsSettingsRepositoryImpl 119 ): ControlsSettingsRepository 120 121 @Binds 122 abstract fun provideDialogManager( 123 manager: ControlsSettingsDialogManagerImpl 124 ): ControlsSettingsDialogManager 125 126 @Binds 127 abstract fun provideMetricsLogger(logger: ControlsMetricsLoggerImpl): ControlsMetricsLogger 128 129 @Binds 130 abstract fun provideControlActionCoordinator( 131 coordinator: ControlActionCoordinatorImpl 132 ): ControlActionCoordinator 133 134 @Binds 135 abstract fun provideAuthorizedPanelsRepository( 136 repository: AuthorizedPanelsRepositoryImpl 137 ): AuthorizedPanelsRepository 138 139 @Binds 140 abstract fun providePreferredPanelRepository( 141 repository: SelectedComponentRepositoryImpl 142 ): SelectedComponentRepository 143 144 @BindsOptionalOf 145 abstract fun optionalPersistenceWrapper(): ControlsFavoritePersistenceWrapper 146 147 @BindsOptionalOf 148 abstract fun provideControlsTileResourceConfiguration(): ControlsTileResourceConfiguration 149 150 @Binds 151 @IntoMap 152 @ClassKey(ControlsProviderSelectorActivity::class) 153 abstract fun provideControlsProviderActivity( 154 activity: ControlsProviderSelectorActivity 155 ): Activity 156 157 @Binds 158 @IntoMap 159 @ClassKey(ControlsFavoritingActivity::class) 160 abstract fun provideControlsFavoritingActivity( 161 activity: ControlsFavoritingActivity 162 ): Activity 163 164 @Binds 165 @IntoMap 166 @ClassKey(ControlsEditingActivity::class) 167 abstract fun provideControlsEditingActivity( 168 activity: ControlsEditingActivity 169 ): Activity 170 171 @Binds 172 @IntoMap 173 @ClassKey(ControlsRequestDialog::class) 174 abstract fun provideControlsRequestDialog( 175 activity: ControlsRequestDialog 176 ): Activity 177 178 @Binds 179 @IntoMap 180 @ClassKey(ControlsActivity::class) 181 abstract fun provideControlsActivity(activity: ControlsActivity): Activity 182 183 @Binds 184 @IntoMap 185 @StringKey(DeviceControlsTile.TILE_SPEC) 186 abstract fun bindDeviceControlsTile(controlsTile: DeviceControlsTile): QSTileImpl<*> 187 } 188