Merge "Remove contents of DependencyProvider." into tm-dev
diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/ModeSwitchesController.java b/packages/SystemUI/src/com/android/systemui/accessibility/ModeSwitchesController.java
index 5e48ee3..0cc1b2d 100644
--- a/packages/SystemUI/src/com/android/systemui/accessibility/ModeSwitchesController.java
+++ b/packages/SystemUI/src/com/android/systemui/accessibility/ModeSwitchesController.java
@@ -28,6 +28,8 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.systemui.dagger.SysUISingleton;
 
+import javax.inject.Inject;
+
 /**
  * A class to control {@link MagnificationModeSwitch}. It shows the button UI with following
  * conditions:
@@ -44,6 +46,7 @@
     private final DisplayIdIndexSupplier<MagnificationModeSwitch> mSwitchSupplier;
     private SwitchListener mSwitchListenerDelegate;
 
+    @Inject
     public ModeSwitchesController(Context context) {
         mSwitchSupplier = new SwitchSupplier(context,
                 context.getSystemService(DisplayManager.class), this::onSwitch);
diff --git a/packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcher.kt b/packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcher.kt
index b7aebc1..d757b62 100644
--- a/packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcher.kt
+++ b/packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcher.kt
@@ -31,10 +31,13 @@
 import com.android.internal.annotations.VisibleForTesting
 import com.android.systemui.Dumpable
 import com.android.systemui.broadcast.logging.BroadcastDispatcherLogger
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Background
 import com.android.systemui.dump.DumpManager
 import com.android.systemui.settings.UserTracker
 import java.io.PrintWriter
 import java.util.concurrent.Executor
+import javax.inject.Inject
 
 data class ReceiverData(
     val receiver: BroadcastReceiver,
@@ -63,14 +66,15 @@
  * Broadcast handling may be asynchronous *without* calling goAsync(), as it's running within sysui
  * and doesn't need to worry about being killed.
  */
