From 1f859716a8e4b8c12d69ca8b3db8344de577d5c7 Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Mon, 3 Oct 2016 13:57:28 -0700 Subject: [PATCH] Restrict AVD and VD parsing to the current element instead of the whole document This CL changes the AVD xml parsing to parsing only within the current element, which prevents AVD parsing from always skipping to the end of the doucment. So things that are defined after AVD in the same document can be picked up by the xml parser. The same fix has been applied to VD as well. BUG: 31865175 Test: Manually following comment #1 in the bug above Change-Id: I4ebdce1eb2e92d6f6e2c37caed9607253d24602f --- .../android/graphics/drawable/AnimatedVectorDrawable.java | 6 +++++- graphics/java/android/graphics/drawable/VectorDrawable.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java index dcca431ea7544..c24d31334be00 100644 --- a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java @@ -455,7 +455,11 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 { int eventType = parser.getEventType(); float pathErrorScale = 1; - while (eventType != XmlPullParser.END_DOCUMENT) { + final int innerDepth = parser.getDepth() + 1; + + // Parse everything until the end of the animated-vector element. + while (eventType != XmlPullParser.END_DOCUMENT + && (parser.getDepth() >= innerDepth || eventType != XmlPullParser.END_TAG)) { if (eventType == XmlPullParser.START_TAG) { final String tagName = parser.getName(); if (ANIMATED_VECTOR.equals(tagName)) { diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index 9ff69650294dd..ab96f61df0ec3 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -710,7 +710,11 @@ public class VectorDrawable extends Drawable { groupStack.push(state.mRootGroup); int eventType = parser.getEventType(); - while (eventType != XmlPullParser.END_DOCUMENT) { + final int innerDepth = parser.getDepth() + 1; + + // Parse everything until the end of the vector element. + while (eventType != XmlPullParser.END_DOCUMENT + && (parser.getDepth() >= innerDepth || eventType != XmlPullParser.END_TAG)) { if (eventType == XmlPullParser.START_TAG) { final String tagName = parser.getName(); final VGroup currentGroup = groupStack.peek();