diff options
| author | 2023-05-08 21:34:07 +0000 | |
|---|---|---|
| committer | 2023-05-09 18:58:18 +0000 | |
| commit | f0e8060ce04e02eaf6329d358c9f8a505294ce3f (patch) | |
| tree | 71fe3548d3db0a8ae76148e8b54c2a1b2529ee26 | |
| parent | 1f1c22fc353c0e091fa869ed453ff296a4c033fe (diff) | |
Do not re-pin unpinned HUNs
Fixes: 277952658
Test: HeadsUpManagerTest
Test: allow FSIs, send FSI HUN with voice reply, open shade,
send inline reply, close shade => HUN not repinned
Change-Id: Ib1e2a520d4163c2d5cf70471fffa2e2931f8d62e
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java | 16 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HeadsUpManagerTest.java | 48 |
2 files changed, 62 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java index 9ede6ce29963..ed8050a031d8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java @@ -140,7 +140,13 @@ public abstract class HeadsUpManager extends AlertingNotificationManager { } protected boolean shouldHeadsUpBecomePinned(@NonNull NotificationEntry entry) { - return hasFullScreenIntent(entry); + final HeadsUpEntry headsUpEntry = getHeadsUpEntry(entry.getKey()); + if (headsUpEntry == null) { + // This should not happen since shouldHeadsUpBecomePinned is always called after adding + // the NotificationEntry into AlertingNotificationManager's mAlertEntries map. + return hasFullScreenIntent(entry); + } + return hasFullScreenIntent(entry) && !headsUpEntry.wasUnpinned; } protected boolean hasFullScreenIntent(@NonNull NotificationEntry entry) { @@ -151,6 +157,9 @@ public abstract class HeadsUpManager extends AlertingNotificationManager { @NonNull HeadsUpManager.HeadsUpEntry headsUpEntry, boolean isPinned) { mLogger.logSetEntryPinned(headsUpEntry.mEntry, isPinned); NotificationEntry entry = headsUpEntry.mEntry; + if (!isPinned) { + headsUpEntry.wasUnpinned = true; + } if (entry.isRowPinned() != isPinned) { entry.setRowPinned(isPinned); updatePinnedMode(); @@ -177,7 +186,9 @@ public abstract class HeadsUpManager extends AlertingNotificationManager { protected void onAlertEntryAdded(AlertEntry alertEntry) { NotificationEntry entry = alertEntry.mEntry; entry.setHeadsUp(true); - setEntryPinned((HeadsUpEntry) alertEntry, shouldHeadsUpBecomePinned(entry)); + + final boolean shouldPin = shouldHeadsUpBecomePinned(entry); + setEntryPinned((HeadsUpEntry) alertEntry, shouldPin); EventLogTags.writeSysuiHeadsUpStatus(entry.getKey(), 1 /* visible */); for (OnHeadsUpChangedListener listener : mListeners) { listener.onHeadsUpStateChanged(entry, true); @@ -411,6 +422,7 @@ public abstract class HeadsUpManager extends AlertingNotificationManager { protected class HeadsUpEntry extends AlertEntry { public boolean remoteInputActive; protected boolean expanded; + protected boolean wasUnpinned; @Override public boolean isSticky() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HeadsUpManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HeadsUpManagerTest.java index 13a2baa9f3f1..487d26d21824 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HeadsUpManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HeadsUpManagerTest.java @@ -114,6 +114,54 @@ public class HeadsUpManagerTest extends AlertingNotificationManagerTest { } @Test + public void testShouldHeadsUpBecomePinned_hasFSI_notUnpinned_true() { + // Set up NotifEntry with FSI + NotificationEntry notifEntry = new NotificationEntryBuilder() + .setSbn(createNewNotification(/* id= */ 0)) + .build(); + notifEntry.getSbn().getNotification().fullScreenIntent = PendingIntent.getActivity( + getContext(), 0, new Intent(getContext(), this.getClass()), + PendingIntent.FLAG_MUTABLE_UNAUDITED); + + // Add notifEntry to ANM mAlertEntries map and make it NOT unpinned + mHeadsUpManager.showNotification(notifEntry); + HeadsUpManager.HeadsUpEntry headsUpEntry = + mHeadsUpManager.getHeadsUpEntry(notifEntry.getKey()); + headsUpEntry.wasUnpinned = false; + + assertTrue(mHeadsUpManager.shouldHeadsUpBecomePinned(notifEntry)); + } + + @Test + public void testShouldHeadsUpBecomePinned_wasUnpinned_false() { + // Set up NotifEntry with FSI + NotificationEntry notifEntry = new NotificationEntryBuilder() + .setSbn(createNewNotification(/* id= */ 0)) + .build(); + notifEntry.getSbn().getNotification().fullScreenIntent = PendingIntent.getActivity( + getContext(), 0, new Intent(getContext(), this.getClass()), + PendingIntent.FLAG_MUTABLE_UNAUDITED); + + // Add notifEntry to ANM mAlertEntries map and make it unpinned + mHeadsUpManager.showNotification(notifEntry); + HeadsUpManager.HeadsUpEntry headsUpEntry = + mHeadsUpManager.getHeadsUpEntry(notifEntry.getKey()); + headsUpEntry.wasUnpinned = true; + + assertFalse(mHeadsUpManager.shouldHeadsUpBecomePinned(notifEntry)); + } + + @Test + public void testShouldHeadsUpBecomePinned_noFSI_false() { + // Set up NotifEntry with no FSI + NotificationEntry notifEntry = new NotificationEntryBuilder() + .setSbn(createNewNotification(/* id= */ 0)) + .build(); + + assertFalse(mHeadsUpManager.shouldHeadsUpBecomePinned(notifEntry)); + } + + @Test public void testShowNotification_autoDismissesWithAccessibilityTimeout() { doReturn(TEST_A11Y_AUTO_DISMISS_TIME).when(mAccessibilityMgr) .getRecommendedTimeoutMillis(anyInt(), anyInt()); |