diff options
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt | 15 | ||||
-rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt | 37 |
2 files changed, 48 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt index fbc608eddc14..d82f8e722744 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt @@ -226,10 +226,14 @@ constructor( private val insetListener = View.OnApplyWindowInsetsListener { view, insets -> - updateConstraintsForInsets(view as MotionLayout, insets) - lastInsets = WindowInsets(insets) - - view.onApplyWindowInsets(insets) + val windowInsets = WindowInsets(insets) + if (windowInsets != lastInsets) { + updateConstraintsForInsets(view as MotionLayout, insets) + lastInsets = windowInsets + view.onApplyWindowInsets(insets) + } else { + insets + } } private var singleCarrier = false @@ -513,6 +517,9 @@ constructor( systemIconsHoverContainer.setOnClickListener(null) systemIconsHoverContainer.isClickable = false } + + lastInsets?.let { updateConstraintsForInsets(header, it) } + header.jumpToState(header.startState) updatePosition() updateScrollY() diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt index 1d348b13a481..a5cd81ff3116 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt @@ -811,6 +811,43 @@ class ShadeHeaderControllerTest : SysuiTestCase() { } @Test + fun sameInsetsTwice_listenerCallsOnApplyWindowInsetsOnlyOnce() { + val windowInsets = createWindowInsets() + + val captor = ArgumentCaptor.forClass(View.OnApplyWindowInsetsListener::class.java) + verify(view).setOnApplyWindowInsetsListener(capture(captor)) + + val listener = captor.value + + listener.onApplyWindowInsets(view, windowInsets) + + verify(view, times(1)).onApplyWindowInsets(any()) + + listener.onApplyWindowInsets(view, windowInsets) + + verify(view, times(1)).onApplyWindowInsets(any()) + } + + @Test + fun twoDifferentInsets_listenerCallsOnApplyWindowInsetsTwice() { + val windowInsets1 = WindowInsets(Rect(1, 2, 3, 4)) + val windowInsets2 = WindowInsets(Rect(5, 6, 7, 8)) + + val captor = ArgumentCaptor.forClass(View.OnApplyWindowInsetsListener::class.java) + verify(view).setOnApplyWindowInsetsListener(capture(captor)) + + val listener = captor.value + + listener.onApplyWindowInsets(view, windowInsets1) + + verify(view, times(1)).onApplyWindowInsets(any()) + + listener.onApplyWindowInsets(view, windowInsets2) + + verify(view, times(2)).onApplyWindowInsets(any()) + } + + @Test fun alarmIconNotIgnored() { verify(statusIcons, Mockito.never()) .addIgnoredSlot(context.getString(com.android.internal.R.string.status_bar_alarm_clock)) |