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

Commit 676a5b43 authored by riddle_hsu's avatar riddle_hsu Committed by Steve Kondik
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 6e4e03ed
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -3946,16 +3946,18 @@ final class ActivityStack {
    }

    void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) {
        boolean setFirstAsLast = mStackSupervisor.getFocusedStack() == this;
        boolean first = 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;
            }
@@ -3984,6 +3986,10 @@ final class ActivityStack {
            ci.baseActivity = r.intent.getComponent();
            ci.topActivity = top.intent.getComponent();
            ci.lastActiveTime = task.lastActiveTime;
            if (setFirstAsLast && first) {
                ci.lastActiveTime = SystemClock.elapsedRealtime();
                first = false;
            }

            if (top.task != null) {
                ci.description = top.task.lastDescription;