[Central Surfaces] Make NotificationStackScrollLayout a singleton.

Bug: 277762009
Test: compiles; shade works
Test: atest NotificationStackScrollLayoutControllerTest
Change-Id: I79c72e38cc5c187cfe6fc08c8e4f5427d9407e83
This commit is contained in:
Caitlin Shkuratov
2023-04-17 15:21:06 +00:00
parent 1f774adcf4
commit 8816c72a14
5 changed files with 79 additions and 76 deletions

View File

@@ -1021,9 +1021,6 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
userAvatarContainer,
keyguardUserSwitcherView);
NotificationStackScrollLayout stackScrollLayout = mView.findViewById(
R.id.notification_stack_scroller);
mNotificationStackScrollLayoutController.attach(stackScrollLayout);
mNotificationStackScrollLayoutController.setOnHeightChangedListener(
new NsslHeightChangedListener());
mNotificationStackScrollLayoutController.setOnEmptySpaceClickListener(

View File

@@ -19,6 +19,7 @@ package com.android.systemui.shade
import android.view.LayoutInflater
import com.android.systemui.R
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout
import dagger.Module
import dagger.Provides
@@ -40,5 +41,14 @@ abstract class ShadeModule {
"R.layout.super_notification_shade could not be properly inflated"
)
}
// TODO(b/277762009): Only allow this view's controller to inject the view. See above.
@Provides
@SysUISingleton
fun providesNotificationStackScrollLayout(
notificationShadeWindowView: NotificationShadeWindowView,
): NotificationStackScrollLayout {
return notificationShadeWindowView.findViewById(R.id.notification_stack_scroller)
}
}
}

View File

