2/Trimming tasks based on active and visibility

- Add logic to trim tasks beyond the max-recents policy, including
  migrating the trimming of quiet profile tasks and visibile tasks
  to the system (to ensure callers always get a consistent list)
- Remove trimmed recent tasks from the active task list
- Add logic to actually handle config_hasRecents to determine whether to
  apply visibility filtering (otherwise only filters by max-recents as
  before)

Bug: 34270611
Test: runtest --path frameworks/base/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java

Change-Id: If17586cd9e8ac1ae8f112239381adc96a0528123
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 543d492..5221afd 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -3016,7 +3016,13 @@
     }
 
     @Override
-    public void onRecentTaskRemoved(TaskRecord task) {
+    public void onRecentTaskRemoved(TaskRecord task, boolean wasTrimmed) {
+        if (wasTrimmed) {
+            // Task was trimmed from the recent tasks list -- remove the active task record as well
+            // since the user won't really be able to go back to it
+            removeTaskByIdLocked(task.taskId, false /* killProcess */,
+                    false /* removeFromRecents */);
+        }
         task.removedFromRecents();
     }