Destroy ActivityRecord when it is removed from the hierarchy

When activity is finishing from back, it may be added to the
ActivityTaskSupervisor#mFinishingActivities and wait for the resume
activity IDLE before destroy.

However, TaskFragmentOrganizer will be notified to apply WCT to delete
the TaskFragment that has no running activity before that is done. It
will cause the activity removed from the hierarchy before the destroy is
called.

Fix: 195454840
Test: Verify with Sidecar + Demo app
Change-Id: I60d9217d061ee53421661bde496b5fb320f01b87
This commit is contained in:
Chris Li
2021-08-04 17:04:51 -07:00
parent d80f48c3bd
commit eccc88a8b5
2 changed files with 16 additions and 1 deletions

View File

@@ -3687,7 +3687,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
@Override
void removeImmediately() {
if (!finishing) {
if (!isState(DESTROYING, DESTROYED)) {
// If Task#removeImmediately is called directly with alive activities, ensure that the
// activities are destroyed and detached from process.
destroyImmediately("removeImmediately");

View File

@@ -1615,6 +1615,21 @@ public class ActivityRecordTests extends WindowTestsBase {
assertFalse(wpc.hasActivities());
}
@Test
public void testRemoveImmediatelyWithFinishingActivity() throws RemoteException {
final ActivityRecord activity = createActivityWithTask();
final WindowProcessController wpc = activity.app;
activity.makeFinishingLocked();
assertTrue(activity.finishing);
activity.getTask().removeImmediately("test");
verify(mAtm.getLifecycleManager()).scheduleTransaction(any(), eq(activity.appToken),
isA(DestroyActivityItem.class));
assertFalse(wpc.hasActivities());
assertEquals(DESTROYING, activity.getState());
}
@Test
public void testRemoveFromHistory() {
final ActivityRecord activity = createActivityWithTask();