@@ -627,6 +627,7 @@ public class NotificationStackScrollLayoutController {
@Inject
public NotificationStackScrollLayoutController(
NotificationStackScrollLayout view,
@Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress,
NotificationGutsManager notificationGutsManager,
NotificationVisibilityProvider visibilityProvider,
@@ -668,6 +669,7 @@ public class NotificationStackScrollLayoutController {
NotificationTargetsHelper notificationTargetsHelper,
SecureSettings secureSettings,
NotificationDismissibilityProvider dismissibilityProvider) {
mView = view;
mStackStateLogger = stackLogger;
mLogger = logger;
mAllowLongPress = allowLongPress;
@@ -711,10 +713,10 @@ public class NotificationStackScrollLayoutController {
mSecureSettings = secureSettings;
mDismissibilityProvider = dismissibilityProvider;
updateResources();
setUpView();
}
public void attach(NotificationStackScrollLayout view) {
mView = view;
private void setUpView() {
mView.setLogger(mStackStateLogger);
mView.setController(this);
mView.setLogger(mLogger);

View File

@@ -95,14 +95,6 @@ public abstract class StatusBarViewModule {
public static final String SHADE_HEADER = "large_screen_shade_header";
public static final String STATUS_BAR_FRAGMENT = "status_bar_fragment";
/** */
@Provides
@CentralSurfacesComponent.CentralSurfacesScope
public static NotificationStackScrollLayout providesNotificationStackScrollLayout(
NotificationShadeWindowView notificationShadeWindowView) {
return notificationShadeWindowView.findViewById(R.id.notification_stack_scroller);
}
/** */
@Provides
@CentralSurfacesComponent.CentralSurfacesScope

View File

@@ -152,67 +152,18 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
MockitoAnnotations.initMocks(this);
when(mNotificationSwipeHelperBuilder.build()).thenReturn(mNotificationSwipeHelper);
mController = new NotificationStackScrollLayoutController(
true,
mNotificationGutsManager,
mVisibilityProvider,
mHeadsUpManager,
mNotificationRoundnessManager,
mTunerService,
mDeviceProvisionedController,
mDynamicPrivacyController,
mConfigurationController,
mSysuiStatusBarStateController,
mKeyguardMediaController,
mKeyguardBypassController,
mZenModeController,
mNotificationLockscreenUserManager,
mMetricsLogger,
mDumpManager,
new FalsingCollectorFake(),
new FalsingManagerFake(),
mResources,
mNotificationSwipeHelperBuilder,
mCentralSurfaces,
mScrimController,
mGroupExpansionManager,
mSilentHeaderController,
mNotifPipeline,
mNotifPipelineFlags,
mNotifCollection,
mLockscreenShadeTransitionController,
mUiEventLogger,
mRemoteInputManager,
mVisibilityLocationProviderDelegator,
mSeenNotificationsProvider,
mShadeController,
mJankMonitor,
mStackLogger,
mLogger,
mNotificationStackSizeCalculator,
mFeatureFlags,
mNotificationTargetsHelper,
mSecureSettings,
mock(NotificationDismissibilityProvider.class)
);
when(mNotificationStackScrollLayout.isAttachedToWindow()).thenReturn(true);
}
@Test
public void testAttach_viewAlreadyAttached() {
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
verify(mConfigurationController).addCallback(
any(ConfigurationController.ConfigurationListener.class));
}
@Test
public void testAttach_viewAttachedAfterInit() {
when(mNotificationStackScrollLayout.isAttachedToWindow()).thenReturn(false);
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ false);
verify(mConfigurationController, never()).addCallback(
any(ConfigurationController.ConfigurationListener.class));
@@ -225,7 +176,8 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
@Test
public void testOnDensityOrFontScaleChanged_reInflatesFooterViews() {
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
mController.mConfigurationListener.onDensityOrFontScaleChanged();
verify(mNotificationStackScrollLayout).reinflateViews();
}
@@ -233,7 +185,7 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
@Test
public void testUpdateEmptyShadeView_notificationsVisible_zenHiding() {
when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(true);
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
setupShowEmptyShadeViewState(true);
reset(mNotificationStackScrollLayout);
@@ -253,7 +205,7 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
@Test
public void testUpdateEmptyShadeView_notificationsHidden_zenNotHiding() {
when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(false);
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
setupShowEmptyShadeViewState(true);
reset(mNotificationStackScrollLayout);
@@ -273,7 +225,8 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
@Test
public void testUpdateEmptyShadeView_splitShadeMode_alwaysShowEmptyView() {
when(mZenModeController.areNotificationsHiddenInShade()).thenReturn(false);
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
verify(mSysuiStatusBarStateController).addCallback(
mStateListenerArgumentCaptor.capture(), anyInt());
StatusBarStateController.StateListener stateListener =
@@ -299,11 +252,11 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
@Test
public void testOnUserChange_verifySensitiveProfile() {
when(mNotificationLockscreenUserManager.isAnyProfilePublicMode()).thenReturn(true);
initController(/* viewIsAttached= */ true);
ArgumentCaptor<UserChangedListener> userChangedCaptor = ArgumentCaptor
.forClass(UserChangedListener.class);
mController.attach(mNotificationStackScrollLayout);
verify(mNotificationLockscreenUserManager)
.addUserChangedListener(userChangedCaptor.capture());
reset(mNotificationStackScrollLayout);
@@ -317,7 +270,7 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
public void testOnStatePostChange_verifyIfProfileIsPublic() {
when(mNotificationLockscreenUserManager.isAnyProfilePublicMode()).thenReturn(true);
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
verify(mSysuiStatusBarStateController).addCallback(
mStateListenerArgumentCaptor.capture(), anyInt());
@@ -337,7 +290,7 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
ArgumentCaptor<OnMenuEventListener> onMenuEventListenerArgumentCaptor =
ArgumentCaptor.forClass(OnMenuEventListener.class);
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
verify(mNotificationSwipeHelperBuilder).setOnMenuEventListener(
onMenuEventListenerArgumentCaptor.capture());
@@ -358,7 +311,7 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
ArgumentCaptor<OnMenuEventListener> onMenuEventListenerArgumentCaptor =
ArgumentCaptor.forClass(OnMenuEventListener.class);
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
verify(mNotificationSwipeHelperBuilder).setOnMenuEventListener(
onMenuEventListenerArgumentCaptor.capture());
@@ -377,7 +330,7 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
dismissListenerArgumentCaptor = ArgumentCaptor.forClass(
NotificationStackScrollLayout.ClearAllListener.class);
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
verify(mNotificationStackScrollLayout).setClearAllListener(
dismissListenerArgumentCaptor.capture());
@@ -394,7 +347,7 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
ArgumentCaptor.forClass(RemoteInputController.Callback.class);
doNothing().when(mRemoteInputManager).addControllerCallback(callbackCaptor.capture());
when(mRemoteInputManager.isRemoteInputActive()).thenReturn(false);
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
verify(mNotificationStackScrollLayout).setIsRemoteInputActive(false);
RemoteInputController.Callback callback = callbackCaptor.getValue();
callback.onRemoteInputActive(true);
@@ -403,8 +356,8 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
@Test
public void testSetNotifStats_updatesHasFilteredOutSeenNotifications() {
initController(/* viewIsAttached= */ true);
mSeenNotificationsProvider.setHasFilteredOutSeenNotifications(true);
mController.attach(mNotificationStackScrollLayout);
mController.getNotifStackController().setNotifStats(NotifStats.getEmpty());
verify(mNotificationStackScrollLayout).setHasFilteredOutSeenNotifications(true);
verify(mNotificationStackScrollLayout).updateFooter();
@@ -414,7 +367,7 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
@Test
public void testAttach_updatesViewStatusBarState() {
// GIVEN: Controller is attached
mController.attach(mNotificationStackScrollLayout);
initController(/* viewIsAttached= */ true);
ArgumentCaptor<StatusBarStateController.StateListener> captor =
ArgumentCaptor.forClass(StatusBarStateController.StateListener.class);
verify(mSysuiStatusBarStateController).addCallback(captor.capture(), anyInt());
@@ -458,6 +411,55 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase {
}
}
private void initController(boolean viewIsAttached) {
when(mNotificationStackScrollLayout.isAttachedToWindow()).thenReturn(viewIsAttached);
mController = new NotificationStackScrollLayoutController(
mNotificationStackScrollLayout,
true,
mNotificationGutsManager,
mVisibilityProvider,
mHeadsUpManager,
mNotificationRoundnessManager,
mTunerService,
mDeviceProvisionedController,
mDynamicPrivacyController,
mConfigurationController,
mSysuiStatusBarStateController,
mKeyguardMediaController,
mKeyguardBypassController,
mZenModeController,
mNotificationLockscreenUserManager,
mMetricsLogger,
mDumpManager,
new FalsingCollectorFake(),
new FalsingManagerFake(),
mResources,
mNotificationSwipeHelperBuilder,
mCentralSurfaces,
mScrimController,
mGroupExpansionManager,
mSilentHeaderController,
mNotifPipeline,
mNotifPipelineFlags,
mNotifCollection,
mLockscreenShadeTransitionController,
mUiEventLogger,
mRemoteInputManager,
mVisibilityLocationProviderDelegator,
mSeenNotificationsProvider,
mShadeController,
mJankMonitor,
mStackLogger,
mLogger,
mNotificationStackSizeCalculator,
mFeatureFlags,
mNotificationTargetsHelper,
mSecureSettings,
mock(NotificationDismissibilityProvider.class)
);
}
static class LogMatcher implements ArgumentMatcher<LogMaker> {
private int mCategory, mType;