From a4ef031f89aefb10a718bd5d734b442ec2d6ccaa Mon Sep 17 00:00:00 2001 From: Shengsong Tan Date: Tue, 22 Jun 2021 15:28:00 +0900 Subject: 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 --- services/core/java/com/android/server/wm/RunningTasks.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/RunningTasks.java b/services/core/java/com/android/server/wm/RunningTasks.java index 7ba772c18455..1533245a75ca 100644 --- a/services/core/java/com/android/server/wm/RunningTasks.java +++ b/services/core/java/com/android/server/wm/RunningTasks.java @@ -43,7 +43,11 @@ class RunningTasks { // Comparator to sort by last active time (descending) private static final Comparator 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 mTmpSortedSet = new TreeSet<>(LAST_ACTIVE_TIME_COMPARATOR); -- cgit v1.2.3-59-g8ed1b