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