Loading core/tests/coretests/src/android/graphics/FontListParserTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -325,6 +325,6 @@ public final class FontListParserTest { XmlPullParser parser = Xml.newPullParser(); parser.setInput(buffer, "UTF-8"); parser.nextTag(); return FontListParser.readFamily(parser, "", null); return FontListParser.readFamily(parser, "", null, true); } } graphics/java/android/graphics/FontListParser.java +31 −10 Original line number Diff line number Diff line Loading @@ -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); } /** Loading Loading @@ -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 */); } } Loading @@ -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()); Loading @@ -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 Loading @@ -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"); Loading @@ -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); } Loading @@ -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); } Loading @@ -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); Loading Loading @@ -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), Loading graphics/java/android/graphics/fonts/FontCustomizationParser.java +1 −1 Original line number Diff line number Diff line Loading @@ -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); } Loading services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -963,7 +963,7 @@ public final class UpdatableFontDirTest { parser.setInput(is, "UTF-8"); parser.nextTag(); FontConfig.FontFamily fontFamily = FontListParser.readFamily(parser, "", null); FontConfig.FontFamily fontFamily = FontListParser.readFamily(parser, "", null, true); List<FontUpdateRequest.Font> fonts = new ArrayList<>(); for (FontConfig.Font font : fontFamily.getFontList()) { String name = font.getFile().getName(); Loading Loading
core/tests/coretests/src/android/graphics/FontListParserTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -325,6 +325,6 @@ public final class FontListParserTest { XmlPullParser parser = Xml.newPullParser(); parser.setInput(buffer, "UTF-8"); parser.nextTag(); return FontListParser.readFamily(parser, "", null); return FontListParser.readFamily(parser, "", null, true); } }
graphics/java/android/graphics/FontListParser.java +31 −10 Original line number Diff line number Diff line Loading @@ -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); } /** Loading Loading @@ -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 */); } } Loading @@ -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()); Loading @@ -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 Loading @@ -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"); Loading @@ -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); } Loading @@ -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); } Loading @@ -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); Loading Loading @@ -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), Loading
graphics/java/android/graphics/fonts/FontCustomizationParser.java +1 −1 Original line number Diff line number Diff line Loading @@ -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); } Loading
services/tests/servicestests/src/com/android/server/graphics/fonts/UpdatableFontDirTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -963,7 +963,7 @@ public final class UpdatableFontDirTest { parser.setInput(is, "UTF-8"); parser.nextTag(); FontConfig.FontFamily fontFamily = FontListParser.readFamily(parser, "", null); FontConfig.FontFamily fontFamily = FontListParser.readFamily(parser, "", null, true); List<FontUpdateRequest.Font> fonts = new ArrayList<>(); for (FontConfig.Font font : fontFamily.getFontList()) { String name = font.getFile().getName(); Loading