Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui; |
| 16 | |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 17 | import android.content.Context; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 18 | import android.content.res.Configuration; |
Adrian Roos | 7a8ae8a | 2017-08-02 16:26:50 +0200 | [diff] [blame] | 19 | import android.hardware.SensorManager; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 20 | import android.os.Handler; |
| 21 | import android.os.HandlerThread; |
| 22 | import android.os.Looper; |
| 23 | import android.os.Process; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 24 | import android.os.ServiceManager; |
jovanak | 206d6e4 | 2018-10-17 10:08:20 -0700 | [diff] [blame] | 25 | import android.os.UserHandle; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 26 | import android.util.ArrayMap; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 27 | import android.util.DisplayMetrics; |
Jason Monk | 2044e6e | 2017-10-13 10:34:40 -0400 | [diff] [blame] | 28 | import android.view.IWindowManager; |
| 29 | import android.view.WindowManagerGlobal; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 30 | |
| 31 | import com.android.internal.annotations.VisibleForTesting; |
Christine Franks | 5397f03 | 2017-11-01 18:35:16 -0700 | [diff] [blame] | 32 | import com.android.internal.app.ColorDisplayController; |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 33 | import com.android.internal.logging.MetricsLogger; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 34 | import com.android.internal.statusbar.IStatusBarService; |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 35 | import com.android.internal.util.Preconditions; |
Jason Monk | 6a73e63 | 2017-03-17 11:08:30 -0400 | [diff] [blame] | 36 | import com.android.settingslib.bluetooth.LocalBluetoothManager; |
Fabian Kozynski | 1f32cf0 | 2018-10-23 12:23:31 -0400 | [diff] [blame] | 37 | import com.android.systemui.appops.AppOpsController; |
| 38 | import com.android.systemui.appops.AppOpsControllerImpl; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 39 | import com.android.systemui.assist.AssistManager; |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 40 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Jason Monk | 790442e | 2017-02-13 17:49:39 -0500 | [diff] [blame] | 41 | import com.android.systemui.fragments.FragmentService; |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 42 | import com.android.systemui.keyguard.ScreenLifecycle; |
| 43 | import com.android.systemui.keyguard.WakefulnessLifecycle; |
Jason Monk | ec34da8 | 2017-02-24 15:57:05 -0500 | [diff] [blame] | 44 | import com.android.systemui.plugins.ActivityStarter; |
| 45 | import com.android.systemui.plugins.PluginDependencyProvider; |
Fabian Kozynski | 1f32cf0 | 2018-10-23 12:23:31 -0400 | [diff] [blame] | 46 | import com.android.systemui.plugins.PluginInitializerImpl; |
Jason Monk | 782cd67 | 2017-03-22 12:50:57 -0400 | [diff] [blame] | 47 | import com.android.systemui.plugins.VolumeDialogController; |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 48 | import com.android.systemui.power.EnhancedEstimates; |
| 49 | import com.android.systemui.power.EnhancedEstimatesImpl; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 50 | import com.android.systemui.power.PowerNotificationWarnings; |
| 51 | import com.android.systemui.power.PowerUI; |
Charles Chen | 61325fb | 2018-11-07 20:04:17 +0800 | [diff] [blame^] | 52 | import com.android.systemui.recents.OverviewProxyService; |
| 53 | import com.android.systemui.shared.plugins.PluginManager; |
| 54 | import com.android.systemui.shared.plugins.PluginManagerImpl; |
| 55 | import com.android.systemui.statusbar.DisplayNavigationBarController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 56 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
Matthew Ng | e2b4d79 | 2018-03-09 13:42:18 -0800 | [diff] [blame] | 57 | import com.android.systemui.statusbar.VibratorHelper; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 58 | import com.android.systemui.statusbar.notification.NotificationData.KeyguardEnvironment; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 59 | import com.android.systemui.statusbar.phone.ConfigurationControllerImpl; |
| 60 | import com.android.systemui.statusbar.phone.DarkIconDispatcherImpl; |
Fabian Kozynski | 1f32cf0 | 2018-10-23 12:23:31 -0400 | [diff] [blame] | 61 | import com.android.systemui.statusbar.phone.KeyguardEnvironmentImpl; |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 62 | import com.android.systemui.statusbar.phone.LightBarController; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 63 | import com.android.systemui.statusbar.phone.LockscreenGestureLogger; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 64 | import com.android.systemui.statusbar.phone.ManagedProfileController; |
| 65 | import com.android.systemui.statusbar.phone.ManagedProfileControllerImpl; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 66 | import com.android.systemui.statusbar.phone.ShadeController; |
| 67 | import com.android.systemui.statusbar.phone.StatusBar; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 68 | import com.android.systemui.statusbar.phone.StatusBarIconController; |
| 69 | import com.android.systemui.statusbar.phone.StatusBarIconControllerImpl; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 70 | import com.android.systemui.statusbar.phone.StatusBarRemoteInputCallback; |
Lucas Dupin | 1a8588d | 2018-08-21 12:18:47 -0700 | [diff] [blame] | 71 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 72 | import com.android.systemui.statusbar.policy.AccessibilityController; |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 73 | import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 74 | import com.android.systemui.statusbar.policy.BatteryController; |
| 75 | import com.android.systemui.statusbar.policy.BatteryControllerImpl; |
| 76 | import com.android.systemui.statusbar.policy.BluetoothController; |
| 77 | import com.android.systemui.statusbar.policy.BluetoothControllerImpl; |
| 78 | import com.android.systemui.statusbar.policy.CastController; |
| 79 | import com.android.systemui.statusbar.policy.CastControllerImpl; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 80 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 81 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 82 | import com.android.systemui.statusbar.policy.DataSaverController; |
| 83 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 84 | import com.android.systemui.statusbar.policy.DeviceProvisionedControllerImpl; |
Jason Monk | 1d9632d | 2017-02-09 13:20:04 -0800 | [diff] [blame] | 85 | import com.android.systemui.statusbar.policy.ExtensionController; |
| 86 | import com.android.systemui.statusbar.policy.ExtensionControllerImpl; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 87 | import com.android.systemui.statusbar.policy.FlashlightController; |
| 88 | import com.android.systemui.statusbar.policy.FlashlightControllerImpl; |
| 89 | import com.android.systemui.statusbar.policy.HotspotController; |
| 90 | import com.android.systemui.statusbar.policy.HotspotControllerImpl; |
Jason Monk | f8c2f7b | 2017-09-06 09:22:29 -0400 | [diff] [blame] | 91 | import com.android.systemui.statusbar.policy.IconLogger; |
| 92 | import com.android.systemui.statusbar.policy.IconLoggerImpl; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 93 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
| 94 | import com.android.systemui.statusbar.policy.KeyguardMonitorImpl; |
| 95 | import com.android.systemui.statusbar.policy.LocationController; |
| 96 | import com.android.systemui.statusbar.policy.LocationControllerImpl; |
| 97 | import com.android.systemui.statusbar.policy.NetworkController; |
| 98 | import com.android.systemui.statusbar.policy.NetworkControllerImpl; |
| 99 | import com.android.systemui.statusbar.policy.NextAlarmController; |
| 100 | import com.android.systemui.statusbar.policy.NextAlarmControllerImpl; |
| 101 | import com.android.systemui.statusbar.policy.RotationLockController; |
| 102 | import com.android.systemui.statusbar.policy.RotationLockControllerImpl; |
| 103 | import com.android.systemui.statusbar.policy.SecurityController; |
| 104 | import com.android.systemui.statusbar.policy.SecurityControllerImpl; |
| 105 | import com.android.systemui.statusbar.policy.UserInfoController; |
| 106 | import com.android.systemui.statusbar.policy.UserInfoControllerImpl; |
| 107 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
| 108 | import com.android.systemui.statusbar.policy.ZenModeController; |
| 109 | import com.android.systemui.statusbar.policy.ZenModeControllerImpl; |
Jason Monk | d4afe15 | 2017-05-01 15:37:43 -0400 | [diff] [blame] | 110 | import com.android.systemui.tuner.TunablePadding.TunablePaddingService; |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 111 | import com.android.systemui.tuner.TunerService; |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 112 | import com.android.systemui.tuner.TunerServiceImpl; |
Adrian Roos | 7a8ae8a | 2017-08-02 16:26:50 +0200 | [diff] [blame] | 113 | import com.android.systemui.util.AsyncSensorManager; |
Adrian Roos | 9125068 | 2017-02-06 14:48:15 -0800 | [diff] [blame] | 114 | import com.android.systemui.util.leak.GarbageMonitor; |
Adrian Roos | e1e0b48 | 2017-02-02 16:00:59 -0800 | [diff] [blame] | 115 | import com.android.systemui.util.leak.LeakDetector; |
Adrian Roos | 9125068 | 2017-02-06 14:48:15 -0800 | [diff] [blame] | 116 | import com.android.systemui.util.leak.LeakReporter; |
Jason Monk | 782cd67 | 2017-03-22 12:50:57 -0400 | [diff] [blame] | 117 | import com.android.systemui.volume.VolumeDialogControllerImpl; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 118 | |
| 119 | import java.io.FileDescriptor; |
| 120 | import java.io.PrintWriter; |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 121 | import java.util.HashMap; |
Jason Monk | 790442e | 2017-02-13 17:49:39 -0500 | [diff] [blame] | 122 | import java.util.function.Consumer; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * Class to handle ugly dependencies throughout sysui until we determine the |
| 126 | * long-term dependency injection solution. |
| 127 | * |
| 128 | * Classes added here should be things that are expected to live the lifetime of sysui, |
| 129 | * and are generally applicable to many parts of sysui. They will be lazily |
| 130 | * initialized to ensure they aren't created on form factors that don't need them |
| 131 | * (e.g. HotspotController on TV). Despite being lazily initialized, it is expected |
| 132 | * that all dependencies will be gotten during sysui startup, and not during runtime |
| 133 | * to avoid jank. |
| 134 | * |
| 135 | * All classes used here are expected to manage their own lifecycle, meaning if |
| 136 | * they have no clients they should not have any registered resources like bound |
| 137 | * services, registered receivers, etc. |
| 138 | */ |
| 139 | public class Dependency extends SystemUI { |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 140 | private static final String TAG = "Dependency"; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * Key for getting a background Looper for background work. |
| 144 | */ |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 145 | public static final DependencyKey<Looper> BG_LOOPER = new DependencyKey<>("background_looper"); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 146 | /** |
Amin Shaikh | 947f76d | 2018-08-27 15:55:57 -0400 | [diff] [blame] | 147 | * Key for getting a background Handler for background work. |
| 148 | */ |
| 149 | public static final DependencyKey<Handler> BG_HANDLER = new DependencyKey<>("background_handler"); |
| 150 | /** |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 151 | * Key for getting a Handler for receiving time tick broadcasts on. |
| 152 | */ |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 153 | public static final DependencyKey<Handler> TIME_TICK_HANDLER = |
| 154 | new DependencyKey<>("time_tick_handler"); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 155 | /** |
| 156 | * Generic handler on the main thread. |
| 157 | */ |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 158 | public static final DependencyKey<Handler> MAIN_HANDLER = new DependencyKey<>("main_handler"); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 159 | |
Adrian Roos | 9125068 | 2017-02-06 14:48:15 -0800 | [diff] [blame] | 160 | /** |
| 161 | * An email address to send memory leak reports to by default. |
| 162 | */ |
| 163 | public static final DependencyKey<String> LEAK_REPORT_EMAIL |
| 164 | = new DependencyKey<>("leak_report_email"); |
| 165 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 166 | private final ArrayMap<Object, Object> mDependencies = new ArrayMap<>(); |
| 167 | private final ArrayMap<Object, DependencyProvider> mProviders = new ArrayMap<>(); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 168 | |
| 169 | @Override |
| 170 | public void start() { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 171 | // TODO: Think about ways to push these creation rules out of Dependency to cut down |
| 172 | // on imports. |
| 173 | mProviders.put(TIME_TICK_HANDLER, () -> { |
| 174 | HandlerThread thread = new HandlerThread("TimeTick"); |
| 175 | thread.start(); |
| 176 | return new Handler(thread.getLooper()); |
| 177 | }); |
| 178 | mProviders.put(BG_LOOPER, () -> { |
| 179 | HandlerThread thread = new HandlerThread("SysUiBg", |
| 180 | Process.THREAD_PRIORITY_BACKGROUND); |
| 181 | thread.start(); |
| 182 | return thread.getLooper(); |
| 183 | }); |
Amin Shaikh | 947f76d | 2018-08-27 15:55:57 -0400 | [diff] [blame] | 184 | mProviders.put(BG_HANDLER, () -> new Handler(getDependency(BG_LOOPER))); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 185 | mProviders.put(MAIN_HANDLER, () -> new Handler(Looper.getMainLooper())); |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 186 | mProviders.put(ActivityStarter.class, () -> new ActivityStarterDelegate()); |
| 187 | mProviders.put(ActivityStarterDelegate.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 188 | getDependency(ActivityStarter.class)); |
| 189 | |
Adrian Roos | 7a8ae8a | 2017-08-02 16:26:50 +0200 | [diff] [blame] | 190 | mProviders.put(AsyncSensorManager.class, () -> |
Kevin Chyn | ac56f74 | 2018-10-09 16:20:25 -0700 | [diff] [blame] | 191 | new AsyncSensorManager(mContext.getSystemService(SensorManager.class), |
| 192 | getDependency(PluginManager.class))); |
Adrian Roos | 7a8ae8a | 2017-08-02 16:26:50 +0200 | [diff] [blame] | 193 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 194 | mProviders.put(BluetoothController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 195 | new BluetoothControllerImpl(mContext, getDependency(BG_LOOPER))); |
| 196 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 197 | mProviders.put(LocationController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 198 | new LocationControllerImpl(mContext, getDependency(BG_LOOPER))); |
| 199 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 200 | mProviders.put(RotationLockController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 201 | new RotationLockControllerImpl(mContext)); |
| 202 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 203 | mProviders.put(NetworkController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 204 | new NetworkControllerImpl(mContext, getDependency(BG_LOOPER), |
| 205 | getDependency(DeviceProvisionedController.class))); |
| 206 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 207 | mProviders.put(ZenModeController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 208 | new ZenModeControllerImpl(mContext, getDependency(MAIN_HANDLER))); |
| 209 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 210 | mProviders.put(HotspotController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 211 | new HotspotControllerImpl(mContext)); |
| 212 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 213 | mProviders.put(CastController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 214 | new CastControllerImpl(mContext)); |
| 215 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 216 | mProviders.put(FlashlightController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 217 | new FlashlightControllerImpl(mContext)); |
| 218 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 219 | mProviders.put(KeyguardMonitor.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 220 | new KeyguardMonitorImpl(mContext)); |
| 221 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 222 | mProviders.put(UserSwitcherController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 223 | new UserSwitcherController(mContext, getDependency(KeyguardMonitor.class), |
| 224 | getDependency(MAIN_HANDLER), getDependency(ActivityStarter.class))); |
| 225 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 226 | mProviders.put(UserInfoController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 227 | new UserInfoControllerImpl(mContext)); |
| 228 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 229 | mProviders.put(BatteryController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 230 | new BatteryControllerImpl(mContext)); |
| 231 | |
Christine Franks | 5397f03 | 2017-11-01 18:35:16 -0700 | [diff] [blame] | 232 | mProviders.put(ColorDisplayController.class, () -> |
| 233 | new ColorDisplayController(mContext)); |
Christine Franks | 69c2d1d | 2017-01-23 14:45:29 -0800 | [diff] [blame] | 234 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 235 | mProviders.put(ManagedProfileController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 236 | new ManagedProfileControllerImpl(mContext)); |
| 237 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 238 | mProviders.put(NextAlarmController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 239 | new NextAlarmControllerImpl(mContext)); |
| 240 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 241 | mProviders.put(DataSaverController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 242 | get(NetworkController.class).getDataSaverController()); |
| 243 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 244 | mProviders.put(AccessibilityController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 245 | new AccessibilityController(mContext)); |
| 246 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 247 | mProviders.put(DeviceProvisionedController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 248 | new DeviceProvisionedControllerImpl(mContext)); |
| 249 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 250 | mProviders.put(PluginManager.class, () -> |
Tony Wickham | 023cb19 | 2018-09-13 15:23:04 -0700 | [diff] [blame] | 251 | new PluginManagerImpl(mContext, new PluginInitializerImpl())); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 252 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 253 | mProviders.put(AssistManager.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 254 | new AssistManager(getDependency(DeviceProvisionedController.class), mContext)); |
| 255 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 256 | mProviders.put(SecurityController.class, () -> |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 257 | new SecurityControllerImpl(mContext)); |
| 258 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 259 | mProviders.put(LeakDetector.class, LeakDetector::create); |
Adrian Roos | e1e0b48 | 2017-02-02 16:00:59 -0800 | [diff] [blame] | 260 | |
Adrian Roos | 9125068 | 2017-02-06 14:48:15 -0800 | [diff] [blame] | 261 | mProviders.put(LEAK_REPORT_EMAIL, () -> null); |
| 262 | |
| 263 | mProviders.put(LeakReporter.class, () -> new LeakReporter( |
| 264 | mContext, |
| 265 | getDependency(LeakDetector.class), |
| 266 | getDependency(LEAK_REPORT_EMAIL))); |
| 267 | |
Dan Sandler | 4d90d1e | 2018-03-23 16:29:06 -0400 | [diff] [blame] | 268 | mProviders.put( |
| 269 | GarbageMonitor.class, |
| 270 | () -> |
| 271 | new GarbageMonitor( |
| 272 | mContext, |
| 273 | getDependency(BG_LOOPER), |
| 274 | getDependency(LeakDetector.class), |
| 275 | getDependency(LeakReporter.class))); |
Adrian Roos | 9125068 | 2017-02-06 14:48:15 -0800 | [diff] [blame] | 276 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 277 | mProviders.put(TunerService.class, () -> |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 278 | new TunerServiceImpl(mContext)); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 279 | |
Lucas Dupin | 1a8588d | 2018-08-21 12:18:47 -0700 | [diff] [blame] | 280 | mProviders.put(StatusBarWindowController.class, () -> |
| 281 | new StatusBarWindowController(mContext)); |
Jason Monk | 421a941 | 2017-02-06 09:15:21 -0800 | [diff] [blame] | 282 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 283 | mProviders.put(DarkIconDispatcher.class, () -> |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 284 | new DarkIconDispatcherImpl(mContext)); |
| 285 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 286 | mProviders.put(ConfigurationController.class, () -> |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 287 | new ConfigurationControllerImpl(mContext)); |
| 288 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 289 | mProviders.put(StatusBarIconController.class, () -> |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 290 | new StatusBarIconControllerImpl(mContext)); |
| 291 | |
Adrian Roos | 369907f | 2017-07-14 14:53:39 +0200 | [diff] [blame] | 292 | mProviders.put(ScreenLifecycle.class, () -> |
| 293 | new ScreenLifecycle()); |
| 294 | |
| 295 | mProviders.put(WakefulnessLifecycle.class, () -> |
| 296 | new WakefulnessLifecycle()); |
| 297 | |
Jason Monk | 790442e | 2017-02-13 17:49:39 -0500 | [diff] [blame] | 298 | mProviders.put(FragmentService.class, () -> |
| 299 | new FragmentService(mContext)); |
| 300 | |
Jason Monk | 1d9632d | 2017-02-09 13:20:04 -0800 | [diff] [blame] | 301 | mProviders.put(ExtensionController.class, () -> |
Jason Monk | 0b80c4e | 2017-05-01 15:38:34 -0400 | [diff] [blame] | 302 | new ExtensionControllerImpl(mContext)); |
Jason Monk | 1d9632d | 2017-02-09 13:20:04 -0800 | [diff] [blame] | 303 | |
Jason Monk | ec34da8 | 2017-02-24 15:57:05 -0500 | [diff] [blame] | 304 | mProviders.put(PluginDependencyProvider.class, () -> |
| 305 | new PluginDependencyProvider(get(PluginManager.class))); |
| 306 | |
Jason Monk | 6a73e63 | 2017-03-17 11:08:30 -0400 | [diff] [blame] | 307 | mProviders.put(LocalBluetoothManager.class, () -> |
jovanak | 206d6e4 | 2018-10-17 10:08:20 -0700 | [diff] [blame] | 308 | LocalBluetoothManager.create(mContext, getDependency(BG_HANDLER), |
| 309 | UserHandle.ALL)); |
Jason Monk | 6a73e63 | 2017-03-17 11:08:30 -0400 | [diff] [blame] | 310 | |
Jason Monk | 782cd67 | 2017-03-22 12:50:57 -0400 | [diff] [blame] | 311 | mProviders.put(VolumeDialogController.class, () -> |
| 312 | new VolumeDialogControllerImpl(mContext)); |
| 313 | |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 314 | mProviders.put(MetricsLogger.class, () -> new MetricsLogger()); |
| 315 | |
Jason Monk | 91e587e | 2017-04-13 13:41:23 -0400 | [diff] [blame] | 316 | mProviders.put(AccessibilityManagerWrapper.class, |
| 317 | () -> new AccessibilityManagerWrapper(mContext)); |
| 318 | |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 319 | // Creating a new instance will trigger color extraction. |
| 320 | // Thankfully this only happens once - during boot - and WallpaperManagerService |
| 321 | // loads colors from cache. |
Lucas Dupin | 1ead7fc | 2017-05-24 14:14:44 -0700 | [diff] [blame] | 322 | mProviders.put(SysuiColorExtractor.class, () -> new SysuiColorExtractor(mContext)); |
Lucas Dupin | 314d41f | 2017-05-08 15:52:58 -0700 | [diff] [blame] | 323 | |
Jason Monk | d4afe15 | 2017-05-01 15:37:43 -0400 | [diff] [blame] | 324 | mProviders.put(TunablePaddingService.class, () -> new TunablePaddingService()); |
| 325 | |
Dan Sandler | f5aafb9 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 326 | mProviders.put(ForegroundServiceController.class, |
| 327 | () -> new ForegroundServiceControllerImpl(mContext)); |
| 328 | |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 329 | mProviders.put(UiOffloadThread.class, UiOffloadThread::new); |
| 330 | |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 331 | mProviders.put(PowerUI.WarningsUI.class, () -> new PowerNotificationWarnings(mContext)); |
| 332 | |
Jason Monk | f8c2f7b | 2017-09-06 09:22:29 -0400 | [diff] [blame] | 333 | mProviders.put(IconLogger.class, () -> new IconLoggerImpl(mContext, |
| 334 | getDependency(BG_LOOPER), getDependency(MetricsLogger.class))); |
| 335 | |
Jason Monk | 73112d3 | 2017-09-06 16:53:53 -0400 | [diff] [blame] | 336 | mProviders.put(LightBarController.class, () -> new LightBarController(mContext)); |
| 337 | |
Jason Monk | 2044e6e | 2017-10-13 10:34:40 -0400 | [diff] [blame] | 338 | mProviders.put(IWindowManager.class, () -> WindowManagerGlobal.getWindowManagerService()); |
| 339 | |
Matthew Ng | 13dbf87 | 2017-10-27 11:02:14 -0700 | [diff] [blame] | 340 | mProviders.put(OverviewProxyService.class, () -> new OverviewProxyService(mContext)); |
| 341 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 342 | mProviders.put(EnhancedEstimates.class, () -> new EnhancedEstimatesImpl()); |
| 343 | |
Matthew Ng | e2b4d79 | 2018-03-09 13:42:18 -0800 | [diff] [blame] | 344 | mProviders.put(VibratorHelper.class, () -> new VibratorHelper(mContext)); |
| 345 | |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 346 | mProviders.put(IStatusBarService.class, () -> IStatusBarService.Stub.asInterface( |
| 347 | ServiceManager.getService(Context.STATUS_BAR_SERVICE))); |
| 348 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 349 | // Single instance of DisplayMetrics, gets updated by StatusBar, but can be used |
| 350 | // anywhere it is needed. |
| 351 | mProviders.put(DisplayMetrics.class, () -> new DisplayMetrics()); |
| 352 | |
| 353 | mProviders.put(LockscreenGestureLogger.class, () -> new LockscreenGestureLogger()); |
| 354 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 355 | mProviders.put(KeyguardEnvironment.class, () -> new KeyguardEnvironmentImpl()); |
| 356 | mProviders.put(ShadeController.class, () -> |
| 357 | SysUiServiceProvider.getComponent(mContext, StatusBar.class)); |
| 358 | mProviders.put(NotificationRemoteInputManager.Callback.class, |
| 359 | () -> new StatusBarRemoteInputCallback(mContext)); |
| 360 | |
| 361 | mProviders.put(InitController.class, InitController::new); |
| 362 | |
Fabian Kozynski | 1f32cf0 | 2018-10-23 12:23:31 -0400 | [diff] [blame] | 363 | mProviders.put(AppOpsController.class, () -> |
| 364 | new AppOpsControllerImpl(mContext, getDependency(BG_LOOPER))); |
| 365 | |
Charles Chen | 61325fb | 2018-11-07 20:04:17 +0800 | [diff] [blame^] | 366 | mProviders.put(DisplayNavigationBarController.class, () -> |
| 367 | new DisplayNavigationBarController(mContext, getDependency(MAIN_HANDLER))); |
| 368 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 369 | // Put all dependencies above here so the factory can override them if it wants. |
| 370 | SystemUIFactory.getInstance().injectDependencies(mProviders, mContext); |
Alison Cichowlas | fa7614d | 2018-05-09 19:35:11 -0400 | [diff] [blame] | 371 | |
| 372 | sDependency = this; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | @Override |
Jason Monk | e107202 | 2017-04-06 15:14:18 -0400 | [diff] [blame] | 376 | public synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 377 | super.dump(fd, pw, args); |
| 378 | pw.println("Dumping existing controllers:"); |
| 379 | mDependencies.values().stream().filter(obj -> obj instanceof Dumpable) |
| 380 | .forEach(o -> ((Dumpable) o).dump(fd, pw, args)); |
| 381 | } |
| 382 | |
| 383 | @Override |
Jason Monk | e107202 | 2017-04-06 15:14:18 -0400 | [diff] [blame] | 384 | protected synchronized void onConfigurationChanged(Configuration newConfig) { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 385 | super.onConfigurationChanged(newConfig); |
| 386 | mDependencies.values().stream().filter(obj -> obj instanceof ConfigurationChangedReceiver) |
| 387 | .forEach(o -> ((ConfigurationChangedReceiver) o).onConfigurationChanged(newConfig)); |
| 388 | } |
| 389 | |
| 390 | protected final <T> T getDependency(Class<T> cls) { |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 391 | return getDependencyInner(cls); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 392 | } |
| 393 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 394 | protected final <T> T getDependency(DependencyKey<T> key) { |
| 395 | return getDependencyInner(key); |
| 396 | } |
| 397 | |
Jason Monk | e107202 | 2017-04-06 15:14:18 -0400 | [diff] [blame] | 398 | private synchronized <T> T getDependencyInner(Object key) { |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 399 | @SuppressWarnings("unchecked") |
| 400 | T obj = (T) mDependencies.get(key); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 401 | if (obj == null) { |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 402 | obj = createDependency(key); |
| 403 | mDependencies.put(key, obj); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 404 | } |
| 405 | return obj; |
| 406 | } |
| 407 | |
| 408 | @VisibleForTesting |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 409 | protected <T> T createDependency(Object cls) { |
| 410 | Preconditions.checkArgument(cls instanceof DependencyKey<?> || cls instanceof Class<?>); |
| 411 | |
| 412 | @SuppressWarnings("unchecked") |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 413 | DependencyProvider<T> provider = mProviders.get(cls); |
| 414 | if (provider == null) { |
Evan Laird | f12a1f10 | 2017-09-13 14:05:37 -0400 | [diff] [blame] | 415 | throw new IllegalArgumentException("Unsupported dependency " + cls |
| 416 | + ". " + mProviders.size() + " providers known."); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 417 | } |
| 418 | return provider.createDependency(); |
| 419 | } |
| 420 | |
| 421 | private static Dependency sDependency; |
| 422 | |
| 423 | public interface DependencyProvider<T> { |
| 424 | T createDependency(); |
| 425 | } |
| 426 | |
Jason Monk | 790442e | 2017-02-13 17:49:39 -0500 | [diff] [blame] | 427 | private <T> void destroyDependency(Class<T> cls, Consumer<T> destroy) { |
| 428 | T dep = (T) mDependencies.remove(cls); |
| 429 | if (dep != null && destroy != null) { |
| 430 | destroy.accept(dep); |
| 431 | } |
| 432 | } |
| 433 | |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 434 | /** |
| 435 | * Used in separate processes (like tuner settings) to init the dependencies. |
| 436 | */ |
| 437 | public static void initDependencies(Context context) { |
| 438 | if (sDependency != null) return; |
| 439 | Dependency d = new Dependency(); |
Jason Monk | 790442e | 2017-02-13 17:49:39 -0500 | [diff] [blame] | 440 | d.mContext = context; |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 441 | d.mComponents = new HashMap<>(); |
| 442 | d.start(); |
| 443 | } |
| 444 | |
Jason Monk | 790442e | 2017-02-13 17:49:39 -0500 | [diff] [blame] | 445 | /** |
| 446 | * Used in separate process teardown to ensure the context isn't leaked. |
| 447 | * |
| 448 | * TODO: Remove once PreferenceFragment doesn't reference getActivity() |
| 449 | * anymore and these context hacks are no longer needed. |
| 450 | */ |
| 451 | public static void clearDependencies() { |
| 452 | sDependency = null; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Checks to see if a dependency is instantiated, if it is it removes it from |
| 457 | * the cache and calls the destroy callback. |
| 458 | */ |
| 459 | public static <T> void destroy(Class<T> cls, Consumer<T> destroy) { |
| 460 | sDependency.destroyDependency(cls, destroy); |
| 461 | } |
| 462 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 463 | public static <T> T get(Class<T> cls) { |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 464 | return sDependency.getDependency(cls); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 465 | } |
| 466 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 467 | public static <T> T get(DependencyKey<T> cls) { |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 468 | return sDependency.getDependency(cls); |
| 469 | } |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 470 | |
| 471 | public static final class DependencyKey<V> { |
| 472 | private final String mDisplayName; |
| 473 | |
| 474 | public DependencyKey(String displayName) { |
| 475 | mDisplayName = displayName; |
| 476 | } |
| 477 | |
| 478 | @Override |
| 479 | public String toString() { |
| 480 | return mDisplayName; |
| 481 | } |
| 482 | } |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 483 | } |