Inline notif pipeline flag in NotifRemoteInputMgr

This change is a no-op; the flag is now enabled-by-default, so all
removed code paths here are effectively dead.

Bug: 200269355
Test: atest SystemUITests
Change-Id: Ifa554b42821c35860add7f7538658c5a48384c66
Merged-In: Ifa554b42821c35860add7f7538658c5a48384c66
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java
index 5cdd01f..78b3b0a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java
@@ -286,10 +286,6 @@
                 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
         mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
         mRebuilder = rebuilder;
-        if (!mNotifPipelineFlags.isNewPipelineEnabled()) {
-            mRemoteInputListener = createLegacyRemoteInputLifetimeExtender(mainHandler,
-                    notificationEntryManager, smartReplyController);
-        }
         mKeyguardManager = context.getSystemService(KeyguardManager.class);
         mStatusBarStateController = statusBarStateController;
         mRemoteInputUriController = remoteInputUriController;
@@ -313,34 +309,19 @@
                     int reason) {
                 // We're removing the notification, the smart controller can forget about it.
                 mSmartReplyController.stopSending(entry);
-
-                if (removedByUser && entry != null) {
-                    onPerformRemoveNotification(entry, entry.getKey());
-                }
             }
         });
     }
 
     /** Add a listener for various remote input events.  Works with NEW pipeline only. */
     public void setRemoteInputListener(@NonNull RemoteInputListener remoteInputListener) {
-        if (mNotifPipelineFlags.isNewPipelineEnabled()) {
-            if (mRemoteInputListener != null) {
-                throw new IllegalStateException("mRemoteInputListener is already set");
-            }
-            mRemoteInputListener = remoteInputListener;
-            if (mRemoteInputController != null) {
-                mRemoteInputListener.setRemoteInputController(mRemoteInputController);
-            }
+        if (mRemoteInputListener != null) {
+            throw new IllegalStateException("mRemoteInputListener is already set");
         }
-    }
-
-    @NonNull
-    @VisibleForTesting
-    protected LegacyRemoteInputLifetimeExtender createLegacyRemoteInputLifetimeExtender(
-            Handler mainHandler,
-            NotificationEntryManager notificationEntryManager,
-            SmartReplyController smartReplyController) {
-        return new LegacyRemoteInputLifetimeExtender();
+        mRemoteInputListener = remoteInputListener;
+        if (mRemoteInputController != null) {
+            mRemoteInputListener.setRemoteInputController(mRemoteInputController);
+        }
     }
 
     /** Initializes this component with the provided dependencies. */
@@ -381,12 +362,6 @@
                 }
             }
         });
-        if (!mNotifPipelineFlags.isNewPipelineEnabled()) {
-            mSmartReplyController.setCallback((entry, reply) -> {
-                StatusBarNotification newSbn = mRebuilder.rebuildForSendingSmartReply(entry, reply);
-                mEntryManager.updateNotification(newSbn, null /* ranking */);
-            });
-        }
     }
 
     public void addControllerCallback(RemoteInputController.Callback callback) {
@@ -588,19 +563,6 @@
         return v.findViewWithTag(RemoteInputView.VIEW_TAG);
     }
 
