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

Commit 129f414e authored by Nader Jawad's avatar Nader Jawad
Browse files

Fixed issue where XmlPullParserExceptions are thrown with

Theme defined GradientDrawable attributes

Fixed issue where attributes that are supposed to be defined
together would throw exceptions if they are configured through
multiple inflation passes both with and without theme attributes.
Removed conditional logic that would parse attributes only
if the corresponding gradient type matched. Instead, attributes
are parsed on each inflation pass, falling back on previously
resolved parameters in the absence of a field. Validation
of the radius parameters has moved to ensureValidRect

Test: Added test to GradientDrawableTest
Bug: 127838188
Change-Id: Ie05e416eb747c774b9a39d4d0be28e1e775f0db5
parent 57fd2215
Loading
Loading
Loading
Loading
+61 −64
Original line number Diff line number Diff line
@@ -1312,6 +1312,10 @@ public class GradientDrawable extends Drawable {
                    y0 = r.top + (r.bottom - r.top) * st.mCenterY;

                    float radius = st.mGradientRadius;
                    if (Float.compare(radius, 0.0f) == -1 || Float.isNaN(radius)) {
                        throw new IllegalArgumentException("Gradient radius must be a valid "
                                + "number greater than or equal to 0");
                    }
                    if (st.mGradientRadiusType == RADIUS_TYPE_FRACTION) {
                        // Fall back to parent width or height if intrinsic
                        // size is not specified.
@@ -1759,7 +1763,6 @@ public class GradientDrawable extends Drawable {
            st.mGradientColors[1] = endColor;
        }

        if (st.mGradient == LINEAR_GRADIENT) {
        int angle = (int) a.getFloat(R.styleable.GradientDrawableGradient_angle, st.mAngle);
        angle %= 360;

@@ -1797,7 +1800,7 @@ public class GradientDrawable extends Drawable {
                st.mOrientation = Orientation.TL_BR;
                break;
        }
        } else {

        final TypedValue tv = a.peekValue(R.styleable.GradientDrawableGradient_gradientRadius);
        if (tv != null) {
            final float radius;
@@ -1822,12 +1825,6 @@ public class GradientDrawable extends Drawable {

            st.mGradientRadius = radius;
            st.mGradientRadiusType = radiusType;
            } else if (st.mGradient == RADIAL_GRADIENT) {
                throw new XmlPullParserException(
                        a.getPositionDescription()
                        + "<gradient> tag requires 'gradientRadius' "
                        + "attribute with radial type");
            }
        }
    }