Merge "Promote #setAdjacentTaskFragment to TestApi" into sc-v2-dev am: 2c452240ea

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15528180

Change-Id: I5116fe69b2a674d3428c014c91e450340c2207b8
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index f7164cf..df46822 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -3295,6 +3295,7 @@
     method @NonNull public android.window.WindowContainerTransaction scheduleFinishEnterPip(@NonNull android.window.WindowContainerToken, @NonNull android.graphics.Rect);
     method @NonNull public android.window.WindowContainerTransaction setActivityWindowingMode(@NonNull android.window.WindowContainerToken, int);
     method @NonNull public android.window.WindowContainerTransaction setAdjacentRoots(@NonNull android.window.WindowContainerToken, @NonNull android.window.WindowContainerToken);
+    method @NonNull public android.window.WindowContainerTransaction setAdjacentTaskFragments(@NonNull android.os.IBinder, @Nullable android.os.IBinder, @Nullable android.window.WindowContainerTransaction.TaskFragmentAdjacentParams);
     method @NonNull public android.window.WindowContainerTransaction setAppBounds(@NonNull android.window.WindowContainerToken, @NonNull android.graphics.Rect);
     method @NonNull public android.window.WindowContainerTransaction setBounds(@NonNull android.window.WindowContainerToken, @NonNull android.graphics.Rect);
     method @NonNull public android.window.WindowContainerTransaction setBoundsChangeTransaction(@NonNull android.window.WindowContainerToken, @NonNull android.view.SurfaceControl.Transaction);
@@ -3310,6 +3311,15 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.window.WindowContainerTransaction> CREATOR;
   }
 