-    public ArrayList<NotificationLifetimeExtender> getLifetimeExtenders() {
-        // OLD pipeline code ONLY; can assume implementation
-        return ((LegacyRemoteInputLifetimeExtender) mRemoteInputListener).mLifetimeExtenders;
-    }
-
-    @VisibleForTesting
-    void onPerformRemoveNotification(NotificationEntry entry, final String key) {
-        // OLD pipeline code ONLY; can assume implementation
-        ((LegacyRemoteInputLifetimeExtender) mRemoteInputListener)
-                .mKeysKeptForRemoteInputHistory.remove(key);
-        cleanUpRemoteInputForUserRemoval(entry);
-    }
-
     /**
      * Disable remote input on the entry and remove the remote input view.
      * This should be called when a user dismisses a notification that won't be lifetime extended.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
index aa061d7..bd69cc38 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
@@ -212,8 +212,6 @@
                 mEntryManager.setUpWithPresenter(this);
                 mEntryManager.addNotificationLifetimeExtender(mHeadsUpManager);
                 mEntryManager.addNotificationLifetimeExtender(mGutsManager);
-                mEntryManager.addNotificationLifetimeExtenders(
-                        remoteInputManager.getLifetimeExtenders());
             }
             notificationInterruptStateProvider.addSuppressor(mInterruptSuppressor);
             mLockscreenUserManager.setUpWithPresenter(this);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java
index 2691ff9..34d13c7 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java
@@ -16,12 +16,9 @@
 
 package com.android.systemui.statusbar;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertTrue;
 
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.app.Notification;
@@ -30,19 +27,14 @@
 import android.os.Looper;
 import android.os.SystemClock;
 import android.os.UserHandle;
-import android.service.notification.NotificationListenerService;
 import android.testing.AndroidTestingRunner;
 import android.testing.TestableLooper;
 
-import androidx.annotation.NonNull;
 import androidx.test.filters.SmallTest;
 
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.dump.DumpManager;
 import com.android.systemui.plugins.statusbar.StatusBarStateController;
-import com.android.systemui.statusbar.NotificationRemoteInputManager.LegacyRemoteInputLifetimeExtender.RemoteInputActiveExtender;
-import com.android.systemui.statusbar.NotificationRemoteInputManager.LegacyRemoteInputLifetimeExtender.RemoteInputHistoryExtender;
-import com.android.systemui.statusbar.NotificationRemoteInputManager.LegacyRemoteInputLifetimeExtender.SmartReplyHistoryExtender;
 import com.android.systemui.statusbar.notification.NotifPipelineFlags;
 import com.android.systemui.statusbar.notification.NotificationEntryManager;
 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -52,8 +44,6 @@
 import com.android.systemui.statusbar.phone.CentralSurfaces;
 import com.android.systemui.statusbar.policy.RemoteInputUriController;
 
-import com.google.android.collect.Sets;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -76,23 +66,15 @@
     @Mock private NotificationRemoteInputManager.Callback mCallback;
     @Mock private RemoteInputController mController;
     @Mock private SmartReplyController mSmartReplyController;
-    @Mock private NotificationListenerService.RankingMap mRanking;
     @Mock private ExpandableNotificationRow mRow;
     @Mock private StatusBarStateController mStateController;
     @Mock private RemoteInputUriController mRemoteInputUriController;
     @Mock private NotificationClickNotifier mClickNotifier;
-
-    // Dependency mocks:
     @Mock private NotificationEntryManager mEntryManager;
     @Mock private NotificationLockscreenUserManager mLockscreenUserManager;
 
     private TestableNotificationRemoteInputManager mRemoteInputManager;
     private NotificationEntry mEntry;
-    private RemoteInputHistoryExtender mRemoteInputHistoryExtender;
-    private SmartReplyHistoryExtender mSmartReplyHistoryExtender;
-    private RemoteInputActiveExtender mRemoteInputActiveExtender;
-    private TestableNotificationRemoteInputManager.FakeLegacyRemoteInputLifetimeExtender
-            mLegacyRemoteInputLifetimeExtender;
 
     @Before
     public void setUp() {
@@ -121,21 +103,7 @@
                 .build();
         mEntry.setRow(mRow);
 
-        mRemoteInputManager.setUpWithPresenterForTest(mCallback,
-                mDelegate, mController);
-        for (NotificationLifetimeExtender extender : mRemoteInputManager.getLifetimeExtenders()) {
-            extender.setCallback(
-                    mock(NotificationLifetimeExtender.NotificationSafeToRemoveCallback.class));
-        }
-    }
-
-    @Test
-    public void testPerformOnRemoveNotification() {
-        when(mController.isRemoteInputActive(mEntry)).thenReturn(true);
-        mRemoteInputManager.onPerformRemoveNotification(mEntry, mEntry.getKey());
-
-        assertFalse(mEntry.mRemoteEditImeVisible);
-        verify(mController).removeRemoteInput(mEntry, null);
+        mRemoteInputManager.setUpWithPresenterForTest(mCallback, mDelegate, mController);
     }
 
     @Test
@@ -143,7 +111,6 @@
         when(mController.isRemoteInputActive(mEntry)).thenReturn(true);
 
         assertTrue(mRemoteInputManager.isRemoteInputActive(mEntry));
-        assertTrue(mRemoteInputActiveExtender.shouldExtendLifetime(mEntry));
     }
 
     @Test
@@ -152,7 +119,6 @@
         when(mController.isSpinning(mEntry.getKey())).thenReturn(true);
 
         assertTrue(mRemoteInputManager.shouldKeepForRemoteInputHistory(mEntry));
-        assertTrue(mRemoteInputHistoryExtender.shouldExtendLifetime(mEntry));
     }
 
     @Test
@@ -161,7 +127,6 @@
         mEntry.lastRemoteInputSent = SystemClock.elapsedRealtime();
 
         assertTrue(mRemoteInputManager.shouldKeepForRemoteInputHistory(mEntry));
-        assertTrue(mRemoteInputHistoryExtender.shouldExtendLifetime(mEntry));
     }
 
     @Test
@@ -170,20 +135,6 @@
         when(mSmartReplyController.isSendingSmartReply(mEntry.getKey())).thenReturn(true);
 
         assertTrue(mRemoteInputManager.shouldKeepForSmartReplyHistory(mEntry));
-        assertTrue(mSmartReplyHistoryExtender.shouldExtendLifetime(mEntry));
-    }
-
-    @Test
-    public void testNotificationWithRemoteInputActiveIsRemovedOnCollapse() {
-        mRemoteInputActiveExtender.setShouldManageLifetime(mEntry, true /* shouldManage */);
-
-        assertEquals(mLegacyRemoteInputLifetimeExtender.getEntriesKeptForRemoteInputActive(),
-                Sets.newArraySet(mEntry));
-
-        mRemoteInputManager.onPanelCollapsed();
-
-        assertTrue(
-                mLegacyRemoteInputLifetimeExtender.getEntriesKeptForRemoteInputActive().isEmpty());
     }
 
     private class TestableNotificationRemoteInputManager extends NotificationRemoteInputManager {
@@ -227,28 +178,5 @@
             mRemoteInputController = controller;
         }
 
