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.statusbar.policy.dagger;
18 
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.os.UserManager;
22 
23 import com.android.internal.R;
24 import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
25 import com.android.systemui.dagger.SysUISingleton;
26 import com.android.systemui.dagger.qualifiers.Main;
27 import com.android.systemui.log.LogBuffer;
28 import com.android.systemui.log.LogBufferFactory;
29 import com.android.systemui.settings.UserTracker;
30 import com.android.systemui.statusbar.connectivity.AccessPointController;
31 import com.android.systemui.statusbar.connectivity.AccessPointControllerImpl;
32 import com.android.systemui.statusbar.connectivity.NetworkController;
33 import com.android.systemui.statusbar.connectivity.NetworkControllerImpl;
34 import com.android.systemui.statusbar.connectivity.WifiPickerTrackerFactory;
35 import com.android.systemui.statusbar.phone.ConfigurationControllerImpl;
36 import com.android.systemui.statusbar.policy.BatteryControllerLogger;
37 import com.android.systemui.statusbar.policy.BluetoothController;
38 import com.android.systemui.statusbar.policy.BluetoothControllerImpl;
39 import com.android.systemui.statusbar.policy.CastController;
40 import com.android.systemui.statusbar.policy.CastControllerImpl;
41 import com.android.systemui.statusbar.policy.ConfigurationController;
42 import com.android.systemui.statusbar.policy.DataSaverController;
43 import com.android.systemui.statusbar.policy.DeviceControlsController;
44 import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl;
45 import com.android.systemui.statusbar.policy.DevicePostureController;
46 import com.android.systemui.statusbar.policy.DevicePostureControllerImpl;
47 import com.android.systemui.statusbar.policy.ExtensionController;
48 import com.android.systemui.statusbar.policy.ExtensionControllerImpl;
49 import com.android.systemui.statusbar.policy.FlashlightController;
50 import com.android.systemui.statusbar.policy.FlashlightControllerImpl;
51 import com.android.systemui.statusbar.policy.HotspotController;
52 import com.android.systemui.statusbar.policy.HotspotControllerImpl;
53 import com.android.systemui.statusbar.policy.KeyguardStateController;
54 import com.android.systemui.statusbar.policy.KeyguardStateControllerImpl;
55 import com.android.systemui.statusbar.policy.LocationController;
56 import com.android.systemui.statusbar.policy.LocationControllerImpl;
57 import com.android.systemui.statusbar.policy.NextAlarmController;
58 import com.android.systemui.statusbar.policy.NextAlarmControllerImpl;
59 import com.android.systemui.statusbar.policy.RotationLockController;
60 import com.android.systemui.statusbar.policy.RotationLockControllerImpl;
61 import com.android.systemui.statusbar.policy.SecurityController;
62 import com.android.systemui.statusbar.policy.SecurityControllerImpl;
63 import com.android.systemui.statusbar.policy.SensitiveNotificationProtectionController;
64 import com.android.systemui.statusbar.policy.SensitiveNotificationProtectionControllerImpl;
65 import com.android.systemui.statusbar.policy.SplitShadeStateController;
66 import com.android.systemui.statusbar.policy.SplitShadeStateControllerImpl;
67 import com.android.systemui.statusbar.policy.UserInfoController;
68 import com.android.systemui.statusbar.policy.UserInfoControllerImpl;
69 import com.android.systemui.statusbar.policy.WalletController;
70 import com.android.systemui.statusbar.policy.WalletControllerImpl;
71 import com.android.systemui.statusbar.policy.ZenModeController;
72 import com.android.systemui.statusbar.policy.ZenModeControllerImpl;
73 import com.android.systemui.statusbar.policy.bluetooth.BluetoothRepository;
74 import com.android.systemui.statusbar.policy.bluetooth.BluetoothRepositoryImpl;
75 import com.android.systemui.statusbar.policy.data.repository.DeviceProvisioningRepositoryModule;
76 import com.android.systemui.statusbar.policy.data.repository.ZenModeRepositoryModule;
77 
78 import dagger.Binds;
79 import dagger.Module;
80 import dagger.Provides;
81 
82 import java.util.concurrent.Executor;
83 
84 import javax.inject.Named;
85 
86 /** Dagger Module for code in the statusbar.policy package. */
87 @Module(includes = { DeviceProvisioningRepositoryModule.class, ZenModeRepositoryModule.class })
88 public interface StatusBarPolicyModule {
89 
90     String DEVICE_STATE_ROTATION_LOCK_DEFAULTS = "DEVICE_STATE_ROTATION_LOCK_DEFAULTS";
91 
92     /** */
93     @Binds
provideBluetoothController(BluetoothControllerImpl controllerImpl)94     BluetoothController provideBluetoothController(BluetoothControllerImpl controllerImpl);
95 
96     /** */
97     @Binds
provideBluetoothRepository(BluetoothRepositoryImpl impl)98     BluetoothRepository provideBluetoothRepository(BluetoothRepositoryImpl impl);
99 
100     /** */
101     @Binds
provideCastController(CastControllerImpl controllerImpl)102     CastController provideCastController(CastControllerImpl controllerImpl);
103 
104     /** */
105     @Binds
bindConfigurationController(ConfigurationControllerImpl impl)106     ConfigurationController bindConfigurationController(ConfigurationControllerImpl impl);
107 
108     /** */
109     @Binds
provideExtensionController(ExtensionControllerImpl controllerImpl)110     ExtensionController provideExtensionController(ExtensionControllerImpl controllerImpl);
111 
112     /** */
113     @Binds
provideFlashlightController(FlashlightControllerImpl controllerImpl)114     FlashlightController provideFlashlightController(FlashlightControllerImpl controllerImpl);
115 
116     /** */
117     @Binds
provideKeyguardMonitor(KeyguardStateControllerImpl controllerImpl)118     KeyguardStateController provideKeyguardMonitor(KeyguardStateControllerImpl controllerImpl);
119 
120     /** */
121     @Binds
provideSplitShadeStateController( SplitShadeStateControllerImpl splitShadeStateControllerImpl)122     SplitShadeStateController provideSplitShadeStateController(
123             SplitShadeStateControllerImpl splitShadeStateControllerImpl);
124 
125     /** */
126     @Binds
provideHotspotController(HotspotControllerImpl controllerImpl)127     HotspotController provideHotspotController(HotspotControllerImpl controllerImpl);
128 
129     /** */
130     @Binds
provideLocationController(LocationControllerImpl controllerImpl)131     LocationController provideLocationController(LocationControllerImpl controllerImpl);
132 
133     /** */
134     @Binds
provideNetworkController(NetworkControllerImpl controllerImpl)135     NetworkController provideNetworkController(NetworkControllerImpl controllerImpl);
136 
137     /** */
138     @Binds
provideNextAlarmController(NextAlarmControllerImpl controllerImpl)139     NextAlarmController provideNextAlarmController(NextAlarmControllerImpl controllerImpl);
140 
141     /** */
142     @Binds
provideRotationLockController(RotationLockControllerImpl controllerImpl)143     RotationLockController provideRotationLockController(RotationLockControllerImpl controllerImpl);
144 
145     /** */
146     @Binds
provideSecurityController(SecurityControllerImpl controllerImpl)147     SecurityController provideSecurityController(SecurityControllerImpl controllerImpl);
148 
149     /** */
150     @Binds
provideSensitiveNotificationProtectionController( SensitiveNotificationProtectionControllerImpl controllerImpl)151     SensitiveNotificationProtectionController provideSensitiveNotificationProtectionController(
152             SensitiveNotificationProtectionControllerImpl controllerImpl);
153 
154     /** */
155     @Binds
provideUserInfoContrller(UserInfoControllerImpl controllerImpl)156     UserInfoController provideUserInfoContrller(UserInfoControllerImpl controllerImpl);
157 
158     /** */
159     @Binds
provideZenModeController(ZenModeControllerImpl controllerImpl)160     ZenModeController provideZenModeController(ZenModeControllerImpl controllerImpl);
161 
162     /** */
163     @Binds
provideDeviceControlsController( DeviceControlsControllerImpl controllerImpl)164     DeviceControlsController provideDeviceControlsController(
165             DeviceControlsControllerImpl controllerImpl);
166 
167     /** */
168     @Binds
provideWalletController(WalletControllerImpl controllerImpl)169     WalletController provideWalletController(WalletControllerImpl controllerImpl);
170 
171     /** */
172     @Binds
provideAccessPointController( AccessPointControllerImpl accessPointControllerImpl)173     AccessPointController provideAccessPointController(
174             AccessPointControllerImpl accessPointControllerImpl);
175 
176     /** */
177     @Binds
provideDevicePostureController( DevicePostureControllerImpl devicePostureControllerImpl)178     DevicePostureController provideDevicePostureController(
179             DevicePostureControllerImpl devicePostureControllerImpl);
180 
181     /** */
182     @SysUISingleton
183     @Provides
provideAccessPointControllerImpl( UserManager userManager, UserTracker userTracker, @Main Executor mainExecutor, WifiPickerTrackerFactory wifiPickerTrackerFactory )184     static AccessPointControllerImpl  provideAccessPointControllerImpl(
185             UserManager userManager,
186             UserTracker userTracker,
187             @Main Executor mainExecutor,
188             WifiPickerTrackerFactory wifiPickerTrackerFactory
189     ) {
190         AccessPointControllerImpl controller = new AccessPointControllerImpl(
191                 userManager,
192                 userTracker,
193                 mainExecutor,
194                 wifiPickerTrackerFactory
195         );
196         controller.init();
197         return controller;
198     }
199 
200     /** Returns a singleton instance of DeviceStateRotationLockSettingsManager */
201     @SysUISingleton
202     @Provides
provideAutoRotateSettingsManager( Context context)203     static DeviceStateRotationLockSettingsManager provideAutoRotateSettingsManager(
204             Context context) {
205         return DeviceStateRotationLockSettingsManager.getInstance(context);
206     }
207 
208     /**
209      * Default values for per-device state rotation lock settings.
210      */
211     @Provides
212     @Named(DEVICE_STATE_ROTATION_LOCK_DEFAULTS)
providesDeviceStateRotationLockDefaults(@ain Resources resources)213     static String[] providesDeviceStateRotationLockDefaults(@Main Resources resources) {
214         return resources.getStringArray(
215                 R.array.config_perDeviceStateRotationLockDefaults);
216     }
217 
218     /** */
219     @Provides
220     @SysUISingleton
provideDataSaverController(NetworkController networkController)221     static DataSaverController provideDataSaverController(NetworkController networkController) {
222         return networkController.getDataSaverController();
223     }
224 
225     /** Provides a log buffer for BatteryControllerImpl */
226     @Provides
227     @SysUISingleton
228     @BatteryControllerLog
provideBatteryControllerLog(LogBufferFactory factory)229     static LogBuffer provideBatteryControllerLog(LogBufferFactory factory) {
230         return factory.create(BatteryControllerLogger.TAG, 30);
231     }
232 }
233