From fbbaffca330b07b247c15ca04b817c8fd7f0f07a Mon Sep 17 00:00:00 2001 From: Caitlin Cassidy Date: Tue, 12 Oct 2021 19:00:38 +0000 Subject: [PATCH] [Ongoing Call] Only listen for the swipe gesture while in immersive mode. Test: manual: Do a swipe up on the status bar while not in immersive, then open a landscape immersive app and verify the status bar still shows (i.e. it wasn't dismissed by the previous swipe) Test: new unit tests Bug: 195839150 Change-Id: I1913c25c29b635979b0cb89d815b2d2c6cc40530 --- .../ongoingcall/OngoingCallController.kt | 18 +++- .../ongoingcall/OngoingCallControllerTest.kt | 83 ++++++++++++++----- 2 files changed, 78 insertions(+), 23 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt index 04f97d2d216b9..3806d9a2925c0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt @@ -201,11 +201,8 @@ class OngoingCallController @Inject constructor( statusBarWindowController.ifPresent { it.setOngoingProcessRequiresStatusBarVisible(true) } - // TODO(b/195839150): Only listen for the gesture when in immersive mode. - swipeStatusBarAwayGestureHandler.ifPresent { - it.addOnGestureDetectedCallback(TAG, this::onSwipeAwayGestureDetected) - } } + updateGestureListening() mListeners.forEach { l -> l.onOngoingCallStateChanged(animate = true) } } else { // If we failed to update the chip, don't store the call info. Then [hasOngoingCall] @@ -293,6 +290,18 @@ class OngoingCallController @Inject constructor( return procState <= ActivityManager.PROCESS_STATE_TOP } + private fun updateGestureListening() { + if (callNotificationInfo == null + || callNotificationInfo?.statusBarSwipedAway == true + || !isFullscreen) { + swipeStatusBarAwayGestureHandler.ifPresent { it.removeOnGestureDetectedCallback(TAG) } + } else { + swipeStatusBarAwayGestureHandler.ifPresent { + it.addOnGestureDetectedCallback(TAG, this::onSwipeAwayGestureDetected) + } + } + } + private fun removeChip() { callNotificationInfo = null tearDownChipView() @@ -335,6 +344,7 @@ class OngoingCallController @Inject constructor( override fun onFullscreenStateChanged(isFullscreen: Boolean) { this@OngoingCallController.isFullscreen = isFullscreen updateChipClickListener() + updateGestureListening() } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt index 53b7c319e3abd..3d2ff47e3cdd2 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt @@ -149,14 +149,6 @@ class OngoingCallControllerTest : SysuiTestCase() { verify(mockStatusBarWindowController).setOngoingProcessRequiresStatusBarVisible(true) } - @Test - fun onEntryUpdated_isOngoingCallNotif_swipeGestureCallbackAdded() { - notifCollectionListener.onEntryUpdated(createOngoingCallNotifEntry()) - - verify(mockSwipeStatusBarAwayGestureHandler) - .addOnGestureDetectedCallback(anyString(), any()) - } - @Test fun onEntryUpdated_notOngoingCallNotif_listenerNotNotified() { notifCollectionListener.onEntryUpdated(createNotCallNotifEntry()) @@ -258,17 +250,6 @@ class OngoingCallControllerTest : SysuiTestCase() { verify(mockStatusBarWindowController).setOngoingProcessRequiresStatusBarVisible(false) } - @Test - fun onEntryUpdated_callNotifAddedThenRemoved_swipeGestureCallbackRemoved() { - val ongoingCallNotifEntry = createOngoingCallNotifEntry() - notifCollectionListener.onEntryAdded(ongoingCallNotifEntry) - - notifCollectionListener.onEntryRemoved(ongoingCallNotifEntry, REASON_USER_STOPPED) - - verify(mockSwipeStatusBarAwayGestureHandler) - .removeOnGestureDetectedCallback(anyString()) - } - /** Regression test for b/188491504. */ @Test fun onEntryRemoved_removedNotifHasSameKeyAsAddedNotif_listenerNotified() { @@ -509,6 +490,70 @@ class OngoingCallControllerTest : SysuiTestCase() { assertThat(chipView.hasOnClickListeners()).isTrue() } + // Swipe gesture tests + + @Test + fun callStartedInImmersiveMode_swipeGestureCallbackAdded() { + getStateListener().onFullscreenStateChanged(true) + + notifCollectionListener.onEntryUpdated(createOngoingCallNotifEntry()) + + verify(mockSwipeStatusBarAwayGestureHandler) + .addOnGestureDetectedCallback(anyString(), any()) + } + + @Test + fun callStartedNotInImmersiveMode_swipeGestureCallbackNotAdded() { + getStateListener().onFullscreenStateChanged(false) + + notifCollectionListener.onEntryUpdated(createOngoingCallNotifEntry()) + + verify(mockSwipeStatusBarAwayGestureHandler, never()) + .addOnGestureDetectedCallback(anyString(), any()) + } + + @Test + fun transitionToImmersiveMode_swipeGestureCallbackAdded() { + notifCollectionListener.onEntryUpdated(createOngoingCallNotifEntry()) + + getStateListener().onFullscreenStateChanged(true) + + verify(mockSwipeStatusBarAwayGestureHandler) + .addOnGestureDetectedCallback(anyString(), any()) + } + + @Test + fun transitionOutOfImmersiveMode_swipeGestureCallbackRemoved() { + getStateListener().onFullscreenStateChanged(true) + notifCollectionListener.onEntryUpdated(createOngoingCallNotifEntry()) + reset(mockSwipeStatusBarAwayGestureHandler) + + getStateListener().onFullscreenStateChanged(false) + + verify(mockSwipeStatusBarAwayGestureHandler) + .removeOnGestureDetectedCallback(anyString()) + } + + @Test + fun callEndedWhileInImmersiveMode_swipeGestureCallbackRemoved() { + getStateListener().onFullscreenStateChanged(true) + val ongoingCallNotifEntry = createOngoingCallNotifEntry() + notifCollectionListener.onEntryAdded(ongoingCallNotifEntry) + reset(mockSwipeStatusBarAwayGestureHandler) + + notifCollectionListener.onEntryRemoved(ongoingCallNotifEntry, REASON_USER_STOPPED) + + verify(mockSwipeStatusBarAwayGestureHandler) + .removeOnGestureDetectedCallback(anyString()) + } + + // TODO(b/195839150): Add test + // swipeGesturedTriggeredPreviously_entersImmersiveModeAgain_callbackNotAdded(). That's + // difficult to add now because we have no way to trigger [SwipeStatusBarAwayGestureHandler]'s + // callbacks in test. + + // END swipe gesture tests + private fun createOngoingCallNotifEntry() = createCallNotifEntry(ongoingCallStyle) private fun createScreeningCallNotifEntry() = createCallNotifEntry(screeningCallStyle)