Finish noHistory activities immediately after resumed activity shown.

Previously, we were waiting for the newly resumed activity to become
idle before cleaning up stopping activities. However, if an activity
does not enter idle, this will be delayed until idle timeout. This
behavior causes the noHistory flag to not be honored as described.

This changelist addresses the issue by waiting for window visible,
rather than activity idle, before cleaning up noHistory activities.

Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test CtsServicesHostTestCases android.server.cts.ActivityManagerActivityVisibilityTests#testNoHistoryActivityFinishedResumedActivityNotIdle
Change-Id: I827d94816d307ec455a30d933a2255bf61739b3d
Fixes: 37234980
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 358d36d..d5b54ca 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -3500,6 +3500,23 @@
         return mService.mUserController.isCurrentProfileLocked(userId);
     }
 
+    /**
+     * Returns whether a stopping activity is present that should be stopped after visible, rather
+     * than idle.
+     * @return {@code true} if such activity is present. {@code false} otherwise.
+     */
+    boolean isStoppingNoHistoryActivity() {
+        // Activities that are marked as nohistory should be stopped immediately after the resumed
+        // activity has become visible.
+        for (ActivityRecord record : mStoppingActivities) {
+            if (record.isNoHistory()) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     final ArrayList<ActivityRecord> processStoppingActivitiesLocked(ActivityRecord idleActivity,
             boolean remove, boolean processPausingActivities) {
         ArrayList<ActivityRecord> stops = null;