"Merge" activity-only transitions into ongoing recents

Since activity-only transitions don't impact recents
state, we can just apply them directly without interrupting
the current recents animation.

Bug: 269691226
Test: launch an app which launches an activity (into itself)
      after a delay (eg. notification permissions). Enter
      recents before that happens.
Change-Id: I356bcc93b975f9979f8ff6cda3c190c2e9ad3a3f
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java
index 2ec64b0..db75be7 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentsTransitionHandler.java
@@ -414,9 +414,11 @@
             boolean hasChangingApp = false;
             final TransitionUtil.LeafTaskFilter leafTaskFilter =
                     new TransitionUtil.LeafTaskFilter();
+            boolean hasTaskChange = false;
             for (int i = 0; i < info.getChanges().size(); ++i) {
                 final TransitionInfo.Change change = info.getChanges().get(i);
                 final ActivityManager.RunningTaskInfo taskInfo = change.getTaskInfo();
+                hasTaskChange = hasTaskChange || taskInfo != null;
                 final boolean isLeafTask = leafTaskFilter.test(change);
                 if (TransitionUtil.isOpeningType(change.getMode())) {
                     if (mRecentsTask != null && mRecentsTask.equals(change.getContainer())) {
@@ -520,7 +522,12 @@
                 didMergeThings = true;
                 mState = STATE_NEW_TASK;
             }
-            if (!didMergeThings) {
+            if (!hasTaskChange) {
+                // Activity only transition, so consume the merge as it doesn't affect the rest of
+                // recents.
+                Slog.d(TAG, "Got an activity only transition during recents, so apply directly");
+                mergeActivityOnly(info, t);
+            } else if (!didMergeThings) {
                 // Didn't recognize anything in incoming transition so don't merge it.
                 Slog.w(TAG, "Don't know how to merge this transition.");
                 return;
@@ -538,6 +545,19 @@
             }
         }
 
+        /** For now, just set-up a jump-cut to the new activity. */
+        private void mergeActivityOnly(TransitionInfo info, SurfaceControl.Transaction t) {
+            for (int i = 0; i < info.getChanges().size(); ++i) {
+                final TransitionInfo.Change change = info.getChanges().get(i);
+                if (TransitionUtil.isOpeningType(change.getMode())) {
+                    t.show(change.getLeash());
+                    t.setAlpha(change.getLeash(), 1.f);
+                } else if (TransitionUtil.isClosingType(change.getMode())) {
+                    t.hide(change.getLeash());
+                }
+            }
+        }
+
         @Override
         public TaskSnapshot screenshotTask(int taskId) {
             try {