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