Updating QS state to default when going from or to split shade

When going from split shade to regular shade Quick Settings now will be collapsed. When changing to split shade, they will be expanded - which was already the case with UI but internal state of NPVC was not reflecting thatand it caused most bottom tiles to not work after rotating to landscape. Changing to default state will likely prevent many nasty bugs in the future.

Also renaming `mShouldUseSplitNotificationShade` to `mSplitShadeEnabled` which is nicer, shorter and better follows the usual convention of *Enabled.

Bug: 228198572
Fixes: 230612123
Test: 1. Rotate from split shade to regular shade and see QS are collapsed
2. Rotate from portrait with collapsed QS to split shade and see most bottom tiles are working

Change-Id: I13eedf62b92dd5eb06056739f3950c76b6601a07
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 d241b90..636be74 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
@@ -323,7 +323,7 @@
     private final LargeScreenShadeHeaderController mLargeScreenShadeHeaderController;
     private final RecordingController mRecordingController;
     private final PanelEventsEmitter mPanelEventsEmitter;
-    private boolean mShouldUseSplitNotificationShade;
+    private boolean mSplitShadeEnabled;
     // The bottom padding reserved for elements of the keyguard measuring notifications
     private float mKeyguardNotificationBottomPadding;
     /**
@@ -814,7 +814,7 @@
         mKeyguardUserSwitcherComponentFactory = keyguardUserSwitcherComponentFactory;
         mFragmentService = fragmentService;
         mSettingsChangeObserver = new SettingsChangeObserver(handler);
-        mShouldUseSplitNotificationShade =
+        mSplitShadeEnabled =
                 LargeScreenUtils.shouldUseSplitNotificationShade(mResources);
         mView.setWillNotDraw(!DEBUG);
         mLargeScreenShadeHeaderController = largeScreenShadeHeaderController;
@@ -1029,7 +1029,7 @@
         });
 
         mView.setAccessibilityDelegate(mAccessibilityDelegate);
-        if (mShouldUseSplitNotificationShade) {
+        if (mSplitShadeEnabled) {
             updateResources();
         }
 
@@ -1126,20 +1126,18 @@
         mSplitShadeNotificationsScrimMarginBottom =
                 mResources.getDimensionPixelSize(
                         R.dimen.split_shade_notifications_scrim_margin_bottom);
-
         mShelfAndLockIconOverlap =
                 mResources.getDimensionPixelSize(R.dimen.shelf_and_lock_icon_overlap);
 
-        final boolean newShouldUseSplitNotificationShade =
+        final boolean newSplitShadeEnabled =
                 LargeScreenUtils.shouldUseSplitNotificationShade(mResources);
-        final boolean splitNotificationShadeChanged =
-                mShouldUseSplitNotificationShade != newShouldUseSplitNotificationShade;
+        final boolean splitShadeChanged = mSplitShadeEnabled != newSplitShadeEnabled;
+        mSplitShadeEnabled = newSplitShadeEnabled;
 
-        mShouldUseSplitNotificationShade = newShouldUseSplitNotificationShade;
         boolean useLargeScreenShadeHeader =
                 LargeScreenUtils.shouldUseLargeScreenShadeHeader(mView.getResources());
         if (mQs != null) {
-            mQs.setInSplitShade(mShouldUseSplitNotificationShade);
+            mQs.setInSplitShade(mSplitShadeEnabled);
         }
         mLargeScreenShadeHeaderHeight =
                 mResources.getDimensionPixelSize(R.dimen.large_screen_shade_header_height);
@@ -1155,7 +1153,12 @@
 
         mKeyguardMediaController.refreshMediaPosition();
 
-        if (splitNotificationShadeChanged) {
+        if (splitShadeChanged) {
+            // when we switch from split shade to regular shade we want to enforce setting qs to
+            // the default state: expanded for split shade and collapsed otherwise
+            if (!isOnKeyguard() && mPanelExpanded) {
+                setQsExpanded(mSplitShadeEnabled);
+            }
             updateClockAppearance();
             updateQsState();
             mNotificationStackScrollLayoutController.updateFooter();
@@ -1384,7 +1387,7 @@
             updateClockAppearance();
         }
         if (!onKeyguard) {
-            if (mShouldUseSplitNotificationShade) {
+            if (mSplitShadeEnabled) {
                 // Quick settings are not on the top of the notifications
                 // when in split shade mode (they are on the left side),
                 // so we should not add a padding for them
@@ -1412,10 +1415,9 @@
                 .getVisibleNotificationCount() != 0
                 || mMediaDataManager.hasActiveMediaOrRecommendation();
         boolean splitShadeWithActiveMedia =
-                mShouldUseSplitNotificationShade
-                        && mMediaDataManager.hasActiveMediaOrRecommendation();
+                mSplitShadeEnabled && mMediaDataManager.hasActiveMediaOrRecommendation();
         boolean shouldAnimateClockChange = mScreenOffAnimationController.shouldAnimateClockChange();
-        if ((hasVisibleNotifications && !mShouldUseSplitNotificationShade)
+        if ((hasVisibleNotifications && !mSplitShadeEnabled)
                 || (splitShadeWithActiveMedia && !mDozing)) {
             mKeyguardStatusViewController.displayClock(SMALL, shouldAnimateClockChange);
         } else {
@@ -1452,7 +1454,7 @@
                 bypassEnabled, getUnlockedStackScrollerPadding(),
                 computeQsExpansionFraction(),
                 mDisplayTopInset,
-                mShouldUseSplitNotificationShade,
+                mSplitShadeEnabled,
                 udfpsAodTopLocation,
                 mKeyguardStatusViewController.getClockBottom(mStatusBarHeaderHeightKeyguard),
                 mKeyguardStatusViewController.isClockTopAligned());
@@ -1482,8 +1484,7 @@
         boolean hasVisibleNotifications = mNotificationStackScrollLayoutController
                 .getVisibleNotificationCount() != 0
                 || mMediaDataManager.hasActiveMediaOrRecommendation();
-        boolean shouldBeCentered = !mShouldUseSplitNotificationShade || !hasVisibleNotifications
-                || mDozing;
+        boolean shouldBeCentered = !mSplitShadeEnabled || !hasVisibleNotifications || mDozing;
         if (mStatusViewCentered != shouldBeCentered) {
             mStatusViewCentered = shouldBeCentered;
             ConstraintSet constraintSet = new ConstraintSet();
@@ -1492,7 +1493,7 @@
             constraintSet.connect(R.id.keyguard_status_view, END, statusConstraint, END);
             if (animate) {
                 ChangeBounds transition = new ChangeBounds();
-                if (mShouldUseSplitNotificationShade) {
+                if (mSplitShadeEnabled) {
                     // Excluding media from the transition on split-shade, as it doesn't transition
                     // horizontally properly.
                     transition.excludeTarget(R.id.status_view_media_container, true);
@@ -1649,7 +1650,7 @@
 
     private void setShowShelfOnly(boolean shelfOnly) {
         mNotificationStackScrollLayoutController.setShouldShowShelfOnly(
-                shelfOnly && !mShouldUseSplitNotificationShade);
+                shelfOnly && !mSplitShadeEnabled);
     }
 
     public void closeQs() {
@@ -1690,7 +1691,7 @@
             mQsExpandImmediate = true;
             setShowShelfOnly(true);
         }
-        if (mShouldUseSplitNotificationShade && isOnKeyguard()) {
+        if (mSplitShadeEnabled && isOnKeyguard()) {
             // It's a special case as this method is likely to not be initiated by finger movement
             // but rather called from adb shell or accessibility service.
             // We're using LockscreenShadeTransitionController because on lockscreen that's the
@@ -1920,7 +1921,7 @@
         int flingType;
         if (expandsQs && !isCancelMotionEvent) {
             flingType = FLING_EXPAND;
-        } else if (mShouldUseSplitNotificationShade) {
+        } else if (mSplitShadeEnabled) {
             flingType = FLING_HIDE;
         } else {
             flingType = FLING_COLLAPSE;
@@ -1986,11 +1987,11 @@
 
 
     private boolean handleQsTouch(MotionEvent event) {
-        if (mShouldUseSplitNotificationShade && touchXOutsideOfQs(event.getX())) {
+        if (mSplitShadeEnabled && touchXOutsideOfQs(event.getX())) {
             return false;
         }
         final int action = event.getActionMasked();
-        boolean collapsedQs = !mQsExpanded && !mShouldUseSplitNotificationShade;
+        boolean collapsedQs = !mQsExpanded && !mSplitShadeEnabled;
         boolean expandedShadeCollapsedQs = getExpandedFraction() == 1f && mBarState != KEYGUARD
                 && collapsedQs && isQsExpansionEnabled();
         if (action == MotionEvent.ACTION_DOWN && expandedShadeCollapsedQs) {
@@ -2008,7 +2009,7 @@
         }
         if (!mQsExpandImmediate && mQsTracking) {
             onQsTouch(event);
-            if (!mConflictingQsExpansionGesture && !mShouldUseSplitNotificationShade) {
+            if (!mConflictingQsExpansionGesture && !mSplitShadeEnabled) {
                 return true;
             }
         }
@@ -2299,7 +2300,7 @@
     }
 
     private void updateQsState() {
-        boolean qsFullScreen = mQsExpanded && !mShouldUseSplitNotificationShade;
+        boolean qsFullScreen = mQsExpanded && !mSplitShadeEnabled;
         mNotificationStackScrollLayoutController.setQsFullScreen(qsFullScreen);
         mNotificationStackScrollLayoutController.setScrollingEnabled(
                 mBarState != KEYGUARD && (!qsFullScreen || mQsExpansionFromOverscroll));
@@ -2347,7 +2348,7 @@
     private void updateQsExpansion() {
         if (mQs == null) return;
         final float squishiness;
-        if ((mQsExpandImmediate || mQsExpanded) && !mShouldUseSplitNotificationShade) {
+        if ((mQsExpandImmediate || mQsExpanded) && !mSplitShadeEnabled) {
             squishiness = 1;
         } else if (mLockscreenShadeTransitionController.getQSDragProgress() > 0) {
             squishiness = mLockscreenShadeTransitionController.getQSDragProgress();
@@ -2356,7 +2357,7 @@
                     .getNotificationSquishinessFraction();
         }
         final float qsExpansionFraction = computeQsExpansionFraction();
-        final float adjustedExpansionFraction = mShouldUseSplitNotificationShade
+        final float adjustedExpansionFraction = mSplitShadeEnabled
                 ? 1f : computeQsExpansionFraction();
         mQs.setQsExpansion(adjustedExpansionFraction, getExpandedFraction(), getHeaderTranslation(),
                 squishiness);
@@ -2365,7 +2366,7 @@
         mScrimController.setQsPosition(qsExpansionFraction, qsPanelBottomY);
         setQSClippingBounds();
 
-        if (mShouldUseSplitNotificationShade) {
+        if (mSplitShadeEnabled) {
             // In split shade we want to pretend that QS are always collapsed so their behaviour and
             // interactions don't influence notifications as they do in portrait. But we want to set
             // 0 explicitly in case we're rotating from non-split shade with QS expansion of 1.
@@ -2405,7 +2406,7 @@
 
     private void updateQSExpansionEnabledAmbient() {
         final float scrollRangeToTop = mAmbientState.getTopPadding() - mQuickQsHeaderHeight;
-        mQsExpansionEnabledAmbient = mShouldUseSplitNotificationShade
+        mQsExpansionEnabledAmbient = mSplitShadeEnabled
                 || (mAmbientState.getScrollY() <= scrollRangeToTop);
         setQsExpansionEnabled();
     }
@@ -2429,7 +2430,7 @@
 
     private int calculateTopQsClippingBound(int qsPanelBottomY) {
         int top;
-        if (mShouldUseSplitNotificationShade) {
+        if (mSplitShadeEnabled) {
             top = Math.min(qsPanelBottomY, mLargeScreenShadeHeaderHeight);
         } else {
             if (mTransitioningToFullShadeProgress > 0.0f) {
@@ -2463,7 +2464,7 @@
     }
 
     private int calculateBottomQsClippingBound(int top) {
-        if (mShouldUseSplitNotificationShade) {
+        if (mSplitShadeEnabled) {
             return top + mNotificationStackScrollLayoutController.getHeight()
                     + mSplitShadeNotificationsScrimMarginBottom;
         } else {
@@ -2560,7 +2561,7 @@
                     // qsTranslation should only be positive during pulse expansion because it's
                     // already translating in from the top
                     qsTranslation = Math.max(0, (top - mQs.getHeader().getHeight()) / 2.0f);
-                } else if (!mShouldUseSplitNotificationShade) {
+                } else if (!mSplitShadeEnabled) {
                     qsTranslation = (top - mQs.getHeader().getHeight()) * QS_PARALLAX_AMOUNT;
                 }
             }
@@ -2574,11 +2575,11 @@
                     mQsClipTop,
                     mQsClipBottom,
                     radius, qsVisible
-                    && !mShouldUseSplitNotificationShade);
+                    && !mSplitShadeEnabled);
         }
         mKeyguardStatusViewController.setClipBounds(
                 clipStatusView ? mKeyguardStatusAreaClipBounds : null);
-        if (!qsVisible && mShouldUseSplitNotificationShade) {
+        if (!qsVisible && mSplitShadeEnabled) {
             // On the lockscreen when qs isn't visible, we don't want the bounds of the shade to
             // be visible, otherwise you can see the bounds once swiping up to see bouncer
             mScrimController.setNotificationsBounds(0, 0, 0, 0);
@@ -2586,12 +2587,11 @@
             // Increase the height of the notifications scrim when not in split shade
             // (e.g. portrait tablet) so the rounded corners are not visible at the bottom,
             // in this case they are rendered off-screen
-            final int notificationsScrimBottom =
-                    mShouldUseSplitNotificationShade ? bottom : bottom + radius;
+            final int notificationsScrimBottom = mSplitShadeEnabled ? bottom : bottom + radius;
             mScrimController.setNotificationsBounds(left, top, right, notificationsScrimBottom);
         }
 
-        if (mShouldUseSplitNotificationShade) {
+        if (mSplitShadeEnabled) {
             mKeyguardStatusBarViewController.setNoTopClipping();
         } else {
             mKeyguardStatusBarViewController.updateTopClipping(top);
@@ -2605,7 +2605,7 @@
         int nsslRight = right - mNotificationStackScrollLayoutController.getLeft();
         int nsslTop = top - mNotificationStackScrollLayoutController.getTop();
         int nsslBottom = bottom - mNotificationStackScrollLayoutController.getTop();
-        int bottomRadius = mShouldUseSplitNotificationShade ? radius : 0;
+        int bottomRadius = mSplitShadeEnabled ? radius : 0;
         mNotificationStackScrollLayoutController.setRoundedClippingBounds(
                 nsslLeft, nsslTop, nsslRight, nsslBottom, radius, bottomRadius);
     }
@@ -2647,7 +2647,7 @@
     }
 
     private float calculateNotificationsTopPadding() {
-        if (mShouldUseSplitNotificationShade && !mKeyguardShowing) {
+        if (mSplitShadeEnabled && !mKeyguardShowing) {
             return 0;
         }
         if (mKeyguardShowing && (mQsExpandImmediate
@@ -2920,7 +2920,7 @@
     private boolean shouldQuickSettingsIntercept(float x, float y, float yDiff) {
         if (!isQsExpansionEnabled() || mCollapsedOnDown
                 || (mKeyguardShowing && mKeyguardBypassController.getBypassEnabled())
-                || mShouldUseSplitNotificationShade) {
+                || mSplitShadeEnabled) {
             return false;
         }
         View header = mKeyguardShowing || mQs == null ? mKeyguardStatusBar : mQs.getHeader();
@@ -2951,7 +2951,7 @@
             return true;
         }
 
-        return !mShouldUseSplitNotificationShade && (isInSettings() || mIsPanelCollapseOnQQS);
+        return !mSplitShadeEnabled && (isInSettings() || mIsPanelCollapseOnQQS);
     }
 
     @Override
@@ -3135,7 +3135,7 @@
         float appearAmount = mNotificationStackScrollLayoutController
                 .calculateAppearFraction(mExpandedHeight);
         float startHeight = -mQsExpansionHeight;
-        if (!mShouldUseSplitNotificationShade && mBarState == StatusBarState.SHADE) {
+        if (!mSplitShadeEnabled && mBarState == StatusBarState.SHADE) {
             // Small parallax as we pull down and clip QS
             startHeight = -mQsExpansionHeight * QS_PARALLAX_AMOUNT;
         }
@@ -3683,7 +3683,7 @@
             mQs.setCollapseExpandAction(mCollapseExpandAction);
             mQs.setHeaderClickable(isQsExpansionEnabled());
             mQs.setOverscrolling(mStackScrollerOverscrolling);
-            mQs.setInSplitShade(mShouldUseSplitNotificationShade);
+            mQs.setInSplitShade(mSplitShadeEnabled);
 
             // recompute internal state when qspanel height changes
             mQs.getView().addOnLayoutChangeListener(
@@ -4358,7 +4358,7 @@
         @Override
         public void onOverscrollTopChanged(float amount, boolean isRubberbanded) {
             // When in split shade, overscroll shouldn't carry through to QS
-            if (mShouldUseSplitNotificationShade) {
+            if (mSplitShadeEnabled) {
                 return;
             }
             cancelQsAnimation();
@@ -4376,7 +4376,7 @@
         @Override
         public void flingTopOverscroll(float velocity, boolean open) {
             // in split shade mode we want to expand/collapse QS only when touch happens within QS
-            if (mShouldUseSplitNotificationShade && touchXOutsideOfQs(mInitialTouchX)) {
+            if (mSplitShadeEnabled && touchXOutsideOfQs(mInitialTouchX)) {
                 return;
             }
             mLastOverscroll = 0f;
@@ -4716,7 +4716,7 @@
                 // the top of QS
                 if (!mQsExpanded) {
                     // TODO(b/185683835) Nicer clipping when using new spacial model
-                    if (mShouldUseSplitNotificationShade) {
+                    if (mSplitShadeEnabled) {
                         mQs.animateHeaderSlidingOut();
                     }
                 }
@@ -4913,7 +4913,7 @@
 
     private void updateQSMinHeight() {
         float previousMin = mQsMinExpansionHeight;
-        if (mKeyguardShowing || mShouldUseSplitNotificationShade) {
+        if (mKeyguardShowing || mSplitShadeEnabled) {
             mQsMinExpansionHeight = 0;
         } else {
             mQsMinExpansionHeight = mQs.getQsMinExpansionHeight();
@@ -5047,7 +5047,7 @@
             // we need to ignore it on keyguard as this is a false alarm - transition from unlocked
             // to locked will trigger this event and we're not actually in the process of opening
             // the shade, lockscreen is just always expanded
-            if (mShouldUseSplitNotificationShade && !isOnKeyguard()) {
+            if (mSplitShadeEnabled && !isOnKeyguard()) {
                 mQsExpandImmediate = true;
             }
             mCentralSurfaces.makeExpandedVisible(false);
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 356d002..7ebf750 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
@@ -1090,6 +1090,21 @@
     }
 
     @Test
+    public void testQsExpansionChangedToDefaultWhenRotatingFromOrToSplitShade() {
+        // to make sure shade is in expanded state
+        mNotificationPanelViewController.startWaitingForOpenPanelGesture();
+        assertThat(mNotificationPanelViewController.isQsExpanded()).isFalse();
+
+        // switch to split shade from portrait (default state)
+        enableSplitShade(/* enabled= */ true);
+        assertThat(mNotificationPanelViewController.isQsExpanded()).isTrue();
+
+        // switch to portrait from split shade
+        enableSplitShade(/* enabled= */ false);
+        assertThat(mNotificationPanelViewController.isQsExpanded()).isFalse();
+    }
+
+    @Test
     public void interceptTouchEvent_withinQs_shadeExpanded_startsQsTracking() {
         mNotificationPanelViewController.mQs = mQs;
         when(mQsFrame.getX()).thenReturn(0f);