Merge "launcher: enable swipe down to open focused app" into sc-v2-dev
diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java
index 180af0b..051485a 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java
@@ -34,7 +34,6 @@
 import com.android.launcher3.anim.AnimatorPlaybackController;
 import com.android.launcher3.anim.Interpolators;
 import com.android.launcher3.anim.PendingAnimation;
-import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.touch.BaseSwipeDetector;
 import com.android.launcher3.touch.PagedOrientationHandler;
 import com.android.launcher3.touch.SingleAxisSwipeDetector;
@@ -158,26 +157,21 @@
                         mTaskBeingDragged = view;
                         int upDirection = mRecentsView.getPagedOrientationHandler()
                                 .getUpDirection(mIsRtl);
-                        if (!SysUINavigationMode.getMode(mActivity).hasGestures || (
-                                mActivity.getDeviceProfile().isTablet
-                                        && FeatureFlags.ENABLE_OVERVIEW_GRID.get())) {
-                            // Don't allow swipe down to open if we don't support swipe up
-                            // to enter overview, or when grid layout is enabled.
-                            directionsToDetectScroll = upDirection;
-                            mAllowGoingUp = true;
-                            mAllowGoingDown = false;
-                        } else {
-                            // The task can be dragged up to dismiss it,
-                            // and down to open if it's the current page.
-                            mAllowGoingUp = true;
-                            if (i == mRecentsView.getCurrentPage()) {
-                                mAllowGoingDown = true;
-                                directionsToDetectScroll = DIRECTION_BOTH;
-                            } else {
-                                mAllowGoingDown = false;
-                                directionsToDetectScroll = upDirection;
-                            }
-                        }
+
+                        // The task can be dragged up to dismiss it
+                        mAllowGoingUp = true;
+
+                        // The task can be dragged down to open it if:
+                        // - It's the current page
+                        // - We support gestures to enter overview
+                        // - It's the focused task if in grid view
+                        // - The task is snapped
+                        mAllowGoingDown = i == mRecentsView.getCurrentPage()
+                                && SysUINavigationMode.getMode(mActivity).hasGestures
+                                && (!mRecentsView.showAsGrid() || mTaskBeingDragged.isFocusedTask())
+                                && mRecentsView.isTaskSnapped(i);
+
+                        directionsToDetectScroll = mAllowGoingDown ? DIRECTION_BOTH : upDirection;
                         break;
                     }
                 }
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index aee5ff8..6844f9f 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -949,6 +949,16 @@
                 && taskEnd <= end);
     }
 
+    /**
+     * Returns true if the task is snapped.
+     *
+     * @param taskIndex the index of the task
+     */
+    public boolean isTaskSnapped(int taskIndex) {
+        return getScrollForPage(taskIndex + mTaskViewStartIndex)
+                == getPagedOrientationHandler().getPrimaryScroll(this);
+    }
+
     public TaskView getTaskView(int taskId) {
         for (int i = 0; i < getTaskViewCount(); i++) {
             TaskView taskView = getTaskViewAt(i);