-        @NonNull
-        @Override
-        protected LegacyRemoteInputLifetimeExtender createLegacyRemoteInputLifetimeExtender(
-                Handler mainHandler,
-                NotificationEntryManager notificationEntryManager,
-                SmartReplyController smartReplyController) {
-            mLegacyRemoteInputLifetimeExtender = new FakeLegacyRemoteInputLifetimeExtender();
-            return mLegacyRemoteInputLifetimeExtender;
-        }
-
-        class FakeLegacyRemoteInputLifetimeExtender extends LegacyRemoteInputLifetimeExtender {
-
-            @Override
-            protected void addLifetimeExtenders() {
-                mRemoteInputActiveExtender = new RemoteInputActiveExtender();
-                mRemoteInputHistoryExtender = new RemoteInputHistoryExtender();
-                mSmartReplyHistoryExtender = new SmartReplyHistoryExtender();
-                mLifetimeExtenders.add(mRemoteInputHistoryExtender);
-                mLifetimeExtenders.add(mSmartReplyHistoryExtender);
-                mLifetimeExtenders.add(mRemoteInputActiveExtender);
-            }
-        }
-
     }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java
index 3500e4d..c75aa81 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java
@@ -17,15 +17,15 @@
 import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertTrue;
 
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import android.app.ActivityManager;
 import android.app.Notification;
 import android.os.Handler;
-import android.os.Looper;
 import android.os.RemoteException;
 import android.os.UserHandle;
 import android.service.notification.StatusBarNotification;
@@ -39,14 +39,12 @@
 import com.android.systemui.R;
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.dump.DumpManager;
-import com.android.systemui.plugins.statusbar.StatusBarStateController;
-import com.android.systemui.statusbar.notification.NotifPipelineFlags;
-import com.android.systemui.statusbar.notification.NotificationEntryManager;
+import com.android.systemui.statusbar.notification.collection.NotifPipeline;
 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
 import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
+import com.android.systemui.statusbar.notification.collection.coordinator.RemoteInputCoordinator;
+import com.android.systemui.statusbar.notification.collection.notifcollection.InternalNotifUpdater;
 import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
-import com.android.systemui.statusbar.phone.CentralSurfaces;
-import com.android.systemui.statusbar.policy.RemoteInputUriController;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -54,8 +52,6 @@
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
-import java.util.Optional;
-
 @RunWith(AndroidTestingRunner.class)
 @TestableLooper.RunWithLooper
 @SmallTest
