am e8a94224: Merge "Return tasks in correct order." into klp-dev

* commit 'e8a9422495d6af9fc68cf4e838a4a5f19177034b':
  Return tasks in correct order.
This commit is contained in:
Craig Mautner
2013-09-19 13:05:43 -07:00
committed by Android Git Automerger
3 changed files with 42 additions and 6 deletions

View File

@@ -679,6 +679,12 @@ public class ActivityManager {
*/
public int numRunning;
/**
* Last time task was run. For sorting.
* @hide
*/
public long lastActiveTime;
public RunningTaskInfo() {
}

View File

@@ -3323,11 +3323,10 @@ final class ActivityStack {
return didSomething;
}
ActivityRecord getTasksLocked(int maxNum, IThumbnailReceiver receiver,
ActivityRecord getTasksLocked(IThumbnailReceiver receiver,
PendingThumbnailsRecord pending, List<RunningTaskInfo> list) {
ActivityRecord topRecord = null;
for (int taskNdx = mTaskHistory.size() - 1; maxNum > 0 && taskNdx >= 0;
--maxNum, --taskNdx) {
for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
final TaskRecord task = mTaskHistory.get(taskNdx);
ActivityRecord r = null;
ActivityRecord top = null;
@@ -3358,6 +3357,8 @@ final class ActivityStack {
ci.id = task.taskId;
ci.baseActivity = r.intent.getComponent();
ci.topActivity = top.intent.getComponent();
ci.lastActiveTime = task.lastActiveTime;
if (top.thumbHolder != null) {
ci.description = top.thumbHolder.lastDescription;
}

View File

@@ -548,14 +548,43 @@ public final class ActivityStackSupervisor {
ActivityRecord getTasksLocked(int maxNum, IThumbnailReceiver receiver,
PendingThumbnailsRecord pending, List<RunningTaskInfo> list) {
ActivityRecord r = null;
for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
// Gather all of the running tasks for each stack into runningTaskLists.
final int numStacks = mStacks.size();
ArrayList<RunningTaskInfo>[] runningTaskLists = new ArrayList[numStacks];
for (int stackNdx = numStacks - 1; stackNdx >= 0; --stackNdx) {
final ActivityStack stack = mStacks.get(stackNdx);
final ActivityRecord ar =
stack.getTasksLocked(maxNum - list.size(), receiver, pending, list);
ArrayList<RunningTaskInfo> stackTaskList = new ArrayList<RunningTaskInfo>();
runningTaskLists[stackNdx] = stackTaskList;
final ActivityRecord ar = stack.getTasksLocked(receiver, pending, stackTaskList);
if (isFrontStack(stack)) {
r = ar;
}
}
// The lists are already sorted from most recent to oldest. Just pull the most recent off
// each list and add it to list. Stop when all lists are empty or maxNum reached.
while (maxNum > 0) {
long mostRecentActiveTime = Long.MIN_VALUE;
ArrayList<RunningTaskInfo> selectedStackList = null;
for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
ArrayList<RunningTaskInfo> stackTaskList = runningTaskLists[stackNdx];
if (!stackTaskList.isEmpty()) {
final long lastActiveTime = stackTaskList.get(0).lastActiveTime;
if (lastActiveTime > mostRecentActiveTime) {
mostRecentActiveTime = lastActiveTime;
selectedStackList = stackTaskList;
}
}
}
if (selectedStackList != null) {
list.add(selectedStackList.remove(0));
--maxNum;
} else {
break;
}
}
return r;
}