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