Fix regression in task trimming

- This change does not affect the trimming of inactive or visible tasks.
  The previous logic was too aggressive in clearing tasks that were being
  moved in the recent task list (only in the case when a new task is being
  added).  In particular if the two tasks share affinities, we should
  clean up the old task, but not clear it in replacing the task in the
  recents list.

Test: com.android.server.am.RecentTasksTest
Test: android.server.am.ActivityManagerDisplayTests
Test: #testContentDestroyOnDisplayRemoved
Bug: 70636181

Change-Id: If6275ff1d9d8f842ce1122e1229b46fae92c43b0
Signed-off-by: Winson Chung <winsonc@google.com>
2 files changed