@@ -67,57 +63,50 @@
     private static final int TEST_CHOICE_COUNT = 4;
     private static final int TEST_ACTION_COUNT = 3;
 
-    private Notification mNotification;
     private NotificationEntry mEntry;
     private SmartReplyController mSmartReplyController;
-    private NotificationRemoteInputManager mRemoteInputManager;
 
     @Mock private NotificationVisibilityProvider mVisibilityProvider;
-    @Mock private RemoteInputController.Delegate mDelegate;
-    @Mock private NotificationRemoteInputManager.Callback mCallback;
     @Mock private StatusBarNotification mSbn;
-    @Mock private NotificationEntryManager mNotificationEntryManager;
     @Mock private IStatusBarService mIStatusBarService;
-    @Mock private StatusBarStateController mStatusBarStateController;
-    @Mock private RemoteInputUriController mRemoteInputUriController;
     @Mock private NotificationClickNotifier mClickNotifier;
+    @Mock private InternalNotifUpdater mInternalNotifUpdater;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        mDependency.injectTestDependency(NotificationEntryManager.class,
-                mNotificationEntryManager);
 
         mSmartReplyController = new SmartReplyController(
                 mock(DumpManager.class),
                 mVisibilityProvider,
                 mIStatusBarService,
                 mClickNotifier);
-        mDependency.injectTestDependency(SmartReplyController.class,
-                mSmartReplyController);
-
-        mRemoteInputManager = new NotificationRemoteInputManager(mContext,
-                mock(NotifPipelineFlags.class),
-                mock(NotificationLockscreenUserManager.class),
-                mSmartReplyController,
-                mVisibilityProvider,
-                mNotificationEntryManager,
+        RemoteInputCoordinator remoteInputCoordinator = new RemoteInputCoordinator(
+                mock(DumpManager.class),
                 new RemoteInputNotificationRebuilder(mContext),
-                () -> Optional.of(mock(CentralSurfaces.class)),
-                mStatusBarStateController,
-                Handler.createAsync(Looper.myLooper()),
-                mRemoteInputUriController,
-                mClickNotifier,
-                mock(ActionClickLogger.class),
-                mock(DumpManager.class));
-        mRemoteInputManager.setUpWithCallback(mCallback, mDelegate);
-        mNotification = new Notification.Builder(mContext, "")
+                mock(NotificationRemoteInputManager.class),
+                mock(Handler.class),
+                mSmartReplyController);
+        remoteInputCoordinator.setRemoteInputController(mock(RemoteInputController.class));
+        NotifPipeline notifPipeline = mock(NotifPipeline.class);
+        when(notifPipeline.getInternalNotifUpdater(anyString())).thenReturn(mInternalNotifUpdater);
+        remoteInputCoordinator.attach(notifPipeline);
+
+        Notification notification = new Notification.Builder(mContext, "")
                 .setSmallIcon(R.drawable.ic_person)
                 .setContentTitle("Title")
                 .setContentText("Text").build();
-
-        mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID,
-                0, mNotification, new UserHandle(ActivityManager.getCurrentUser()), null, 0);
+        mSbn = new StatusBarNotification(
+                TEST_PACKAGE_NAME,
+                TEST_PACKAGE_NAME,
+                0,
+                null,
+                TEST_UID,
+                0,
+                notification,
+                new UserHandle(ActivityManager.getCurrentUser()),
+                null,
+                0);
         mEntry = new NotificationEntryBuilder()
                 .setSbn(mSbn)
                 .build();
@@ -128,10 +117,9 @@
         mSmartReplyController.smartReplySent(mEntry, TEST_CHOICE_INDEX, TEST_CHOICE_TEXT,
                 MetricsEvent.LOCATION_UNKNOWN, false /* modifiedBeforeSending */);
 
-        // Sending smart reply should make calls to NotificationEntryManager
-        // to update the notification with reply and spinner.
-        verify(mNotificationEntryManager).updateNotification(
-                argThat(sbn -> sbn.getKey().equals(mSbn.getKey())), isNull());
+        // Sending smart reply should update the notification with reply and spinner.
+        verify(mInternalNotifUpdater).onInternalNotificationUpdate(
+                argThat(sbn -> sbn.getKey().equals(mSbn.getKey())), anyString());
     }
 
     @Test