Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc5e60a5 authored by Alexander Roederer's avatar Alexander Roederer Committed by Android (Google) Code Review
Browse files

Merge "Rebuild on lifetime extended update" into main

parents 8f0b4a3d 5aae7b86
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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 */);
    }
+9 −0
Original line number Diff line number Diff line
@@ -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
+19 −1
Original line number Diff line number Diff line
@@ -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,11 +209,28 @@ 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() {