+  public static class WindowContainerTransaction.TaskFragmentAdjacentParams {
+    ctor public WindowContainerTransaction.TaskFragmentAdjacentParams();
+    ctor public WindowContainerTransaction.TaskFragmentAdjacentParams(@NonNull android.os.Bundle);
+    method public void setShouldDelayPrimaryLastActivityRemoval(boolean);
+    method public void setShouldDelaySecondaryLastActivityRemoval(boolean);
+    method public boolean shouldDelayPrimaryLastActivityRemoval();
+    method public boolean shouldDelaySecondaryLastActivityRemoval();
+  }
+
   public abstract class WindowContainerTransactionCallback {
     ctor public WindowContainerTransactionCallback();
     method public abstract void onTransactionReady(int, @NonNull android.view.SurfaceControl.Transaction);
diff --git a/core/java/android/window/WindowContainerTransaction.java b/core/java/android/window/WindowContainerTransaction.java
index 387837d..9d6488d 100644
--- a/core/java/android/window/WindowContainerTransaction.java
+++ b/core/java/android/window/WindowContainerTransaction.java
@@ -512,17 +512,16 @@
      * @param fragmentToken2    client assigned unique token to create TaskFragment with specified
      *                          in {@link TaskFragmentCreationParams#getFragmentToken()}. If it is
      *                          {@code null}, the transaction will reset the adjacent TaskFragment.
-     * @hide
      */
     @NonNull
     public WindowContainerTransaction setAdjacentTaskFragments(
             @NonNull IBinder fragmentToken1, @Nullable IBinder fragmentToken2,
-            @Nullable TaskFragmentAdjacentOptions options) {
+            @Nullable TaskFragmentAdjacentParams params) {
         final HierarchyOp hierarchyOp =
                 new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS)
                         .setContainer(fragmentToken1)
                         .setReparentContainer(fragmentToken2)
-                        .setLaunchOptions(options != null ? options.toBundle() : null)
+                        .setLaunchOptions(params != null ? params.toBundle() : null)
                         .build();
         mHierarchyOps.add(hierarchyOp);
         return this;
@@ -1304,9 +1303,8 @@
     /**
      * Helper class for building an options Bundle that can be used to set adjacent rules of
      * TaskFragments.
-     * @hide
      */
-    public static class TaskFragmentAdjacentOptions {
+    public static class TaskFragmentAdjacentParams {
         private static final String DELAY_PRIMARY_LAST_ACTIVITY_REMOVAL =
                 "android:transaction.adjacent.option.delay_primary_removal";
         private static final String DELAY_SECONDARY_LAST_ACTIVITY_REMOVAL =
@@ -1315,29 +1313,43 @@
         private boolean mDelayPrimaryLastActivityRemoval;
         private boolean mDelaySecondaryLastActivityRemoval;
 
-        public TaskFragmentAdjacentOptions() {
+        public TaskFragmentAdjacentParams() {
         }
 
-        public TaskFragmentAdjacentOptions(@NonNull Bundle bundle) {
+        public TaskFragmentAdjacentParams(@NonNull Bundle bundle) {
             mDelayPrimaryLastActivityRemoval = bundle.getBoolean(
                     DELAY_PRIMARY_LAST_ACTIVITY_REMOVAL);
             mDelaySecondaryLastActivityRemoval = bundle.getBoolean(
                     DELAY_SECONDARY_LAST_ACTIVITY_REMOVAL);
         }
 
-        public void setDelayPrimaryLastActivityRemoval(boolean delay) {
+        /** @see #shouldDelayPrimaryLastActivityRemoval() */
+        public void setShouldDelayPrimaryLastActivityRemoval(boolean delay) {
             mDelayPrimaryLastActivityRemoval = delay;
         }
 
-        public void setDelaySecondaryLastActivityRemoval(boolean delay) {
+        /** @see #shouldDelaySecondaryLastActivityRemoval() */
+        public void setShouldDelaySecondaryLastActivityRemoval(boolean delay) {
             mDelaySecondaryLastActivityRemoval = delay;
         }
 
-        public boolean isDelayPrimaryLastActivityRemoval() {
+        /**
+         * Whether to delay the last activity of the primary adjacent TaskFragment being immediately
+         * removed while finishing.
+         * <p>
+         * It is usually set to {@code true} to give organizer an opportunity to perform other
+         * actions or animations. An example is to finish together with the adjacent TaskFragment.
+         * </p>
+         */
+        public boolean shouldDelayPrimaryLastActivityRemoval() {
             return mDelayPrimaryLastActivityRemoval;
         }
 
-        public boolean isDelaySecondaryLastActivityRemoval() {
+        /**
+         * Similar to {@link #shouldDelayPrimaryLastActivityRemoval()}, but for the secondary
+         * TaskFragment.
+         */
+        public boolean shouldDelaySecondaryLastActivityRemoval() {
             return mDelaySecondaryLastActivityRemoval;
         }
 
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/organizer/JetpackTaskFragmentOrganizer.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/organizer/JetpackTaskFragmentOrganizer.java
index 9212a0f..46c8ffe 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/organizer/JetpackTaskFragmentOrganizer.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/organizer/JetpackTaskFragmentOrganizer.java
@@ -210,17 +210,17 @@
 
     void setAdjacentTaskFragments(@NonNull WindowContainerTransaction wct,
             @NonNull IBinder primary, @Nullable IBinder secondary, @Nullable SplitRule splitRule) {
-        WindowContainerTransaction.TaskFragmentAdjacentOptions adjacentOptions = null;
+        WindowContainerTransaction.TaskFragmentAdjacentParams adjacentParams = null;
         final boolean finishSecondaryWithPrimary =
                 splitRule != null && SplitContainer.shouldFinishSecondaryWithPrimary(splitRule);
         final boolean finishPrimaryWithSecondary =
                 splitRule != null && SplitContainer.shouldFinishPrimaryWithSecondary(splitRule);
         if (finishSecondaryWithPrimary || finishPrimaryWithSecondary) {
-            adjacentOptions = new WindowContainerTransaction.TaskFragmentAdjacentOptions();
-            adjacentOptions.setDelayPrimaryLastActivityRemoval(finishSecondaryWithPrimary);
-            adjacentOptions.setDelaySecondaryLastActivityRemoval(finishPrimaryWithSecondary);
+            adjacentParams = new WindowContainerTransaction.TaskFragmentAdjacentParams();
+            adjacentParams.setShouldDelayPrimaryLastActivityRemoval(finishSecondaryWithPrimary);
+            adjacentParams.setShouldDelaySecondaryLastActivityRemoval(finishPrimaryWithSecondary);
         }
-        wct.setAdjacentTaskFragments(primary, secondary, adjacentOptions);
+        wct.setAdjacentTaskFragments(primary, secondary, adjacentParams);
     }
 
     TaskFragmentCreationParams createFragmentOptions(IBinder fragmentToken, IBinder ownerToken,
diff --git a/services/core/java/com/android/server/wm/WindowOrganizerController.java b/services/core/java/com/android/server/wm/WindowOrganizerController.java
index 8bcd62d..834b6e6 100644
--- a/services/core/java/com/android/server/wm/WindowOrganizerController.java
+++ b/services/core/java/com/android/server/wm/WindowOrganizerController.java
@@ -733,18 +733,18 @@
                 tf1.setAdjacentTaskFragment(tf2);
 
                 final Bundle bundle = hop.getLaunchOptions();
-                final WindowContainerTransaction.TaskFragmentAdjacentOptions adjacentOptions =
-                        bundle != null ? new WindowContainerTransaction.TaskFragmentAdjacentOptions(
+                final WindowContainerTransaction.TaskFragmentAdjacentParams adjacentParams =
+                        bundle != null ? new WindowContainerTransaction.TaskFragmentAdjacentParams(
                                 bundle) : null;
-                if (adjacentOptions == null) {
+                if (adjacentParams == null) {
                     break;
                 }
 
                 tf1.setDelayLastActivityRemoval(
-                        adjacentOptions.isDelayPrimaryLastActivityRemoval());
+                        adjacentParams.shouldDelayPrimaryLastActivityRemoval());
                 if (tf2 != null) {
                     tf2.setDelayLastActivityRemoval(
-                            adjacentOptions.isDelaySecondaryLastActivityRemoval());
+                            adjacentParams.shouldDelaySecondaryLastActivityRemoval());
                 }
                 break;
         }