Ensure ActivityStack's cached resumed activity is updated.
ActivityStack stores a reference to its resumed activity for quicker
future reference. Currently, children must inform the ActivityStack
of any movement in order to properly set this value. We are missing
cases today, causing stale values to persist.
This changelist addresses by updating the stack's paused and resumed
activity references whenever the ancestor stack changes when a task
or activity's parent is changed.
Change-Id: I5ef6db6af3d7e304012c54afa996fbfff28e9110
Fixes: 75992227
Test: atest FrameworksServicesTests:com.android.server.am.ActivityStackTests#testResumedActivityFromActivityReparenting
Test: atest FrameworksServicesTests:com.android.server.am.ActivityStackTests#testPrimarySplitScreenToFullscreenWhenMovedToBack
Test: atest CtsActivityManagerDeviceTestCases:ActivityManagerPinnedStackTests#testFinishPipActivityWithTaskOverlay
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 034cb2e..fccd685 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -927,7 +927,26 @@
if (stack != null && !stack.isInStackLocked(this)) {
throw new IllegalStateException("Task must be added as a Stack child first.");
}
+ final ActivityStack oldStack = mStack;
mStack = stack;
+
+ // If the new {@link TaskRecord} is from a different {@link ActivityStack}, remove this
+ // {@link ActivityRecord} from its current {@link ActivityStack}.
+
+ if (oldStack != mStack) {
+ for (int i = getChildCount() - 1; i >= 0; --i) {
+ final ActivityRecord activity = getChildAt(i);
+
+ if (oldStack != null) {
+ oldStack.onActivityRemovedFromStack(activity);
+ }
+
+ if (mStack != null) {
+ stack.onActivityAddedToStack(activity);
+ }
+ }
+ }
+
onParentChanged();
}
@@ -1232,6 +1251,7 @@
index = Math.min(size, index);
mActivities.add(index, r);
+
updateEffectiveIntent();
if (r.isPersistable()) {
mService.notifyTaskPersisterLocked(this, false);
@@ -1257,7 +1277,7 @@
* @return true if this was the last activity in the task.
*/
boolean removeActivity(ActivityRecord r) {
- return removeActivity(r, false /*reparenting*/);
+ return removeActivity(r, false /* reparenting */);
}
boolean removeActivity(ActivityRecord r, boolean reparenting) {
@@ -1266,7 +1286,7 @@
"Activity=" + r + " does not belong to task=" + this);
}
- r.setTask(null /*task*/, reparenting);
+ r.setTask(null /* task */, reparenting /* reparenting */);
if (mActivities.remove(r) && r.fullscreen) {
// Was previously in list.