diff options
8 files changed, 136 insertions, 103 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 75f70ae8eb7a..ecf524c49b75 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -71,6 +71,7 @@ import com.android.systemui.screenshot.dagger.ScreenshotModule; import com.android.systemui.security.data.repository.SecurityRepositoryModule; import com.android.systemui.settings.DisplayTracker; import com.android.systemui.shade.ShadeController; +import com.android.systemui.shade.ShadeModule; import com.android.systemui.shade.transition.LargeScreenShadeInterpolator; import com.android.systemui.shade.transition.LargeScreenShadeInterpolatorImpl; import com.android.systemui.smartspace.dagger.SmartspaceModule; @@ -175,6 +176,7 @@ import javax.inject.Named; SecurityRepositoryModule.class, ScreenRecordModule.class, SettingsUtilModule.class, + ShadeModule.class, SmartRepliesInflationModule.class, SmartspaceModule.class, StatusBarPipelineModule.class, diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java index 34ecce9fa6fd..d28ccff1bfae 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java @@ -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( diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowView.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowView.java index 2b6327f3eedf..d75190e7289a 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowView.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowView.java @@ -84,10 +84,6 @@ public class NotificationShadeWindowView extends FrameLayout { setMotionEventSplittingEnabled(false); } - public NotificationPanelView getNotificationPanelView() { - return findViewById(R.id.notification_panel); - } - @Override public WindowInsets onApplyWindowInsets(WindowInsets windowInsets) { final Insets insets = windowInsets.getInsetsIgnoringVisibility(systemBars()); diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt new file mode 100644 index 000000000000..b0b9ab240988 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 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.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 + +/** Module for classes related to the notification shade. */ +@Module +abstract class ShadeModule { + companion object { + @Provides + @SysUISingleton + // TODO(b/277762009): Do something similar to + // {@link StatusBarWindowModule.InternalWindowView} so that only + // {@link NotificationShadeWindowViewController} can inject this view. + fun providesNotificationShadeWindowView( + layoutInflater: LayoutInflater, + ): NotificationShadeWindowView { + return layoutInflater.inflate(R.layout.super_notification_shade, /* root= */ null) + as NotificationShadeWindowView? + ?: throw IllegalStateException( + "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) + } + + // TODO(b/277762009): Only allow this view's controller to inject the view. See above. + @Provides + @SysUISingleton + fun providesNotificationPanelView( + notificationShadeWindowView: NotificationShadeWindowView, + ): NotificationPanelView { + return notificationShadeWindowView.findViewById(R.id.notification_panel) + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java index 4177263efbd0..9979cc4fa9d5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java @@ -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); 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 db20eeccf763..75e87cc2afa1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java @@ -1645,6 +1645,8 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { mNotificationShadeWindowView = mCentralSurfacesComponent.getNotificationShadeWindowView(); mNotificationShadeWindowViewController = mCentralSurfacesComponent .getNotificationShadeWindowViewController(); + // TODO(b/277762009): Inject [NotificationShadeWindowView] directly into the controller. + // (Right now, there's a circular dependency.) mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView); mNotificationShadeWindowViewController.setupExpandedStatusBar(); NotificationPanelViewController npvc = 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 015ee7b5682a..53c4cf79c478 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 @@ -98,29 +98,6 @@ public abstract class StatusBarViewModule { /** */ @Provides @CentralSurfacesComponent.CentralSurfacesScope - public static NotificationShadeWindowView providesNotificationShadeWindowView( - LayoutInflater layoutInflater) { - NotificationShadeWindowView notificationShadeWindowView = (NotificationShadeWindowView) - layoutInflater.inflate(R.layout.super_notification_shade, /* root= */ null); - if (notificationShadeWindowView == null) { - throw new IllegalStateException( - "R.layout.super_notification_shade could not be properly inflated"); - } - - return notificationShadeWindowView; - } - - /** */ - @Provides - @CentralSurfacesComponent.CentralSurfacesScope - public static NotificationStackScrollLayout providesNotificationStackScrollLayout( - NotificationShadeWindowView notificationShadeWindowView) { - return notificationShadeWindowView.findViewById(R.id.notification_stack_scroller); - } - - /** */ - @Provides - @CentralSurfacesComponent.CentralSurfacesScope public static NotificationShelf providesNotificationShelf(LayoutInflater layoutInflater, NotificationStackScrollLayout notificationStackScrollLayout) { NotificationShelf view = (NotificationShelf) layoutInflater.inflate( @@ -158,14 +135,6 @@ public abstract class StatusBarViewModule { } /** */ - @Provides - @CentralSurfacesComponent.CentralSurfacesScope - public static NotificationPanelView getNotificationPanelView( - NotificationShadeWindowView notificationShadeWindowView) { - return notificationShadeWindowView.getNotificationPanelView(); - } - - /** */ @Binds @CentralSurfacesComponent.CentralSurfacesScope abstract ShadeViewController bindsShadeViewController( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutControllerTest.java index 45b1f4d898a6..0ae012cd5e90 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutControllerTest.java @@ -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; |