diff options
3 files changed, 37 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputNotificationRebuilder.java b/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputNotificationRebuilder.java index 80c3551b7de0..321b6084831e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputNotificationRebuilder.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/RemoteInputNotificationRebuilder.java @@ -71,6 +71,15 @@ public class RemoteInputNotificationRebuilder { @NonNull public StatusBarNotification rebuildForCanceledSmartReplies( NotificationEntry entry) { + return rebuildWithExistingReplies(entry); + } + + /** + * Rebuilds to include any previously-added remote input replies. + * For when the app cancels a notification that has already been lifetime extended. + */ + @NonNull + public StatusBarNotification rebuildWithExistingReplies(NotificationEntry entry) { return rebuildWithRemoteInputInserted(entry, null /* remoteInputText */, false /* showSpinner */, null /* mimeType */, null /* uri */); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinator.kt index 28fff1519032..fe59d732cceb 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinator.kt @@ -127,6 +127,15 @@ class RemoteInputCoordinator @Inject constructor( mSmartReplyController.stopSending(entry) mNotifUpdater.onInternalNotificationUpdate(newSbn, "Extending lifetime of notification with smart reply") + } else { + // The app may have re-cancelled a notification after it had already + // been lifetime extended. + // Rebuild the notification with the replies it already had to ensure + // those replies continue to be displayed. + val newSbn = mRebuilder.rebuildWithExistingReplies(entry) + mNotifUpdater.onInternalNotificationUpdate(newSbn, + "Extending lifetime of notification that has already been " + + "lifetime extended.") } } else { // Notifications updated without FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinatorTest.kt index 85b8b03a1b46..d3df48e9ef02 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RemoteInputCoordinatorTest.kt @@ -98,6 +98,7 @@ class RemoteInputCoordinatorTest : SysuiTestCase() { `when`(rebuilder.rebuildForCanceledSmartReplies(any())).thenReturn(sbn) `when`(rebuilder.rebuildForRemoteInputReply(any())).thenReturn(sbn) `when`(rebuilder.rebuildForSendingSmartReply(any(), any())).thenReturn(sbn) + `when`(rebuilder.rebuildWithExistingReplies(any())).thenReturn(sbn) } val remoteInputActiveExtender get() = coordinator.mRemoteInputActiveExtender @@ -208,13 +209,30 @@ class RemoteInputCoordinatorTest : SysuiTestCase() { it.onEntryUpdated(entry, true) } - verify(rebuilder, times(1)).rebuildForCanceledSmartReplies(entry) verify(smartReplyController, times(1)).stopSending(entry) } @Test @EnableFlags(FLAG_LIFETIME_EXTENSION_REFACTOR) + fun testRepeatedUpdateTriggersRebuild() { + // Create notification with LIFETIME_EXTENDED_BY_DIRECT_REPLY flag. + val entry = NotificationEntryBuilder() + .setId(3) + .setTag("entry") + .setFlag(mContext, Notification.FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY, true) + .build() + `when`(remoteInputManager.shouldKeepForRemoteInputHistory(entry)).thenReturn(false) + `when`(remoteInputManager.shouldKeepForSmartReplyHistory(entry)).thenReturn(false) + collectionListeners.forEach { + it.onEntryUpdated(entry, true) + } + + verify(rebuilder, times(1)).rebuildWithExistingReplies(entry) + } + + @Test + @EnableFlags(FLAG_LIFETIME_EXTENSION_REFACTOR) fun testLifetimeExtensionListenerClearsRemoteInputs() { // Create notification with LIFETIME_EXTENDED_BY_DIRECT_REPLY flag. val entry = NotificationEntryBuilder() |