Find pending AppearedActivity first
Bug: 369460497
When the new activity is launched to the topmost TF because the source activity was in that TF, and the source activity is finished before resolving the new activity, we will try to see if the new activity match a rule with the split activities below. If matched, it can be reparented.
Change-Id: Ib5016fc5648f3f6d89b501e8d43014c915eb51e8
Signed-off-by: tanxiaoyan <[email protected]>
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskContainer.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskContainer.java
index 20ad53e..bf7ee27 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskContainer.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/TaskContainer.java
@@ -323,8 +323,16 @@
@Nullable
TaskFragmentContainer getContainerWithActivity(@NonNull IBinder activityToken) {
- return getContainer(container -> container.hasAppearedActivity(activityToken)
- || container.hasPendingAppearedActivity(activityToken));
+ // When the new activity is launched to the topmost TF because the source activity
+ // was in that TF, and the source activity is finished before resolving the new activity,
+ // we will try to see if the new activity match a rule with the split activities below.
+ // If matched, it can be reparented.
+ final TaskFragmentContainer taskFragmentContainer
+ = getContainer(container -> container.hasPendingAppearedActivity(activityToken));
+ if (taskFragmentContainer != null) {
+ return taskFragmentContainer;
+ }
+ return getContainer(container -> container.hasAppearedActivity(activityToken));
}
@Nullable
diff --git a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java
index 7fab371..bc4916a 100644
--- a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java
+++ b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/TaskFragmentContainerTest.java
@@ -535,7 +535,8 @@
// container1.
container2.setInfo(mTransaction, mInfo);
- assertTrue(container2.hasActivity(mActivity.getActivityToken()));
+ assertTrue(container1.hasActivity(mActivity.getActivityToken()));
+ assertFalse(container2.hasActivity(mActivity.getActivityToken()));
// When the pending appeared record is removed from container1, we respect the appeared
// record in container2.
container1.removePendingAppearedActivity(mActivity.getActivityToken());