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; |
| 25 | import android.content.Context; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 26 | import android.hardware.SensorPrivacyManager; |
Christine Franks | 71e003e | 2019-01-24 14:40:20 -0800 | [diff] [blame] | 27 | import android.hardware.display.NightDisplayListener; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 28 | import android.os.Handler; |
| 29 | import android.os.HandlerThread; |
| 30 | import android.os.Looper; |
| 31 | import android.os.Process; |
| 32 | import android.os.ServiceManager; |
| 33 | import android.os.UserHandle; |
| 34 | import android.util.DisplayMetrics; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 35 | import android.view.IWindowManager; |
| 36 | import android.view.WindowManagerGlobal; |
| 37 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 38 | import com.android.internal.logging.MetricsLogger; |
| 39 | import com.android.internal.statusbar.IStatusBarService; |
| 40 | import com.android.settingslib.bluetooth.LocalBluetoothManager; |
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; |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 44 | import com.android.systemui.statusbar.NavigationBarController; |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 45 | import com.android.systemui.statusbar.phone.AutoHideController; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 46 | import com.android.systemui.statusbar.phone.ConfigurationControllerImpl; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 47 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 48 | import com.android.systemui.statusbar.policy.DataSaverController; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.NetworkController; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 50 | import com.android.systemui.util.leak.LeakDetector; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 51 | |
| 52 | import javax.inject.Named; |
| 53 | import javax.inject.Singleton; |
| 54 | |
| 55 | import dagger.Module; |
| 56 | import dagger.Provides; |
| 57 | |
| 58 | /** |
| 59 | * Provides dependencies for the root component of sysui injection. |
| 60 | * See SystemUI/docs/dagger.md |
| 61 | */ |
| 62 | @Module |
| 63 | public class DependencyProvider { |
| 64 | |
| 65 | @Singleton |
| 66 | @Provides |
| 67 | @Named(TIME_TICK_HANDLER_NAME) |
| 68 | public Handler provideHandler() { |
| 69 | HandlerThread thread = new HandlerThread("TimeTick"); |
| 70 | thread.start(); |
| 71 | return new Handler(thread.getLooper()); |
| 72 | } |
| 73 | |
| 74 | @Singleton |
| 75 | @Provides |
| 76 | @Named(BG_LOOPER_NAME) |
| 77 | public Looper provideBgLooper() { |
| 78 | HandlerThread thread = new HandlerThread("SysUiBg", |
| 79 | Process.THREAD_PRIORITY_BACKGROUND); |
| 80 | thread.start(); |
| 81 | return thread.getLooper(); |
| 82 | } |
| 83 | |
| 84 | @Singleton |
| 85 | @Provides |
| 86 | @Named(BG_HANDLER_NAME) |
| 87 | public Handler provideBgHandler(@Named(BG_LOOPER_NAME) Looper bgLooper) { |
| 88 | return new Handler(bgLooper); |
| 89 | } |
| 90 | |
| 91 | @Singleton |
| 92 | @Provides |
| 93 | @Named(MAIN_HANDLER_NAME) |
| 94 | public Handler provideMainHandler() { |
| 95 | return new Handler(Looper.getMainLooper()); |
| 96 | } |
| 97 | |
| 98 | @Singleton |
| 99 | @Provides |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 100 | public DataSaverController provideDataSaverController(NetworkController networkController) { |
| 101 | return networkController.getDataSaverController(); |
| 102 | } |
| 103 | |
| 104 | @Singleton |
| 105 | @Provides |
Brad Stenning | 32cedc1 | 2018-12-20 11:25:06 -0800 | [diff] [blame] | 106 | @Nullable |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 107 | public LocalBluetoothManager provideLocalBluetoothController(Context context, |
| 108 | @Named(BG_HANDLER_NAME) Handler bgHandler) { |
| 109 | return LocalBluetoothManager.create(context, bgHandler, |
| 110 | UserHandle.ALL); |
| 111 | } |
| 112 | |
| 113 | @Singleton |
| 114 | @Provides |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 115 | public MetricsLogger provideMetricsLogger() { |
| 116 | return new MetricsLogger(); |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | @Singleton |
| 120 | @Provides |
| 121 | public IWindowManager provideIWindowManager() { |
| 122 | return WindowManagerGlobal.getWindowManagerService(); |
| 123 | } |
| 124 | |
| 125 | @Singleton |
| 126 | @Provides |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 127 | public IStatusBarService provideIStatusBarService() { |
| 128 | return IStatusBarService.Stub.asInterface( |
| 129 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| 130 | } |
| 131 | |
| 132 | @Singleton |
| 133 | @Provides |
| 134 | // Single instance of DisplayMetrics, gets updated by StatusBar, but can be used |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 135 | // anywhere it is needed. |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 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 SensorPrivacyManager provideSensorPrivacyManager(Context context) { |
| 143 | return context.getSystemService(SensorPrivacyManager.class); |
| 144 | } |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 145 | |
| 146 | @Singleton |
| 147 | @Provides |
| 148 | public LeakDetector provideLeakDetector() { |
| 149 | return LeakDetector.create(); |
| 150 | |
| 151 | } |
| 152 | |
| 153 | @Singleton |
| 154 | @Provides |
Christine Franks | 71e003e | 2019-01-24 14:40:20 -0800 | [diff] [blame] | 155 | public NightDisplayListener provideNightDisplayListener(Context context) { |
| 156 | return new NightDisplayListener(context); |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | @Singleton |
| 160 | @Provides |
| 161 | public PluginManager providePluginManager(Context context) { |
| 162 | return new PluginManagerImpl(context, new PluginInitializerImpl()); |
| 163 | } |
| 164 | |
| 165 | @Singleton |
| 166 | @Provides |
Charles Chen | 10ca70b | 2018-11-28 00:03:38 +0800 | [diff] [blame] | 167 | public NavigationBarController provideNavigationBarController(Context context, |
| 168 | @Named(MAIN_HANDLER_NAME) Handler mainHandler) { |
| 169 | return new NavigationBarController(context, mainHandler); |
| 170 | } |
| 171 | |
| 172 | @Singleton |
| 173 | @Provides |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 174 | public ConfigurationController provideConfigurationController(Context context) { |
| 175 | return new ConfigurationControllerImpl(context); |
| 176 | } |
Charles Chen | 8c9a83f | 2018-12-18 17:44:10 +0800 | [diff] [blame] | 177 | |
| 178 | @Singleton |
| 179 | @Provides |
| 180 | public AutoHideController provideAutoHideController(Context context, |
| 181 | @Named(MAIN_HANDLER_NAME) Handler mainHandler) { |
| 182 | return new AutoHideController(context, mainHandler); |
| 183 | } |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 184 | } |