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

Commit 5aae7b86 authored by Alexander Roederer's avatar Alexander Roederer
Browse files

Rebuild on lifetime extended update

Rebuilds the notification when a lifetime extended notification has a
system update sent to it. Without this, an app that cancels a
notification a second time after a direct reply has already occured and
the notification is lifetime extended will see a second update sent (one
on the direct reply, and one on the cancelation),
which will clear any remote input history items from the notification.

Bug: 299448097
Bug: 327511827
Flag: ACONFIG android.app.lifetime_extension_refactor STAGING
Test: atest RemoteInputCoordinatorTest.kt, build and flash
Change-Id: I982bfe2dfc4a74b6d401ceb5a6edca291e564cc7
parent dcacfa43
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() {