Reset the preferred top focus stack when task visibility changes

- The change in visibility of a task does not always trigger a
  stack order change, which won't trigger the previously set
  top focus stack to be reset for the next activity launch.

Bug: 154658401
Test: Verify we don't regress on b/112084174, and open an activity
      from a bubbled task
Change-Id: I8770448b3ac40c384e8e93ca7ee37f1f8aa80cf4
diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java
index 3dc6723..2b0de9b 100644
--- a/services/core/java/com/android/server/wm/TaskDisplayArea.java
+++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java
@@ -680,6 +680,13 @@
         onStackOrderChanged(stack);
     }
 
+    void resetPreferredTopFocusableStackIfBelow(Task task) {
+        if (mPreferredTopFocusableStack != null
+                && mPreferredTopFocusableStack.compareTo(task) < 0) {
+            mPreferredTopFocusableStack = null;
+        }
+    }
+
     void positionStackAt(int position, ActivityStack child, boolean includingParents) {
         positionChildAt(position, child, includingParents);
         mDisplayContent.layoutAndAssignWindowLayersIfNeeded();