-open class BroadcastDispatcher @JvmOverloads constructor (
+@SysUISingleton
+open class BroadcastDispatcher @Inject constructor(
     private val context: Context,
-    private val bgLooper: Looper,
-    private val bgExecutor: Executor,
+    @Background private val bgLooper: Looper,
+    @Background private val bgExecutor: Executor,
     private val dumpManager: DumpManager,
     private val logger: BroadcastDispatcherLogger,
     private val userTracker: UserTracker,
-    private val removalPendingStore: PendingRemovalStore = PendingRemovalStore(logger)
+    private val removalPendingStore: PendingRemovalStore
 ) : Dumpable {
 
     // Only modify in BG thread
diff --git a/packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcherModule.java b/packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcherModule.java
new file mode 100644
index 0000000..cc08188
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcherModule.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.broadcast;
+
+import com.android.systemui.CoreStartable;
+
+import dagger.Binds;
+import dagger.Module;
+import dagger.multibindings.ClassKey;
+import dagger.multibindings.IntoMap;
+
+/** */
+@Module
+public abstract class BroadcastDispatcherModule {
+    /** Ensures BroadcastDispatcher is initialized. */
+    @Binds
+    @IntoMap
+    @ClassKey(BroadcastDispatcherStartable.class)
+    abstract CoreStartable bindsBroadastDispatcherStartable(BroadcastDispatcherStartable s);
+}
diff --git a/packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcherStartable.kt b/packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcherStartable.kt
new file mode 100644
index 0000000..d7b263a
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcherStartable.kt
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.broadcast
+
+import android.content.Context
+import com.android.systemui.CoreStartable
+import javax.inject.Inject
+
+class BroadcastDispatcherStartable @Inject constructor(
+    context: Context,
+    val broadcastDispatcher: BroadcastDispatcher
+) : CoreStartable(context) {
+
+    override fun start() {
+        broadcastDispatcher.initialize()
+    }
+}
\ No newline at end of file
diff --git a/packages/SystemUI/src/com/android/systemui/broadcast/PendingRemovalStore.kt b/packages/SystemUI/src/com/android/systemui/broadcast/PendingRemovalStore.kt
index ebf4983..a5d730f 100644
--- a/packages/SystemUI/src/com/android/systemui/broadcast/PendingRemovalStore.kt
+++ b/packages/SystemUI/src/com/android/systemui/broadcast/PendingRemovalStore.kt
@@ -8,6 +8,7 @@
 import com.android.systemui.broadcast.logging.BroadcastDispatcherLogger
 import com.android.systemui.util.indentIfPossible
 import java.io.PrintWriter
+import javax.inject.Inject
 
 /**
  * Store information about requests for unregistering receivers from [BroadcastDispatcher], before
@@ -15,7 +16,7 @@
  *
  * This helps make unregistering a receiver a *sync* operation.
  */
-class PendingRemovalStore(
+class PendingRemovalStore @Inject constructor(
     private val logger: BroadcastDispatcherLogger
 ) : Dumpable {
     @GuardedBy("pendingRemoval")
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/AndroidInternalsModule.java b/packages/SystemUI/src/com/android/systemui/dagger/AndroidInternalsModule.java
new file mode 100644
index 0000000..48c54bc
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/dagger/AndroidInternalsModule.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.dagger;
+
+import android.content.Context;
+
+import com.android.internal.logging.MetricsLogger;
+import com.android.internal.util.NotificationMessagingUtil;
+import com.android.internal.widget.LockPatternUtils;
+
+import dagger.Module;
+import dagger.Provides;
+
+/**
+ * Provides items imported from com.android.internal.
+ */
+@Module
+public class AndroidInternalsModule {
+    /** */
+    @Provides
+    @SysUISingleton
+    public LockPatternUtils provideLockPatternUtils(Context context) {
+        return new LockPatternUtils(context);
+    }
+
+    /** */
+    @Provides
+    @SysUISingleton
+    public MetricsLogger provideMetricsLogger() {
+        return new MetricsLogger();
+    }
+
+    /** */
+    @Provides
+    public NotificationMessagingUtil provideNotificationMessagingUtil(Context context) {
+        return new NotificationMessagingUtil(context);
+    }
+
+}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java b/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java
index fa23842..31ad36f 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java
@@ -16,279 +16,24 @@
 
 package com.android.systemui.dagger;
 
-import static com.android.systemui.Dependency.TIME_TICK_HANDLER_NAME;
-
-import android.annotation.Nullable;
-import android.annotation.SuppressLint;
-import android.app.INotificationManager;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.om.OverlayManager;
-import android.hardware.display.AmbientDisplayConfiguration;
-import android.hardware.display.ColorDisplayManager;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.view.Choreographer;
-import android.view.IWindowManager;
-import android.view.LayoutInflater;
-
-import com.android.internal.logging.MetricsLogger;
-import com.android.internal.util.NotificationMessagingUtil;
-import com.android.internal.widget.LockPatternUtils;
-import com.android.keyguard.KeyguardUpdateMonitor;
-import com.android.keyguard.ViewMediatorCallback;
-import com.android.settingslib.bluetooth.LocalBluetoothManager;
-import com.android.systemui.Prefs;
-import com.android.systemui.R;
-import com.android.systemui.accessibility.AccessibilityButtonModeObserver;
-import com.android.systemui.accessibility.AccessibilityButtonTargetsObserver;
-import com.android.systemui.accessibility.ModeSwitchesController;
-import com.android.systemui.accessibility.floatingmenu.AccessibilityFloatingMenuController;
-import com.android.systemui.broadcast.BroadcastDispatcher;
-import com.android.systemui.broadcast.logging.BroadcastDispatcherLogger;
-import com.android.systemui.dagger.qualifiers.Background;
-import com.android.systemui.dagger.qualifiers.Main;
-import com.android.systemui.doze.AlwaysOnDisplayPolicy;
-import com.android.systemui.dump.DumpManager;
-import com.android.systemui.keyguard.KeyguardViewMediator;
-import com.android.systemui.qs.ReduceBrightColorsController;
-import com.android.systemui.settings.UserTracker;
-import com.android.systemui.shared.system.ActivityManagerWrapper;
-import com.android.systemui.shared.system.DevicePolicyManagerWrapper;
-import com.android.systemui.shared.system.TaskStackChangeListeners;
-import com.android.systemui.shared.system.WindowManagerWrapper;
-import com.android.systemui.statusbar.connectivity.NetworkController;
-import com.android.systemui.statusbar.phone.AutoHideController;
-import com.android.systemui.statusbar.phone.ConfigurationControllerImpl;
-import com.android.systemui.statusbar.policy.ConfigurationController;
-import com.android.systemui.statusbar.policy.DataSaverController;
-import com.android.systemui.theme.ThemeOverlayApplier;
-import com.android.systemui.util.leak.LeakDetector;
-import com.android.systemui.util.settings.SecureSettings;
-
-import java.util.concurrent.Executor;
-
-import javax.inject.Named;
+import com.android.systemui.broadcast.BroadcastDispatcherModule;
+import com.android.systemui.theme.ThemeModule;
+import com.android.systemui.util.leak.LeakModule;
 
 import dagger.Module;
-import dagger.Provides;
 
 /**
- * Provides dependencies for the root component of sysui injection.
- *
- * Only SystemUI owned classes and instances should go in here. Other, framework-owned classes
- * should go in {@link FrameworkServicesModule}.
- *
- * See SystemUI/docs/dagger.md
+ * @deprecated This module is going away. Don't put anything in here.
  */
-@Module(includes = {NightDisplayListenerModule.class})
+@Deprecated
+@Module(includes = {
+        AndroidInternalsModule.class,
+        BroadcastDispatcherModule.class,
+        LeakModule.class,
+        NightDisplayListenerModule.class,
+        SharedLibraryModule.class,
+        SettingsLibraryModule.class,
+        ThemeModule.class
+})
 public class DependencyProvider {
-
-    /** */
-    @Provides
-    @SysUISingleton
-    @Named(TIME_TICK_HANDLER_NAME)
-    public Handler provideTimeTickHandler() {
-        HandlerThread thread = new HandlerThread("TimeTick");
-        thread.start();
-        return new Handler(thread.getLooper());
-    }
-
-    /** */
-    @Provides
-    @Main
-    public SharedPreferences provideSharePreferences(Context context) {
-        return Prefs.get(context);
-    }
-
-    /** */
-    @Provides
-    public AmbientDisplayConfiguration provideAmbientDisplayConfiguration(Context context) {
-        return new AmbientDisplayConfiguration(context);
-    }
-
-    /** */
-    @Provides
-    public Handler provideHandler() {
-        return new Handler();
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public DataSaverController provideDataSaverController(NetworkController networkController) {
-        return networkController.getDataSaverController();
-    }
-
-    @Provides
-    @SysUISingleton
-    public INotificationManager provideINotificationManager() {
-        return INotificationManager.Stub.asInterface(
-                ServiceManager.getService(Context.NOTIFICATION_SERVICE));
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public LayoutInflater providerLayoutInflater(Context context) {
-        return LayoutInflater.from(context);
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public LeakDetector provideLeakDetector(DumpManager dumpManager) {
-        return LeakDetector.create(dumpManager);
-    }
-
-    @SuppressLint("MissingPermission")
-    @SysUISingleton
-    @Provides
-    @Nullable
-    static LocalBluetoothManager provideLocalBluetoothController(Context context,
-            @Background Handler bgHandler) {
-        return LocalBluetoothManager.create(context, bgHandler, UserHandle.ALL);
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public MetricsLogger provideMetricsLogger() {
-        return new MetricsLogger();
-    }
-
-    /** */
-    @SysUISingleton
-    @Provides
-    static ThemeOverlayApplier provideThemeOverlayManager(Context context,
-            @Background Executor bgExecutor,
-            @Main Executor mainExecutor,
-            OverlayManager overlayManager,
-            DumpManager dumpManager) {
-        return new ThemeOverlayApplier(overlayManager, bgExecutor, mainExecutor,
-                context.getString(R.string.launcher_overlayable_package),
-                context.getString(R.string.themepicker_overlayable_package), dumpManager);
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public AccessibilityFloatingMenuController provideAccessibilityFloatingMenuController(
-            Context context, AccessibilityButtonTargetsObserver accessibilityButtonTargetsObserver,
-            AccessibilityButtonModeObserver accessibilityButtonModeObserver,
-            KeyguardUpdateMonitor keyguardUpdateMonitor) {
-        return new AccessibilityFloatingMenuController(context, accessibilityButtonTargetsObserver,
-                accessibilityButtonModeObserver, keyguardUpdateMonitor);
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public ConfigurationController provideConfigurationController(Context context) {
-        return new ConfigurationControllerImpl(context);
-    }
-
-    /** */
-    @SysUISingleton
-    @Provides
-    public AutoHideController provideAutoHideController(Context context,
-            @Main Handler mainHandler, IWindowManager iWindowManager) {
-        return new AutoHideController(context, mainHandler, iWindowManager);
-    }
-
-    /** */
-    @SysUISingleton
-    @Provides
-    public ReduceBrightColorsController provideReduceBrightColorsListener(
-            @Background Handler bgHandler, UserTracker userTracker,
-            ColorDisplayManager colorDisplayManager, SecureSettings secureSettings) {
-        return new ReduceBrightColorsController(userTracker, bgHandler,
-                colorDisplayManager, secureSettings);
-    }
-
-    @Provides
-    @SysUISingleton
-    public ActivityManagerWrapper provideActivityManagerWrapper() {
-        return ActivityManagerWrapper.getInstance();
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public TaskStackChangeListeners provideTaskStackChangeListeners() {
-        return TaskStackChangeListeners.getInstance();
-    }
-
-    /** Provides and initializes the {#link BroadcastDispatcher} for SystemUI */
-    @Provides
-    @SysUISingleton
-    public BroadcastDispatcher providesBroadcastDispatcher(
-            Context context,
-            @Background Looper backgroundLooper,
-            @Background Executor backgroundExecutor,
-            DumpManager dumpManager,
-            BroadcastDispatcherLogger logger,
-            UserTracker userTracker
-    ) {
-        BroadcastDispatcher bD = new BroadcastDispatcher(context, backgroundLooper,
-                backgroundExecutor, dumpManager, logger, userTracker);
-        bD.initialize();
-        return bD;
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public DevicePolicyManagerWrapper provideDevicePolicyManagerWrapper() {
-        return DevicePolicyManagerWrapper.getInstance();
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public LockPatternUtils provideLockPatternUtils(Context context) {
-        return new LockPatternUtils(context);
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public AlwaysOnDisplayPolicy provideAlwaysOnDisplayPolicy(Context context) {
-        return new AlwaysOnDisplayPolicy(context);
-    }
-
-    /***/
-    @Provides
-    public NotificationMessagingUtil provideNotificationMessagingUtil(Context context) {
-        return new NotificationMessagingUtil(context);
-    }
-
-    /** */
-    @Provides
-    public ViewMediatorCallback providesViewMediatorCallback(KeyguardViewMediator viewMediator) {
-        return viewMediator.getViewMediatorCallback();
-    }
-
-    /** */
-    @Provides
-    public WindowManagerWrapper providesWindowManagerWrapper() {
-        return WindowManagerWrapper.getInstance();
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public Choreographer providesChoreographer() {
-        return Choreographer.getInstance();
-    }
-
-    /** */
-    @Provides
-    @SysUISingleton
-    public ModeSwitchesController providesModeSwitchesController(Context context) {
-        return new ModeSwitchesController(context);
-    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java b/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
index 535b548..e512b7c 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
@@ -22,6 +22,7 @@
 import android.app.AlarmManager;
 import android.app.IActivityManager;
 import android.app.IActivityTaskManager;
+import android.app.INotificationManager;
 import android.app.IWallpaperManager;
 import android.app.KeyguardManager;
 import android.app.NotificationManager;
@@ -35,6 +36,7 @@
 import android.content.ClipboardManager;
 import android.content.ContentResolver;
 import android.content.Context;
+import android.content.SharedPreferences;
 import android.content.om.OverlayManager;
 import android.content.pm.IPackageManager;
 import android.content.pm.LauncherApps;
@@ -44,6 +46,7 @@
 import android.hardware.SensorManager;
 import android.hardware.SensorPrivacyManager;
 import android.hardware.devicestate.DeviceStateManager;
+import android.hardware.display.AmbientDisplayConfiguration;
 import android.hardware.display.ColorDisplayManager;
 import android.hardware.display.DisplayManager;
 import android.hardware.face.FaceManager;
@@ -68,8 +71,10 @@
 import android.telephony.CarrierConfigManager;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
+import android.view.Choreographer;
 import android.view.CrossWindowBlurListeners;
 import android.view.IWindowManager;
+import android.view.LayoutInflater;
 import android.view.ViewConfiguration;
 import android.view.WindowManager;
 import android.view.WindowManagerGlobal;
@@ -82,6 +87,7 @@
 import com.android.internal.jank.InteractionJankMonitor;
 import com.android.internal.statusbar.IStatusBarService;
 import com.android.internal.util.LatencyTracker;
+import com.android.systemui.Prefs;
 import com.android.systemui.dagger.qualifiers.DisplayId;
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.shared.system.PackageManagerWrapper;
@@ -116,6 +122,12 @@
         return context.getSystemService(AlarmManager.class);
     }
 
+    /** */
+    @Provides
+    public AmbientDisplayConfiguration provideAmbientDisplayConfiguration(Context context) {
+        return new AmbientDisplayConfiguration(context);
+    }
+
     @Provides
     @Singleton
     static AudioManager provideAudioManager(Context context) {
@@ -128,6 +140,13 @@
         return context.getSystemService(CaptioningManager.class);
     }
 
+    /** */
+    @Provides
+    @Singleton
+    public Choreographer providesChoreographer() {
+        return Choreographer.getInstance();
+    }
+
     @Provides
     @Singleton
     static ColorDisplayManager provideColorDisplayManager(Context context) {
@@ -293,6 +312,13 @@
         return context.getSystemService(LauncherApps.class);
     }
 
+    /** */
+    @Provides
+    @Singleton
+    public LayoutInflater providerLayoutInflater(Context context) {
+        return LayoutInflater.from(context);
+    }
+
     @Provides
     static MediaRouter2Manager provideMediaRouter2Manager(Context context) {
         return MediaRouter2Manager.getInstance(context);
@@ -315,6 +341,14 @@
         return context.getSystemService(NotificationManager.class);
     }
 
+    /** */
+    @Provides
+    @Singleton
+    public INotificationManager provideINotificationManager() {
+        return INotificationManager.Stub.asInterface(
+                ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+    }
+
     @Provides
     @Singleton
     static PackageManager providePackageManager(Context context) {
@@ -336,6 +370,13 @@
 
     /** */
     @Provides
+    @Main
+    public SharedPreferences provideSharePreferences(Context context) {
+        return Prefs.get(context);
+    }
+
+    /** */
+    @Provides
     @Singleton
     static UiModeManager provideUiModeManager(Context context) {
         return context.getSystemService(UiModeManager.class);
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SettingsLibraryModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SettingsLibraryModule.java
new file mode 100644
index 0000000..14626e1
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SettingsLibraryModule.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.dagger;
+
+import android.annotation.Nullable;
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.os.Handler;
+import android.os.UserHandle;
+
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.systemui.dagger.qualifiers.Background;
+
+import dagger.Module;
+import dagger.Provides;
+
+/** */
+@Module
+public class SettingsLibraryModule {
+
+    /** */
+    @SuppressLint("MissingPermission")
+    @SysUISingleton
+    @Provides
+    @Nullable
+    static LocalBluetoothManager provideLocalBluetoothController(Context context,
+            @Background Handler bgHandler) {
+        return LocalBluetoothManager.create(context, bgHandler, UserHandle.ALL);
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SharedLibraryModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SharedLibraryModule.java
new file mode 100644
index 0000000..be156157
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SharedLibraryModule.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.dagger;
+
+import com.android.systemui.shared.system.ActivityManagerWrapper;
+import com.android.systemui.shared.system.DevicePolicyManagerWrapper;
+import com.android.systemui.shared.system.TaskStackChangeListeners;
+import com.android.systemui.shared.system.WindowManagerWrapper;
+
+import dagger.Module;
+import dagger.Provides;
+
+/** */
+@Module
+public class SharedLibraryModule {
+
+    /** */
+    @Provides
+    @SysUISingleton
+    public ActivityManagerWrapper provideActivityManagerWrapper() {
+        return ActivityManagerWrapper.getInstance();
+    }
+
+    /** */
+    @Provides
+    @SysUISingleton
+    public DevicePolicyManagerWrapper provideDevicePolicyManagerWrapper() {
+        return DevicePolicyManagerWrapper.getInstance();
+    }
+
+    /** */
+    @Provides
+    @SysUISingleton
+    public TaskStackChangeListeners provideTaskStackChangeListeners() {
+        return TaskStackChangeListeners.getInstance();
+    }
+
+    /** */
+    @Provides
+    public WindowManagerWrapper providesWindowManagerWrapper() {
+        return WindowManagerWrapper.getInstance();
+    }
+
+}
diff --git a/packages/SystemUI/src/com/android/systemui/doze/AlwaysOnDisplayPolicy.java b/packages/SystemUI/src/com/android/systemui/doze/AlwaysOnDisplayPolicy.java
index 735b3cd..55df779 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/AlwaysOnDisplayPolicy.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/AlwaysOnDisplayPolicy.java
@@ -29,11 +29,15 @@
 import android.util.Log;
 
 import com.android.systemui.R;
+import com.android.systemui.dagger.SysUISingleton;
+
+import javax.inject.Inject;
 
 /**
  * Class to store the policy for AOD, which comes from
  * {@link android.provider.Settings.Global}
  */
+@SysUISingleton
 public class AlwaysOnDisplayPolicy {
     public static final String TAG = "AlwaysOnDisplayPolicy";
 
@@ -130,6 +134,7 @@
     private final Context mContext;
     private SettingsObserver mSettingsObserver;
 
+    @Inject
     public AlwaysOnDisplayPolicy(Context context) {
         context = context.getApplicationContext();
         mContext = context;
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
index 71dfa74..165af13 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java
@@ -25,6 +25,7 @@
 import com.android.keyguard.KeyguardDisplayManager;
 import com.android.keyguard.KeyguardUpdateMonitor;
 import com.android.keyguard.KeyguardViewController;
+import com.android.keyguard.ViewMediatorCallback;
 import com.android.keyguard.dagger.KeyguardQsUserSwitchComponent;
 import com.android.keyguard.dagger.KeyguardStatusBarViewComponent;
 import com.android.keyguard.dagger.KeyguardStatusViewComponent;
@@ -127,4 +128,10 @@
                 notificationShadeWindowController,
                 activityLaunchAnimator);
     }
+
+    /** */
+    @Provides
+    public ViewMediatorCallback providesViewMediatorCallback(KeyguardViewMediator viewMediator) {
+        return viewMediator.getViewMediatorCallback();
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/qs/ReduceBrightColorsController.java b/packages/SystemUI/src/com/android/systemui/qs/ReduceBrightColorsController.java
index 42d603e..39d081d 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/ReduceBrightColorsController.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/ReduceBrightColorsController.java
@@ -26,6 +26,7 @@
 
 import androidx.annotation.NonNull;
 
+import com.android.systemui.dagger.SysUISingleton;
 import com.android.systemui.dagger.qualifiers.Background;
 import com.android.systemui.settings.UserTracker;
 import com.android.systemui.statusbar.policy.CallbackController;
@@ -38,6 +39,7 @@
 /**
  * @hide
  */
+@SysUISingleton
 public class ReduceBrightColorsController implements
         CallbackController<ReduceBrightColorsController.Listener> {
     private final ColorDisplayManager mManager;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoHideController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoHideController.java
index 111cbbe..3ccef9d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoHideController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoHideController.java
@@ -23,12 +23,14 @@
 import android.view.IWindowManager;
 import android.view.MotionEvent;
 
+import com.android.systemui.dagger.SysUISingleton;
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.statusbar.AutoHideUiElement;
 
 import javax.inject.Inject;
 
 /** A controller to control all auto-hide things. Also see {@link AutoHideUiElement}. */
+@SysUISingleton
 public class AutoHideController {
     private static final String TAG = "AutoHideController";
     private static final long AUTO_HIDE_TIMEOUT_MS = 2250;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt
index 96fa8a5..34cd1ce 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ConfigurationControllerImpl.kt
@@ -20,11 +20,14 @@
 import android.graphics.Rect
 import android.os.LocaleList
 import android.view.View.LAYOUT_DIRECTION_RTL
+import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.statusbar.policy.ConfigurationController
 
 import java.util.ArrayList
+import javax.inject.Inject
 
-class ConfigurationControllerImpl(context: Context) : ConfigurationController {
+@SysUISingleton
+class ConfigurationControllerImpl @Inject constructor(context: Context) : ConfigurationController {
 
     private val listeners: MutableList<ConfigurationController.ConfigurationListener> = ArrayList()
     private val lastConfig = Configuration()
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/StatusBarPolicyModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/StatusBarPolicyModule.java
index c326835..1b73539 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/StatusBarPolicyModule.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/StatusBarPolicyModule.java
@@ -29,10 +29,13 @@
 import com.android.systemui.statusbar.connectivity.AccessPointControllerImpl;
 import com.android.systemui.statusbar.connectivity.NetworkController;
 import com.android.systemui.statusbar.connectivity.NetworkControllerImpl;
+import com.android.systemui.statusbar.phone.ConfigurationControllerImpl;
 import com.android.systemui.statusbar.policy.BluetoothController;
 import com.android.systemui.statusbar.policy.BluetoothControllerImpl;
 import com.android.systemui.statusbar.policy.CastController;
 import com.android.systemui.statusbar.policy.CastControllerImpl;
+import com.android.systemui.statusbar.policy.ConfigurationController;
+import com.android.systemui.statusbar.policy.DataSaverController;
 import com.android.systemui.statusbar.policy.DeviceControlsController;
 import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl;
 import com.android.systemui.statusbar.policy.DevicePostureController;
@@ -85,6 +88,10 @@
 
     /** */
     @Binds
+    ConfigurationController bindConfigurationController(ConfigurationControllerImpl impl);
+
+    /** */
+    @Binds
     ExtensionController provideExtensionController(ExtensionControllerImpl controllerImpl);
 
     /** */
@@ -182,4 +189,11 @@
         return resources.getStringArray(
                 R.array.config_perDeviceStateRotationLockDefaults);
     }
+
+    /** */
+    @Provides
+    @SysUISingleton
+    static DataSaverController provideDataSaverController(NetworkController networkController) {
+        return networkController.getDataSaverController();
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeModule.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeModule.java
new file mode 100644
index 0000000..7fa90df
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeModule.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.theme;
+
+import android.content.res.Resources;
+
+import com.android.systemui.R;
+import com.android.systemui.dagger.qualifiers.Main;
+import com.android.systemui.util.concurrency.SysUIConcurrencyModule;
+
+import javax.inject.Named;
+
+import dagger.Module;
+import dagger.Provides;
+
+/** */
+@Module(includes = {SysUIConcurrencyModule.class})
+public class ThemeModule {
+    static final String LAUNCHER_PACKAGE = "theme_launcher_package";
+    static final String THEME_PICKER_PACKAGE = "theme_picker_package";
+
+    /** */
+    @Provides
+    @Named(LAUNCHER_PACKAGE)
+    static String provideLauncherPackage(@Main Resources resources) {
+        return resources.getString(R.string.launcher_overlayable_package);
+    }
+
+    /** */
+    @Provides
+    @Named(THEME_PICKER_PACKAGE)
+    static String provideThemePickerPackage(@Main Resources resources) {
+        return resources.getString(R.string.themepicker_overlayable_package);
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java
index d795d81..ba39367 100644
--- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java
+++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayApplier.java
@@ -31,6 +31,7 @@
 
 import com.android.systemui.Dumpable;
 import com.android.systemui.dagger.SysUISingleton;
+import com.android.systemui.dagger.qualifiers.Background;
 import com.android.systemui.dump.DumpManager;
 
 import com.google.android.collect.Lists;
@@ -45,6 +46,9 @@
 import java.util.concurrent.Executor;
 import java.util.stream.Collectors;
 
+import javax.inject.Inject;
+import javax.inject.Named;
+
 /**
  * Responsible for orchestrating overlays, based on user preferences and other inputs from
  * {@link ThemeOverlayController}.
@@ -134,17 +138,17 @@
     private final Map<String, String> mCategoryToTargetPackage = new ArrayMap<>();
     private final OverlayManager mOverlayManager;
     private final Executor mBgExecutor;
-    private final Executor mMainExecutor;
     private final String mLauncherPackage;
     private final String mThemePickerPackage;
 
+    @Inject
     public ThemeOverlayApplier(OverlayManager overlayManager,
-            Executor bgExecutor,
-            Executor mainExecutor,
-            String launcherPackage, String themePickerPackage, DumpManager dumpManager) {
+            @Background Executor bgExecutor,
+            @Named(ThemeModule.LAUNCHER_PACKAGE) String launcherPackage,
+            @Named(ThemeModule.THEME_PICKER_PACKAGE) String themePickerPackage,
+            DumpManager dumpManager) {
         mOverlayManager = overlayManager;
         mBgExecutor = bgExecutor;
-        mMainExecutor = mainExecutor;
         mLauncherPackage = launcherPackage;
         mThemePickerPackage = themePickerPackage;
         mTargetPackageToCategories.put(ANDROID_PACKAGE, Sets.newHashSet(
diff --git a/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java b/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java
index 107fe87..323db5c 100644
--- a/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java
+++ b/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java
@@ -64,6 +64,15 @@
     }
 
     /**
+     * @deprecated Use @Main Handler.
+     */
+    @Deprecated
+    @Provides
+    public static Handler provideHandler() {
+        return new Handler();
+    }
+
+    /**
      * Provide a Main-Thread Executor.
      */
     @Provides
diff --git a/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java b/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java
index 8f61abc..8c736dc 100644
--- a/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java
+++ b/packages/SystemUI/src/com/android/systemui/util/concurrency/SysUIConcurrencyModule.java
@@ -16,6 +16,8 @@
 
 package com.android.systemui.util.concurrency;
 
+import static com.android.systemui.Dependency.TIME_TICK_HANDLER_NAME;
+
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.Looper;
@@ -28,6 +30,8 @@
 
 import java.util.concurrent.Executor;
 
+import javax.inject.Named;
+
 import dagger.Module;
 import dagger.Provides;
 
@@ -162,4 +166,14 @@
             @Background DelayableExecutor executor) {
         return new MessageRouterImpl(executor);
     }
+
+    /** */
+    @Provides
+    @SysUISingleton
+    @Named(TIME_TICK_HANDLER_NAME)
+    public static Handler provideTimeTickHandler() {
+        HandlerThread thread = new HandlerThread("TimeTick");
+        thread.start();
+        return new Handler(thread.getLooper());
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/util/leak/LeakDetector.java b/packages/SystemUI/src/com/android/systemui/util/leak/LeakDetector.java
index 95e8273..f0e3890 100644
--- a/packages/SystemUI/src/com/android/systemui/util/leak/LeakDetector.java
+++ b/packages/SystemUI/src/com/android/systemui/util/leak/LeakDetector.java
@@ -17,9 +17,9 @@
 package com.android.systemui.util.leak;
 
 import android.os.Build;
+import android.util.IndentingPrintWriter;
 
 import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.IndentingPrintWriter;
 import com.android.systemui.Dumpable;
 import com.android.systemui.dump.DumpManager;
 
@@ -133,17 +133,4 @@
         pw.decreaseIndent();
         pw.println();
     }
-
-    public static LeakDetector create(DumpManager dumpManager) {
-        if (ENABLED) {
-            TrackedCollections collections = new TrackedCollections();
-            return new LeakDetector(
-                    collections,
-                    new TrackedGarbage(collections),
-                    new TrackedObjects(collections),
-                    dumpManager);
-        } else {
-            return new LeakDetector(null, null, null, dumpManager);
-        }
-    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/util/leak/LeakModule.java b/packages/SystemUI/src/com/android/systemui/util/leak/LeakModule.java
new file mode 100644
index 0000000..8f5b4d6
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/util/leak/LeakModule.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.util.leak;
+
+import com.android.systemui.dagger.SysUISingleton;
+import com.android.systemui.dump.DumpManager;
+import com.android.systemui.util.Compile;
+
+import dagger.Module;
+import dagger.Provides;
+
+/** */
+@Module
+public class LeakModule {
+    @Provides
+    @SysUISingleton
+    LeakDetector providesLeakDetector(DumpManager dumpManager, TrackedCollections collections) {
+        if (Compile.IS_DEBUG) {
+            return new LeakDetector(
+                    collections,
+                    new TrackedGarbage(collections),
+                    new TrackedObjects(collections),
+                    dumpManager);
+        } else {
+            return new LeakDetector(null, null, null, dumpManager);
+        }
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/util/leak/TrackedCollections.java b/packages/SystemUI/src/com/android/systemui/util/leak/TrackedCollections.java
index 5577daf..a3e13bd 100644
--- a/packages/SystemUI/src/com/android/systemui/util/leak/TrackedCollections.java
+++ b/packages/SystemUI/src/com/android/systemui/util/leak/TrackedCollections.java
@@ -24,6 +24,8 @@
 import java.util.Map;
 import java.util.function.Predicate;
 
+import javax.inject.Inject;
+
 /**
  * Tracks the size of collections.
  */
@@ -34,6 +36,10 @@
     private final WeakIdentityHashMap<Collection<?>, CollectionState> mCollections
             = new WeakIdentityHashMap<>();
 
+    @Inject
+    TrackedCollections() {
+    }
+
     /**
      * @see LeakDetector#trackCollection(Collection, String)
      */
diff --git a/packages/SystemUI/tests/src/com/android/systemui/broadcast/FakeBroadcastDispatcher.kt b/packages/SystemUI/tests/src/com/android/systemui/broadcast/FakeBroadcastDispatcher.kt
index 141b3b44..53dcc8d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/broadcast/FakeBroadcastDispatcher.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/broadcast/FakeBroadcastDispatcher.kt
@@ -37,7 +37,8 @@
     dumpManager: DumpManager,
     logger: BroadcastDispatcherLogger,
     userTracker: UserTracker
-) : BroadcastDispatcher(context, looper, executor, dumpManager, logger, userTracker) {
+) : BroadcastDispatcher(
+    context, looper, executor, dumpManager, logger, userTracker, PendingRemovalStore(logger)) {
 
     private val registeredReceivers = ArraySet<BroadcastReceiver>()
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayApplierTest.java b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayApplierTest.java
index 2c461ae..3032ff1f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayApplierTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayApplierTest.java
@@ -104,7 +104,7 @@
     public void setup() throws Exception {
         MockitoAnnotations.initMocks(this);
         mManager = new ThemeOverlayApplier(mOverlayManager,
-                MoreExecutors.directExecutor(), MoreExecutors.directExecutor(),
+                MoreExecutors.directExecutor(),
                 LAUNCHER_PACKAGE, THEMEPICKER_PACKAGE, mDumpManager) {
             @Override
             protected OverlayManagerTransaction.Builder getTransactionBuilder() {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/leak/LeakDetectorTest.java b/packages/SystemUI/tests/src/com/android/systemui/util/leak/LeakDetectorTest.java
index 3ee1a27..8f93433 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/util/leak/LeakDetectorTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/util/leak/LeakDetectorTest.java
@@ -52,6 +52,8 @@
     private Object mObject;
     private Collection<?> mCollection;
 
+
+
     private CollectionWaiter trackObjectWith(Consumer<Object> tracker) {
         mObject = new Object();
         CollectionWaiter collectionWaiter = ReferenceTestUtils.createCollectionWaiter(mObject);
@@ -69,7 +71,9 @@
 
     @Before
     public void setup() {
-        mLeakDetector = LeakDetector.create(Mockito.mock(DumpManager.class));
+        TrackedCollections collections = new TrackedCollections();
+        mLeakDetector = new LeakDetector(collections, new TrackedGarbage(collections),
+                new TrackedObjects(collections), Mockito.mock(DumpManager.class));
 
         // Note: Do not try to factor out object / collection waiter creation. The optimizer will
         // try and cache accesses to fields and thus create a GC root for the duration of the test