Avoid killing task process after its activity was died
Some tests may have the order: 1. removeTask in tearDown Schedule KILL_TASK_PROCESSES_TIMEOUT_MSG to wait for the activity to be destroyed. 2. forceStopPackage in tearDown The process is forced killed, but the scheduled timeout is not cleared. 3. Launch the app again in a short time If the timeout reaches before the activity attached to the new process, the process will be killed so the test is failed due to target activity not detected. Originally the pending-kill state is consumed (clear flag and kill task processes) only when the activity is destroyed. So this change ensures it is done by the general cleanup that is also called when the process died. Fix: 293185893 Fix: 293280011 Test: atest RecentTasksTest#testRemovePackageByName Change-Id: I8cf8d67cc7cd39b6cc8db91498dc901f494ae85e
This commit is contained in:
@@ -621,6 +621,13 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
|
||||
mFinishingActivities.remove(r);
|
||||
|
||||
stopWaitingForActivityVisible(r);
|
||||
|
||||
final Task task = r.getTask();
|
||||
if (task != null && task.mKillProcessesOnDestroyed && task.getTopMostActivity() == r) {
|
||||
// The activity is destroyed or its process is died, so cancel the pending kill.
|
||||
task.mKillProcessesOnDestroyed = false;
|
||||
removeTimeoutOfKillProcessesOnDestroyed(task);
|
||||
}
|
||||
}
|
||||
|
||||
/** There is no valid launch time, just stop waiting. */
|
||||
@@ -1901,9 +1908,13 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
|
||||
killTaskProcessesIfPossible(task);
|
||||
}
|
||||
|
||||
private void removeTimeoutOfKillProcessesOnDestroyed(Task task) {
|
||||
mHandler.removeMessages(KILL_TASK_PROCESSES_TIMEOUT_MSG, task);
|
||||
}
|
||||
|
||||
void killTaskProcessesOnDestroyedIfNeeded(Task task) {
|
||||
if (task == null || !task.mKillProcessesOnDestroyed) return;
|
||||
mHandler.removeMessages(KILL_TASK_PROCESSES_TIMEOUT_MSG, task);
|
||||
removeTimeoutOfKillProcessesOnDestroyed(task);
|
||||
killTaskProcessesIfPossible(task);
|
||||
}
|
||||
|
||||
@@ -2776,7 +2787,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
|
||||
} break;
|
||||
case KILL_TASK_PROCESSES_TIMEOUT_MSG: {
|
||||
final Task task = (Task) msg.obj;
|
||||
if (task.mKillProcessesOnDestroyed) {
|
||||
if (task.mKillProcessesOnDestroyed && task.hasActivity()) {
|
||||
Slog.i(TAG, "Destroy timeout of remove-task, attempt to kill " + task);
|
||||
killTaskProcessesIfPossible(task);
|
||||
}
|
||||
|
||||
@@ -1038,6 +1038,13 @@ public class RecentTasksTest extends WindowTestsBase {
|
||||
top.setState(ActivityRecord.State.DESTROYING, "test");
|
||||
top.destroyed("test");
|
||||
assertFalse(task.mKillProcessesOnDestroyed);
|
||||
|
||||
// If the process is died, the state should be cleared.
|
||||
final Task lastTask = tasks.get(0);
|
||||
lastTask.addChild(top);
|
||||
lastTask.mKillProcessesOnDestroyed = true;
|
||||
top.handleAppDied();
|
||||
assertFalse(lastTask.mKillProcessesOnDestroyed);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user