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

Commit 0aa004c3 authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

LayoutLib: fix crash when shadow size <=0.

Drawing empty rects results in IllegalArgumentException on Mac JRE 1.6.
Prevent that by checking the bounds before attempting to draw the rect.

Bug: 20687353
Change-Id: I45f48ee125196480bb6510cc49b24d2122bc3e48
parent a00cf127
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.view;
import com.android.layoutlib.bridge.impl.ResourceHelper;

import android.graphics.Canvas;
import android.graphics.Canvas_Delegate;
import android.graphics.LinearGradient;
import android.graphics.Outline;
import android.graphics.Paint;
@@ -125,6 +126,9 @@ public class RectShadowPainter {

    private static void sideShadow(Canvas canvas, Paint edgePaint,
            RectF edgeShadowRect, float dx, float dy, int rotations) {
        if (isRectEmpty(edgeShadowRect)) {
            return;
        }
        int saved = canvas.save();
        canvas.translate(dx, dy);
        canvas.rotate(rotations * PERPENDICULAR_ANGLE);
@@ -153,4 +157,15 @@ public class RectShadowPainter {
        canvas.drawPath(path, paint);
        canvas.restoreToCount(saved);
    }

    /**
     * Differs from {@link RectF#isEmpty()} as this first converts the rect to int and then checks.
     * <p/>
     * This is required because {@link Canvas_Delegate#native_drawRect(long, float, float, float,
     * float, long)} casts the co-ordinates to int and we want to ensure that it doesn't end up
     * drawing empty rectangles, which results in IllegalArgumentException.
     */
    private static boolean isRectEmpty(RectF rect) {
        return (int) rect.left >= (int) rect.right || (int) rect.top >= (int) rect.bottom;
    }
}