Couple mResumedActivity to Activity lifecycle.
mResumedActivity is a cached reference to the currently resumed
activity in a stack. Previously, this value was set on demand at
various points in the code. This can lead to discord with the
ActivityRecord if the activity updates state without the containing
ActivityStack being directly aware of the change.
This changelist addresses the issue by placing mResumedActivity
behind an accessor. A callback path has been added from
ActivityRecord to the ActivityStack, signaling when the activity's
state has changed. The stack can then update the state accordingly.
Test: atest FrameworksServicesTests:com.android.server.am.ActivityStackTests#testResumedActivity
Bug: 66344012
Fixes: 74118620
Change-Id: If950fd4c41f044ec67722ccc5b1d631cead70bce
diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java b/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java
index 32a29a2..5c3a2b4 100644
--- a/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java
+++ b/services/tests/servicestests/src/com/android/server/am/ActivityStackTests.java
@@ -26,6 +26,8 @@
import static com.android.server.am.ActivityStack.ActivityState.DESTROYED;
import static com.android.server.am.ActivityStack.ActivityState.DESTROYING;
+import static com.android.server.am.ActivityStack.ActivityState.PAUSING;
+import static com.android.server.am.ActivityStack.ActivityState.RESUMED;
import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_DESTROYING;
import static org.junit.Assert.assertEquals;
@@ -99,7 +101,7 @@
// Simulate the a resumed activity set during
// {@link ActivityStack#resumeTopActivityUncheckedLocked}.
mSupervisor.inResumeTopActivity = true;
- mStack.mResumedActivity = r;
+ r.setState(RESUMED, "testNoPauseDuringResumeTopActivity");
final boolean waiting = mStack.goToSleepIfPossible(false);
@@ -107,7 +109,18 @@
assertFalse(waiting);
// Make sure the resumed activity is untouched.
- assertEquals(mStack.mResumedActivity, r);
+ assertEquals(mStack.getResumedActivity(), r);
+ }
+
+ @Test
+ public void testResumedActivity() throws Exception {
+ final ActivityRecord r = new ActivityBuilder(mService).setTask(mTask).build();
+ assertEquals(mStack.getResumedActivity(), null);
+ r.setState(RESUMED, "testResumedActivity");
+ assertEquals(mStack.getResumedActivity(), r);
+ r.setState(PAUSING, "testResumedActivity");
+ assertEquals(mStack.getResumedActivity(), null);
+
}
@Test