From 5e9e3e488b0cf9529549bbc388f2a7c5d9aa300b Mon Sep 17 00:00:00 2001 From: Lyn Han Date: Wed, 20 Apr 2022 16:32:32 -0400 Subject: [PATCH] Fix stack height jump during lockscreen=>shade and aod<=>ls Fixes: 229882633 Test: NotificationPanelViewControllerTest Test: press power button to wakeup and sleep swipedown from lockscreen to go to shade => observe no stack height jump Change-Id: I6575f733b17d6c8905150c0a7854d752dd0a5cfe --- .../NotificationPanelViewController.java | 11 ++++++- .../NotificationPanelViewControllerTest.java | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) 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 adf70a255b4ff..0b46f07f8e8bb 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java @@ -1233,6 +1233,11 @@ public class NotificationPanelViewController extends PanelViewController { mKeyguardBottomArea.initQRCodeScanner(mQRCodeScannerController); } + @VisibleForTesting + void setMaxDisplayedNotifications(int maxAllowed) { + mMaxAllowedKeyguardNotifications = maxAllowed; + } + private void updateMaxDisplayedNotifications(boolean recompute) { if (recompute) { mMaxAllowedKeyguardNotifications = Math.max(computeMaxKeyguardNotifications(), 1); @@ -1463,7 +1468,11 @@ public class NotificationPanelViewController extends PanelViewController { /** * @return the maximum keyguard notifications that can fit on the screen */ - private int computeMaxKeyguardNotifications() { + @VisibleForTesting + int computeMaxKeyguardNotifications() { + if (mAmbientState.getFractionToShade() > 0 || mAmbientState.getDozeAmount() > 0) { + return mMaxAllowedKeyguardNotifications; + } float topPadding = mNotificationStackScrollLayoutController.getTopPadding(); float shelfIntrinsicHeight = mNotificationShelfController.getVisibility() == View.GONE 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 71f1f0b0f7cf0..cad603c85bbcb 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 @@ -557,6 +557,37 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase { mMainHandler.removeCallbacksAndMessages(null); } + @Test + public void computeMaxKeyguardNotifications_lockscreenToShade_returnsExistingMax() { + when(mAmbientState.getFractionToShade()).thenReturn(0.5f); + mNotificationPanelViewController.setMaxDisplayedNotifications(-1); + + // computeMaxKeyguardNotifications sets maxAllowed to 0 at minimum if it updates the value + assertThat(mNotificationPanelViewController.computeMaxKeyguardNotifications()) + .isEqualTo(-1); + } + + @Test + public void computeMaxKeyguardNotifications_dozeAmountNotZero_returnsExistingMax() { + when(mAmbientState.getDozeAmount()).thenReturn(0.5f); + mNotificationPanelViewController.setMaxDisplayedNotifications(-1); + + // computeMaxKeyguardNotifications sets maxAllowed to 0 at minimum if it updates the value + assertThat(mNotificationPanelViewController.computeMaxKeyguardNotifications()) + .isEqualTo(-1); + } + + @Test + public void computeMaxKeyguardNotifications_noTransition_updatesMax() { + when(mAmbientState.getFractionToShade()).thenReturn(0f); + when(mAmbientState.getDozeAmount()).thenReturn(0f); + mNotificationPanelViewController.setMaxDisplayedNotifications(-1); + + // computeMaxKeyguardNotifications sets maxAllowed to 0 at minimum if it updates the value + assertThat(mNotificationPanelViewController.computeMaxKeyguardNotifications()) + .isNotEqualTo(-1); + } + @Test public void testSetPanelScrimMinFraction() { mNotificationPanelViewController.setPanelScrimMinFraction(0.5f);