From 583de1621da042b02ae8af6c1f10081aa67eb609 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 15 May 2023 22:09:39 +0000 Subject: [PATCH] Only set drag shadow params if they are valid - Invalid params trigger an exception to be thrown when starting a system drag Bug: 269016702 Test: Presubmit Change-Id: I4b1953afd72ab1c6d41f3b5b536f9578ef40d792 --- .../taskbar/TaskbarDragController.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java index 72add4fc77..b2e082218a 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java @@ -36,6 +36,7 @@ import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.os.UserHandle; +import android.util.Log; import android.util.Pair; import android.view.DragEvent; import android.view.MotionEvent; @@ -87,6 +88,7 @@ import java.util.function.Predicate; */ public class TaskbarDragController extends DragController implements TaskbarControllers.LoggableTaskbarController { + private static final String TAG = "TaskbarDragController"; private static final boolean DEBUG_DRAG_SHADOW_SURFACE = false; private static final int ANIM_DURATION_RETURN_ICON_TO_TASKBAR = 300; @@ -319,12 +321,26 @@ public class TaskbarDragController extends DragController im @Override public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { int iconSize = Math.max(mDragIconSize, btv.getWidth()); - shadowSize.set(iconSize, iconSize); + if (iconSize > 0) { + shadowSize.set(iconSize, iconSize); + } else { + Log.d(TAG, "Invalid icon size, dragSize=" + mDragIconSize + + " viewWidth=" + btv.getWidth()); + } + // The registration point was taken before the icon scaled to mDragIconSize, so // offset the registration to where the touch is on the new size. int offsetX = (mDragIconSize - mDragObject.dragView.getDragRegionWidth()) / 2; int offsetY = (mDragIconSize - mDragObject.dragView.getDragRegionHeight()) / 2; - shadowTouchPoint.set(mRegistrationX + offsetX, mRegistrationY + offsetY); + int touchX = mRegistrationX + offsetX; + int touchY = mRegistrationY + offsetY; + if (touchX >= 0 && touchY >= 0) { + shadowTouchPoint.set(touchX, touchY); + } else { + Log.d(TAG, "Invalid touch point, " + + "registrationXY=(" + mRegistrationX + ", " + mRegistrationY + ") " + + "offsetXY=(" + offsetX + ", " + offsetY + ")"); + } } @Override