Do not trim tasks when updating activity visibilities

When updating visibility of all activities, the state of activity
may be changed to resumed, and it will also be added to recents
task. If the max amount of task is reached, the inactive tasks will
be trimmed. So it is possible that the index of visibility-update
loop becomes out of bounds.

Though it can also be solved by checking the index every time, that
seems to be a bit unintuitive and waste. And skip trimming should
also reduce the side effect of visibility-update to focus on its
major functionality.

Fixes: 154809437
Fixes: 142627724
Test: RecentTasksTest#testAddTasksInVisibilityUpdate_expectNoTrim

Change-Id: Iba66f2e6ce0beae3ef1187549318ef8779154a3b
diff --git a/services/core/java/com/android/server/wm/KeyguardController.java b/services/core/java/com/android/server/wm/KeyguardController.java
index f672394..4c10d58 100644
--- a/services/core/java/com/android/server/wm/KeyguardController.java
+++ b/services/core/java/com/android/server/wm/KeyguardController.java
@@ -70,7 +70,6 @@
     private boolean mKeyguardGoingAway;
     private boolean mDismissalRequested;
     private int mBeforeUnoccludeTransit;
-    private int mVisibilityTransactionDepth;
     private final SparseArray<KeyguardDisplayState> mDisplayStates = new SparseArray<>();
     private final ActivityTaskManagerService mService;
     private RootWindowContainer mRootWindowContainer;
@@ -252,24 +251,6 @@
     }
 
     /**
-     * Starts a batch of visibility updates.
-     */
-    void beginActivityVisibilityUpdate() {
-        mVisibilityTransactionDepth++;
-    }
-
-    /**
-     * Ends a batch of visibility updates. After all batches are done, this method makes sure to
-     * update lockscreen occluded/dismiss state if needed.
-     */
-    void endActivityVisibilityUpdate() {
-        mVisibilityTransactionDepth--;
-        if (mVisibilityTransactionDepth == 0) {
-            visibilitiesUpdated();
-        }
-    }
-
-    /**
      * @return True if we may show an activity while Keyguard is showing because we are in the
      *         process of dismissing it anyways, false otherwise.
      */
@@ -292,7 +273,11 @@
                 && !mWindowManager.isKeyguardSecure(mService.getCurrentUserId());
     }
 
-    private void visibilitiesUpdated() {
+    /**
+     * Makes sure to update lockscreen occluded/dismiss state if needed after completing all
+     * visibility updates ({@link ActivityStackSupervisor#endActivityVisibilityUpdate}).
+     */
+    void visibilitiesUpdated() {
         boolean requestDismissKeyguard = false;
         for (int displayNdx = mRootWindowContainer.getChildCount() - 1;
              displayNdx >= 0; displayNdx--) {
@@ -568,7 +553,6 @@
         pw.println(prefix + "  mKeyguardGoingAway=" + mKeyguardGoingAway);
         dumpDisplayStates(pw, prefix);
         pw.println(prefix + "  mDismissalRequested=" + mDismissalRequested);
-        pw.println(prefix + "  mVisibilityTransactionDepth=" + mVisibilityTransactionDepth);
         pw.println();
     }