Merge "Use fonts_fallback XML only when flag is ON." into main
diff --git a/core/java/android/text/flags/deprecate_fonts_xml.aconfig b/core/java/android/text/flags/deprecate_fonts_xml.aconfig
new file mode 100644
index 0000000..58dc210
--- /dev/null
+++ b/core/java/android/text/flags/deprecate_fonts_xml.aconfig
@@ -0,0 +1,8 @@
+package: "com.android.text.flags"
+
+flag {
+ name: "deprecate_fonts_xml"
+ namespace: "text"
+ description: "Feature flag for deprecating fonts.xml. By setting true for this feature flag, the new font configuration XML, /system/etc/font_fallback.xml is used. The new XML has a new syntax and flexibility of variable font declarations, but it is not compatible with the apps that reads fonts.xml. So, fonts.xml is maintained as a subset of the font_fallback.xml"
+ bug: "281769620"
+}
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index 9fb627f..4c4e8fa 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -1475,7 +1475,10 @@
String locale = SystemProperties.get("persist.sys.locale", "en-US");
String script = ULocale.addLikelySubtags(ULocale.forLanguageTag(locale)).getScript();
- FontConfig config = SystemFonts.getSystemPreinstalledFontConfig();
+ // The feature flag cannot be referred from Zygote. Use legacy fonts.xml for preloading font
+ // files.
+ // TODO(nona): Use new XML file once the feature is fully launched.
+ FontConfig config = SystemFonts.getSystemPreinstalledFontConfigFromLegacyXml();
for (int i = 0; i < config.getFontFamilies().size(); ++i) {
FontConfig.FontFamily family = config.getFontFamilies().get(i);
if (!family.getLocaleList().isEmpty()) {
diff --git a/graphics/java/android/graphics/fonts/SystemFonts.java b/graphics/java/android/graphics/fonts/SystemFonts.java
index 36bfb98..9810022 100644
--- a/graphics/java/android/graphics/fonts/SystemFonts.java
+++ b/graphics/java/android/graphics/fonts/SystemFonts.java
@@ -48,6 +48,8 @@
private static final String TAG = "SystemFonts";
private static final String FONTS_XML = "/system/etc/font_fallback.xml";
+ private static final String LEGACY_FONTS_XML = "/system/etc/fonts.xml";
+
/** @hide */
public static final String SYSTEM_FONT_DIR = "/system/fonts/";
private static final String OEM_XML = "/product/etc/fonts_customization.xml";
@@ -230,7 +232,13 @@
long lastModifiedDate,
int configVersion
) {
- return getSystemFontConfigInternal(FONTS_XML, SYSTEM_FONT_DIR, OEM_XML, OEM_FONT_DIR,
+ final String fontsXml;
+ if (com.android.text.flags.Flags.deprecateFontsXml()) {
+ fontsXml = FONTS_XML;
+ } else {
+ fontsXml = LEGACY_FONTS_XML;
+ }
+ return getSystemFontConfigInternal(fontsXml, SYSTEM_FONT_DIR, OEM_XML, OEM_FONT_DIR,
updatableFontMap, lastModifiedDate, configVersion);
}
@@ -255,10 +263,24 @@
* @hide
*/
public static @NonNull FontConfig getSystemPreinstalledFontConfig() {
- return getSystemFontConfigInternal(FONTS_XML, SYSTEM_FONT_DIR, OEM_XML, OEM_FONT_DIR, null,
+ final String fontsXml;
+ if (com.android.text.flags.Flags.deprecateFontsXml()) {
+ fontsXml = FONTS_XML;
+ } else {
+ fontsXml = LEGACY_FONTS_XML;
+ }
+ return getSystemFontConfigInternal(fontsXml, SYSTEM_FONT_DIR, OEM_XML, OEM_FONT_DIR, null,
0, 0);
}
+ /**
+ * @hide
+ */
+ public static @NonNull FontConfig getSystemPreinstalledFontConfigFromLegacyXml() {
+ return getSystemFontConfigInternal(LEGACY_FONTS_XML, SYSTEM_FONT_DIR, OEM_XML, OEM_FONT_DIR,
+ null, 0, 0);
+ }
+
/* package */ static @NonNull FontConfig getSystemFontConfigInternal(
@NonNull String fontsXml,
@NonNull String systemFontDir,