Hide overview and app icon split option when appropriate

Don't show app menu icon split option or overview
action split option when current taskView is already in
split or there are not at least 2 tasks with which to
invoke split

Fixes: 197245395
Test: Tested with small and large screen,
dismissing tasks in overview, with and without
GroupedTaskView as main running task

Change-Id: I90cc3c39e4d94662cb87314a210d45d145b6e026
diff --git a/quickstep/src/com/android/quickstep/TaskOverlayFactory.java b/quickstep/src/com/android/quickstep/TaskOverlayFactory.java
index eb5c43f..978fb57 100644
--- a/quickstep/src/com/android/quickstep/TaskOverlayFactory.java
+++ b/quickstep/src/com/android/quickstep/TaskOverlayFactory.java
@@ -107,6 +107,13 @@
 
     public static void addSplitOptions(List<SystemShortcut> outShortcuts,
             BaseDraggingActivity activity, TaskView taskView, DeviceProfile deviceProfile) {
+        int[] taskViewTaskIds = taskView.getTaskIds();
+        boolean alreadyHasMultipleTasks = taskViewTaskIds[0] != -1 &&
+                taskViewTaskIds[1] != -1;
+        if (alreadyHasMultipleTasks) {
+            return;
+        }
+
         PagedOrientationHandler orientationHandler =
                 taskView.getRecentsView().getPagedOrientationHandler();
         List<SplitPositionOption> positions =
diff --git a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
index 5d1c202..1b28c53 100644
--- a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
+++ b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java
@@ -223,7 +223,6 @@
         mDp = dp;
         updateVerticalMargin(SysUINavigationMode.getMode(getContext()));
         requestLayout();
-        setSplitButtonVisible(mDp.isTablet);
     }
 
     public void setSplitButtonVisible(boolean visible) {
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 810ecce..6947fc5 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -1500,7 +1500,7 @@
         mActionsView.setDp(dp);
         mOrientationState.setDeviceProfile(dp);
 
-        // Update RecentsView adn TaskView's DeviceProfile dependent layout.
+        // Update RecentsView and TaskView's DeviceProfile dependent layout.
         updateOrientationHandler();
     }
 
@@ -2593,7 +2593,6 @@
         mFirstFloatingTaskView.setAlpha(1);
         mFirstFloatingTaskView.addAnimation(anim, startingTaskRect,
                 mTempRect, mSplitHiddenTaskView, true /*fadeWithThumbnail*/);
-        anim.addEndListener(aBoolean -> mActionsView.setSplitButtonVisible(false));
     }
 
     /**
@@ -2933,6 +2932,7 @@
                         dispatchScrollChanged();
                     }
                 }
+                updateFocusedSplitButtonVisibility();
                 onDismissAnimationEnds();
                 mPendingAnimation = null;
             }
@@ -2941,6 +2941,19 @@
     }
 
     /**
+     * Shows split button if
+     * * We're in large screen
+     * * We're not already in split
+     * * There are at least 2 tasks to invoke split
+     */
+    private void updateFocusedSplitButtonVisibility() {
+        mActionsView.setSplitButtonVisible(mActivity.getDeviceProfile().isTablet &&
+                !(getRunningTaskView() instanceof GroupedTaskView) &&
+                getTaskViewCount() > 1
+        );
+    }
+
+    /**
      * Returns all the tasks in the top row, without the focused task
      */
     private IntArray getTopRowIdArray() {
@@ -3745,7 +3758,6 @@
             mSecondSplitHiddenTaskView.setVisibility(VISIBLE);
             mSecondSplitHiddenTaskView = null;
         }
-        mActionsView.setSplitButtonVisible(true);
     }
 
     private void updateDeadZoneRects() {
@@ -3960,6 +3972,7 @@
     @Override
     protected void notifyPageSwitchListener(int prevPage) {
         super.notifyPageSwitchListener(prevPage);
+        updateFocusedSplitButtonVisibility();
         loadVisibleTaskData(TaskView.FLAG_UPDATE_ALL);
         updateEnabledOverlays();
     }