From ccfd9427cef83a1359b381e7629472cf167749c4 Mon Sep 17 00:00:00 2001 From: Michal Brzezinski Date: Wed, 21 Sep 2022 11:54:52 +0100 Subject: Making sure QS tile pages are reset when collapsing split shade Expanded state passed to QSPanelController was always true for split shade. Making it work as qsExpanded in QSFragment means controller can react to not expanded state correctly and reset tile pages. That required some extra changes in NPVC, otherwise QS expansion was broken when rotating between split and portrait shade. This should have been done some time ago already as QS expanded state is working properly in split shade, that is qsExpanded is true when split shade is expanded, false otherwise. Fixes: 247799702 Test: QSFragmentTest Test: expand split shade -> swipe to another qs tiles page -> close split shade and expand it again -> qs tiles should be back to the first page Change-Id: Id5865a18273e9e3becbdc3a85be975ea1e0dae7b --- .../src/com/android/systemui/qs/QSFragment.java | 15 +++++++-------- .../shade/NotificationPanelViewController.java | 22 ++++++++++------------ .../com/android/systemui/qs/QSFragmentTest.java | 13 +++++++++++++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java b/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java index 7b27cf45979f..653d9dd8b6a4 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java @@ -442,20 +442,19 @@ public class QSFragment extends LifecycleFragment implements QS, CommandQueue.Ca } private void updateQsState() { - final boolean expanded = mQsExpanded || mInSplitShade; - final boolean expandVisually = expanded || mStackScrollerOverscrolling + final boolean expandVisually = mQsExpanded || mStackScrollerOverscrolling || mHeaderAnimating; - mQSPanelController.setExpanded(expanded); + mQSPanelController.setExpanded(mQsExpanded); boolean keyguardShowing = isKeyguardState(); - mHeader.setVisibility((expanded || !keyguardShowing || mHeaderAnimating + mHeader.setVisibility((mQsExpanded || !keyguardShowing || mHeaderAnimating || mShowCollapsedOnKeyguard) ? View.VISIBLE : View.INVISIBLE); mHeader.setExpanded((keyguardShowing && !mHeaderAnimating && !mShowCollapsedOnKeyguard) - || (expanded && !mStackScrollerOverscrolling), mQuickQSPanelController); + || (mQsExpanded && !mStackScrollerOverscrolling), mQuickQSPanelController); boolean qsPanelVisible = !mQsDisabled && expandVisually; - boolean footerVisible = qsPanelVisible && (expanded || !keyguardShowing || mHeaderAnimating - || mShowCollapsedOnKeyguard); + boolean footerVisible = qsPanelVisible && (mQsExpanded || !keyguardShowing + || mHeaderAnimating || mShowCollapsedOnKeyguard); mFooter.setVisibility(footerVisible ? View.VISIBLE : View.INVISIBLE); if (mQSFooterActionController != null) { mQSFooterActionController.setVisible(footerVisible); @@ -463,7 +462,7 @@ public class QSFragment extends LifecycleFragment implements QS, CommandQueue.Ca mQSFooterActionsViewModel.onVisibilityChangeRequested(footerVisible); } mFooter.setExpanded((keyguardShowing && !mHeaderAnimating && !mShowCollapsedOnKeyguard) - || (expanded && !mStackScrollerOverscrolling)); + || (mQsExpanded && !mStackScrollerOverscrolling)); mQSPanelController.setVisibility(qsPanelVisible ? View.VISIBLE : View.INVISIBLE); if (DEBUG) { Log.d(TAG, "Footer: " + footerVisible + ", QS Panel: " + qsPanelVisible); diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java index 1011a6d831e6..03dd3369773e 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java @@ -3123,26 +3123,24 @@ public final class NotificationPanelViewController extends PanelViewController { } if (mQsExpandImmediate || (mQsExpanded && !mQsTracking && mQsExpansionAnimator == null && !mQsExpansionFromOverscroll)) { - float t; - if (mKeyguardShowing) { - + float qsExpansionFraction; + if (mSplitShadeEnabled) { + qsExpansionFraction = 1; + } else if (mKeyguardShowing) { // On Keyguard, interpolate the QS expansion linearly to the panel expansion - t = expandedHeight / (getMaxPanelHeight()); + qsExpansionFraction = expandedHeight / (getMaxPanelHeight()); } else { // In Shade, interpolate linearly such that QS is closed whenever panel height is // minimum QS expansion + minStackHeight - float - panelHeightQsCollapsed = + float panelHeightQsCollapsed = mNotificationStackScrollLayoutController.getIntrinsicPadding() + mNotificationStackScrollLayoutController.getLayoutMinHeight(); float panelHeightQsExpanded = calculatePanelHeightQsExpanded(); - t = - (expandedHeight - panelHeightQsCollapsed) / (panelHeightQsExpanded - - panelHeightQsCollapsed); + qsExpansionFraction = (expandedHeight - panelHeightQsCollapsed) + / (panelHeightQsExpanded - panelHeightQsCollapsed); } - float - targetHeight = - mQsMinExpansionHeight + t * (mQsMaxExpansionHeight - mQsMinExpansionHeight); + float targetHeight = mQsMinExpansionHeight + + qsExpansionFraction * (mQsMaxExpansionHeight - mQsMinExpansionHeight); setQsExpansion(targetHeight); } updateExpandedHeight(expandedHeight); diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java index 5d5918de3d9e..2a66773f924e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSFragmentTest.java @@ -402,6 +402,19 @@ public class QSFragmentTest extends SysuiBaseFragmentTest { verify(mQSPanelController).setListening(eq(true), anyBoolean()); } + @Test + public void passCorrectExpansionState_inSplitShade() { + QSFragment fragment = resumeAndGetFragment(); + enableSplitShade(); + clearInvocations(mQSPanelController); + + fragment.setExpanded(true); + verify(mQSPanelController).setExpanded(true); + + fragment.setExpanded(false); + verify(mQSPanelController).setExpanded(false); + } + @Override protected Fragment instantiate(Context context, String className, Bundle arguments) { MockitoAnnotations.initMocks(this); -- cgit v1.2.3-59-g8ed1b From 3e9e2d401c7c91ba4e98a235564d9117f876e018 Mon Sep 17 00:00:00 2001 From: Michal Brzezinski Date: Mon, 26 Sep 2022 12:38:41 +0100 Subject: Making sure QS panel is always visible when expanding split shade When we swipe quickly on launcher to expand shade sometimes we go through path where notifyExpandingFinished() is called at the beginning of the movement - when focus transfer happens and expand() is called. This sets `mQsExpandImmediate` to false but it should be always true when expanding split shade. Fix is to move resetting `mQsExpandImmediate` to onPanelStateChanged reacting to OPEN/CLOSE which should be called only once and only at the end of motion. This fix also coincidentally fixes b/237909902 as it was caused by not resetting `mQsExpandImmediate` after showing heads up notification, now it's done when we transition to CLOSE state. Test: NotificationPanelViewControllerTest Test: which quick flings on launcher try to expand and close shade many times -> notice QS always visible Fixes: 248555255 Fixes: 237909902 Change-Id: I64e54765fe39182ff7f71d1d6407d3e38df051b1 --- .../shade/NotificationPanelViewController.java | 15 ++++++++--- .../shade/NotificationPanelViewControllerTest.java | 31 +++++++++++++--------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java index 03dd3369773e..6c2708194837 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java @@ -430,6 +430,7 @@ public final class NotificationPanelViewController extends PanelViewController { /** * Determines if QS should be already expanded when expanding shade. * Used for split shade, two finger gesture as well as accessibility shortcut to QS. + * It needs to be set when movement starts as it resets at the end of expansion/collapse. */ @VisibleForTesting boolean mQsExpandImmediate; @@ -1737,8 +1738,10 @@ public final class NotificationPanelViewController extends PanelViewController { } private void setQsExpandImmediate(boolean expandImmediate) { - mQsExpandImmediate = expandImmediate; - mPanelEventsEmitter.notifyExpandImmediateChange(expandImmediate); + if (expandImmediate != mQsExpandImmediate) { + mQsExpandImmediate = expandImmediate; + mPanelEventsEmitter.notifyExpandImmediateChange(expandImmediate); + } } private void setShowShelfOnly(boolean shelfOnly) { @@ -3326,7 +3329,11 @@ public final class NotificationPanelViewController extends PanelViewController { } else { setListening(true); } - setQsExpandImmediate(false); + if (mBarState != SHADE) { + // updating qsExpandImmediate is done in onPanelStateChanged for unlocked shade but + // on keyguard panel state is always OPEN so we need to have that extra update + setQsExpandImmediate(false); + } setShowShelfOnly(false); mTwoFingerQsExpandPossible = false; updateTrackingHeadsUp(null); @@ -4985,6 +4992,7 @@ public final class NotificationPanelViewController extends PanelViewController { updateQSExpansionEnabledAmbient(); if (state == STATE_OPEN && mCurrentPanelState != state) { + setQsExpandImmediate(false); mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); } if (state == STATE_OPENING) { @@ -4997,6 +5005,7 @@ public final class NotificationPanelViewController extends PanelViewController { mCentralSurfaces.makeExpandedVisible(false); } if (state == STATE_CLOSED) { + setQsExpandImmediate(false); // Close the status bar in the next frame so we can show the end of the // animation. mView.post(mMaybeHideExpandedRunnable); diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java index b40d5ac69d7b..0c60d3c72c2a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java @@ -23,6 +23,9 @@ import static com.android.keyguard.KeyguardClockSwitch.SMALL; import static com.android.systemui.statusbar.StatusBarState.KEYGUARD; import static com.android.systemui.statusbar.StatusBarState.SHADE; import static com.android.systemui.statusbar.StatusBarState.SHADE_LOCKED; +import static com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManagerKt.STATE_CLOSED; +import static com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManagerKt.STATE_OPEN; +import static com.android.systemui.statusbar.phone.panelstate.PanelExpansionStateManagerKt.STATE_OPENING; import static com.google.common.truth.Truth.assertThat; @@ -1249,14 +1252,10 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase { @Test public void testQsToBeImmediatelyExpandedWhenOpeningPanelInSplitShade() { enableSplitShade(/* enabled= */ true); - // set panel state to CLOSED - mPanelExpansionStateManager.onPanelExpansionChanged(/* fraction= */ 0, - /* expanded= */ false, /* tracking= */ false, /* dragDownPxAmount= */ 0); + mPanelExpansionStateManager.updateState(STATE_CLOSED); assertThat(mNotificationPanelViewController.mQsExpandImmediate).isFalse(); - // change panel state to OPENING - mPanelExpansionStateManager.onPanelExpansionChanged(/* fraction= */ 0.5f, - /* expanded= */ true, /* tracking= */ true, /* dragDownPxAmount= */ 100); + mPanelExpansionStateManager.updateState(STATE_OPENING); assertThat(mNotificationPanelViewController.mQsExpandImmediate).isTrue(); } @@ -1264,15 +1263,23 @@ public class NotificationPanelViewControllerTest extends SysuiTestCase { @Test public void testQsNotToBeImmediatelyExpandedWhenGoingFromUnlockedToLocked() { enableSplitShade(/* enabled= */ true); - // set panel state to CLOSED - mPanelExpansionStateManager.onPanelExpansionChanged(/* fraction= */ 0, - /* expanded= */ false, /* tracking= */ false, /* dragDownPxAmount= */ 0); + mPanelExpansionStateManager.updateState(STATE_CLOSED); - // go to lockscreen, which also sets fraction to 1.0f and makes shade "expanded" mStatusBarStateController.setState(KEYGUARD); - mPanelExpansionStateManager.onPanelExpansionChanged(/* fraction= */ 1, - /* expanded= */ true, /* tracking= */ true, /* dragDownPxAmount= */ 0); + // going to lockscreen would trigger STATE_OPENING + mPanelExpansionStateManager.updateState(STATE_OPENING); + + assertThat(mNotificationPanelViewController.mQsExpandImmediate).isFalse(); + } + + @Test + public void testQsImmediateResetsWhenPanelOpensOrCloses() { + mNotificationPanelViewController.mQsExpandImmediate = true; + mPanelExpansionStateManager.updateState(STATE_OPEN); + assertThat(mNotificationPanelViewController.mQsExpandImmediate).isFalse(); + mNotificationPanelViewController.mQsExpandImmediate = true; + mPanelExpansionStateManager.updateState(STATE_CLOSED); assertThat(mNotificationPanelViewController.mQsExpandImmediate).isFalse(); } -- cgit v1.2.3-59-g8ed1b