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 42d122d6f9ac5..14b0763580e93 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 @@ -209,7 +209,11 @@ public class NotificationStackScrollLayoutController { public void onViewAttachedToWindow(View v) { mConfigurationController.addCallback(mConfigurationListener); mZenModeController.addCallback(mZenModeControllerCallback); - mBarState = mStatusBarStateController.getState(); + final int newBarState = mStatusBarStateController.getState(); + if (newBarState != mBarState) { + mStateListener.onStateChanged(newBarState); + mStateListener.onStatePostChange(); + } mStatusBarStateController.addCallback( mStateListener, SysuiStatusBarStateController.RANK_STACK_SCROLLER); } 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 9f6f082d07c40..ff26a43c00062 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 @@ -413,6 +413,37 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase { verify(mNotificationStackScrollLayout).updateEmptyShadeView(anyBoolean(), anyBoolean()); } + @Test + public void testAttach_updatesViewStatusBarState() { + // GIVEN: Controller is attached + mController.attach(mNotificationStackScrollLayout); + ArgumentCaptor captor = + ArgumentCaptor.forClass(StatusBarStateController.StateListener.class); + verify(mSysuiStatusBarStateController).addCallback(captor.capture(), anyInt()); + StatusBarStateController.StateListener stateListener = captor.getValue(); + + // WHEN: StatusBarState changes to SHADE + when(mSysuiStatusBarStateController.getState()).thenReturn(SHADE); + stateListener.onStateChanged(SHADE); + + // THEN: NSSL is updated with the current state + verify(mNotificationStackScrollLayout).setStatusBarState(SHADE); + + // WHEN: Controller is detached + mController.mOnAttachStateChangeListener + .onViewDetachedFromWindow(mNotificationStackScrollLayout); + + // WHEN: StatusBarState changes to KEYGUARD + when(mSysuiStatusBarStateController.getState()).thenReturn(KEYGUARD); + + // WHEN: Controller is re-attached + mController.mOnAttachStateChangeListener + .onViewAttachedToWindow(mNotificationStackScrollLayout); + + // THEN: NSSL is updated with the current state + verify(mNotificationStackScrollLayout).setStatusBarState(KEYGUARD); + } + private LogMaker logMatcher(int category, int type) { return argThat(new LogMatcher(category, type)); }