Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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; |
| 18 | |
| 19 | import static com.android.systemui.Dependency.BG_HANDLER_NAME; |
| 20 | import static com.android.systemui.Dependency.BG_LOOPER_NAME; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 21 | import static com.android.systemui.Dependency.MAIN_HANDLER_NAME; |
| 22 | import static com.android.systemui.Dependency.TIME_TICK_HANDLER_NAME; |
| 23 | |
| 24 | import android.annotation.Nullable; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 25 | import android.app.INotificationManager; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 26 | import android.content.Context; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 27 | import android.hardware.SensorPrivacyManager; |
Christine Franks | 71e003e | 2019-01-24 14:40:20 -0800 | [diff] [blame] | 28 | import android.hardware.display.NightDisplayListener; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 29 | import android.os.Handler; |
| 30 | import android.os.HandlerThread; |
| 31 | import android.os.Looper; |
| 32 | import android.os.Process; |
| 33 | import android.os.ServiceManager; |
| 34 | import android.os.UserHandle; |
| 35 | import android.util.DisplayMetrics; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 36 | import android.view.IWindowManager; |
| 37 | import android.view.WindowManagerGlobal; |
| 38 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 39 | import com.android.internal.logging.MetricsLogger; |
| 40 | import com.android.internal.statusbar.IStatusBarService; |
| 41 | import com.android.settingslib.bluetooth.LocalBluetoothManager; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 42 | import com.android.systemui.plugins.PluginInitializerImpl; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 43 | import com.android.systemui.shared.plugins.PluginManager; |
| 44 | import com.android.systemui.shared.plugins.PluginManagerImpl; |
Gustav Sennton | 5a4fc21 | 2019-02-28 16:12:27 +0000 | [diff] [blame] | 45 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
| 46 | import com.android.systemui.shared.system.DevicePolicyManagerWrapper; |
| 47 | import com.android.systemui.shared.system.PackageManagerWrapper; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 48 | import com.android.systemui.statusbar.NavigationBarController; |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 49 | import com.android.systemui.statusbar.phone.AutoHideController; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 50 | import com.android.systemui.statusbar.phone.ConfigurationControllerImpl; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 51 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 52 | import com.android.systemui.statusbar.policy.DataSaverController; |
yoshiki iguchi | ac2ffdd | 2019-03-20 19:17:35 +0900 | [diff] [blame^] | 53 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 54 | import com.android.systemui.statusbar.policy.DeviceProvisionedControllerImpl; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 55 | import com.android.systemui.statusbar.policy.NetworkController; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 56 | import com.android.systemui.util.leak.LeakDetector; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 57 | |
| 58 | import javax.inject.Named; |
| 59 | import javax.inject.Singleton; |
| 60 | |
| 61 | import dagger.Module; |
| 62 | import dagger.Provides; |
| 63 | |
| 64 | /** |
| 65 | * Provides dependencies for the root component of sysui injection. |
| 66 | * See SystemUI/docs/dagger.md |
| 67 | */ |
| 68 | @Module |
| 69 | public class DependencyProvider { |
| 70 | |
| 71 | @Singleton |
| 72 | @Provides |
| 73 | @Named(TIME_TICK_HANDLER_NAME) |
| 74 | public Handler provideHandler() { |
| 75 | HandlerThread thread = new HandlerThread("TimeTick"); |
| 76 | thread.start(); |
| 77 | return new Handler(thread.getLooper()); |
| 78 | } |
| 79 | |
| 80 | @Singleton |
| 81 | @Provides |
| 82 | @Named(BG_LOOPER_NAME) |
| 83 | public Looper provideBgLooper() { |
| 84 | HandlerThread thread = new HandlerThread("SysUiBg", |
| 85 | Process.THREAD_PRIORITY_BACKGROUND); |
| 86 | thread.start(); |
| 87 | return thread.getLooper(); |
| 88 | } |
| 89 | |
| 90 | @Singleton |
| 91 | @Provides |
| 92 | @Named(BG_HANDLER_NAME) |
| 93 | public Handler provideBgHandler(@Named(BG_LOOPER_NAME) Looper bgLooper) { |
| 94 | return new Handler(bgLooper); |
| 95 | } |
| 96 | |
| 97 | @Singleton |
| 98 | @Provides |
| 99 | @Named(MAIN_HANDLER_NAME) |
| 100 | public Handler provideMainHandler() { |
| 101 | return new Handler(Looper.getMainLooper()); |
| 102 | } |
| 103 | |
| 104 | @Singleton |
| 105 | @Provides |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 106 | public DataSaverController provideDataSaverController(NetworkController networkController) { |
| 107 | return networkController.getDataSaverController(); |
| 108 | } |
| 109 | |
| 110 | @Singleton |
| 111 | @Provides |
Brad Stenning | 32cedc1 | 2018-12-20 11:25:06 -0800 | [diff] [blame] | 112 | @Nullable |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 113 | public LocalBluetoothManager provideLocalBluetoothController(Context context, |
| 114 | @Named(BG_HANDLER_NAME) Handler bgHandler) { |
| 115 | return LocalBluetoothManager.create(context, bgHandler, |
| 116 | UserHandle.ALL); |
| 117 | } |
| 118 | |
| 119 | @Singleton |
| 120 | @Provides |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 121 | public MetricsLogger provideMetricsLogger() { |
| 122 | return new MetricsLogger(); |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Singleton |
| 126 | @Provides |
| 127 | public IWindowManager provideIWindowManager() { |
| 128 | return WindowManagerGlobal.getWindowManagerService(); |
| 129 | } |
| 130 | |
| 131 | @Singleton |
| 132 | @Provides |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 133 | public IStatusBarService provideIStatusBarService() { |
| 134 | return IStatusBarService.Stub.asInterface( |
| 135 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| 136 | } |
| 137 | |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 138 | /** */ |
| 139 | @Singleton |
| 140 | @Provides |
| 141 | public INotificationManager provideINotificationManager() { |
| 142 | return INotificationManager.Stub.asInterface( |
| 143 | ServiceManager.getService(Context.NOTIFICATION_SERVICE)); |
| 144 | } |
| 145 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 146 | @Singleton |
| 147 | @Provides |
| 148 | // Single instance of DisplayMetrics, gets updated by StatusBar, but can be used |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 149 | // anywhere it is needed. |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 150 | public DisplayMetrics provideDisplayMetrics() { |
| 151 | return new DisplayMetrics(); |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | @Singleton |
| 155 | @Provides |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 156 | public SensorPrivacyManager provideSensorPrivacyManager(Context context) { |
| 157 | return context.getSystemService(SensorPrivacyManager.class); |
| 158 | } |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 159 | |
| 160 | @Singleton |
| 161 | @Provides |
| 162 | public LeakDetector provideLeakDetector() { |
| 163 | return LeakDetector.create(); |
| 164 | |
| 165 | } |
| 166 | |
| 167 | @Singleton |
| 168 | @Provides |
Christine Franks | e17d742 | 2019-02-11 10:42:07 -0800 | [diff] [blame] | 169 | public NightDisplayListener provideNightDisplayListener(Context context, |
| 170 | @Named(BG_HANDLER_NAME) Handler bgHandler) { |
| 171 | return new NightDisplayListener(context, bgHandler); |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | @Singleton |
| 175 | @Provides |
| 176 | public PluginManager providePluginManager(Context context) { |
| 177 | return new PluginManagerImpl(context, new PluginInitializerImpl()); |
| 178 | } |
| 179 | |
| 180 | @Singleton |
| 181 | @Provides |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 182 | public NavigationBarController provideNavigationBarController(Context context, |
| 183 | @Named(MAIN_HANDLER_NAME) Handler mainHandler) { |
| 184 | return new NavigationBarController(context, mainHandler); |
| 185 | } |
| 186 | |
| 187 | @Singleton |
| 188 | @Provides |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 189 | public ConfigurationController provideConfigurationController(Context context) { |
| 190 | return new ConfigurationControllerImpl(context); |
| 191 | } |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 192 | |
| 193 | @Singleton |
| 194 | @Provides |
| 195 | public AutoHideController provideAutoHideController(Context context, |
| 196 | @Named(MAIN_HANDLER_NAME) Handler mainHandler) { |
| 197 | return new AutoHideController(context, mainHandler); |
| 198 | } |
Gustav Sennton | 5a4fc21 | 2019-02-28 16:12:27 +0000 | [diff] [blame] | 199 | |
| 200 | @Singleton |
| 201 | @Provides |
| 202 | public ActivityManagerWrapper provideActivityManagerWrapper() { |
| 203 | return ActivityManagerWrapper.getInstance(); |
| 204 | } |
| 205 | |
| 206 | @Singleton |
| 207 | @Provides |
| 208 | public DevicePolicyManagerWrapper provideDevicePolicyManagerWrapper() { |
| 209 | return DevicePolicyManagerWrapper.getInstance(); |
| 210 | } |
| 211 | |
| 212 | @Singleton |
| 213 | @Provides |
| 214 | public PackageManagerWrapper providePackageManagerWrapper() { |
| 215 | return PackageManagerWrapper.getInstance(); |
| 216 | } |
yoshiki iguchi | ac2ffdd | 2019-03-20 19:17:35 +0900 | [diff] [blame^] | 217 | |
| 218 | @Singleton |
| 219 | @Provides |
| 220 | public DeviceProvisionedController provideDeviceProvisionedController(Context context, |
| 221 | @Named(MAIN_HANDLER_NAME) Handler mainHandler) { |
| 222 | return new DeviceProvisionedControllerImpl(context, mainHandler); |
| 223 | } |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 224 | } |