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