From 036054e88c356290a14ddccc62d55fff4ba719ed Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Mon, 23 May 2022 20:59:26 +0000 Subject: [PATCH] [LockScreen] Update bar state in NPVC. When view is attached to window in NPVC, we add a listener to the bar state controller; however we do not update to the existing bar state if any. This means that if the listener is added before the bar state change is made, then we will default to 0 (SHADE) for NVPC. We have experienced strange LS states because of this. Bug: 230911766 Test: Added a 5s delay to adding the callback to experience the weird state. Added a unit test. Change-Id: Ieb6d6537eb002b03beceef6f701b826df48feeeb --- .../phone/NotificationPanelViewController.java | 1 + .../phone/NotificationPanelViewControllerTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java index 81270c55411fd..4a912572b7edf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java @@ -4842,6 +4842,7 @@ public class NotificationPanelViewController extends PanelViewController { mFragmentService.getFragmentHostManager(mView) .addTagListener(QS.TAG, mFragmentListener); mStatusBarStateController.addCallback(mStatusBarStateListener); + mStatusBarStateListener.onStateChanged(mStatusBarStateController.getState()); mConfigurationController.addCallback(mConfigurationListener); // Theme might have changed between inflating this view and attaching it to the // window, so diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java index 7ebf750e219cb..fa9161a19cb1a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationPanelViewControllerTest.java @@ -1143,6 +1143,19 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase { assertThat(mNotificationPanelViewController.isQsTracking()).isFalse(); } + @Test + public void testOnAttachRefreshStatusBarState() { + mStatusBarStateController.setState(KEYGUARD); + when(mKeyguardStateController.isKeyguardFadingAway()).thenReturn(false); + for (View.OnAttachStateChangeListener listener : mOnAttachStateChangeListeners) { + listener.onViewAttachedToWindow(mView); + } + verify(mKeyguardStatusViewController).setKeyguardStatusViewVisibility( + KEYGUARD/*statusBarState*/, + false/*keyguardFadingAway*/, + false/*goingToFullShade*/, SHADE/*oldStatusBarState*/); + } + private static MotionEvent createMotionEvent(int x, int y, int action) { return MotionEvent.obtain( /* downTime= */ 0, /* eventTime= */ 0, action, x, y, /* metaState= */ 0);