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