[ActivityManager] Improve task order of getRunningTasks.

Symptom:
During switching task in same stack, the first result
of getRunningTasks will be the behind stack's top task.
e.g.
 App Task X is starting task Y, the first entry may be home.

Root Cause:
TaskRecord's lastActiveTime is updated when pausing
or resuming. When X task launch a new task Y, Y is
on the top of task history, before X complete pause,
Y's lastActiveTime will be 0 because it is a new task.
Then when comparing the front task with other stack,
other stack will be regarded as the newer one.

Solution:
If the stack is focused stack, give the top task with the last time.

Change-Id: I0adc07608e03d333e0120a0dbc52a0fbbbb12f34
This commit is contained in:
riddle_hsu
2015-04-07 11:30:09 +08:00
parent 7200f661c1
commit ddc74155c9

View File

@@ -3900,16 +3900,18 @@ final class ActivityStack {
}
void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) {
boolean focusedStack = mStackSupervisor.getFocusedStack() == this;
boolean topTask = true;
for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
final TaskRecord task = mTaskHistory.get(taskNdx);
if (task.getTopActivity() == null) {
continue;
}
ActivityRecord r = null;
ActivityRecord top = null;
int numActivities = 0;
int numRunning = 0;
final ArrayList<ActivityRecord> activities = task.mActivities;
if (activities.isEmpty()) {
continue;
}
if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) {
continue;
}
@@ -3938,14 +3940,18 @@ final class ActivityStack {
ci.baseActivity = r.intent.getComponent();
ci.topActivity = top.intent.getComponent();
ci.lastActiveTime = task.lastActiveTime;
if (focusedStack && topTask) {
// Give the latest time to ensure foreground task can be sorted
// at the first, because lastActiveTime of creating task is 0.
ci.lastActiveTime = System.currentTimeMillis();
topTask = false;
}
if (top.task != null) {
ci.description = top.task.lastDescription;
}
ci.numActivities = numActivities;
ci.numRunning = numRunning;
//System.out.println(
// "#" + maxNum + ": " + " descr=" + ci.description);
list.add(ci);
}
}