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