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

Commit d2199604 authored by Winson Chung's avatar Winson Chung
Browse files

Prevent reiterating over same stack tasks when calculating running tasks

- Clear the stack task list before each fetch and don't re-add all of them.
  There is no functional change since the tasks are added to the same set
  which will dedupe them.

Bug: 112467578
Test: atest FrameworksServicesTests:RunningTasksTest
Change-Id: I9c65771429b30d8e1d357843235b1a6deebfd402
parent e4c7d37e
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -54,19 +54,17 @@ class RunningTasks {

        // Gather all of the tasks across all of the tasks, and add them to the sorted set
        mTmpSortedSet.clear();
        mTmpStackTasks.clear();
        final int numDisplays = activityDisplays.size();
        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
            final ActivityDisplay display = activityDisplays.valueAt(displayNdx);
            for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) {
                final ActivityStack stack = display.getChildAt(stackNdx);
                mTmpStackTasks.clear();
                stack.getRunningTasks(mTmpStackTasks, ignoreActivityType, ignoreWindowingMode,
                        callingUid, allowed);
                for (int i = mTmpStackTasks.size() - 1; i >= 0; i--) {
                mTmpSortedSet.addAll(mTmpStackTasks);
            }
        }
        }

        // Take the first {@param maxNum} tasks and create running task infos for them
        final Iterator<TaskRecord> iter = mTmpSortedSet.iterator();
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ import org.junit.runner.RunWith;
import java.util.ArrayList;

/**
 * runtest --path frameworks/base/services/tests/servicestests/src/com/android/server/am/RunningTasksTest.java
 * atest FrameworksServicesTests:RunningTasksTest
 */
@MediumTest
@Presubmit