From ef49a02eddb7341bc5031175dce3d343af9f4ad1 Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Wed, 18 Aug 2021 17:21:04 +0800 Subject: Prevent activity being destroyed immediately if embedded The embedded activity was destroyed immediately when being finished because the next top activity was on the adjacent TaskFragment and was already visible. Therefore, the finishing animation was played before the organizer requested to finish the activity on the adjacent TaskFragment. Prevent the last activity of the embedded TaskFragment to be removed immediately if the organizer requested to. Bug: 189386466 Test: finish both activities on separate TaskFragments Change-Id: I916eddc4dcf0de3bc7ed7264296f441d1b7bb726 --- .../android/window/WindowContainerTransaction.java | 52 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'core/java/android/window/WindowContainerTransaction.java') diff --git a/core/java/android/window/WindowContainerTransaction.java b/core/java/android/window/WindowContainerTransaction.java index 342df4f9eee3..387837d82acf 100644 --- a/core/java/android/window/WindowContainerTransaction.java +++ b/core/java/android/window/WindowContainerTransaction.java @@ -516,11 +516,13 @@ public final class WindowContainerTransaction implements Parcelable { */ @NonNull public WindowContainerTransaction setAdjacentTaskFragments( - @NonNull IBinder fragmentToken1, @Nullable IBinder fragmentToken2) { + @NonNull IBinder fragmentToken1, @Nullable IBinder fragmentToken2, + @Nullable TaskFragmentAdjacentOptions options) { final HierarchyOp hierarchyOp = new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS) .setContainer(fragmentToken1) .setReparentContainer(fragmentToken2) + .setLaunchOptions(options != null ? options.toBundle() : null) .build(); mHierarchyOps.add(hierarchyOp); return this; @@ -1298,4 +1300,52 @@ public final class WindowContainerTransaction implements Parcelable { } } } + + /** + * Helper class for building an options Bundle that can be used to set adjacent rules of + * TaskFragments. + * @hide + */ + public static class TaskFragmentAdjacentOptions { + 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 = + "android:transaction.adjacent.option.delay_secondary_removal"; + + private boolean mDelayPrimaryLastActivityRemoval; + private boolean mDelaySecondaryLastActivityRemoval; + + public TaskFragmentAdjacentOptions() { + } + + public TaskFragmentAdjacentOptions(@NonNull Bundle bundle) { + mDelayPrimaryLastActivityRemoval = bundle.getBoolean( + DELAY_PRIMARY_LAST_ACTIVITY_REMOVAL); + mDelaySecondaryLastActivityRemoval = bundle.getBoolean( + DELAY_SECONDARY_LAST_ACTIVITY_REMOVAL); + } + + public void setDelayPrimaryLastActivityRemoval(boolean delay) { + mDelayPrimaryLastActivityRemoval = delay; + } + + public void setDelaySecondaryLastActivityRemoval(boolean delay) { + mDelaySecondaryLastActivityRemoval = delay; + } + + public boolean isDelayPrimaryLastActivityRemoval() { + return mDelayPrimaryLastActivityRemoval; + } + + public boolean isDelaySecondaryLastActivityRemoval() { + return mDelaySecondaryLastActivityRemoval; + } + + Bundle toBundle() { + final Bundle b = new Bundle(); + b.putBoolean(DELAY_PRIMARY_LAST_ACTIVITY_REMOVAL, mDelayPrimaryLastActivityRemoval); + b.putBoolean(DELAY_SECONDARY_LAST_ACTIVITY_REMOVAL, mDelaySecondaryLastActivityRemoval); + return b; + } + } } -- cgit v1.2.3