Pass context into the constructor of SystemUI objects.

The next step is to remove `components` from the SystemUI objects
and replace them with Dagger injection.

Bug: 138786270
Test: atest SystemUITests
Change-Id: I27415a8fa8ba0378599356426d849c9cfb9879d2
diff --git a/packages/SystemUI/proguard.flags b/packages/SystemUI/proguard.flags
index 22b0ab7..3e74970 100644
--- a/packages/SystemUI/proguard.flags
+++ b/packages/SystemUI/proguard.flags
@@ -35,3 +35,7 @@
     *;
 }
 -keep class androidx.core.app.CoreComponentFactory
+
+-keep public class * extends com.android.systemui.SystemUI {
+    public <init>(android.content.Context);
+}
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/LatencyTester.java b/packages/SystemUI/src/com/android/systemui/LatencyTester.java
index 50f1b44..ddbabee 100644
--- a/packages/SystemUI/src/com/android/systemui/LatencyTester.java
+++ b/packages/SystemUI/src/com/android/systemui/LatencyTester.java
@@ -41,6 +41,10 @@
     private static final String ACTION_TURN_ON_SCREEN =
             "com.android.systemui.latency.ACTION_TURN_ON_SCREEN";
 
+    public LatencyTester(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         if (!Build.IS_DEBUGGABLE) {
diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
index 3e068b0..5b2fe61 100644
--- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
+++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
@@ -132,6 +132,10 @@
         return result;
     }
 
+    public ScreenDecorations(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         mHandler = startHandlerThread();
diff --git a/packages/SystemUI/src/com/android/systemui/ServiceBinder.java b/packages/SystemUI/src/com/android/systemui/ServiceBinder.java
index e761a2b..e61268e 100644
--- a/packages/SystemUI/src/com/android/systemui/ServiceBinder.java
+++ b/packages/SystemUI/src/com/android/systemui/ServiceBinder.java
@@ -19,6 +19,7 @@
 import android.app.Service;
 
 import com.android.systemui.doze.DozeService;
+import com.android.systemui.keyguard.KeyguardService;
 
 import dagger.Binds;
 import dagger.Module;
@@ -30,8 +31,15 @@
  */
 @Module
 public abstract class ServiceBinder {
+    /** */
     @Binds
     @IntoMap
     @ClassKey(DozeService.class)
     public abstract Service bindDozeService(DozeService service);
+
+    /** */
+    @Binds
+    @IntoMap
+    @ClassKey(KeyguardService.class)
+    public abstract Service bindKeyguardService(KeyguardService service);
 }
diff --git a/packages/SystemUI/src/com/android/systemui/SizeCompatModeActivityController.java b/packages/SystemUI/src/com/android/systemui/SizeCompatModeActivityController.java
index c54f6306..a8591bb 100644
--- a/packages/SystemUI/src/com/android/systemui/SizeCompatModeActivityController.java
+++ b/packages/SystemUI/src/com/android/systemui/SizeCompatModeActivityController.java
@@ -59,12 +59,13 @@
     /** Only show once automatically in the process life. */
     private boolean mHasShownHint;
 
-    public SizeCompatModeActivityController() {
-        this(ActivityManagerWrapper.getInstance());
+    public SizeCompatModeActivityController(Context context) {
+        this(context, ActivityManagerWrapper.getInstance());
     }
 
     @VisibleForTesting
-    SizeCompatModeActivityController(ActivityManagerWrapper am) {
+    SizeCompatModeActivityController(Context context, ActivityManagerWrapper am) {
+        super(context);
         am.registerTaskStackListener(new TaskStackChangeListener() {
             @Override
             public void onSizeCompatModeActivityChanged(int displayId, IBinder activityToken) {
diff --git a/packages/SystemUI/src/com/android/systemui/SliceBroadcastRelayHandler.java b/packages/SystemUI/src/com/android/systemui/SliceBroadcastRelayHandler.java
index b3fc69e..92fbd25 100644
--- a/packages/SystemUI/src/com/android/systemui/SliceBroadcastRelayHandler.java
+++ b/packages/SystemUI/src/com/android/systemui/SliceBroadcastRelayHandler.java
@@ -39,6 +39,10 @@
 
     private final ArrayMap<Uri, BroadcastRelay> mRelays = new ArrayMap<>();
 
+    public SliceBroadcastRelayHandler(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         if (DEBUG) Log.d(TAG, "Start");
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUI.java b/packages/SystemUI/src/com/android/systemui/SystemUI.java
index 30fbef6..7570037 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUI.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUI.java
@@ -26,9 +26,13 @@
 import java.util.Map;
 
 public abstract class SystemUI implements SysUiServiceProvider {
-    public Context mContext;
+    protected final Context mContext;
     public Map<Class<?>, Object> mComponents;
 
+    public SystemUI(Context context) {
+        mContext = context;
+    }
+
     public abstract void start();
 
     protected void onConfigurationChanged(Configuration newConfig) {
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
index 56b5d08..189e511 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
@@ -42,6 +42,8 @@
 import com.android.systemui.statusbar.phone.StatusBarWindowController;
 import com.android.systemui.util.NotificationChannels;
 
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -193,18 +195,18 @@
             try {
                 SystemUI obj = mComponentHelper.resolveSystemUI(clsName);
                 if (obj == null) {
-                    obj = (SystemUI) Class.forName(clsName).newInstance();
+                    Constructor constructor = Class.forName(clsName).getConstructor(Context.class);
+                    obj = (SystemUI) constructor.newInstance(this);
                 }
                 mServices[i] = obj;
-            } catch (ClassNotFoundException ex) {
-                throw new RuntimeException(ex);
-            } catch (IllegalAccessException ex) {
-                throw new RuntimeException(ex);
-            } catch (InstantiationException ex) {
+            } catch (ClassNotFoundException
+                    | NoSuchMethodException
+                    | IllegalAccessException
+                    | InstantiationException
+                    | InvocationTargetException ex) {
                 throw new RuntimeException(ex);
             }
 
-            mServices[i].mContext = this;
             mServices[i].mComponents = mComponents;
             if (DEBUG) Log.d(TAG, "running: " + mServices[i]);
             mServices[i].start();
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIBinder.java b/packages/SystemUI/src/com/android/systemui/SystemUIBinder.java
index 785038f..696e23a 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIBinder.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIBinder.java
@@ -32,6 +32,13 @@
  */
 @Module(includes = {RecentsModule.class})
 public abstract class SystemUIBinder {
+
+    /** Inject into GarbageMonitor.Service. */
+    @Binds
+    @IntoMap
+    @ClassKey(GarbageMonitor.Service.class)
+    public abstract SystemUI bindGarbageMonitorService(GarbageMonitor.Service service);
+
     /** Inject into KeyguardViewMediator. */
     @Binds
     @IntoMap
@@ -50,9 +57,4 @@
     @ClassKey(Recents.class)
     public abstract SystemUI bindRecents(Recents sysui);
 
-    /** Inject into GarbageMonitor.Service. */
-    @Binds
-    @IntoMap
-    @ClassKey(GarbageMonitor.Service.class)
-    public abstract SystemUI bindGarbageMonitorService(GarbageMonitor.Service service);
 }
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
index 530dcdc..ae2543c 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
@@ -170,6 +170,7 @@
     }
 
     public VolumeDialogComponent createVolumeDialogComponent(SystemUI systemUi, Context context) {
+        // TODO: dagger injection.
         return new VolumeDialogComponent(systemUi, context);
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/VendorServices.java b/packages/SystemUI/src/com/android/systemui/VendorServices.java
index 0be6b12..13d847b 100644
--- a/packages/SystemUI/src/com/android/systemui/VendorServices.java
+++ b/packages/SystemUI/src/com/android/systemui/VendorServices.java
@@ -16,11 +16,17 @@
 
 package com.android.systemui;
 
+import android.content.Context;
+
 /**
  * Placeholder for any vendor-specific services.
  */
 public class VendorServices extends SystemUI {
 
+    public VendorServices(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         // no-op
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
index 4c2afb0..cdc2623 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
@@ -172,12 +172,13 @@
         }
     }
 
-    public AuthController() {
-        this(new Injector());
+    public AuthController(Context context) {
+        this(context, new Injector());
     }
 
     @VisibleForTesting
-    AuthController(Injector injector) {
+    AuthController(Context context, Injector injector) {
+        super(context);
         mInjector = injector;
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsComponent.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsComponent.java
index e8ef454..c11127d 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsComponent.java
@@ -35,6 +35,10 @@
     private Extension<GlobalActions> mExtension;
     private IStatusBarService mBarService;
 
+    public GlobalActionsComponent(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         mBarService = IStatusBarService.Stub.asInterface(
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java b/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java
index 7d52a9a..42f455a 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java
@@ -117,6 +117,10 @@
 
     private int mState;
 
+    public KeyboardUI(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         mContext = super.mContext;
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardLifecyclesDispatcher.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardLifecyclesDispatcher.java
index b3481c5..4a33590 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardLifecyclesDispatcher.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardLifecyclesDispatcher.java
@@ -19,9 +19,13 @@
 import android.os.Handler;
 import android.os.Message;
 
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
 /**
  * Dispatches the lifecycles keyguard gets from WindowManager on the main thread.
  */
+@Singleton
 public class KeyguardLifecyclesDispatcher {
 
     static final int SCREEN_TURNING_ON = 0;
@@ -37,6 +41,7 @@
     private final ScreenLifecycle mScreenLifecycle;
     private final WakefulnessLifecycle mWakefulnessLifecycle;
 
+    @Inject
     public KeyguardLifecyclesDispatcher(ScreenLifecycle screenLifecycle,
             WakefulnessLifecycle wakefulnessLifecycle) {
         mScreenLifecycle = screenLifecycle;
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java
index 81247cd..9f4056f 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java
@@ -33,25 +33,30 @@
 import com.android.internal.policy.IKeyguardExitCallback;
 import com.android.internal.policy.IKeyguardService;
 import com.android.internal.policy.IKeyguardStateCallback;
-import com.android.systemui.Dependency;
 import com.android.systemui.SystemUIApplication;
 
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+@Singleton
 public class KeyguardService extends Service {
     static final String TAG = "KeyguardService";
     static final String PERMISSION = android.Manifest.permission.CONTROL_KEYGUARD;
 
-    private KeyguardViewMediator mKeyguardViewMediator;
-    private KeyguardLifecyclesDispatcher mKeyguardLifecyclesDispatcher;
+    private final KeyguardViewMediator mKeyguardViewMediator;
+    private final KeyguardLifecyclesDispatcher mKeyguardLifecyclesDispatcher;
+
+    @Inject
+    public KeyguardService(KeyguardViewMediator keyguardViewMediator,
+                           KeyguardLifecyclesDispatcher keyguardLifecyclesDispatcher) {
+        super();
+        mKeyguardViewMediator = keyguardViewMediator;
+        mKeyguardLifecyclesDispatcher = keyguardLifecyclesDispatcher;
+    }
 
     @Override
     public void onCreate() {
         ((SystemUIApplication) getApplication()).startServicesIfNeeded();
-        mKeyguardViewMediator =
-                ((SystemUIApplication) getApplication()).getComponent(KeyguardViewMediator.class);
-        mKeyguardLifecyclesDispatcher = new KeyguardLifecyclesDispatcher(
-                Dependency.get(ScreenLifecycle.class),
-                Dependency.get(WakefulnessLifecycle.class));
-
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index a8027c0..200f174 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -685,9 +685,8 @@
             Context context,
             FalsingManager falsingManager,
             LockPatternUtils lockPatternUtils) {
-        super();
+        super(context);
 
-        mContext = context;
         mFalsingManager = falsingManager;
 
         mLockPatternUtils = lockPatternUtils;
diff --git a/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java b/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java
index aebadf9..4c96de2 100644
--- a/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java
+++ b/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java
@@ -59,6 +59,10 @@
     private final NotificationPlayer mAsyncPlayer = new NotificationPlayer(TAG);
     private final HashMap<IBinder, Client> mClients = new HashMap<IBinder, Client>();
 
+    public RingtonePlayer(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         mAsyncPlayer.setUsesWakeLock(mContext);
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipUI.java b/packages/SystemUI/src/com/android/systemui/pip/PipUI.java
index 682c76c..4d5e350 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/PipUI.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipUI.java
@@ -19,6 +19,7 @@
 import static android.content.pm.PackageManager.FEATURE_LEANBACK_ONLY;
 import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
 
+import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.os.UserHandle;
@@ -39,6 +40,10 @@
 
     private boolean mSupportsPip;
 
+    public PipUI(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         PackageManager pm = mContext.getPackageManager();
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
index a258f35..98f0b2a 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
@@ -103,7 +103,8 @@
     private final BroadcastDispatcher mBroadcastDispatcher;
 
     @Inject
-    public PowerUI(BroadcastDispatcher broadcastDispatcher) {
+    public PowerUI(Context context, BroadcastDispatcher broadcastDispatcher) {
+        super(context);
         mBroadcastDispatcher = broadcastDispatcher;
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/Recents.java b/packages/SystemUI/src/com/android/systemui/recents/Recents.java
index a1b4a93..0a8264b 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/Recents.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/Recents.java
@@ -17,6 +17,7 @@
 package com.android.systemui.recents;
 
 import android.content.ContentResolver;
+import android.content.Context;
 import android.content.res.Configuration;
 import android.graphics.Rect;
 import android.provider.Settings;
@@ -37,7 +38,8 @@
     private final RecentsImplementation mImpl;
 
     @Inject
-    public Recents(RecentsImplementation impl) {
+    public Recents(Context context, RecentsImplementation impl) {
+        super(context);
         mImpl = impl;
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/shortcut/ShortcutKeyDispatcher.java b/packages/SystemUI/src/com/android/systemui/shortcut/ShortcutKeyDispatcher.java
index 07675e2..df9791d 100644
--- a/packages/SystemUI/src/com/android/systemui/shortcut/ShortcutKeyDispatcher.java
+++ b/packages/SystemUI/src/com/android/systemui/shortcut/ShortcutKeyDispatcher.java
@@ -19,6 +19,7 @@
 import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_BOTTOM_OR_RIGHT;
 import static android.app.ActivityTaskManager.SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT;
 
+import android.content.Context;
 import android.content.res.Configuration;
 import android.os.RemoteException;
 import android.util.Log;
@@ -52,6 +53,10 @@
     protected final long SC_DOCK_LEFT = META_MASK | KeyEvent.KEYCODE_LEFT_BRACKET;
     protected final long SC_DOCK_RIGHT = META_MASK | KeyEvent.KEYCODE_RIGHT_BRACKET;
 
+    public ShortcutKeyDispatcher(Context context) {
+        super(context);
+    }
+
     /**
      * Registers a shortcut key to window manager.
      * @param shortcutCode packed representation of shortcut key code and meta information
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java
index cd2074f..c8b2b6a 100644
--- a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java
@@ -19,6 +19,7 @@
 import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
 
+import android.content.Context;
 import android.content.res.Configuration;
 import android.os.RemoteException;
 import android.util.Log;
@@ -50,6 +51,10 @@
     private boolean mHomeStackResizable = false;
     private ForcedResizableInfoActivityController mForcedResizableController;
 
+    public Divider(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         mWindowManager = new DividerWindowManager(mContext);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
index 36e04fe..d6a8f90 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -1101,6 +1101,10 @@
     // Need this class since CommandQueue already extends IStatusBar.Stub, so CommandQueueStart
     // is needed so it can extend SystemUI.
     public static class CommandQueueStart extends SystemUI {
+        public CommandQueueStart(Context context) {
+            super(context);
+        }
+
         @Override
         public void start() {
             putComponent(CommandQueue.class, new CommandQueue(mContext));
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/InstantAppNotifier.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/InstantAppNotifier.java
index a5b7fa7..f284f73 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/InstantAppNotifier.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/InstantAppNotifier.java
@@ -31,6 +31,7 @@
 import android.app.PendingIntent;
 import android.app.SynchronousUserSwitchObserver;
 import android.content.ComponentName;
+import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.IPackageManager;
@@ -60,7 +61,7 @@
 
 import java.util.List;
 
-/** The clsss to show notification(s) of instant apps. This may show multiple notifications on
+/** The class to show notification(s) of instant apps. This may show multiple notifications on
  * splitted screen.
  */
 public class InstantAppNotifier extends SystemUI
@@ -74,7 +75,9 @@
     private boolean mDockedStackExists;
     private KeyguardStateController mKeyguardStateController;
 
-    public InstantAppNotifier() {}
+    public InstantAppNotifier(Context context) {
+        super(context);
+    }
 
     @Override
     public void start() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index 2b80d22..f0c0527 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -620,6 +620,7 @@
 
     @Inject
     public StatusBar(
+            Context context,
             LightBarController lightBarController,
             AutoHideController autoHideController,
             KeyguardUpdateMonitor keyguardUpdateMonitor,
@@ -674,6 +675,7 @@
             StatusBarWindowController statusBarWindowController,
             StatusBarWindowViewController.Builder statusBarWindowViewControllerBuilder,
             NotifLog notifLog) {
+        super(context);
         mLightBarController = lightBarController;
         mAutoHideController = autoHideController;
         mKeyguardUpdateMonitor = keyguardUpdateMonitor;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java
index b80b6d5..c2ed7df 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java
@@ -36,6 +36,10 @@
  */
 public class TvStatusBar extends SystemUI implements CommandQueue.Callbacks {
 
+    public TvStatusBar(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         putComponent(TvStatusBar.class, this);
diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java
index 89aa797..9a58a35 100644
--- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java
+++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java
@@ -61,6 +61,10 @@
     private ThemeOverlayManager mThemeManager;
     private UserManager mUserManager;
 
+    public ThemeOverlayController(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         if (DEBUG) Log.d(TAG, "Start");
diff --git a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
index ff5bd03..11885c5 100644
--- a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
+++ b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java
@@ -60,6 +60,10 @@
     private NotificationManager mNotificationManager;
     private StorageManager mStorageManager;
 
+    public StorageNotification(Context context) {
+        super(context);
+    }
+
     private static class MoveInfo {
         public int moveId;
         public Bundle extras;
diff --git a/packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java b/packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java
index f35af90..8c60747 100644
--- a/packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java
+++ b/packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java
@@ -38,6 +38,10 @@
     public static String BATTERY     = "BAT";
     public static String HINTS       = "HNT";
 
+    public NotificationChannels(Context context) {
+        super(context);
+    }
+
     public static void createAll(Context context) {
         final NotificationManager nm = context.getSystemService(NotificationManager.class);
         final NotificationChannel batteryChannel = new NotificationChannel(BATTERY,
diff --git a/packages/SystemUI/src/com/android/systemui/util/leak/GarbageMonitor.java b/packages/SystemUI/src/com/android/systemui/util/leak/GarbageMonitor.java
index 2d5ebc4..63db755 100644
--- a/packages/SystemUI/src/com/android/systemui/util/leak/GarbageMonitor.java
+++ b/packages/SystemUI/src/com/android/systemui/util/leak/GarbageMonitor.java
@@ -526,11 +526,13 @@
     }
 
     /** */
+    @Singleton
     public static class Service extends SystemUI implements Dumpable {
         private final GarbageMonitor mGarbageMonitor;
 
         @Inject
-        public Service(GarbageMonitor garbageMonitor) {
+        public Service(Context context, GarbageMonitor garbageMonitor) {
+            super(context);
             mGarbageMonitor = garbageMonitor;
         }
 
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
index f8cf793..d4a88b0 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
@@ -16,6 +16,7 @@
 
 package com.android.systemui.volume;
 
+import android.content.Context;
 import android.content.res.Configuration;
 import android.os.Handler;
 import android.util.Log;
@@ -37,6 +38,10 @@
     private boolean mEnabled;
     private VolumeDialogComponent mVolumeComponent;
 
+    public VolumeUI(Context context) {
+        super(context);
+    }
+
     @Override
     public void start() {
         boolean enableVolumeUi = mContext.getResources().getBoolean(R.bool.enable_volume_ui);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
index 64ab060..c338d70 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
@@ -102,7 +102,7 @@
         when(mFragmentService.getFragmentHostManager(any())).thenReturn(mFragmentHostManager);
 
 
-        mScreenDecorations = new ScreenDecorations() {
+        mScreenDecorations = new ScreenDecorations(mContext) {
             @Override
             public void start() {
                 super.start();
@@ -126,7 +126,6 @@
                 mTestableLooper.processAllMessages();
             }
         };
-        mScreenDecorations.mContext = mContext;
         mScreenDecorations.mComponents = mContext.getComponents();
         reset(mTunerService);
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/SizeCompatModeActivityControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/SizeCompatModeActivityControllerTest.java
index 3ea7150..06999bc 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/SizeCompatModeActivityControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/SizeCompatModeActivityControllerTest.java
@@ -58,13 +58,12 @@
         MockitoAnnotations.initMocks(this);
         doReturn(true).when(mMockButton).show();
 
-        mController = new SizeCompatModeActivityController(mMockAm) {
+        mController = new SizeCompatModeActivityController(mContext, mMockAm) {
             @Override
             RestartActivityButton createRestartButton(Context context) {
                 return mMockButton;
             };
         };
-        mController.mContext = mContext;
 
         ArgumentCaptor<TaskStackChangeListener> listenerCaptor =
                 ArgumentCaptor.forClass(TaskStackChangeListener.class);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/SliceBroadcastRelayHandlerTest.java b/packages/SystemUI/tests/src/com/android/systemui/SliceBroadcastRelayHandlerTest.java
index 19e1a5c..a766885 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/SliceBroadcastRelayHandlerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/SliceBroadcastRelayHandlerTest.java
@@ -35,6 +35,7 @@
 
 import com.android.settingslib.SliceBroadcastRelay;
 
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
@@ -44,6 +45,14 @@
 public class SliceBroadcastRelayHandlerTest extends SysuiTestCase {
 
     private static final String TEST_ACTION = "com.android.systemui.action.TEST_ACTION";
+    private SliceBroadcastRelayHandler mRelayHandler;
+    private Context mSpyContext;
+    @Before
+    public void setup() {
+        mSpyContext = spy(mContext);
+
+        mRelayHandler = new SliceBroadcastRelayHandler(mSpyContext);
+    }
 
     @Test
     public void testRegister() {
@@ -52,8 +61,6 @@
                 .authority("something")
                 .path("test")
                 .build();
-        SliceBroadcastRelayHandler relayHandler = new SliceBroadcastRelayHandler();
-        relayHandler.mContext = spy(mContext);
 
         Intent intent = new Intent(SliceBroadcastRelay.ACTION_REGISTER);
         intent.putExtra(SliceBroadcastRelay.EXTRA_URI, ContentProvider.maybeAddUserId(testUri, 0));
@@ -63,8 +70,8 @@
         intent.putExtra(SliceBroadcastRelay.EXTRA_FILTER, value);
         intent.putExtra(SliceBroadcastRelay.EXTRA_URI, testUri);
 
-        relayHandler.handleIntent(intent);
-        verify(relayHandler.mContext).registerReceiver(any(), eq(value));
+        mRelayHandler.handleIntent(intent);
+        verify(mSpyContext).registerReceiver(any(), eq(value));
     }
 
     @Test
@@ -74,8 +81,6 @@
                 .authority("something")
                 .path("test")
                 .build();
-        SliceBroadcastRelayHandler relayHandler = new SliceBroadcastRelayHandler();
-        relayHandler.mContext = spy(mContext);
 
         Intent intent = new Intent(SliceBroadcastRelay.ACTION_REGISTER);
         intent.putExtra(SliceBroadcastRelay.EXTRA_URI, ContentProvider.maybeAddUserId(testUri, 0));
@@ -84,14 +89,14 @@
         IntentFilter value = new IntentFilter(TEST_ACTION);
         intent.putExtra(SliceBroadcastRelay.EXTRA_FILTER, value);
 
-        relayHandler.handleIntent(intent);
+        mRelayHandler.handleIntent(intent);
         ArgumentCaptor<BroadcastReceiver> relay = ArgumentCaptor.forClass(BroadcastReceiver.class);
-        verify(relayHandler.mContext).registerReceiver(relay.capture(), eq(value));
+        verify(mSpyContext).registerReceiver(relay.capture(), eq(value));
 
         intent = new Intent(SliceBroadcastRelay.ACTION_UNREGISTER);
         intent.putExtra(SliceBroadcastRelay.EXTRA_URI, ContentProvider.maybeAddUserId(testUri, 0));
-        relayHandler.handleIntent(intent);
-        verify(relayHandler.mContext).unregisterReceiver(eq(relay.getValue()));
+        mRelayHandler.handleIntent(intent);
+        verify(mSpyContext).unregisterReceiver(eq(relay.getValue()));
     }
 
     @Test
@@ -101,12 +106,10 @@
                 .authority("something")
                 .path("test")
                 .build();
-        SliceBroadcastRelayHandler relayHandler = new SliceBroadcastRelayHandler();
-        relayHandler.mContext = spy(mContext);
 
         Intent intent = new Intent(SliceBroadcastRelay.ACTION_UNREGISTER);
         intent.putExtra(SliceBroadcastRelay.EXTRA_URI, ContentProvider.maybeAddUserId(testUri, 0));
-        relayHandler.handleIntent(intent);
+        mRelayHandler.handleIntent(intent);
         // No crash
     }
 
@@ -118,9 +121,6 @@
                 .authority("something")
                 .path("test")
                 .build();
-        SliceBroadcastRelayHandler relayHandler = new SliceBroadcastRelayHandler();
-        relayHandler.mContext = spy(mContext);
-
         Intent intent = new Intent(SliceBroadcastRelay.ACTION_REGISTER);
         intent.putExtra(SliceBroadcastRelay.EXTRA_URI, ContentProvider.maybeAddUserId(testUri, 0));
         intent.putExtra(SliceBroadcastRelay.EXTRA_RECEIVER,
@@ -128,10 +128,10 @@
         IntentFilter value = new IntentFilter(TEST_ACTION);
         intent.putExtra(SliceBroadcastRelay.EXTRA_FILTER, value);
 
-        relayHandler.handleIntent(intent);
+        mRelayHandler.handleIntent(intent);
         ArgumentCaptor<BroadcastReceiver> relay = ArgumentCaptor.forClass(BroadcastReceiver.class);
-        verify(relayHandler.mContext).registerReceiver(relay.capture(), eq(value));
-        relay.getValue().onReceive(relayHandler.mContext, new Intent(TEST_ACTION));
+        verify(mSpyContext).registerReceiver(relay.capture(), eq(value));
+        relay.getValue().onReceive(mSpyContext, new Intent(TEST_ACTION));
 
         verify(Receiver.sReceiver, timeout(2000)).onReceive(any(), any());
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java
index dcdb5c3..e1eb3b0 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java
@@ -34,6 +34,7 @@
 import android.app.ActivityManager;
 import android.app.IActivityTaskManager;
 import android.content.ComponentName;
+import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.hardware.biometrics.Authenticator;
@@ -98,8 +99,7 @@
         when(mDialog1.isAllowDeviceCredentials()).thenReturn(false);
         when(mDialog2.isAllowDeviceCredentials()).thenReturn(false);
 
-        mAuthController = new TestableAuthController(new MockInjector());
-        mAuthController.mContext = context;
+        mAuthController = new TestableAuthController(context, new MockInjector());
         mAuthController.mComponents = mContext.getComponents();
 
         mAuthController.start();
@@ -404,8 +404,8 @@
         private int mBuildCount = 0;
         private Bundle mLastBiometricPromptBundle;
 
-        public TestableAuthController(Injector injector) {
-            super(injector);
+        TestableAuthController(Context context, Injector injector) {
+            super(context, injector);
         }
 
         @Override
diff --git a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
index 4958c64..8f4de3f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
@@ -682,8 +682,7 @@
     }
 
     private void createPowerUi() {
-        mPowerUI = new PowerUI(mBroadcastDispatcher);
-        mPowerUI.mContext = mContext;
+        mPowerUI = new PowerUI(mContext, mBroadcastDispatcher);
         mPowerUI.mComponents = mContext.getComponents();
         mPowerUI.mThermalService = mThermalServiceMock;
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
index 12e9be1..f76dc61 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
@@ -286,6 +286,7 @@
                 .thenReturn(mStatusBarWindowViewController);
 
         mStatusBar = new StatusBar(
+                mContext,
                 mLightBarController,
                 mAutoHideController,
                 mKeyguardUpdateMonitor,
@@ -345,7 +346,6 @@
                 mNotifLog);
         // TODO: we should be able to call mStatusBar.start() and have all the below values
         // initialized automatically.
-        mStatusBar.mContext = mContext;
         mStatusBar.mComponents = mContext.getComponents();
         mStatusBar.mStatusBarKeyguardViewManager = mStatusBarKeyguardViewManager;
         mStatusBar.mStatusBarWindow = mStatusBarWindowView;