From 9936216ef1e956074015ee631d04468877155f6d Mon Sep 17 00:00:00 2001 From: Dave Mankoff Date: Thu, 14 Apr 2022 16:32:13 +0000 Subject: [PATCH] Remove contents of DependencyProvider. Now marked as deprecated. Bug: 229228871 Test: manual Change-Id: I872806af23243171e9123c18a5a06201513a3d79 --- .../accessibility/ModeSwitchesController.java | 3 + .../systemui/broadcast/BroadcastDispatcher.kt | 12 +- .../broadcast/BroadcastDispatcherModule.java | 34 +++ .../broadcast/BroadcastDispatcherStartable.kt | 31 ++ .../systemui/broadcast/PendingRemovalStore.kt | 3 +- .../dagger/AndroidInternalsModule.java | 53 ++++ .../systemui/dagger/DependencyProvider.java | 283 +----------------- .../dagger/FrameworkServicesModule.java | 41 +++ .../dagger/SettingsLibraryModule.java | 44 +++ .../systemui/dagger/SharedLibraryModule.java | 58 ++++ .../systemui/doze/AlwaysOnDisplayPolicy.java | 5 + .../keyguard/dagger/KeyguardModule.java | 7 + .../qs/ReduceBrightColorsController.java | 2 + .../statusbar/phone/AutoHideController.java | 2 + .../phone/ConfigurationControllerImpl.kt | 5 +- .../policy/dagger/StatusBarPolicyModule.java | 14 + .../android/systemui/theme/ThemeModule.java | 49 +++ .../systemui/theme/ThemeOverlayApplier.java | 14 +- .../concurrency/GlobalConcurrencyModule.java | 9 + .../concurrency/SysUIConcurrencyModule.java | 14 + .../systemui/util/leak/LeakDetector.java | 15 +- .../systemui/util/leak/LeakModule.java | 42 +++ .../util/leak/TrackedCollections.java | 6 + .../broadcast/FakeBroadcastDispatcher.kt | 3 +- .../theme/ThemeOverlayApplierTest.java | 2 +- .../systemui/util/leak/LeakDetectorTest.java | 6 +- 26 files changed, 460 insertions(+), 297 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcherModule.java create mode 100644 packages/SystemUI/src/com/android/systemui/broadcast/BroadcastDispatcherStartable.kt create mode 100644 packages/SystemUI/src/com/android/systemui/dagger/AndroidInternalsModule.java create mode 100644 packages/SystemUI/src/com/android/systemui/dagger/SettingsLibraryModule.java create mode 100644 packages/SystemUI/src/com/android/systemui/dagger/SharedLibraryModule.java create mode 100644 packages/SystemUI/src/com/android/systemui/theme/ThemeModule.java create mode 100644 packages/SystemUI/src/com/android/systemui/util/leak/LeakModule.java diff --git a/packages/SystemUI/src/com/android/systemui/accessibility/ModeSwitchesController.java b/packages/SystemUI/src/com/android/systemui/accessibility/ModeSwitchesController.java index 5e48ee3d23664..0cc1b2d92e001 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 android.view.Display; 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 @@ public class ModeSwitchesController implements SwitchListener { private final DisplayIdIndexSupplier 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 b7aebc198827b..d757b629c8290 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 android.util.SparseArray 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 @@ private const val DEBUG = true * 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 0000000000000..cc08188ef618e --- /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 0000000000000..d7b263a323ca8 --- /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 ebf498361c2a0..a5d730fc5009a 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.Dumpable 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 @@ import java.io.PrintWriter * * 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 0000000000000..48c54bca69ee4 --- /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 fa2384268b15c..31ad36fb21d86 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 b172e92871ce1..94080bd4dae3e 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.ActivityTaskManager; 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.app.trust.TrustManager; 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.content.res.Resources; 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.telecom.TelecomManager; 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.appwidget.IAppWidgetService; 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 @@ public class FrameworkServicesModule { 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 @@ public class FrameworkServicesModule { return context.getSystemService(CaptioningManager.class); } + /** */ + @Provides + @Singleton + public Choreographer providesChoreographer() { + return Choreographer.getInstance(); + } + @Provides @Singleton static ColorDisplayManager provideColorDisplayManager(Context context) { @@ -293,6 +312,13 @@ public class FrameworkServicesModule { 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 @@ public class FrameworkServicesModule { 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) { @@ -334,6 +368,13 @@ public class FrameworkServicesModule { return context.getSystemService(PowerManager.class); } + /** */ + @Provides + @Main + public SharedPreferences provideSharePreferences(Context context) { + return Prefs.get(context); + } + /** */ @Provides @Singleton 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 0000000000000..14626e1e6515b --- /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 0000000000000..be156157fb723 --- /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 735b3cd4b8242..55df7792e2e66 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.KeyValueListParser; 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 @@ public class AlwaysOnDisplayPolicy { 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 71dfa7433c327..165af135a792f 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.internal.widget.LockPatternUtils; 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 @@ public class KeyguardModule { 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 42d603ec50512..39d081da43cb4 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 android.provider.Settings; 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 @@ import javax.inject.Inject; /** * @hide */ +@SysUISingleton public class ReduceBrightColorsController implements CallbackController { 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 111cbbe817557..3ccef9d6eb14b 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.util.Log; 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 96fa8a5cfd712..34cd1ceeffc71 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.content.res.Configuration 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 = 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 c3268354a5391..1b7353923adaf 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.AccessPointController; 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; @@ -83,6 +86,10 @@ public interface StatusBarPolicyModule { @Binds CastController provideCastController(CastControllerImpl controllerImpl); + /** */ + @Binds + ConfigurationController bindConfigurationController(ConfigurationControllerImpl impl); + /** */ @Binds ExtensionController provideExtensionController(ExtensionControllerImpl controllerImpl); @@ -182,4 +189,11 @@ public interface StatusBarPolicyModule { 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 0000000000000..7fa90df0e7928 --- /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 d795d81e44bff..ba39367e290e4 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 androidx.annotation.VisibleForTesting; 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.Set; 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 @@ public class ThemeOverlayApplier implements Dumpable { private final Map 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 107fe870a07ab..323db5cfd2498 100644 --- a/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java +++ b/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java @@ -63,6 +63,15 @@ public abstract class GlobalConcurrencyModule { return new Handler(mainLooper); } + /** + * @deprecated Use @Main Handler. + */ + @Deprecated + @Provides + public static Handler provideHandler() { + return new Handler(); + } + /** * Provide a Main-Thread Executor. */ 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 8f61abcca4dce..8c736dc9fe709 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 com.android.systemui.dagger.qualifiers.Main; import java.util.concurrent.Executor; +import javax.inject.Named; + import dagger.Module; import dagger.Provides; @@ -162,4 +166,14 @@ public abstract class SysUIConcurrencyModule { @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 95e8273beded7..f0e389078c2f4 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 @@ public class LeakDetector implements Dumpable { 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 0000000000000..8f5b4d6bdce96 --- /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 5577daf7e4bfe..a3e13bd8f72bb 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.Collection; import java.util.Map; import java.util.function.Predicate; +import javax.inject.Inject; + /** * Tracks the size of collections. */ @@ -34,6 +36,10 @@ public class TrackedCollections { private final WeakIdentityHashMap, 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 141b3b446c01f..53dcc8d269c97 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 @@ class FakeBroadcastDispatcher( 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() 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 2c461ae1b598e..3032ff1fe61f1 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 class ThemeOverlayApplierTest extends SysuiTestCase { 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 3ee1a27dc69ae..8f934335e93b0 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 @@ public class LeakDetectorTest extends SysuiTestCase { private Object mObject; private Collection mCollection; + + private CollectionWaiter trackObjectWith(Consumer tracker) { mObject = new Object(); CollectionWaiter collectionWaiter = ReferenceTestUtils.createCollectionWaiter(mObject); @@ -69,7 +71,9 @@ public class LeakDetectorTest extends SysuiTestCase { @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