Merge "[Ongoing Call] Only listen for the swipe gesture while in immersive mode." into sc-v2-dev

This commit is contained in:
Caitlin Cassidy
2021-10-14 14:30:49 +00:00
committed by Android (Google) Code Review
2 changed files with 78 additions and 23 deletions

View File

@@ -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()
}
}

View File

@@ -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)