Fix the same active time tasks disappeared on RunngintTasks

In |getTasks|, a TreeSet is used to sort task by last active time
directly. However, the TreeSet is no duplicatable, so the if the
comparing task have the same lastActiveTime, one of them will be
dropped.

This CL add task id as the extra field on comparator.

Bug: 191729305
Test: manually launch many apps.
Change-Id: Iee39e438224f3ef22bc0a9254be88eec842c61a6
Merged-In: Iee39e438224f3ef22bc0a9254be88eec842c61a6
This commit is contained in:
Shengsong Tan
2021-06-22 15:28:00 +09:00
committed by Will McVicker
parent 51a4954076
commit a4ef031f89

View File

@@ -43,7 +43,11 @@ class RunningTasks {
// Comparator to sort by last active time (descending)
private static final Comparator<Task> LAST_ACTIVE_TIME_COMPARATOR =
(o1, o2) -> Long.signum(o2.lastActiveTime - o1.lastActiveTime);
(o1, o2) -> {
return o1.lastActiveTime == o2.lastActiveTime
? Integer.signum(o2.mTaskId - o1.mTaskId) :
Long.signum(o2.lastActiveTime - o1.lastActiveTime);
};
private final TreeSet<Task> mTmpSortedSet = new TreeSet<>(LAST_ACTIVE_TIME_COMPARATOR);