Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ec96d0d3 authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Stop accepting zero size drag shadow for P.

Since P SurfaceControl does not accept zero size, thus we also stop
creating zero size drag shadow image.

Bug: 72416622
Test: Invoke startDragAndDrop with zero size shadow
Change-Id: I28f9cac419348a2550ac4db7de9016df82fc6385
parent 63e027d0
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view;
import static android.view.accessibility.AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED;
import static java.lang.Math.max;
import android.animation.AnimatorInflater;
@@ -905,6 +906,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    private static boolean sThrowOnInvalidFloatProperties;
    /**
     * Prior to P, {@code #startDragAndDrop} accepts a builder which produces an empty drag shadow.
     * Currently zero size SurfaceControl cannot be created thus we create a dummy 1x1 surface
     * instead.
     */
    private static boolean sAcceptZeroSizeDragShadow;
    /** @hide */
    @IntDef({NOT_FOCUSABLE, FOCUSABLE, FOCUSABLE_AUTO})
    @Retention(RetentionPolicy.SOURCE)
@@ -4839,6 +4847,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            sAlwaysAssignFocus = targetSdkVersion < Build.VERSION_CODES.P;
            sAcceptZeroSizeDragShadow = targetSdkVersion < Build.VERSION_CODES.P;
            sCompatibilityDone = true;
        }
    }
@@ -23542,8 +23552,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
         * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)}
         * and {@link #onDrawShadow(Canvas)} methods are also overridden in order
         * to supply the drag shadow's dimensions and appearance without
         * reference to any View object. If they are not overridden, then the result is an
         * invisible drag shadow.
         * reference to any View object.
         */
        public DragShadowBuilder() {
            mView = new WeakReference<View>(null);
@@ -23697,6 +23706,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        // Create 1x1 surface when zero surface size is specified because SurfaceControl.Builder
        // does not accept zero size surface.
        if (shadowSize.x == 0  || shadowSize.y == 0) {
            if (!sAcceptZeroSizeDragShadow) {
                throw new IllegalStateException("Drag shadow dimensions must be positive");
            }
            shadowSize.x = 1;
            shadowSize.y = 1;
        }