Close overlay onTaskStackChanged when All Apps is visible.

We have too many cases where All Apps can relaunch the current task
behind it to the point where it will not be sustainable to manually
close AFVs in all of these cases.

Test: Manual
Fix: 299169192
Fix: 299169075
Fix: 299169073
Flag: No
Change-Id: If3d9aa756ff5e5d6fbaf5f91d2ccc0c5c11a5c23
diff --git a/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayController.java b/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayController.java
index d4e2be9..2dba263 100644
--- a/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/overlay/TaskbarOverlayController.java
@@ -70,6 +70,18 @@
             // New front task will be below existing overlay, so move out of the way.
             hideWindow();
         }
+
+        @Override
+        public void onTaskStackChanged() {
+            // The other callbacks are insufficient for All Apps, because there are many cases where
+            // it can relaunch the same task already behind it. However, this callback needs to be a
+            // no-op when only EDU is shown, because going between the EDU steps invokes this
+            // callback.
+            if (mControllers.getSharedState() != null
+                    && mControllers.getSharedState().allAppsVisible) {
+                hideWindow();
+            }
+        }
     };
 
     private DeviceProfile mLauncherDeviceProfile;
@@ -199,8 +211,10 @@
 
         @Override
         protected void handleClose(boolean animate) {
-            mTaskbarContext.getDragLayer().removeView(this);
-            Optional.ofNullable(mOverlayContext).ifPresent(c -> closeAllOpenViews(c, animate));
+            if (mIsOpen) {
+                mTaskbarContext.getDragLayer().removeView(this);
+                Optional.ofNullable(mOverlayContext).ifPresent(c -> closeAllOpenViews(c, animate));
+            }
         }
 
         @Override