Loading packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -238,7 +238,7 @@ public abstract class AlertingNotificationManager implements NotificationLifetim * @param key the key to check if removable * @return true if the alert entry can be removed */ protected boolean canRemoveImmediately(String key) { public boolean canRemoveImmediately(String key) { AlertEntry alertEntry = mAlertEntries.get(key); return alertEntry == null || alertEntry.wasShownLongEnough() || alertEntry.mEntry.isRowDismissed(); Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinator.java +12 −9 Original line number Diff line number Diff line Loading @@ -179,23 +179,26 @@ public class HeadsUpCoordinator implements Coordinator { @Override public boolean shouldExtendLifetime(@NonNull NotificationEntry entry, int reason) { boolean isShowingHun = isCurrentlyShowingHun(entry); if (isShowingHun) { boolean extend = !mHeadsUpManager.canRemoveImmediately(entry.getKey()); if (extend) { if (isSticky(entry)) { long removeAfterMillis = mHeadsUpManager.getEarliestRemovalTime(entry.getKey()); if (removeAfterMillis <= 0) return false; mExecutor.executeDelayed(() -> { // make sure that the entry was not updated long removeAfterMillis2 = mHeadsUpManager.getEarliestRemovalTime(entry.getKey()); if (mNotifsExtendingLifetime.contains(entry) && removeAfterMillis2 <= 0) { mHeadsUpManager.removeNotification(entry.getKey(), true); if (mNotifsExtendingLifetime.contains(entry) && mHeadsUpManager.canRemoveImmediately(entry.getKey())) { mHeadsUpManager.removeNotification( entry.getKey(), /* releaseImmediately */ true); } }, removeAfterMillis); } else { // remove as early as possible mExecutor.execute( () -> mHeadsUpManager.removeNotification( entry.getKey(), /* releaseImmediately */ false)); } mNotifsExtendingLifetime.add(entry); } return isShowingHun; return extend; } @Override Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java +1 −1 Original line number Diff line number Diff line Loading @@ -412,7 +412,7 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable, } @Override protected boolean canRemoveImmediately(@NonNull String key) { public boolean canRemoveImmediately(@NonNull String key) { if (mSwipedOutKeys.contains(key)) { // We always instantly dismiss views being manually swiped out. mSwipedOutKeys.remove(key); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -140,10 +140,13 @@ public class HeadsUpCoordinatorTest extends SysuiTestCase { public void testCancelStickyNotification() { when(mHeadsUpManager.isSticky(anyString())).thenReturn(true); addHUN(mEntry); when(mHeadsUpManager.canRemoveImmediately(anyString())).thenReturn(false, true); when(mHeadsUpManager.getEarliestRemovalTime(anyString())).thenReturn(1000L, 0L); assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, 0)); mClock.advanceTime(1000L); mExecutor.runAllReady(); verify(mHeadsUpManager, times(0)) .removeNotification(anyString(), eq(false)); verify(mHeadsUpManager, times(1)) .removeNotification(anyString(), eq(true)); } Loading @@ -156,6 +159,22 @@ public class HeadsUpCoordinatorTest extends SysuiTestCase { assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, 0)); mClock.advanceTime(1000L); mExecutor.runAllReady(); verify(mHeadsUpManager, times(0)) .removeNotification(anyString(), eq(false)); verify(mHeadsUpManager, times(0)) .removeNotification(anyString(), eq(true)); } @Test public void testCancelNotification() { when(mHeadsUpManager.isSticky(anyString())).thenReturn(false); addHUN(mEntry); when(mHeadsUpManager.getEarliestRemovalTime(anyString())).thenReturn(1000L, 500L); assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, 0)); mClock.advanceTime(1000L); mExecutor.runAllReady(); verify(mHeadsUpManager, times(1)) .removeNotification(anyString(), eq(false)); verify(mHeadsUpManager, times(0)) .removeNotification(anyString(), eq(true)); } Loading Loading @@ -189,6 +208,13 @@ public class HeadsUpCoordinatorTest extends SysuiTestCase { // GIVEN there is a HUN, mEntry addHUN(mEntry); given(mHeadsUpManager.canRemoveImmediately(anyString())).willAnswer(i -> { String key = i.getArgument(0); for (NotificationEntry entry : mHuns) { if (entry.getKey().equals(key)) return false; } return true; }); // THEN only the current HUN, mEntry, should be lifetimeExtended assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, /* cancellationReason */ 0)); assertFalse(mNotifLifetimeExtender.shouldExtendLifetime( Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -238,7 +238,7 @@ public abstract class AlertingNotificationManager implements NotificationLifetim * @param key the key to check if removable * @return true if the alert entry can be removed */ protected boolean canRemoveImmediately(String key) { public boolean canRemoveImmediately(String key) { AlertEntry alertEntry = mAlertEntries.get(key); return alertEntry == null || alertEntry.wasShownLongEnough() || alertEntry.mEntry.isRowDismissed(); Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinator.java +12 −9 Original line number Diff line number Diff line Loading @@ -179,23 +179,26 @@ public class HeadsUpCoordinator implements Coordinator { @Override public boolean shouldExtendLifetime(@NonNull NotificationEntry entry, int reason) { boolean isShowingHun = isCurrentlyShowingHun(entry); if (isShowingHun) { boolean extend = !mHeadsUpManager.canRemoveImmediately(entry.getKey()); if (extend) { if (isSticky(entry)) { long removeAfterMillis = mHeadsUpManager.getEarliestRemovalTime(entry.getKey()); if (removeAfterMillis <= 0) return false; mExecutor.executeDelayed(() -> { // make sure that the entry was not updated long removeAfterMillis2 = mHeadsUpManager.getEarliestRemovalTime(entry.getKey()); if (mNotifsExtendingLifetime.contains(entry) && removeAfterMillis2 <= 0) { mHeadsUpManager.removeNotification(entry.getKey(), true); if (mNotifsExtendingLifetime.contains(entry) && mHeadsUpManager.canRemoveImmediately(entry.getKey())) { mHeadsUpManager.removeNotification( entry.getKey(), /* releaseImmediately */ true); } }, removeAfterMillis); } else { // remove as early as possible mExecutor.execute( () -> mHeadsUpManager.removeNotification( entry.getKey(), /* releaseImmediately */ false)); } mNotifsExtendingLifetime.add(entry); } return isShowingHun; return extend; } @Override Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java +1 −1 Original line number Diff line number Diff line Loading @@ -412,7 +412,7 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable, } @Override protected boolean canRemoveImmediately(@NonNull String key) { public boolean canRemoveImmediately(@NonNull String key) { if (mSwipedOutKeys.contains(key)) { // We always instantly dismiss views being manually swiped out. mSwipedOutKeys.remove(key); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/HeadsUpCoordinatorTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -140,10 +140,13 @@ public class HeadsUpCoordinatorTest extends SysuiTestCase { public void testCancelStickyNotification() { when(mHeadsUpManager.isSticky(anyString())).thenReturn(true); addHUN(mEntry); when(mHeadsUpManager.canRemoveImmediately(anyString())).thenReturn(false, true); when(mHeadsUpManager.getEarliestRemovalTime(anyString())).thenReturn(1000L, 0L); assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, 0)); mClock.advanceTime(1000L); mExecutor.runAllReady(); verify(mHeadsUpManager, times(0)) .removeNotification(anyString(), eq(false)); verify(mHeadsUpManager, times(1)) .removeNotification(anyString(), eq(true)); } Loading @@ -156,6 +159,22 @@ public class HeadsUpCoordinatorTest extends SysuiTestCase { assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, 0)); mClock.advanceTime(1000L); mExecutor.runAllReady(); verify(mHeadsUpManager, times(0)) .removeNotification(anyString(), eq(false)); verify(mHeadsUpManager, times(0)) .removeNotification(anyString(), eq(true)); } @Test public void testCancelNotification() { when(mHeadsUpManager.isSticky(anyString())).thenReturn(false); addHUN(mEntry); when(mHeadsUpManager.getEarliestRemovalTime(anyString())).thenReturn(1000L, 500L); assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, 0)); mClock.advanceTime(1000L); mExecutor.runAllReady(); verify(mHeadsUpManager, times(1)) .removeNotification(anyString(), eq(false)); verify(mHeadsUpManager, times(0)) .removeNotification(anyString(), eq(true)); } Loading Loading @@ -189,6 +208,13 @@ public class HeadsUpCoordinatorTest extends SysuiTestCase { // GIVEN there is a HUN, mEntry addHUN(mEntry); given(mHeadsUpManager.canRemoveImmediately(anyString())).willAnswer(i -> { String key = i.getArgument(0); for (NotificationEntry entry : mHuns) { if (entry.getKey().equals(key)) return false; } return true; }); // THEN only the current HUN, mEntry, should be lifetimeExtended assertTrue(mNotifLifetimeExtender.shouldExtendLifetime(mEntry, /* cancellationReason */ 0)); assertFalse(mNotifLifetimeExtender.shouldExtendLifetime( Loading