From 3bbe01239730a77e92f67fbf96cee74276ebaac8 Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Wed, 7 Jun 2023 20:54:43 +0000 Subject: [PATCH] [Central Surfaces] Make NotificationShelf & classes singletons. Bug: 277762009 Test: verify notif shelf still works, across restarts and display size/font changes Test: verify notif shelf still works with NOTIFICATION_SHELF_REFACTOR flag on Test: atest CentralSurfacesImplTest Change-Id: Iabb1d67f167d3134d08a341aa3865b6fa64aeb8b --- .../com/android/systemui/shade/ShadeModule.kt | 31 +++++++++++++ .../interactor/NotificationShelfInteractor.kt | 4 +- .../viewbinder/NotificationShelfViewBinder.kt | 4 +- .../statusbar/phone/CentralSurfacesImpl.java | 5 ++- .../dagger/CentralSurfacesComponent.java | 4 -- .../phone/dagger/StatusBarViewModule.java | 45 ------------------- .../phone/CentralSurfacesImplTest.java | 3 ++ 7 files changed, 41 insertions(+), 55 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt index 1752ff6d531f5..9bdfd99b432cf 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt @@ -37,6 +37,10 @@ import com.android.systemui.privacy.OngoingPrivacyChip import com.android.systemui.scene.ui.view.WindowRootView import com.android.systemui.settings.UserTracker import com.android.systemui.statusbar.LightRevealScrim +import com.android.systemui.statusbar.NotificationShelf +import com.android.systemui.statusbar.NotificationShelfController +import com.android.systemui.statusbar.notification.row.dagger.NotificationShelfComponent +import com.android.systemui.statusbar.notification.shelf.ui.viewbinder.NotificationShelfViewBinderWrapperControllerImpl import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout import com.android.systemui.statusbar.phone.StatusIconContainer import com.android.systemui.statusbar.phone.TapAgainView @@ -49,6 +53,7 @@ import dagger.Provides import dagger.multibindings.ClassKey import dagger.multibindings.IntoMap import javax.inject.Named +import javax.inject.Provider /** Module for classes related to the notification shade. */ @Module @@ -102,6 +107,32 @@ abstract class ShadeModule { return notificationShadeWindowView.findViewById(R.id.notification_stack_scroller) } + @Provides + @SysUISingleton + fun providesNotificationShelfController( + featureFlags: FeatureFlags, + newImpl: Provider, + notificationShelfComponentBuilder: NotificationShelfComponent.Builder, + layoutInflater: LayoutInflater, + notificationStackScrollLayout: NotificationStackScrollLayout, + ): NotificationShelfController { + return if (featureFlags.isEnabled(Flags.NOTIFICATION_SHELF_REFACTOR)) { + newImpl.get() + } else { + val shelfView = + layoutInflater.inflate( + R.layout.status_bar_notification_shelf, + notificationStackScrollLayout, + false + ) as NotificationShelf + val component = + notificationShelfComponentBuilder.notificationShelf(shelfView).build() + val notificationShelfController = component.notificationShelfController + notificationShelfController.init() + notificationShelfController + } + } + // TODO(b/277762009): Only allow this view's controller to inject the view. See above. @Provides @SysUISingleton diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/shelf/domain/interactor/NotificationShelfInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/shelf/domain/interactor/NotificationShelfInteractor.kt index 014406fe49f99..69484b06c776a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/shelf/domain/interactor/NotificationShelfInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/shelf/domain/interactor/NotificationShelfInteractor.kt @@ -17,19 +17,19 @@ package com.android.systemui.statusbar.notification.shelf.domain.interactor import android.os.PowerManager +import com.android.systemui.dagger.SysUISingleton import com.android.systemui.keyguard.data.repository.DeviceEntryFaceAuthRepository import com.android.systemui.keyguard.data.repository.KeyguardRepository import com.android.systemui.statusbar.LockscreenShadeTransitionController import com.android.systemui.statusbar.NotificationShelf import com.android.systemui.statusbar.phone.CentralSurfaces -import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent import com.android.systemui.util.time.SystemClock import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine /** Interactor for the [NotificationShelf] */ -@CentralSurfacesComponent.CentralSurfacesScope +@SysUISingleton class NotificationShelfInteractor @Inject constructor( diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/shelf/ui/viewbinder/NotificationShelfViewBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/shelf/ui/viewbinder/NotificationShelfViewBinder.kt index 12956ab9498a4..252073825bced 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/shelf/ui/viewbinder/NotificationShelfViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/shelf/ui/viewbinder/NotificationShelfViewBinder.kt @@ -19,6 +19,7 @@ package com.android.systemui.statusbar.notification.shelf.ui.viewbinder import android.view.View import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle +import com.android.systemui.dagger.SysUISingleton import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.lifecycle.repeatWhenAttached @@ -32,7 +33,6 @@ import com.android.systemui.statusbar.notification.stack.AmbientState import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController import com.android.systemui.statusbar.phone.NotificationIconAreaController import com.android.systemui.statusbar.phone.NotificationIconContainer -import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent.CentralSurfacesScope import javax.inject.Inject import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.launch @@ -43,7 +43,7 @@ import kotlinx.coroutines.launch * [NotificationShelfController] interface. Once the [LegacyNotificationShelfControllerImpl] is * removed, this class can go away and the ViewBinder can be used directly. */ -@CentralSurfacesScope +@SysUISingleton class NotificationShelfViewBinderWrapperControllerImpl @Inject constructor() : NotificationShelfController { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java index 81048d60c6d9a..5e2806c7c129f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java @@ -744,6 +744,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { Lazy assistManagerLazy, ConfigurationController configurationController, NotificationShadeWindowController notificationShadeWindowController, + NotificationShelfController notificationShelfController, DozeParameters dozeParameters, ScrimController scrimController, Lazy lockscreenWallpaperLazy, @@ -840,6 +841,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { mAssistManagerLazy = assistManagerLazy; mConfigurationController = configurationController; mNotificationShadeWindowController = notificationShadeWindowController; + mNotificationShelfController = notificationShelfController; mDozeServiceHost = dozeServiceHost; mPowerManager = powerManager; mDozeParameters = dozeParameters; @@ -1651,7 +1653,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { mNotifListContainer = mCentralSurfacesComponent.getNotificationListContainer(); mPresenter = mCentralSurfacesComponent.getNotificationPresenter(); mNotificationActivityStarter = mCentralSurfacesComponent.getNotificationActivityStarter(); - mNotificationShelfController = mCentralSurfacesComponent.getNotificationShelfController(); mHeadsUpManager.addListener(mCentralSurfacesComponent.getStatusBarHeadsUpChangeListener()); @@ -3408,7 +3409,7 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { protected Display mDisplay; private int mDisplayId; - protected NotificationShelfController mNotificationShelfController; + private final NotificationShelfController mNotificationShelfController; private final Lazy mAssistManagerLazy; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/CentralSurfacesComponent.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/CentralSurfacesComponent.java index 158f96123d92c..4878459075908 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/CentralSurfacesComponent.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/CentralSurfacesComponent.java @@ -27,7 +27,6 @@ import com.android.systemui.shade.NotificationShadeWindowViewController; import com.android.systemui.shade.QuickSettingsController; import com.android.systemui.shade.ShadeHeaderController; import com.android.systemui.statusbar.NotificationPresenter; -import com.android.systemui.statusbar.NotificationShelfController; import com.android.systemui.statusbar.notification.NotificationActivityStarter; import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinderImpl; import com.android.systemui.statusbar.notification.stack.NotificationListContainer; @@ -89,9 +88,6 @@ public interface CentralSurfacesComponent { */ NotificationShadeWindowView getNotificationShadeWindowView(); - /** */ - NotificationShelfController getNotificationShelfController(); - /** */ NotificationStackScrollLayoutController getNotificationStackScrollLayoutController(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarViewModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarViewModule.java index 4ccbc5a12ea06..5508c9e1aa21a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarViewModule.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarViewModule.java @@ -23,7 +23,6 @@ import com.android.systemui.R; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dump.DumpManager; import com.android.systemui.flags.FeatureFlags; -import com.android.systemui.flags.Flags; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.shade.NotificationPanelView; import com.android.systemui.shade.NotificationPanelViewController; @@ -32,15 +31,9 @@ import com.android.systemui.shade.NotificationsQuickSettingsContainer; import com.android.systemui.shade.ShadeExpansionStateManager; import com.android.systemui.shade.ShadeViewController; import com.android.systemui.statusbar.CommandQueue; -import com.android.systemui.statusbar.LegacyNotificationShelfControllerImpl; -import com.android.systemui.statusbar.NotificationShelf; -import com.android.systemui.statusbar.NotificationShelfController; import com.android.systemui.statusbar.OperatorNameViewController; import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler; -import com.android.systemui.statusbar.notification.row.dagger.NotificationShelfComponent; import com.android.systemui.statusbar.notification.row.ui.viewmodel.ActivatableNotificationViewModelModule; -import com.android.systemui.statusbar.notification.shelf.ui.viewbinder.NotificationShelfViewBinderWrapperControllerImpl; -import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationListViewModelModule; import com.android.systemui.statusbar.phone.KeyguardBottomAreaView; import com.android.systemui.statusbar.phone.NotificationIconAreaController; @@ -68,7 +61,6 @@ import dagger.multibindings.IntoSet; import java.util.concurrent.Executor; import javax.inject.Named; -import javax.inject.Provider; @Module(subcomponents = StatusBarFragmentComponent.class, includes = { @@ -79,43 +71,6 @@ public abstract class StatusBarViewModule { public static final String STATUS_BAR_FRAGMENT = "status_bar_fragment"; - /** */ - @Provides - @CentralSurfacesComponent.CentralSurfacesScope - public static NotificationShelf providesNotificationShelf(LayoutInflater layoutInflater, - NotificationStackScrollLayout notificationStackScrollLayout) { - NotificationShelf view = (NotificationShelf) layoutInflater.inflate( - R.layout.status_bar_notification_shelf, notificationStackScrollLayout, false); - - if (view == null) { - throw new IllegalStateException( - "R.layout.status_bar_notification_shelf could not be properly inflated"); - } - return view; - } - - /** */ - @Provides - @CentralSurfacesComponent.CentralSurfacesScope - public static NotificationShelfController providesStatusBarWindowView( - FeatureFlags featureFlags, - Provider newImpl, - NotificationShelfComponent.Builder notificationShelfComponentBuilder, - NotificationShelf notificationShelf) { - if (featureFlags.isEnabled(Flags.NOTIFICATION_SHELF_REFACTOR)) { - return newImpl.get(); - } else { - NotificationShelfComponent component = notificationShelfComponentBuilder - .notificationShelf(notificationShelf) - .build(); - LegacyNotificationShelfControllerImpl notificationShelfController = - component.getNotificationShelfController(); - notificationShelfController.init(); - - return notificationShelfController; - } - } - /** */ @Binds @CentralSurfacesComponent.CentralSurfacesScope diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java index 5ed9a865de930..d3a9f62c5522b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/CentralSurfacesImplTest.java @@ -145,6 +145,7 @@ import com.android.systemui.statusbar.NotificationMediaManager; import com.android.systemui.statusbar.NotificationRemoteInputManager; import com.android.systemui.statusbar.NotificationShadeDepthController; import com.android.systemui.statusbar.NotificationShadeWindowController; +import com.android.systemui.statusbar.NotificationShelfController; import com.android.systemui.statusbar.OperatorNameViewController; import com.android.systemui.statusbar.PulseExpansionHandler; import com.android.systemui.statusbar.StatusBarState; @@ -273,6 +274,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase { @Mock private NotificationShadeWindowController mNotificationShadeWindowController; @Mock private NotificationIconAreaController mNotificationIconAreaController; @Mock private NotificationShadeWindowViewController mNotificationShadeWindowViewController; + @Mock private NotificationShelfController mNotificationShelfController; @Mock private DozeParameters mDozeParameters; @Mock private Lazy mLockscreenWallpaperLazy; @Mock private LockscreenWallpaper mLockscreenWallpaper; @@ -499,6 +501,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase { () -> mAssistManager, configurationController, mNotificationShadeWindowController, + mNotificationShelfController, mDozeParameters, mScrimController, mLockscreenWallpaperLazy,