Remane shouldExtendLifetime to meaningful maybeExtendLifetime

Test: all pipeline test
Change-Id: If24a2c0bc5b5ab3c26e32dbef4f7c3b6cd618dab
This commit is contained in:
Jay Aliomer
2022-01-10 13:33:43 -05:00
parent ca5641d35a
commit 639a139e5f
10 changed files with 62 additions and 62 deletions

View File

@@ -622,7 +622,7 @@ public class NotifCollection implements Dumpable {
entry.mLifetimeExtenders.clear();
mAmDispatchingToOtherCode = true;
for (NotifLifetimeExtender extender : mLifetimeExtenders) {
if (extender.shouldExtendLifetime(entry, entry.mCancellationReason)) {
if (extender.maybeExtendLifetime(entry, entry.mCancellationReason)) {
mLogger.logLifetimeExtended(entry.getKey(), extender);
entry.mLifetimeExtenders.add(extender);
}

View File

@@ -84,7 +84,7 @@ class GutsCoordinator @Inject constructor(
onEndLifetimeExtensionCallback = callback
}
override fun shouldExtendLifetime(entry: NotificationEntry, reason: Int): Boolean {
override fun maybeExtendLifetime(entry: NotificationEntry, reason: Int): Boolean {
val isShowingGuts = isCurrentlyShowingGuts(entry)
if (isShowingGuts) {
notifsExtendingLifetime.add(entry.key)

View File

@@ -178,7 +178,7 @@ public class HeadsUpCoordinator implements Coordinator {
}
@Override
public boolean shouldExtendLifetime(@NonNull NotificationEntry entry, int reason) {
public boolean maybeExtendLifetime(@NonNull NotificationEntry entry, int reason) {
boolean extend = !mHeadsUpManager.canRemoveImmediately(entry.getKey());
if (extend) {
if (isSticky(entry)) {

View File

@@ -45,7 +45,7 @@ public interface NotifLifetimeExtender {
* called on all lifetime extenders even if earlier ones return true (in other words, multiple
* lifetime extenders can be extending a notification at the same time).
*/
boolean shouldExtendLifetime(@NonNull NotificationEntry entry, @CancellationReason int reason);
boolean maybeExtendLifetime(@NonNull NotificationEntry entry, @CancellationReason int reason);
/**
* Called by the NotifCollection to inform a lifetime extender that its extension of a notif

View File

@@ -73,7 +73,7 @@ abstract class SelfTrackingLifetimeExtender(
final override fun getName(): String = name
final override fun shouldExtendLifetime(entry: NotificationEntry, reason: Int): Boolean {
final override fun maybeExtendLifetime(entry: NotificationEntry, reason: Int): Boolean {
val shouldExtend = queryShouldExtendLifetime(entry)
if (debug) {
Log.d(tag, "$name.shouldExtendLifetime(key=${entry.key}, reason=$reason)" +

View File

@@ -459,7 +459,7 @@ public class NotifCollectionTest extends SysuiTestCase {
mCollection.dismissNotification(entry1, defaultStats(entry1));
// THEN lifetime extenders are never queried
verify(mExtender1, never()).shouldExtendLifetime(eq(entry1), anyInt());
verify(mExtender1, never()).maybeExtendLifetime(eq(entry1), anyInt());
}
@Test
@@ -912,9 +912,9 @@ public class NotifCollectionTest extends SysuiTestCase {
mNoMan.retractNotif(notif2.sbn, REASON_APP_CANCEL);
// THEN each extender is asked whether to extend, even if earlier ones return true
verify(mExtender1).shouldExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender2).shouldExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender3).shouldExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender1).maybeExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender2).maybeExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender3).maybeExtendLifetime(entry2, REASON_APP_CANCEL);
// THEN the entry is not removed
assertTrue(mCollection.getAllNotifs().contains(entry2));
@@ -948,9 +948,9 @@ public class NotifCollectionTest extends SysuiTestCase {
mExtender2.callback.onEndLifetimeExtension(mExtender2, entry2);
// THEN each extender is re-queried
verify(mExtender1).shouldExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender2).shouldExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender3).shouldExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender1).maybeExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender2).maybeExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender3).maybeExtendLifetime(entry2, REASON_APP_CANCEL);
// THEN the entry is not removed
assertTrue(mCollection.getAllNotifs().contains(entry2));
@@ -986,9 +986,9 @@ public class NotifCollectionTest extends SysuiTestCase {
assertTrue(mCollection.getAllNotifs().contains(entry2));
// THEN we don't re-query the extenders
verify(mExtender1, never()).shouldExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender2, never()).shouldExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender3, never()).shouldExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender1, never()).maybeExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender2, never()).maybeExtendLifetime(entry2, REASON_APP_CANCEL);
verify(mExtender3, never()).maybeExtendLifetime(entry2, REASON_APP_CANCEL);
// THEN the entry properly records all extenders that returned true
assertEquals(singletonList(mExtender1), entry2.mLifetimeExtenders);
@@ -1585,7 +1585,7 @@ public class NotifCollectionTest extends SysuiTestCase {
}
@Override
public boolean shouldExtendLifetime(
public boolean maybeExtendLifetime(
@NonNull NotificationEntry entry,
@CancellationReason int reason) {
return shouldExtendLifetime;

View File

@@ -73,43 +73,43 @@ class GutsCoordinatorTest : SysuiTestCase() {
@Test
fun testSimpleLifetimeExtension() {
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isFalse()
notifGutsViewListener.onGutsOpen(entry1, mock(NotificationGuts::class.java))
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isTrue()
notifGutsViewListener.onGutsClose(entry1)
verify(lifetimeExtenderCallback).onEndLifetimeExtension(notifLifetimeExtender, entry1)
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isFalse()
}
@Test
fun testDoubleOpenLifetimeExtension() {
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isFalse()
notifGutsViewListener.onGutsOpen(entry1, mock(NotificationGuts::class.java))
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isTrue()
notifGutsViewListener.onGutsOpen(entry1, mock(NotificationGuts::class.java))
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isTrue()
notifGutsViewListener.onGutsClose(entry1)
verify(lifetimeExtenderCallback).onEndLifetimeExtension(notifLifetimeExtender, entry1)
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isFalse()
}
@Test
fun testTwoEntryLifetimeExtension() {
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry2, 0)).isFalse()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isFalse()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry2, 0)).isFalse()
notifGutsViewListener.onGutsOpen(entry1, mock(NotificationGuts::class.java))
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry2, 0)).isFalse()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isTrue()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry2, 0)).isFalse()
notifGutsViewListener.onGutsOpen(entry2, mock(NotificationGuts::class.java))
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry2, 0)).isTrue()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isTrue()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry2, 0)).isTrue()
notifGutsViewListener.onGutsClose(entry1)
verify(lifetimeExtenderCallback).onEndLifetimeExtension(notifLifetimeExtender, entry1)
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry2, 0)).isTrue()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isFalse()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry2, 0)).isTrue()
notifGutsViewListener.onGutsClose(entry2)
verify(lifetimeExtenderCallback).onEndLifetimeExtension(notifLifetimeExtender, entry2)
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(notifLifetimeExtender.shouldExtendLifetime(entry2, 0)).isFalse()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry1, 0)).isFalse()
assertThat(notifLifetimeExtender.maybeExtendLifetime(entry2, 0)).isFalse()
}
}

View File

@@ -142,7 +142,7 @@ public class HeadsUpCoordinatorTest extends SysuiTestCase {
addHUN(mEntry);
when(mHeadsUpManager.canRemoveImmediately(anyString())).thenReturn(false, true);
when(mHeadsUpManager.getEarliestRemovalTime(anyString())).thenReturn(1000L, 0L);
assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, 0));
assertTrue(mNotifLifetimeExtender.maybeExtendLifetime(mEntry, 0));
mClock.advanceTime(1000L);
mExecutor.runAllReady();
verify(mHeadsUpManager, times(0))
@@ -156,7 +156,7 @@ public class HeadsUpCoordinatorTest extends SysuiTestCase {
when(mHeadsUpManager.isSticky(anyString())).thenReturn(true);
addHUN(mEntry);
when(mHeadsUpManager.getEarliestRemovalTime(anyString())).thenReturn(1000L, 500L);
assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, 0));
assertTrue(mNotifLifetimeExtender.maybeExtendLifetime(mEntry, 0));
mClock.advanceTime(1000L);
mExecutor.runAllReady();
verify(mHeadsUpManager, times(0))
@@ -170,7 +170,7 @@ public class HeadsUpCoordinatorTest extends SysuiTestCase {
when(mHeadsUpManager.isSticky(anyString())).thenReturn(false);
addHUN(mEntry);
when(mHeadsUpManager.getEarliestRemovalTime(anyString())).thenReturn(1000L, 500L);
assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, 0));
assertTrue(mNotifLifetimeExtender.maybeExtendLifetime(mEntry, 0));
mClock.advanceTime(1000L);
mExecutor.runAllReady();
verify(mHeadsUpManager, times(1))
@@ -216,8 +216,8 @@ public class HeadsUpCoordinatorTest extends SysuiTestCase {
return true;
});
// THEN only the current HUN, mEntry, should be lifetimeExtended
assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, /* cancellationReason */ 0));
assertFalse(mNotifLifetimeExtender.shouldExtendLifetime(
assertTrue(mNotifLifetimeExtender.maybeExtendLifetime(mEntry, /* cancellationReason */ 0));
assertFalse(mNotifLifetimeExtender.maybeExtendLifetime(
new NotificationEntryBuilder()
.setPkg("test-package")
.build(), /* cancellationReason */ 0));

View File

@@ -101,27 +101,27 @@ class RemoteInputCoordinatorTest : SysuiTestCase() {
@Test
fun testRemoteInputActive() {
`when`(remoteInputManager.isRemoteInputActive(entry1)).thenReturn(true)
assertThat(remoteInputActiveExtender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(remoteInputHistoryExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(smartReplyHistoryExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(remoteInputActiveExtender.maybeExtendLifetime(entry1, 0)).isTrue()
assertThat(remoteInputHistoryExtender.maybeExtendLifetime(entry1, 0)).isFalse()
assertThat(smartReplyHistoryExtender.maybeExtendLifetime(entry1, 0)).isFalse()
assertThat(listener.isNotificationKeptForRemoteInputHistory(entry1.key)).isFalse()
}
@Test
fun testRemoteInputHistory() {
`when`(remoteInputManager.shouldKeepForRemoteInputHistory(entry1)).thenReturn(true)
assertThat(remoteInputActiveExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(remoteInputHistoryExtender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(smartReplyHistoryExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(remoteInputActiveExtender.maybeExtendLifetime(entry1, 0)).isFalse()
assertThat(remoteInputHistoryExtender.maybeExtendLifetime(entry1, 0)).isTrue()
assertThat(smartReplyHistoryExtender.maybeExtendLifetime(entry1, 0)).isFalse()
assertThat(listener.isNotificationKeptForRemoteInputHistory(entry1.key)).isTrue()
}
@Test
fun testSmartReplyHistory() {
`when`(remoteInputManager.shouldKeepForSmartReplyHistory(entry1)).thenReturn(true)
assertThat(remoteInputActiveExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(remoteInputHistoryExtender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(smartReplyHistoryExtender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(remoteInputActiveExtender.maybeExtendLifetime(entry1, 0)).isFalse()
assertThat(remoteInputHistoryExtender.maybeExtendLifetime(entry1, 0)).isFalse()
assertThat(smartReplyHistoryExtender.maybeExtendLifetime(entry1, 0)).isTrue()
assertThat(listener.isNotificationKeptForRemoteInputHistory(entry1.key)).isTrue()
}
@@ -136,7 +136,7 @@ class RemoteInputCoordinatorTest : SysuiTestCase() {
verify(lifetimeExtensionCallback, never()).onEndLifetimeExtension(any(), any())
// Start extending lifetime & validate that the extension is ended
assertThat(remoteInputActiveExtender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(remoteInputActiveExtender.maybeExtendLifetime(entry1, 0)).isTrue()
assertThat(remoteInputActiveExtender.isExtending(entry1.key)).isTrue()
listener.onPanelCollapsed()
verify(lifetimeExtensionCallback).onEndLifetimeExtension(remoteInputActiveExtender, entry1)

View File

@@ -77,7 +77,7 @@ class SelfTrackingLifetimeExtenderTest : SysuiTestCase() {
@Test
fun testNoExtend() {
`when`(shouldExtend.test(entry1)).thenReturn(false)
assertThat(extender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isFalse()
assertThat(extender.isExtending(entry1.key)).isFalse()
verify(onStarted, never()).accept(entry1)
verify(onCanceled, never()).accept(entry1)
@@ -86,7 +86,7 @@ class SelfTrackingLifetimeExtenderTest : SysuiTestCase() {
@Test
fun testExtendThenCancelForRepost() {
`when`(shouldExtend.test(entry1)).thenReturn(true)
assertThat(extender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isTrue()
verify(onStarted).accept(entry1)
verify(onCanceled, never()).accept(entry1)
assertThat(extender.isExtending(entry1.key)).isTrue()
@@ -108,7 +108,7 @@ class SelfTrackingLifetimeExtenderTest : SysuiTestCase() {
@Test
fun testExtendThenEnd() {
`when`(shouldExtend.test(entry1)).thenReturn(true)
assertThat(extender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isTrue()
verify(onStarted).accept(entry1)
assertThat(extender.isExtending(entry1.key)).isTrue()
extender.endLifetimeExtension(entry1.key)
@@ -119,7 +119,7 @@ class SelfTrackingLifetimeExtenderTest : SysuiTestCase() {
@Test
fun testExtendThenEndAfterDelay() {
`when`(shouldExtend.test(entry1)).thenReturn(true)
assertThat(extender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isTrue()
verify(onStarted).accept(entry1)
assertThat(extender.isExtending(entry1.key)).isTrue()
@@ -142,11 +142,11 @@ class SelfTrackingLifetimeExtenderTest : SysuiTestCase() {
fun testExtendThenEndAll() {
`when`(shouldExtend.test(entry1)).thenReturn(true)
`when`(shouldExtend.test(entry2)).thenReturn(true)
assertThat(extender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isTrue()
verify(onStarted).accept(entry1)
assertThat(extender.isExtending(entry1.key)).isTrue()
assertThat(extender.isExtending(entry2.key)).isFalse()
assertThat(extender.shouldExtendLifetime(entry2, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry2, 0)).isTrue()
verify(onStarted).accept(entry2)
assertThat(extender.isExtending(entry1.key)).isTrue()
assertThat(extender.isExtending(entry2.key)).isTrue()
@@ -160,11 +160,11 @@ class SelfTrackingLifetimeExtenderTest : SysuiTestCase() {
@Test
fun testExtendWithinEndCanReExtend() {
`when`(shouldExtend.test(entry1)).thenReturn(true)
assertThat(extender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isTrue()
verify(onStarted, times(1)).accept(entry1)
`when`(callback.onEndLifetimeExtension(extender, entry1)).thenAnswer {
assertThat(extender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isTrue()
}
extender.endLifetimeExtension(entry1.key)
verify(onStarted, times(2)).accept(entry1)
@@ -174,11 +174,11 @@ class SelfTrackingLifetimeExtenderTest : SysuiTestCase() {
@Test
fun testExtendWithinEndCanNotReExtend() {
`when`(shouldExtend.test(entry1)).thenReturn(true, false)
assertThat(extender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isTrue()
verify(onStarted, times(1)).accept(entry1)
`when`(callback.onEndLifetimeExtension(extender, entry1)).thenAnswer {
assertThat(extender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isFalse()
}
extender.endLifetimeExtension(entry1.key)
verify(onStarted, times(1)).accept(entry1)
@@ -188,11 +188,11 @@ class SelfTrackingLifetimeExtenderTest : SysuiTestCase() {
@Test
fun testExtendWithinEndAllCanReExtend() {
`when`(shouldExtend.test(entry1)).thenReturn(true)
assertThat(extender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isTrue()
verify(onStarted, times(1)).accept(entry1)
`when`(callback.onEndLifetimeExtension(extender, entry1)).thenAnswer {
assertThat(extender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isTrue()
}
extender.endAllLifetimeExtensions()
verify(onStarted, times(2)).accept(entry1)
@@ -202,11 +202,11 @@ class SelfTrackingLifetimeExtenderTest : SysuiTestCase() {
@Test
fun testExtendWithinEndAllCanNotReExtend() {
`when`(shouldExtend.test(entry1)).thenReturn(true, false)
assertThat(extender.shouldExtendLifetime(entry1, 0)).isTrue()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isTrue()
verify(onStarted, times(1)).accept(entry1)
`when`(callback.onEndLifetimeExtension(extender, entry1)).thenAnswer {
assertThat(extender.shouldExtendLifetime(entry1, 0)).isFalse()
assertThat(extender.maybeExtendLifetime(entry1, 0)).isFalse()
}
extender.endAllLifetimeExtensions()
verify(onStarted, times(1)).accept(entry1)