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