Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ddc74155 authored by riddle_hsu's avatar riddle_hsu
Browse files

[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
parent 7200f661
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -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);
        }
    }