diff options
Diffstat (limited to 'graphics/java/android')
5 files changed, 46 insertions, 20 deletions
diff --git a/graphics/java/android/graphics/FontListParser.java b/graphics/java/android/graphics/FontListParser.java index 7f5b7520e76d..93a336e7a408 100644 --- a/graphics/java/android/graphics/FontListParser.java +++ b/graphics/java/android/graphics/FontListParser.java @@ -74,7 +74,7 @@ public class FontListParser { parser.setInput(in, null); parser.nextTag(); return readFamilies(parser, "/system/fonts/", new FontCustomizationParser.Result(), null, - 0, 0); + 0, 0, true); } /** @@ -116,7 +116,7 @@ public class FontListParser { parser.setInput(is, null); parser.nextTag(); return readFamilies(parser, systemFontDir, oemCustomization, updatableFontMap, - lastModifiedDate, configVersion); + lastModifiedDate, configVersion, false /* filter out the non-exising files */); } } @@ -126,7 +126,8 @@ public class FontListParser { @NonNull FontCustomizationParser.Result customization, @Nullable Map<String, File> updatableFontMap, long lastModifiedDate, - int configVersion) + int configVersion, + boolean allowNonExistingFile) throws XmlPullParserException, IOException { List<FontConfig.FontFamily> families = new ArrayList<>(); List<FontConfig.Alias> aliases = new ArrayList<>(customization.getAdditionalAliases()); @@ -139,7 +140,11 @@ public class FontListParser { if (parser.getEventType() != XmlPullParser.START_TAG) continue; String tag = parser.getName(); if (tag.equals("family")) { - FontConfig.FontFamily family = readFamily(parser, fontDir, updatableFontMap); + FontConfig.FontFamily family = readFamily(parser, fontDir, updatableFontMap, + allowNonExistingFile); + if (family == null) { + continue; + } String name = family.getName(); if (name == null || !oemNamedFamilies.containsKey(name)) { // The OEM customization overrides system named family. Skip if OEM @@ -165,9 +170,15 @@ public class FontListParser { /** * Read family tag in fonts.xml or oem_customization.xml + * + * @param parser An XML parser. + * @param fontDir a font directory name. + * @param updatableFontMap a updated font file map. + * @param allowNonExistingFile true to allow font file that doesn't exists + * @return a FontFamily instance. null if no font files are available in this FontFamily. */ - public static FontConfig.FontFamily readFamily(XmlPullParser parser, String fontDir, - @Nullable Map<String, File> updatableFontMap) + public static @Nullable FontConfig.FontFamily readFamily(XmlPullParser parser, String fontDir, + @Nullable Map<String, File> updatableFontMap, boolean allowNonExistingFile) throws XmlPullParserException, IOException { final String name = parser.getAttributeValue(null, "name"); final String lang = parser.getAttributeValue("", "lang"); @@ -177,7 +188,11 @@ public class FontListParser { if (parser.getEventType() != XmlPullParser.START_TAG) continue; final String tag = parser.getName(); if (tag.equals(TAG_FONT)) { - fonts.add(readFont(parser, fontDir, updatableFontMap)); + FontConfig.Font font = readFont(parser, fontDir, updatableFontMap, + allowNonExistingFile); + if (font != null) { + fonts.add(font); + } } else { skip(parser); } @@ -190,6 +205,9 @@ public class FontListParser { intVariant = FontConfig.FontFamily.VARIANT_ELEGANT; } } + if (fonts.isEmpty()) { + return null; + } return new FontConfig.FontFamily(fonts, name, LocaleList.forLanguageTags(lang), intVariant); } @@ -197,10 +215,11 @@ public class FontListParser { private static final Pattern FILENAME_WHITESPACE_PATTERN = Pattern.compile("^[ \\n\\r\\t]+|[ \\n\\r\\t]+$"); - private static FontConfig.Font readFont( + private static @Nullable FontConfig.Font readFont( @NonNull XmlPullParser parser, @NonNull String fontDir, - @Nullable Map<String, File> updatableFontMap) + @Nullable Map<String, File> updatableFontMap, + boolean allowNonExistingFile) throws XmlPullParserException, IOException { String indexStr = parser.getAttributeValue(null, ATTR_INDEX); @@ -253,7 +272,9 @@ public class FontListParser { File file = new File(filePath); - + if (!(allowNonExistingFile || file.isFile())) { + return null; + } return new FontConfig.Font(file, originalPath == null ? null : new File(originalPath), diff --git a/graphics/java/android/graphics/drawable/ColorStateListDrawable.java b/graphics/java/android/graphics/drawable/ColorStateListDrawable.java index 20cd825fe306..423e66c7f657 100644 --- a/graphics/java/android/graphics/drawable/ColorStateListDrawable.java +++ b/graphics/java/android/graphics/drawable/ColorStateListDrawable.java @@ -48,6 +48,12 @@ public class ColorStateListDrawable extends Drawable implements Drawable.Callbac setColorStateList(colorStateList); } + private ColorStateListDrawable(@NonNull ColorStateListDrawableState state) { + mState = state; + initializeColorDrawable(); + onStateChange(getState()); + } + @Override public void draw(@NonNull Canvas canvas) { mColorDrawable.draw(canvas); @@ -286,11 +292,6 @@ public class ColorStateListDrawable extends Drawable implements Drawable.Callbac } } - private ColorStateListDrawable(@NonNull ColorStateListDrawableState state) { - mState = state; - initializeColorDrawable(); - } - private void initializeColorDrawable() { mColorDrawable = new ColorDrawable(); mColorDrawable.setCallback(this); diff --git a/graphics/java/android/graphics/drawable/RippleShader.java b/graphics/java/android/graphics/drawable/RippleShader.java index e7c10819f679..2b4d5b45a009 100644 --- a/graphics/java/android/graphics/drawable/RippleShader.java +++ b/graphics/java/android/graphics/drawable/RippleShader.java @@ -115,7 +115,7 @@ final class RippleShader extends RuntimeShader { + " float fade = min(fadeIn, 1. - fadeOutRipple);\n" + " vec4 circle = in_color * (softCircle(p, center, in_maxRadius " + " * scaleIn, 0.2) * fade);\n" - + " float mask = in_hasMask == 1. ? sample(in_shader).a > 0. ? 1. : 0. : 1.;\n" + + " float mask = in_hasMask == 1. ? sample(in_shader, p).a > 0. ? 1. : 0. : 1.;\n" + " return mix(circle, in_sparkleColor, sparkle) * mask;\n" + "}"; private static final String SHADER = SHADER_UNIFORMS + SHADER_LIB + SHADER_MAIN; diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index 9298d9fcb9a7..4065bd110c7e 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -349,15 +349,19 @@ public class VectorDrawable extends Drawable { private final Rect mTmpBounds = new Rect(); public VectorDrawable() { - this(new VectorDrawableState(null), null); + this(null, null); } /** * The one constructor to rule them all. This is called by all public * constructors to set the state and initialize local properties. */ - private VectorDrawable(@NonNull VectorDrawableState state, @Nullable Resources res) { - mVectorState = state; + private VectorDrawable(@Nullable VectorDrawableState state, @Nullable Resources res) { + // As the mutable, not-thread-safe native instance is stored in VectorDrawableState, we + // need to always do a defensive copy even if mutate() isn't called. Otherwise + // draw() being called on 2 different VectorDrawable instances could still hit the same + // underlying native object. + mVectorState = new VectorDrawableState(state); updateLocalState(res); } diff --git a/graphics/java/android/graphics/fonts/FontCustomizationParser.java b/graphics/java/android/graphics/fonts/FontCustomizationParser.java index 42033ba017bf..9c01a4be381f 100644 --- a/graphics/java/android/graphics/fonts/FontCustomizationParser.java +++ b/graphics/java/android/graphics/fonts/FontCustomizationParser.java @@ -134,7 +134,7 @@ public class FontCustomizationParser { throw new IllegalArgumentException("customizationType must be specified"); } if (customizationType.equals("new-named-family")) { - out.add(FontListParser.readFamily(parser, fontDir, updatableFontMap)); + out.add(FontListParser.readFamily(parser, fontDir, updatableFontMap, false)); } else { throw new IllegalArgumentException("Unknown customizationType=" + customizationType); } |