diff --git a/packages/SystemUI/res/values-television/config.xml b/packages/SystemUI/res/values-television/config.xml index 2eff692301b1f..a9e6d22461b61 100644 --- a/packages/SystemUI/res/values-television/config.xml +++ b/packages/SystemUI/res/values-television/config.xml @@ -24,29 +24,6 @@ com.android.systemui.tv.TvSystemUIFactory - - - com.android.systemui.util.NotificationChannels - com.android.systemui.volume.VolumeUI - com.android.systemui.privacy.television.TvOngoingPrivacyChip - com.android.systemui.statusbar.tv.TvStatusBar - com.android.systemui.statusbar.tv.notifications.TvNotificationPanel - com.android.systemui.statusbar.tv.notifications.TvNotificationHandler - com.android.systemui.statusbar.tv.VpnStatusObserver - com.android.systemui.globalactions.GlobalActionsComponent - com.android.systemui.usb.StorageNotification - com.android.systemui.power.PowerUI - com.android.systemui.media.RingtonePlayer - com.android.systemui.keyboard.KeyboardUI - com.android.systemui.shortcut.ShortcutKeyDispatcher - @string/config_systemUIVendorServiceComponent - com.android.systemui.SliceBroadcastRelayHandler - com.android.systemui.statusbar.notification.InstantAppNotifier - com.android.systemui.accessibility.WindowMagnification - com.android.systemui.toast.ToastUI - com.android.systemui.wmshell.WMShell - com.android.systemui.media.systemsounds.HomeSoundEffectController - 3 diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 47822b77a93fe..34751d8fcf903 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -292,37 +292,6 @@ com.android.systemui.SystemUIFactory - - - com.android.systemui.util.NotificationChannels - com.android.systemui.keyguard.KeyguardViewMediator - com.android.keyguard.KeyguardBiometricLockoutLogger - com.android.systemui.recents.Recents - com.android.systemui.volume.VolumeUI - com.android.systemui.statusbar.phone.StatusBar - com.android.systemui.usb.StorageNotification - com.android.systemui.power.PowerUI - com.android.systemui.media.RingtonePlayer - com.android.systemui.keyboard.KeyboardUI - com.android.systemui.shortcut.ShortcutKeyDispatcher - @string/config_systemUIVendorServiceComponent - com.android.systemui.util.leak.GarbageMonitor$Service - com.android.systemui.LatencyTester - com.android.systemui.globalactions.GlobalActionsComponent - com.android.systemui.ScreenDecorations - com.android.systemui.biometrics.AuthController - com.android.systemui.log.SessionTracker - com.android.systemui.SliceBroadcastRelayHandler - com.android.systemui.statusbar.notification.InstantAppNotifier - com.android.systemui.theme.ThemeOverlayController - com.android.systemui.accessibility.WindowMagnification - com.android.systemui.accessibility.SystemActions - com.android.systemui.toast.ToastUI - com.android.systemui.wmshell.WMShell - com.android.systemui.clipboardoverlay.ClipboardListener - - diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java index 5bdee2a61b9b8..3026ae87ad3ab 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java @@ -49,8 +49,11 @@ import com.android.systemui.util.NotificationChannels; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collections; +import java.util.Comparator; +import java.util.Map; +import java.util.TreeMap; + +import javax.inject.Provider; /** * Application class for SystemUI. @@ -181,17 +184,16 @@ public class SystemUIApplication extends Application implements */ public void startServicesIfNeeded() { - final String[] names = SystemUIFactory.getInstance() - .getSystemUIServiceComponents(getResources()); final String[] additionalNames = SystemUIFactory.getInstance() .getAdditionalSystemUIServiceComponents(getResources()); - final ArrayList serviceComponents = new ArrayList<>(); - Collections.addAll(serviceComponents, names); - Collections.addAll(serviceComponents, additionalNames); - - startServicesIfNeeded(/* metricsPrefix= */ "StartServices", - serviceComponents.toArray(new String[serviceComponents.size()])); + // Sort the startables so that we get a deterministic ordering. + // TODO: make #start idempotent and require users of CoreStartable to call it. + Map, Provider> sortedStartables = new TreeMap<>( + Comparator.comparing(Class::getName)); + sortedStartables.putAll(SystemUIFactory.getInstance().getStartableComponents()); + startServicesIfNeeded( + sortedStartables, "StartServices", additionalNames); } /** @@ -201,16 +203,22 @@ public class SystemUIApplication extends Application implements *

This method must only be called from the main thread.

*/ void startSecondaryUserServicesIfNeeded() { - String[] names = SystemUIFactory.getInstance().getSystemUIServiceComponentsPerUser( - getResources()); - startServicesIfNeeded(/* metricsPrefix= */ "StartSecondaryServices", names); + // Sort the startables so that we get a deterministic ordering. + Map, Provider> sortedStartables = new TreeMap<>( + Comparator.comparing(Class::getName)); + sortedStartables.putAll(SystemUIFactory.getInstance().getStartableComponentsPerUser()); + startServicesIfNeeded( + sortedStartables, "StartSecondaryServices", new String[]{}); } - private void startServicesIfNeeded(String metricsPrefix, String[] services) { + private void startServicesIfNeeded( + Map, Provider> startables, + String metricsPrefix, + String[] services) { if (mServicesStarted) { return; } - mServices = new CoreStartable[services.length]; + mServices = new CoreStartable[startables.size() + services.length]; if (!mBootCompleteCache.isBootComplete()) { // check to see if maybe it was already completed long before we began @@ -230,36 +238,32 @@ public class SystemUIApplication extends Application implements TimingsTraceLog log = new TimingsTraceLog("SystemUIBootTiming", Trace.TRACE_TAG_APP); log.traceBegin(metricsPrefix); + + int i = 0; + for (Map.Entry, Provider> entry : startables.entrySet()) { + String clsName = entry.getKey().getName(); + int j = i; // Copied to make lambda happy. + timeInitialization( + clsName, + () -> mServices[j] = startStartable(clsName, entry.getValue()), + log, + metricsPrefix); + i++; + } + + // Loop over any "additional" startables that are defined in an xml overlay. final int N = services.length; - for (int i = 0; i < N; i++) { + for (i = 0; i < N; i++) { + int j = i; // Copied to make lambda happy. String clsName = services[i]; - if (DEBUG) Log.d(TAG, "loading: " + clsName); - log.traceBegin(metricsPrefix + clsName); - long ti = System.currentTimeMillis(); - try { - CoreStartable obj = mComponentHelper.resolveCoreStartable(clsName); - if (obj == null) { - Constructor constructor = Class.forName(clsName).getConstructor(Context.class); - obj = (CoreStartable) constructor.newInstance(this); - } - mServices[i] = obj; - } catch (ClassNotFoundException - | NoSuchMethodException - | IllegalAccessException - | InstantiationException - | InvocationTargetException ex) { - throw new RuntimeException(ex); - } + timeInitialization( + clsName, + () -> mServices[j + startables.size()] = startAdditionalStartable(clsName), + log, + metricsPrefix); + } - if (DEBUG) Log.d(TAG, "running: " + mServices[i]); - mServices[i].start(); - log.traceEnd(); - - // Warn if initialization of component takes too long - ti = System.currentTimeMillis() - ti; - if (ti > 1000) { - Log.w(TAG, "Initialization of " + clsName + " took " + ti + " ms"); - } + for (i = 0; i < mServices.length; i++) { if (mBootCompleteCache.isBootComplete()) { mServices[i].onBootCompleted(); } @@ -272,6 +276,53 @@ public class SystemUIApplication extends Application implements mServicesStarted = true; } + private void timeInitialization(String clsName, Runnable init, TimingsTraceLog log, + String metricsPrefix) { + long ti = System.currentTimeMillis(); + log.traceBegin(metricsPrefix + " " + clsName); + init.run(); + log.traceEnd(); + + // Warn if initialization of component takes too long + ti = System.currentTimeMillis() - ti; + if (ti > 1000) { + Log.w(TAG, "Initialization of " + clsName + " took " + ti + " ms"); + } + } + + private CoreStartable startAdditionalStartable(String clsName) { + CoreStartable startable; + if (DEBUG) Log.d(TAG, "loading: " + clsName); + try { + startable = mComponentHelper.resolveAdditionalCoreStartable(clsName); + if (startable == null) { + Constructor constructor = Class.forName(clsName).getConstructor( + Context.class); + startable = (CoreStartable) constructor.newInstance(this); + } + } catch (ClassNotFoundException + | NoSuchMethodException + | IllegalAccessException + | InstantiationException + | InvocationTargetException ex) { + throw new RuntimeException(ex); + } + + return startStartable(startable); + } + + private CoreStartable startStartable(String clsName, Provider provider) { + if (DEBUG) Log.d(TAG, "loading: " + clsName); + return startStartable(provider.get()); + } + + private CoreStartable startStartable(CoreStartable startable) { + if (DEBUG) Log.d(TAG, "running: " + startable); + startable.start(); + + return startable; + } + // TODO(b/217567642): add unit tests? There doesn't seem to be a SystemUiApplicationTest... @Override public boolean addDumpable(Dumpable dumpable) { diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java index b3be87731fbc4..582ec2d14d5b2 100644 --- a/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java +++ b/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java @@ -32,10 +32,14 @@ import com.android.systemui.navigationbar.gestural.BackGestureTfClassifierProvid import com.android.systemui.screenshot.ScreenshotNotificationSmartActionsProvider; import com.android.wm.shell.transition.ShellTransitions; +import java.util.Arrays; +import java.util.Map; import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; +import javax.inject.Provider; + /** * Class factory to provide customizable SystemUI components. */ @@ -190,24 +194,32 @@ public class SystemUIFactory { } /** - * Returns the list of system UI components that should be started. + * Returns the list of {@link CoreStartable} components that should be started at startup. */ - public String[] getSystemUIServiceComponents(Resources resources) { - return resources.getStringArray(R.array.config_systemUIServiceComponents); + public Map, Provider> getStartableComponents() { + return mSysUIComponent.getStartables(); } /** * Returns the list of additional system UI components that should be started. */ public String[] getAdditionalSystemUIServiceComponents(Resources resources) { - return resources.getStringArray(R.array.config_additionalSystemUIServiceComponents); + String[] results = resources.getStringArray( + R.array.config_additionalSystemUIServiceComponents); + String vendorComponent = resources.getString( + R.string.config_systemUIVendorServiceComponent); + + results = Arrays.copyOf(results, results.length + 1); + results[results.length - 1] = vendorComponent; + + return results; } /** - * Returns the list of system UI components that should be started per user. + * Returns the list of {@link CoreStartable} components that should be started per user. */ - public String[] getSystemUIServiceComponentsPerUser(Resources resources) { - return resources.getStringArray(R.array.config_systemUIServiceComponentsPerUser); + public Map, Provider> getStartableComponentsPerUser() { + return mSysUIComponent.getPerUserStartables(); } /** diff --git a/packages/SystemUI/src/com/android/systemui/dagger/ContextComponentHelper.java b/packages/SystemUI/src/com/android/systemui/dagger/ContextComponentHelper.java index f53221c959a59..973f6ca388302 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/ContextComponentHelper.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/ContextComponentHelper.java @@ -37,7 +37,7 @@ public interface ContextComponentHelper { Service resolveService(String className); /** Turns a classname into an instance of the class or returns null. */ - CoreStartable resolveCoreStartable(String className); + CoreStartable resolveAdditionalCoreStartable(String className); /** Turns a classname into an instance of the class or returns null. */ BroadcastReceiver resolveBroadcastReceiver(String className); diff --git a/packages/SystemUI/src/com/android/systemui/dagger/ContextComponentResolver.java b/packages/SystemUI/src/com/android/systemui/dagger/ContextComponentResolver.java index fba8d351e9909..99481dac7257d 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/ContextComponentResolver.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/ContextComponentResolver.java @@ -21,6 +21,7 @@ import android.app.Service; import android.content.BroadcastReceiver; import com.android.systemui.CoreStartable; +import com.android.systemui.dagger.qualifiers.AdditionalStartable; import com.android.systemui.recents.RecentsImplementation; import java.util.Map; @@ -35,19 +36,20 @@ import javax.inject.Provider; public class ContextComponentResolver implements ContextComponentHelper { private final Map, Provider> mActivityCreators; private final Map, Provider> mServiceCreators; - private final Map, Provider> mSystemUICreators; + private final Map, Provider> mAdditionalStartableCreators; private final Map, Provider> mRecentsCreators; private final Map, Provider> mBroadcastReceiverCreators; @Inject ContextComponentResolver(Map, Provider> activityCreators, Map, Provider> serviceCreators, - Map, Provider> systemUICreators, + Map, Provider> startableCreators, + @AdditionalStartable Map, Provider> additionalStartableCreators, Map, Provider> recentsCreators, Map, Provider> broadcastReceiverCreators) { mActivityCreators = activityCreators; mServiceCreators = serviceCreators; - mSystemUICreators = systemUICreators; + mAdditionalStartableCreators = additionalStartableCreators; mRecentsCreators = recentsCreators; mBroadcastReceiverCreators = broadcastReceiverCreators; } @@ -88,8 +90,8 @@ public class ContextComponentResolver implements ContextComponentHelper { * Looks up the SystemUI class name to see if Dagger has an instance of it. */ @Override - public CoreStartable resolveCoreStartable(String className) { - return resolve(className, mSystemUICreators); + public CoreStartable resolveAdditionalCoreStartable(String className) { + return resolve(className, mAdditionalStartableCreators); } private T resolve(String className, Map, Provider> creators) { diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java index bda8e3c2ed631..73551058dfd35 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java @@ -18,9 +18,11 @@ package com.android.systemui.dagger; import com.android.keyguard.clock.ClockOptionsProvider; import com.android.systemui.BootCompleteCacheImpl; +import com.android.systemui.CoreStartable; import com.android.systemui.Dependency; import com.android.systemui.InitController; import com.android.systemui.SystemUIAppComponentFactory; +import com.android.systemui.dagger.qualifiers.PerUser; import com.android.systemui.dump.DumpManager; import com.android.systemui.keyguard.KeyguardSliceProvider; import com.android.systemui.media.taptotransfer.MediaTttCommandLineHelper; @@ -51,8 +53,11 @@ import com.android.wm.shell.startingsurface.StartingSurface; import com.android.wm.shell.tasksurfacehelper.TaskSurfaceHelper; import com.android.wm.shell.transition.ShellTransitions; +import java.util.Map; import java.util.Optional; +import javax.inject.Provider; + import dagger.BindsInstance; import dagger.Subcomponent; @@ -65,6 +70,7 @@ import dagger.Subcomponent; DependencyProvider.class, SystemUIBinder.class, SystemUIModule.class, + SystemUICoreStartableModule.class, SystemUIDefaultModule.class}) public interface SysUIComponent { @@ -220,6 +226,16 @@ public interface SysUIComponent { /** */ Optional getMediaTttCommandLineHelper(); + /** + * Returns {@link CoreStartable}s that should be started with the application. + */ + Map, Provider> getStartables(); + + /** + * Returns {@link CoreStartable}s that should be started for every user. + */ + @PerUser Map, Provider> getPerUserStartables(); + /** * Member injection into the supplied argument. */ diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java index ec2beb15959e7..b32f8786899a3 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIBinder.java @@ -16,46 +16,11 @@ package com.android.systemui.dagger; -import com.android.keyguard.KeyguardBiometricLockoutLogger; -import com.android.systemui.CoreStartable; -import com.android.systemui.LatencyTester; -import com.android.systemui.ScreenDecorations; -import com.android.systemui.SliceBroadcastRelayHandler; -import com.android.systemui.accessibility.SystemActions; -import com.android.systemui.accessibility.WindowMagnification; -import com.android.systemui.biometrics.AuthController; -import com.android.systemui.clipboardoverlay.ClipboardListener; -import com.android.systemui.dreams.DreamOverlayRegistrant; -import com.android.systemui.dreams.SmartSpaceComplication; -import com.android.systemui.dreams.complication.DreamClockDateComplication; -import com.android.systemui.dreams.complication.DreamClockTimeComplication; -import com.android.systemui.dreams.complication.DreamWeatherComplication; -import com.android.systemui.globalactions.GlobalActionsComponent; -import com.android.systemui.keyguard.KeyguardViewMediator; import com.android.systemui.keyguard.dagger.KeyguardModule; -import com.android.systemui.log.SessionTracker; -import com.android.systemui.media.dream.MediaDreamSentinel; -import com.android.systemui.media.systemsounds.HomeSoundEffectController; -import com.android.systemui.power.PowerUI; -import com.android.systemui.privacy.television.TvOngoingPrivacyChip; -import com.android.systemui.recents.Recents; import com.android.systemui.recents.RecentsModule; -import com.android.systemui.shortcut.ShortcutKeyDispatcher; import com.android.systemui.statusbar.dagger.StatusBarModule; -import com.android.systemui.statusbar.notification.InstantAppNotifier; -import com.android.systemui.statusbar.phone.StatusBar; -import com.android.systemui.statusbar.tv.TvStatusBar; -import com.android.systemui.statusbar.tv.notifications.TvNotificationPanel; -import com.android.systemui.theme.ThemeOverlayController; -import com.android.systemui.toast.ToastUI; -import com.android.systemui.util.leak.GarbageMonitor; -import com.android.systemui.volume.VolumeUI; -import com.android.systemui.wmshell.WMShell; -import dagger.Binds; import dagger.Module; -import dagger.multibindings.ClassKey; -import dagger.multibindings.IntoMap; /** * SystemUI objects that are injectable should go here. @@ -66,196 +31,4 @@ import dagger.multibindings.IntoMap; KeyguardModule.class, }) public abstract class SystemUIBinder { - /** Inject into AuthController. */ - @Binds - @IntoMap - @ClassKey(AuthController.class) - public abstract CoreStartable bindAuthController(AuthController service); - - /** Inject into SessionTracker. */ - @Binds - @IntoMap - @ClassKey(SessionTracker.class) - public abstract CoreStartable bindSessionTracker(SessionTracker service); - - /** Inject into GarbageMonitor.Service. */ - @Binds - @IntoMap - @ClassKey(GarbageMonitor.Service.class) - public abstract CoreStartable bindGarbageMonitorService(GarbageMonitor.Service sysui); - - /** Inject into ClipboardListener. */ - @Binds - @IntoMap - @ClassKey(ClipboardListener.class) - public abstract CoreStartable bindClipboardListener(ClipboardListener sysui); - - /** Inject into GlobalActionsComponent. */ - @Binds - @IntoMap - @ClassKey(GlobalActionsComponent.class) - public abstract CoreStartable bindGlobalActionsComponent(GlobalActionsComponent sysui); - - /** Inject into InstantAppNotifier. */ - @Binds - @IntoMap - @ClassKey(InstantAppNotifier.class) - public abstract CoreStartable bindInstantAppNotifier(InstantAppNotifier sysui); - - /** Inject into KeyguardViewMediator. */ - @Binds - @IntoMap - @ClassKey(KeyguardViewMediator.class) - public abstract CoreStartable bindKeyguardViewMediator(KeyguardViewMediator sysui); - - /** Inject into KeyguardBiometricLockoutLogger. */ - @Binds - @IntoMap - @ClassKey(KeyguardBiometricLockoutLogger.class) - public abstract CoreStartable bindKeyguardBiometricLockoutLogger( - KeyguardBiometricLockoutLogger sysui); - - /** Inject into LatencyTests. */ - @Binds - @IntoMap - @ClassKey(LatencyTester.class) - public abstract CoreStartable bindLatencyTester(LatencyTester sysui); - - /** Inject into PowerUI. */ - @Binds - @IntoMap - @ClassKey(PowerUI.class) - public abstract CoreStartable bindPowerUI(PowerUI sysui); - - /** Inject into Recents. */ - @Binds - @IntoMap - @ClassKey(Recents.class) - public abstract CoreStartable bindRecents(Recents sysui); - - /** Inject into ScreenDecorations. */ - @Binds - @IntoMap - @ClassKey(ScreenDecorations.class) - public abstract CoreStartable bindScreenDecorations(ScreenDecorations sysui); - - /** Inject into ShortcutKeyDispatcher. */ - @Binds - @IntoMap - @ClassKey(ShortcutKeyDispatcher.class) - public abstract CoreStartable bindsShortcutKeyDispatcher(ShortcutKeyDispatcher sysui); - - /** Inject into SliceBroadcastRelayHandler. */ - @Binds - @IntoMap - @ClassKey(SliceBroadcastRelayHandler.class) - public abstract CoreStartable bindSliceBroadcastRelayHandler(SliceBroadcastRelayHandler sysui); - - /** Inject into StatusBar. */ - @Binds - @IntoMap - @ClassKey(StatusBar.class) - public abstract CoreStartable bindsStatusBar(StatusBar sysui); - - /** Inject into SystemActions. */ - @Binds - @IntoMap - @ClassKey(SystemActions.class) - public abstract CoreStartable bindSystemActions(SystemActions sysui); - - /** Inject into ThemeOverlayController. */ - @Binds - @IntoMap - @ClassKey(ThemeOverlayController.class) - public abstract CoreStartable bindThemeOverlayController(ThemeOverlayController sysui); - - /** Inject into ToastUI. */ - @Binds - @IntoMap - @ClassKey(ToastUI.class) - public abstract CoreStartable bindToastUI(ToastUI service); - - /** Inject into TvStatusBar. */ - @Binds - @IntoMap - @ClassKey(TvStatusBar.class) - public abstract CoreStartable bindsTvStatusBar(TvStatusBar sysui); - - /** Inject into TvNotificationPanel. */ - @Binds - @IntoMap - @ClassKey(TvNotificationPanel.class) - public abstract CoreStartable bindsTvNotificationPanel(TvNotificationPanel sysui); - - /** Inject into TvOngoingPrivacyChip. */ - @Binds - @IntoMap - @ClassKey(TvOngoingPrivacyChip.class) - public abstract CoreStartable bindsTvOngoingPrivacyChip(TvOngoingPrivacyChip sysui); - - /** Inject into VolumeUI. */ - @Binds - @IntoMap - @ClassKey(VolumeUI.class) - public abstract CoreStartable bindVolumeUI(VolumeUI sysui); - - /** Inject into WindowMagnification. */ - @Binds - @IntoMap - @ClassKey(WindowMagnification.class) - public abstract CoreStartable bindWindowMagnification(WindowMagnification sysui); - - /** Inject into WMShell. */ - @Binds - @IntoMap - @ClassKey(WMShell.class) - public abstract CoreStartable bindWMShell(WMShell sysui); - - /** Inject into HomeSoundEffectController. */ - @Binds - @IntoMap - @ClassKey(HomeSoundEffectController.class) - public abstract CoreStartable bindHomeSoundEffectController(HomeSoundEffectController sysui); - - /** Inject into DreamOverlay. */ - @Binds - @IntoMap - @ClassKey(DreamOverlayRegistrant.class) - public abstract CoreStartable bindDreamOverlayRegistrant( - DreamOverlayRegistrant dreamOverlayRegistrant); - - /** Inject into SmartSpaceComplication.Registrant */ - @Binds - @IntoMap - @ClassKey(SmartSpaceComplication.Registrant.class) - public abstract CoreStartable bindSmartSpaceComplicationRegistrant( - SmartSpaceComplication.Registrant registrant); - - /** Inject into MediaDreamSentinel. */ - @Binds - @IntoMap - @ClassKey(MediaDreamSentinel.class) - public abstract CoreStartable bindMediaDreamSentinel( - MediaDreamSentinel sentinel); - - /** Inject into DreamClockTimeComplication.Registrant */ - @Binds - @IntoMap - @ClassKey(DreamClockTimeComplication.Registrant.class) - public abstract CoreStartable bindDreamClockTimeComplicationRegistrant( - DreamClockTimeComplication.Registrant registrant); - - /** Inject into DreamClockDateComplication.Registrant */ - @Binds - @IntoMap - @ClassKey(DreamClockDateComplication.Registrant.class) - public abstract CoreStartable bindDreamClockDateComplicationRegistrant( - DreamClockDateComplication.Registrant registrant); - - /** Inject into DreamWeatherComplication.Registrant */ - @Binds - @IntoMap - @ClassKey(DreamWeatherComplication.Registrant.class) - public abstract CoreStartable bindDreamWeatherComplicationRegistrant( - DreamWeatherComplication.Registrant registrant); } diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUICoreStartableModule.kt b/packages/SystemUI/src/com/android/systemui/dagger/SystemUICoreStartableModule.kt new file mode 100644 index 0000000000000..1fd59ac8403aa --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUICoreStartableModule.kt @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2021 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.keyguard.KeyguardBiometricLockoutLogger +import com.android.systemui.CoreStartable +import com.android.systemui.LatencyTester +import com.android.systemui.ScreenDecorations +import com.android.systemui.SliceBroadcastRelayHandler +import com.android.systemui.accessibility.SystemActions +import com.android.systemui.accessibility.WindowMagnification +import com.android.systemui.biometrics.AuthController +import com.android.systemui.clipboardoverlay.ClipboardListener +import com.android.systemui.dagger.qualifiers.AdditionalStartable +import com.android.systemui.dagger.qualifiers.PerUser +import com.android.systemui.dreams.DreamOverlayRegistrant +import com.android.systemui.globalactions.GlobalActionsComponent +import com.android.systemui.keyboard.KeyboardUI +import com.android.systemui.keyguard.KeyguardViewMediator +import com.android.systemui.log.SessionTracker +import com.android.systemui.media.RingtonePlayer +import com.android.systemui.power.PowerUI +import com.android.systemui.recents.Recents +import com.android.systemui.shortcut.ShortcutKeyDispatcher +import com.android.systemui.statusbar.notification.InstantAppNotifier +import com.android.systemui.theme.ThemeOverlayController +import com.android.systemui.toast.ToastUI +import com.android.systemui.usb.StorageNotification +import com.android.systemui.util.NotificationChannels +import com.android.systemui.util.leak.GarbageMonitor +import com.android.systemui.volume.VolumeUI +import com.android.systemui.wmshell.WMShell +import dagger.Binds +import dagger.Module +import dagger.multibindings.ClassKey +import dagger.multibindings.IntoMap + +/** + * Collection of {@link CoreStartable}s that should be run on AOSP. + */ +@Module +abstract class SystemUICoreStartableModule { + /** Inject into AuthController. */ + @Binds + @IntoMap + @ClassKey(AuthController::class) + abstract fun bindAuthController(service: AuthController): CoreStartable + + /** Inject into ClipboardListener. */ + @Binds + @IntoMap + @ClassKey(ClipboardListener::class) + abstract fun bindClipboardListener(sysui: ClipboardListener): CoreStartable + + /** Inject into GarbageMonitor.Service. */ + @Binds + @IntoMap + @ClassKey(GarbageMonitor::class) + abstract fun bindGarbageMonitorService(sysui: GarbageMonitor.Service): CoreStartable + + /** Inject into GlobalActionsComponent. */ + @Binds + @IntoMap + @ClassKey(GlobalActionsComponent::class) + abstract fun bindGlobalActionsComponent(sysui: GlobalActionsComponent): CoreStartable + + /** Inject into InstantAppNotifier. */ + @Binds + @IntoMap + @ClassKey(InstantAppNotifier::class) + abstract fun bindInstantAppNotifier(sysui: InstantAppNotifier): CoreStartable + + /** Inject into KeyboardUI. */ + @Binds + @IntoMap + @ClassKey(KeyboardUI::class) + abstract fun bindKeyboardUI(sysui: KeyboardUI): CoreStartable + + /** Inject into KeyguardBiometricLockoutLogger */ + @Binds + @IntoMap + @ClassKey(KeyguardBiometricLockoutLogger::class) + abstract fun bindKeyguardBiometricLockoutLogger( + sysui: KeyguardBiometricLockoutLogger + ): CoreStartable + + /** Inject into KeyguardViewMediator. */ + @Binds + @IntoMap + @ClassKey(KeyguardViewMediator::class) + abstract fun bindKeyguardViewMediator(sysui: KeyguardViewMediator): CoreStartable + + /** Inject into LatencyTests. */ + @Binds + @IntoMap + @ClassKey(LatencyTester::class) + abstract fun bindLatencyTester(sysui: LatencyTester): CoreStartable + + /** Inject into NotificationChannels. */ + @Binds + @IntoMap + @ClassKey(NotificationChannels::class) + @PerUser + abstract fun bindNotificationChannels(sysui: NotificationChannels): CoreStartable + + /** Inject into PowerUI. */ + @Binds + @IntoMap + @ClassKey(PowerUI::class) + abstract fun bindPowerUI(sysui: PowerUI): CoreStartable + + /** Inject into Recents. */ + @Binds + @IntoMap + @ClassKey(Recents::class) + abstract fun bindRecents(sysui: Recents): CoreStartable + + /** Inject into RingtonePlayer. */ + @Binds + @IntoMap + @ClassKey(RingtonePlayer::class) + abstract fun bind(sysui: RingtonePlayer): CoreStartable + + /** Inject into ScreenDecorations. */ + @Binds + @IntoMap + @ClassKey(ScreenDecorations::class) + abstract fun bindScreenDecorations(sysui: ScreenDecorations): CoreStartable + + /** Inject into SessionTracker. */ + @Binds + @IntoMap + @ClassKey(SessionTracker::class) + abstract fun bindSessionTracker(service: SessionTracker): CoreStartable + + /** Inject into ShortcutKeyDispatcher. */ + @Binds + @IntoMap + @ClassKey(ShortcutKeyDispatcher::class) + abstract fun bindShortcutKeyDispatcher(sysui: ShortcutKeyDispatcher): CoreStartable + + /** Inject into SliceBroadcastRelayHandler. */ + @Binds + @IntoMap + @ClassKey(SliceBroadcastRelayHandler::class) + abstract fun bindSliceBroadcastRelayHandler(sysui: SliceBroadcastRelayHandler): CoreStartable + + /** Inject into StorageNotification. */ + @Binds + @IntoMap + @ClassKey(StorageNotification::class) + abstract fun bindStorageNotification(sysui: StorageNotification): CoreStartable + + /** Inject into SystemActions. */ + @Binds + @IntoMap + @ClassKey(SystemActions::class) + abstract fun bindSystemActions(sysui: SystemActions): CoreStartable + + /** Inject into ThemeOverlayController. */ + @Binds + @IntoMap + @ClassKey(ThemeOverlayController::class) + abstract fun bindThemeOverlayController(sysui: ThemeOverlayController): CoreStartable + + /** Inject into ToastUI. */ + @Binds + @IntoMap + @ClassKey(ToastUI::class) + abstract fun bindToastUI(service: ToastUI): CoreStartable + + /** Inject into VolumeUI. */ + @Binds + @IntoMap + @ClassKey(VolumeUI::class) + abstract fun bindVolumeUI(sysui: VolumeUI): CoreStartable + + /** Inject into WindowMagnification. */ + @Binds + @IntoMap + @ClassKey(WindowMagnification::class) + abstract fun bindWindowMagnification(sysui: WindowMagnification): CoreStartable + + /** Inject into WMShell. */ + @Binds + @IntoMap + @ClassKey(WMShell::class) + abstract fun bindWMShell(sysui: WMShell): CoreStartable + + /** Inject into DreamOverlay. */ + @Binds + @IntoMap + @ClassKey(DreamOverlayRegistrant::class) + @AdditionalStartable + abstract fun bindDreamOverlayRegistrant( + dreamOverlayRegistrant: DreamOverlayRegistrant + ): CoreStartable +} \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIDefaultModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIDefaultModule.java index a178738696918..a4da6b422bde8 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIDefaultModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIDefaultModule.java @@ -48,6 +48,7 @@ import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.NotificationLockscreenUserManager; import com.android.systemui.statusbar.NotificationLockscreenUserManagerImpl; import com.android.systemui.statusbar.NotificationShadeWindowController; +import com.android.systemui.statusbar.dagger.StartStatusBarModule; import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.provider.VisualStabilityProvider; import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager; @@ -86,6 +87,7 @@ import dagger.Provides; MediaModule.class, PowerModule.class, QSModule.class, + StartStatusBarModule.class, VolumeModule.class }) public abstract class SystemUIDefaultModule { diff --git a/packages/SystemUI/src/com/android/systemui/dagger/qualifiers/AdditionalStartable.java b/packages/SystemUI/src/com/android/systemui/dagger/qualifiers/AdditionalStartable.java new file mode 100644 index 0000000000000..9247ce3eabdf8 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/dagger/qualifiers/AdditionalStartable.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2019 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.qualifiers; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import javax.inject.Qualifier; + +@Qualifier +@Documented +@Retention(RUNTIME) +public @interface AdditionalStartable { +} diff --git a/packages/SystemUI/src/com/android/systemui/dagger/qualifiers/PerUser.java b/packages/SystemUI/src/com/android/systemui/dagger/qualifiers/PerUser.java new file mode 100644 index 0000000000000..f6d5ece74ae74 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/dagger/qualifiers/PerUser.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2019 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.qualifiers; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import javax.inject.Qualifier; + +@Qualifier +@Documented +@Retention(RUNTIME) +public @interface PerUser { +} diff --git a/packages/SystemUI/src/com/android/systemui/dump/DumpHandler.kt b/packages/SystemUI/src/com/android/systemui/dump/DumpHandler.kt index fa951fa09ef65..b5c475f1e4b7c 100644 --- a/packages/SystemUI/src/com/android/systemui/dump/DumpHandler.kt +++ b/packages/SystemUI/src/com/android/systemui/dump/DumpHandler.kt @@ -19,6 +19,7 @@ package com.android.systemui.dump import android.content.Context import android.os.SystemClock import android.os.Trace +import com.android.systemui.CoreStartable import com.android.systemui.R import com.android.systemui.dump.DumpHandler.Companion.PRIORITY_ARG_CRITICAL import com.android.systemui.dump.DumpHandler.Companion.PRIORITY_ARG_HIGH @@ -27,6 +28,7 @@ import com.android.systemui.log.LogBuffer import java.io.FileDescriptor import java.io.PrintWriter import javax.inject.Inject +import javax.inject.Provider /** * Oversees SystemUI's output during bug reports (and dumpsys in general) @@ -80,7 +82,8 @@ import javax.inject.Inject class DumpHandler @Inject constructor( private val context: Context, private val dumpManager: DumpManager, - private val logBufferEulogizer: LogBufferEulogizer + private val logBufferEulogizer: LogBufferEulogizer, + private val startables: MutableMap, Provider> ) { /** * Dump the diagnostics! Behavior can be controlled via [args]. @@ -173,12 +176,21 @@ class DumpHandler @Inject constructor( pw.println("SystemUiServiceComponents configuration:") pw.print("vendor component: ") pw.println(context.resources.getString(R.string.config_systemUIVendorServiceComponent)) - dumpServiceList(pw, "global", R.array.config_systemUIServiceComponents) + val services: Array = startables.keys.stream() + .map({ cls -> cls!!.simpleName }) + .toArray() as Array + val additionalServices = context.resources.getStringArray( + R.array.config_additionalSystemUIServiceComponents) + dumpServiceList(pw, "global", services + additionalServices) dumpServiceList(pw, "per-user", R.array.config_systemUIServiceComponentsPerUser) } private fun dumpServiceList(pw: PrintWriter, type: String, resId: Int) { - val services: Array? = context.resources.getStringArray(resId) + val services: Array = context.resources.getStringArray(resId) + dumpServiceList(pw, type, services) + } + + private fun dumpServiceList(pw: PrintWriter, type: String, services: Array?) { pw.print(type) pw.print(": ") if (services == null) { diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java b/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java index 1c0b104b69451..6f7e73fd51902 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java +++ b/packages/SystemUI/src/com/android/systemui/keyboard/KeyboardUI.java @@ -52,6 +52,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.systemui.CoreStartable; import com.android.systemui.Dependency; import com.android.systemui.R; +import com.android.systemui.dagger.SysUISingleton; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -60,6 +61,10 @@ import java.util.Collection; import java.util.List; import java.util.Set; +import javax.inject.Inject; + +/** */ +@SysUISingleton public class KeyboardUI extends CoreStartable implements InputManager.OnTabletModeChangedListener { private static final String TAG = "KeyboardUI"; private static final boolean DEBUG = false; @@ -117,6 +122,7 @@ public class KeyboardUI extends CoreStartable implements InputManager.OnTabletMo private int mState; + @Inject public KeyboardUI(Context context) { super(context); } diff --git a/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java b/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java index ae5f9b63fb3d2..4e35d16457e8b 100644 --- a/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java +++ b/packages/SystemUI/src/com/android/systemui/media/RingtonePlayer.java @@ -38,16 +38,20 @@ import android.provider.MediaStore; import android.util.Log; import com.android.systemui.CoreStartable; +import com.android.systemui.dagger.SysUISingleton; import java.io.FileDescriptor; import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; +import javax.inject.Inject; + /** * Service that offers to play ringtones by {@link Uri}, since our process has * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}. */ +@SysUISingleton public class RingtonePlayer extends CoreStartable { private static final String TAG = "RingtonePlayer"; private static final boolean LOGD = false; @@ -59,6 +63,7 @@ public class RingtonePlayer extends CoreStartable { private final NotificationPlayer mAsyncPlayer = new NotificationPlayer(TAG); private final HashMap mClients = new HashMap(); + @Inject public RingtonePlayer(Context context) { super(context); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/dagger/StartStatusBarModule.kt b/packages/SystemUI/src/com/android/systemui/statusbar/dagger/StartStatusBarModule.kt new file mode 100644 index 0000000000000..46c1abb859b3f --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/dagger/StartStatusBarModule.kt @@ -0,0 +1,33 @@ +/* + * 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.statusbar.dagger + +import com.android.systemui.CoreStartable +import com.android.systemui.statusbar.phone.StatusBar +import dagger.Binds +import dagger.Module +import dagger.multibindings.ClassKey +import dagger.multibindings.IntoMap + +@Module +interface StartStatusBarModule { + /** Start the StatusBar */ + @Binds + @IntoMap + @ClassKey(StatusBar::class) + abstract fun bindsStatusBar(statusBar: StatusBar): CoreStartable +} \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java index e739b9f056f01..e3ebef99f45f9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java @@ -204,7 +204,7 @@ public interface NotificationsModule { static VisualStabilityManager provideVisualStabilityManager( NotificationEntryManager notificationEntryManager, VisualStabilityProvider visualStabilityProvider, - Handler handler, + @Main Handler handler, StatusBarStateController statusBarStateController, WakefulnessLifecycle wakefulnessLifecycle, DumpManager dumpManager) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java index 565b2d333d4ce..95a2a6e75e7a8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java @@ -41,6 +41,7 @@ import com.android.keyguard.ViewMediatorCallback; import com.android.keyguard.dagger.KeyguardBouncerComponent; import com.android.systemui.DejankUtils; import com.android.systemui.classifier.FalsingCollector; +import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.keyguard.DismissCallbackRegistry; import com.android.systemui.shared.system.SysUiStatsLog; import com.android.systemui.statusbar.policy.KeyguardStateController; @@ -115,7 +116,7 @@ public class KeyguardBouncer { BouncerExpansionCallback expansionCallback, KeyguardStateController keyguardStateController, KeyguardUpdateMonitor keyguardUpdateMonitor, - KeyguardBypassController keyguardBypassController, Handler handler, + KeyguardBypassController keyguardBypassController, @Main Handler handler, KeyguardSecurityModel keyguardSecurityModel, KeyguardBouncerComponent.Factory keyguardBouncerComponentFactory) { mContext = context; @@ -647,7 +648,7 @@ public class KeyguardBouncer { DismissCallbackRegistry dismissCallbackRegistry, FalsingCollector falsingCollector, KeyguardStateController keyguardStateController, KeyguardUpdateMonitor keyguardUpdateMonitor, - KeyguardBypassController keyguardBypassController, Handler handler, + KeyguardBypassController keyguardBypassController, @Main Handler handler, KeyguardSecurityModel keyguardSecurityModel, KeyguardBouncerComponent.Factory keyguardBouncerComponentFactory) { mContext = context; diff --git a/packages/SystemUI/src/com/android/systemui/tv/TVSystemUICoreStartableModule.kt b/packages/SystemUI/src/com/android/systemui/tv/TVSystemUICoreStartableModule.kt new file mode 100644 index 0000000000000..3b20b1bd4f2d9 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/tv/TVSystemUICoreStartableModule.kt @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2021 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.tv + +import com.android.systemui.CoreStartable +import com.android.systemui.SliceBroadcastRelayHandler +import com.android.systemui.accessibility.WindowMagnification +import com.android.systemui.dagger.qualifiers.AdditionalStartable +import com.android.systemui.dagger.qualifiers.PerUser +import com.android.systemui.globalactions.GlobalActionsComponent +import com.android.systemui.keyboard.KeyboardUI +import com.android.systemui.media.RingtonePlayer +import com.android.systemui.media.systemsounds.HomeSoundEffectController +import com.android.systemui.power.PowerUI +import com.android.systemui.privacy.television.TvOngoingPrivacyChip +import com.android.systemui.shortcut.ShortcutKeyDispatcher +import com.android.systemui.statusbar.notification.InstantAppNotifier +import com.android.systemui.statusbar.tv.TvStatusBar +import com.android.systemui.statusbar.tv.VpnStatusObserver +import com.android.systemui.statusbar.tv.notifications.TvNotificationHandler +import com.android.systemui.statusbar.tv.notifications.TvNotificationPanel +import com.android.systemui.toast.ToastUI +import com.android.systemui.usb.StorageNotification +import com.android.systemui.util.NotificationChannels +import com.android.systemui.volume.VolumeUI +import com.android.systemui.wmshell.WMShell +import dagger.Binds +import dagger.Module +import dagger.multibindings.ClassKey +import dagger.multibindings.IntoMap +import dagger.multibindings.Multibinds + +/** + * Collection of {@link CoreStartable}s that should be run on TV. + */ +@Module +abstract class TVSystemUICoreStartableModule { + /** Ensure that AdditionalStartables exists. */ + @Multibinds + @AdditionalStartable + abstract fun bindEmptyAdditionalStartables(): Map, CoreStartable> + + /** Inject into GlobalActionsComponent. */ + @Binds + @IntoMap + @ClassKey(GlobalActionsComponent::class) + abstract fun bindGlobalActionsComponent(sysui: GlobalActionsComponent): CoreStartable + + /** Inject into HomeSoundEffectController. */ + @Binds + @IntoMap + @ClassKey(HomeSoundEffectController::class) + abstract fun bindHomeSoundEffectController(sysui: HomeSoundEffectController): CoreStartable + + /** Inject into InstantAppNotifier. */ + @Binds + @IntoMap + @ClassKey(InstantAppNotifier::class) + abstract fun bindInstantAppNotifier(sysui: InstantAppNotifier): CoreStartable + + /** Inject into KeyboardUI. */ + @Binds + @IntoMap + @ClassKey(KeyboardUI::class) + abstract fun bindKeyboardUI(sysui: KeyboardUI): CoreStartable + + /** Inject into NotificationChannels. */ + @Binds + @IntoMap + @ClassKey(NotificationChannels::class) + @PerUser + abstract fun bindNotificationChannels(sysui: NotificationChannels): CoreStartable + + /** Inject into PowerUI. */ + @Binds + @IntoMap + @ClassKey(PowerUI::class) + abstract fun bindPowerUI(sysui: PowerUI): CoreStartable + + /** Inject into RingtonePlayer. */ + @Binds + @IntoMap + @ClassKey(RingtonePlayer::class) + abstract fun bind(sysui: RingtonePlayer): CoreStartable + + /** Inject into ShortcutKeyDispatcher. */ + @Binds + @IntoMap + @ClassKey(ShortcutKeyDispatcher::class) + abstract fun bindShortcutKeyDispatcher(sysui: ShortcutKeyDispatcher): CoreStartable + + /** Inject into SliceBroadcastRelayHandler. */ + @Binds + @IntoMap + @ClassKey(SliceBroadcastRelayHandler::class) + abstract fun bindSliceBroadcastRelayHandler(sysui: SliceBroadcastRelayHandler): CoreStartable + + /** Inject into StorageNotification. */ + @Binds + @IntoMap + @ClassKey(StorageNotification::class) + abstract fun bindStorageNotification(sysui: StorageNotification): CoreStartable + + /** Inject into ToastUI. */ + @Binds + @IntoMap + @ClassKey(ToastUI::class) + abstract fun bindToastUI(service: ToastUI): CoreStartable + + /** Inject into TvNotificationHandler. */ + @Binds + @IntoMap + @ClassKey(TvNotificationHandler::class) + abstract fun bindTvNotificationHandler(sysui: TvNotificationHandler): CoreStartable + + /** Inject into TvNotificationPanel. */ + @Binds + @IntoMap + @ClassKey(TvNotificationPanel::class) + abstract fun bindTvNotificationPanel(sysui: TvNotificationPanel): CoreStartable + + /** Inject into TvOngoingPrivacyChip. */ + @Binds + @IntoMap + @ClassKey(TvOngoingPrivacyChip::class) + abstract fun bindTvOngoingPrivacyChip(sysui: TvOngoingPrivacyChip): CoreStartable + + /** Inject into TvStatusBar. */ + @Binds + @IntoMap + @ClassKey(TvStatusBar::class) + abstract fun bindTvStatusBar(sysui: TvStatusBar): CoreStartable + + /** Inject into VolumeUI. */ + @Binds + @IntoMap + @ClassKey(VolumeUI::class) + abstract fun bindVolumeUI(sysui: VolumeUI): CoreStartable + + /** Inject into VpnStatusObserver. */ + @Binds + @IntoMap + @ClassKey(VpnStatusObserver::class) + abstract fun bindVpnStatusObserver(sysui: VpnStatusObserver): CoreStartable + + /** Inject into WindowMagnification. */ + @Binds + @IntoMap + @ClassKey(WindowMagnification::class) + abstract fun bindWindowMagnification(sysui: WindowMagnification): CoreStartable + + /** Inject into WMShell. */ + @Binds + @IntoMap + @ClassKey(WMShell::class) + abstract fun bindWMShell(sysui: WMShell): CoreStartable +} \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/tv/TvSysUIComponent.java b/packages/SystemUI/src/com/android/systemui/tv/TvSysUIComponent.java index bef05ebb724e9..6fdce1ae4ec28 100644 --- a/packages/SystemUI/src/com/android/systemui/tv/TvSysUIComponent.java +++ b/packages/SystemUI/src/com/android/systemui/tv/TvSysUIComponent.java @@ -34,6 +34,7 @@ import dagger.Subcomponent; DependencyProvider.class, SystemUIBinder.class, SystemUIModule.class, + TVSystemUICoreStartableModule.class, TvSystemUIModule.class, TvSystemUIBinder.class}) public interface TvSysUIComponent extends SysUIComponent { diff --git a/packages/SystemUI/src/com/android/systemui/tv/TvSystemUIBinder.java b/packages/SystemUI/src/com/android/systemui/tv/TvSystemUIBinder.java index d0fb91c9342a1..23f37ec8dc691 100644 --- a/packages/SystemUI/src/com/android/systemui/tv/TvSystemUIBinder.java +++ b/packages/SystemUI/src/com/android/systemui/tv/TvSystemUIBinder.java @@ -16,28 +16,13 @@ package com.android.systemui.tv; -import com.android.systemui.CoreStartable; import com.android.systemui.dagger.GlobalRootComponent; -import com.android.systemui.statusbar.tv.VpnStatusObserver; -import com.android.systemui.statusbar.tv.notifications.TvNotificationHandler; import dagger.Binds; import dagger.Module; -import dagger.multibindings.ClassKey; -import dagger.multibindings.IntoMap; @Module interface TvSystemUIBinder { @Binds GlobalRootComponent bindGlobalRootComponent(TvGlobalRootComponent globalRootComponent); - - @Binds - @IntoMap - @ClassKey(TvNotificationHandler.class) - CoreStartable bindTvNotificationHandler(TvNotificationHandler systemui); - - @Binds - @IntoMap - @ClassKey(VpnStatusObserver.class) - CoreStartable bindVpnStatusObserver(VpnStatusObserver systemui); } diff --git a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java index cf361ec304e56..345fc99f8a547 100644 --- a/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java +++ b/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java @@ -46,10 +46,15 @@ import com.android.internal.R; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.systemui.CoreStartable; import com.android.systemui.SystemUIApplication; +import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.util.NotificationChannels; import java.util.List; +import javax.inject.Inject; + +/** */ +@SysUISingleton public class StorageNotification extends CoreStartable { private static final String TAG = "StorageNotification"; @@ -61,6 +66,7 @@ public class StorageNotification extends CoreStartable { private NotificationManager mNotificationManager; private StorageManager mStorageManager; + @Inject public StorageNotification(Context context) { super(context); } diff --git a/packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java b/packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java index ce7e4cf820816..76dfcb182e972 100644 --- a/packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java +++ b/packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java @@ -29,6 +29,9 @@ import com.android.wm.shell.pip.tv.TvPipNotificationController; import java.util.Arrays; +import javax.inject.Inject; + +// NOT Singleton. Started per-user. public class NotificationChannels extends CoreStartable { public static String ALERTS = "ALR"; public static String SCREENSHOTS_HEADSUP = "SCN_HEADSUP"; @@ -38,6 +41,7 @@ public class NotificationChannels extends CoreStartable { public static String TVPIP = TvPipNotificationController.NOTIFICATION_CHANNEL; // "TVPIP" public static String HINTS = "HNT"; + @Inject public NotificationChannels(Context context) { super(context); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/dump/DumpHandlerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/dump/DumpHandlerTest.kt index 9e67eda576070..57fbbc95efbab 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dump/DumpHandlerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/dump/DumpHandlerTest.kt @@ -62,7 +62,7 @@ class DumpHandlerTest : SysuiTestCase() { fun setUp() { MockitoAnnotations.initMocks(this) - dumpHandler = DumpHandler(mContext, dumpManager, logBufferEulogizer) + dumpHandler = DumpHandler(mContext, dumpManager, logBufferEulogizer, mutableMapOf()) } @Test