[Fold to AOD] Fix large clock blinking when folding a device

Fixes blinking when large clock becomes a small clock
when folding a foldable device: when there are notifications
and split shade is not active we should show small clock.
Clock size (large/small) was updated only in
NotificationPanelViewController#OnLayoutChangeListener
when folding or unfolding. This is called only after
the next layout pass, so sometimes we could see smaller
clock when folding a device.
Added calling clock update each time when split shade
mode activated/deactived.

We don't need to worry about the new layout for calculating
coordinates for updating clocks because it is the same
in both cases (mStatusArea.getTop is not changing and it
equals to the height of the small clock, the actual
movement is controlled by the translation).

Bug: 202844967
Test: fold/unfold multiple times when AOD enabled
Test: atest com.android.systemui.statusbar.phone.NotificationPanelViewControllerTest
Change-Id: I73ee110b6cbd05cfb4a01af10f0d5356ff0c16a2
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 a0f8d05..94d6e0b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
@@ -1141,8 +1141,13 @@
                         R.dimen.split_shade_notifications_scrim_margin_bottom);
         int qsWidth = mResources.getDimensionPixelSize(R.dimen.qs_panel_width);
         int panelWidth = mResources.getDimensionPixelSize(R.dimen.notification_panel_width);
-        mShouldUseSplitNotificationShade =
+
+        final boolean newShouldUseSplitNotificationShade =
                 Utils.shouldUseSplitNotificationShade(mResources);
+        final boolean splitNotificationShadeChanged =
+                mShouldUseSplitNotificationShade != newShouldUseSplitNotificationShade;
+
+        mShouldUseSplitNotificationShade = newShouldUseSplitNotificationShade;
         if (mQs != null) {
             mQs.setInSplitShade(mShouldUseSplitNotificationShade);
         }
@@ -1188,6 +1193,10 @@
         updateKeyguardStatusViewAlignment(/* animate= */false);
 
         mKeyguardMediaController.refreshMediaPosition();
+
+        if (splitNotificationShadeChanged) {
+            updateClockAppearance();
+        }
     }
 
     private static void ensureAllViewsHaveIds(ViewGroup parentView) {
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 479c271..9245c2c 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
@@ -904,6 +904,7 @@
     public void testSwitchesToCorrectClockInSplitShade() {
         mStatusBarStateController.setState(KEYGUARD);
         enableSplitShade(/* enabled= */ true);
+        clearInvocations(mKeyguardStatusViewController);
 
         when(mNotificationStackScrollLayoutController.getVisibleNotificationCount()).thenReturn(0);
         triggerPositionClockAndNotifications();
@@ -918,11 +919,56 @@
     }
 
     @Test
+    public void testHasNotifications_switchesToLargeClockWhenEnteringSplitShade() {
+        mStatusBarStateController.setState(KEYGUARD);
+        when(mNotificationStackScrollLayoutController.getVisibleNotificationCount()).thenReturn(1);
+
+        enableSplitShade(/* enabled= */ true);
+
+        verify(mKeyguardStatusViewController).displayClock(LARGE, /* animate */ true);
+    }
+
+    @Test
+    public void testNoNotifications_switchesToLargeClockWhenEnteringSplitShade() {
+        mStatusBarStateController.setState(KEYGUARD);
+        when(mNotificationStackScrollLayoutController.getVisibleNotificationCount()).thenReturn(0);
+
+        enableSplitShade(/* enabled= */ true);
+
+        verify(mKeyguardStatusViewController).displayClock(LARGE, /* animate */ true);
+    }
+
+    @Test
+    public void testHasNotifications_switchesToSmallClockWhenExitingSplitShade() {
+        mStatusBarStateController.setState(KEYGUARD);
+        enableSplitShade(/* enabled= */ true);
+        clearInvocations(mKeyguardStatusViewController);
+        when(mNotificationStackScrollLayoutController.getVisibleNotificationCount()).thenReturn(1);
+
+        enableSplitShade(/* enabled= */ false);
+
+        verify(mKeyguardStatusViewController).displayClock(SMALL, /* animate */ true);
+    }
+
+    @Test
+    public void testNoNotifications_switchesToLargeClockWhenExitingSplitShade() {
+        mStatusBarStateController.setState(KEYGUARD);
+        enableSplitShade(/* enabled= */ true);
+        clearInvocations(mKeyguardStatusViewController);
+        when(mNotificationStackScrollLayoutController.getVisibleNotificationCount()).thenReturn(0);
+
+        enableSplitShade(/* enabled= */ false);
+
+        verify(mKeyguardStatusViewController).displayClock(LARGE, /* animate */ true);
+    }
+
+    @Test
     public void testSwitchesToBigClockInSplitShadeOnAod() {
         mStatusBarStateController.setState(KEYGUARD);
         enableSplitShade(/* enabled= */ true);
         when(mMediaDataManager.hasActiveMedia()).thenReturn(true);
         when(mNotificationStackScrollLayoutController.getVisibleNotificationCount()).thenReturn(2);
+        clearInvocations(mKeyguardStatusViewController);
 
         mNotificationPanelViewController.setDozing(true, false, null);
 
@@ -934,6 +980,7 @@
         when(mScreenOffAnimationController.shouldAnimateClockChange()).thenReturn(false);
         mStatusBarStateController.setState(KEYGUARD);
         enableSplitShade(/* enabled= */ true);
+        clearInvocations(mKeyguardStatusViewController);
         when(mMediaDataManager.hasActiveMedia()).thenReturn(true);
         when(mNotificationStackScrollLayoutController.getVisibleNotificationCount()).thenReturn(2);
 
@@ -946,6 +993,7 @@
     public void testDisplaysSmallClockOnLockscreenInSplitShadeWhenMediaIsPlaying() {
         mStatusBarStateController.setState(KEYGUARD);
         enableSplitShade(/* enabled= */ true);
+        clearInvocations(mKeyguardStatusViewController);
         when(mMediaDataManager.hasActiveMedia()).thenReturn(true);
 
         // one notification + media player visible