Use Task Position to check if task is below disallowed area

Currently, the TaskPositioner uses the raw y position of the
motion event to check if the task positioner should finish handling the
drag event by calling WCT#setBounds or if it should allow something else
handle it (i.e. DesktopTasksController handling it by transitioning the
task into fullscreen). Meanwhile, DesktopTasksController uses the
position the task is placed by the TaskPositioner (which is calculated
by adding the distance of a drag to the original position of a task) to
check if the visual indicator should be created/destroyed. These
differences cause the visual indicator to be shown in positions where
the task may not transition into fullscreen when released.

This change uses the same method used to position the task (adding the
distance of the drag to the original task position) to check if the
TaskPositioner should handle the end of the drag.

Bug: 296924625
Test: Drag freeform task to top and release as soon as visual indicator
appears. Task should transition to fullscreen.

Change-Id: I80777ee77b502e9e4bcfe40c3a5bed5139758e90
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtility.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtility.java
index e32bd42..cb0a6c7 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtility.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DragPositioningCallbackUtility.java
@@ -143,6 +143,24 @@
     }
 
     /**
+     * Calculates the new position of the top edge of the task and returns true if it is below the
+     * disallowed area.
+     *
+     * @param disallowedAreaForEndBoundsHeight the height of the area that where the task positioner
+     *                                         should not finalize the bounds using WCT#setBounds
+     * @param taskBoundsAtDragStart the bounds of the task on the first drag input event
+     * @param repositionStartPoint initial input coordinate
+     * @param y the y position of the motion event
+     * @return true if the top of the task is below the disallowed area
+     */
+    static boolean isBelowDisallowedArea(int disallowedAreaForEndBoundsHeight,
+            Rect taskBoundsAtDragStart, PointF repositionStartPoint, float y) {
+        final float deltaY = y - repositionStartPoint.y;
+        final float topPosition = taskBoundsAtDragStart.top + deltaY;
+        return topPosition > disallowedAreaForEndBoundsHeight;
+    }
+
+    /**
      * Updates repositionTaskBounds to the final bounds of the task after the drag is finished. If
      * the bounds are outside of the stable bounds, they are shifted to place task at the top of the
      * stable bounds.
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositioner.java
index e0ee252..389db62 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositioner.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/FluidResizeTaskPositioner.java
@@ -125,7 +125,9 @@
             }
             mTaskOrganizer.applyTransaction(wct);
         } else if (mCtrlType == CTRL_TYPE_UNDEFINED
-                && y > mDisallowedAreaForEndBoundsHeight) {
+                && DragPositioningCallbackUtility.isBelowDisallowedArea(
+                mDisallowedAreaForEndBoundsHeight, mTaskBoundsAtDragStart, mRepositionStartPoint,
+                y)) {
             final WindowContainerTransaction wct = new WindowContainerTransaction();
             DragPositioningCallbackUtility.onDragEnd(mRepositionTaskBounds,
                     mTaskBoundsAtDragStart, mStableBounds, mRepositionStartPoint, x, y);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java
index c9c58de..303954a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/VeiledResizeTaskPositioner.java
@@ -142,7 +142,9 @@
                 // won't be called.
                 mDesktopWindowDecoration.hideResizeVeil();
             }
-        } else if (y > mDisallowedAreaForEndBoundsHeight) {
+        } else if (DragPositioningCallbackUtility.isBelowDisallowedArea(
+                mDisallowedAreaForEndBoundsHeight, mTaskBoundsAtDragStart, mRepositionStartPoint,
+                y)) {
             DragPositioningCallbackUtility.onDragEnd(mRepositionTaskBounds,
                     mTaskBoundsAtDragStart, mStableBounds, mRepositionStartPoint, x, y);
             DragPositioningCallbackUtility.applyTaskBoundsChange(new WindowContainerTransaction(),