@@ -93,7 +93,7 @@ public class Typeface {
9393 private static String TAG = "Typeface" ;
9494
9595 /** @hide */
96- public static final boolean ENABLE_LAZY_TYPEFACE_INITIALIZATION = true ;
96+ public static final boolean ENABLE_LAZY_TYPEFACE_INITIALIZATION = false ;
9797
9898 private static final NativeAllocationRegistry sRegistry =
9999 NativeAllocationRegistry .createMalloced (
@@ -184,6 +184,11 @@ public class Typeface {
184184
185185 static final String SANS_SERIF_FAMILY_NAME = "sans-serif" ;
186186
187+ static final String SYSTEM_FONT_CONFIG_LOCATION = "/system/etc/" ;
188+ static final String THEME_FONT_CONFIG_LOCATION = "/data/system/theme/fonts/" ;
189+ static final String THEME_FONT_DIR_LOCATION = "/data/system/theme/fonts/" ;
190+ static final String SYSTEM_FONT_DIR_LOCATION = "/system/fonts/" ;
191+
187192 /**
188193 * Returns the shared memory that used for creating Typefaces.
189194 *
@@ -1177,8 +1182,17 @@ private static Typeface createFromFamiliesWithDefault(android.graphics.FontFamil
11771182 for (int i = 0 ; i < families .length ; i ++) {
11781183 ptrArray [i ] = families [i ].mNativePtr ;
11791184 }
1185+
1186+ long ni ;
1187+
1188+ // getSystemDefaultTypeface can return null, so manually set the native_instance then
1189+ if (fallbackTypeface == null ) {
1190+ ni = 0 ;
1191+ } else {
1192+ ni = fallbackTypeface .native_instance ;
1193+ }
11801194 return new Typeface (nativeCreateFromArray (
1181- ptrArray , fallbackTypeface . native_instance , weight , italic ));
1195+ ptrArray , ni , weight , italic ));
11821196 }
11831197
11841198 // don't allow clients to call this directly
@@ -1231,7 +1245,7 @@ private static android.graphics.FontFamily makeFamilyFromParsed(FontConfig.FontF
12311245 android .graphics .FontFamily fontFamily =
12321246 new android .graphics .FontFamily (family .getLanguages (), family .getVariant ());
12331247 for (FontConfig .Font font : family .getFonts ()) {
1234- String fullPathName = font .getFontFamilyName ();
1248+ String fullPathName = font .getFile (). getAbsolutePath ();
12351249 ByteBuffer fontBuffer = bufferForPath .get (fullPathName );
12361250 if (fontBuffer == null ) {
12371251 try (FileInputStream file = new FileInputStream (fullPathName )) {
@@ -1325,30 +1339,27 @@ private static void addMissingFontAliases(FontConfig src,
13251339 }
13261340 private static void init () {
13271341 // Load font config and initialize Minikin state
1328- File systemFontConfigLocation = getSystemFontConfigLocation ();
1329- File themeFontConfigLocation = getThemeFontConfigLocation ();
1330- File systemConfigFile = new File (systemFontConfigLocation , FONTS_CONFIG );
1331- File themeConfigFile = new File (themeFontConfigLocation , FONTS_CONFIG );
1342+ File systemConfigFile = new File (SYSTEM_FONT_CONFIG_LOCATION , FONTS_CONFIG );
1343+ File themeConfigFile = new File (THEME_FONT_CONFIG_LOCATION , FONTS_CONFIG );
13321344 File configFile = null ;
1333- File fontDir ;
1345+ String fontDir ;
13341346 if (themeConfigFile .exists ()) {
13351347 // /data/system/theme/fonts/ exists so use it and copy default fonts
13361348 configFile = themeConfigFile ;
1337- fontDir = getThemeFontDirLocation () ;
1349+ fontDir = THEME_FONT_DIR_LOCATION ;
13381350 } else {
13391351 configFile = systemConfigFile ;
1340- fontDir = getSystemFontDirLocation () ;
1352+ fontDir = SYSTEM_FONT_DIR_LOCATION ;
13411353 }
13421354 try {
13431355 FontConfig fontConfig = FontListParser .parse (configFile ,
1344- fontDir . getAbsolutePath () );
1356+ fontDir );
13451357 FontConfig systemFontConfig = null ;
13461358 // If the fonts are coming from a theme, we will need to make sure that we include
13471359 // any font families from the system fonts that the theme did not include.
13481360 // NOTE: All the system font families without names ALWAYS get added.
13491361 if (configFile == themeConfigFile ) {
1350- systemFontConfig = FontListParser .parse (systemConfigFile ,
1351- getSystemFontDirLocation ().getAbsolutePath ());
1362+ systemFontConfig = FontListParser .parse (systemConfigFile , SYSTEM_FONT_DIR_LOCATION );
13521363 addFallbackFontsForFamilyName (systemFontConfig , fontConfig , SANS_SERIF_FAMILY_NAME );
13531364 addMissingFontFamilies (systemFontConfig , fontConfig );
13541365 addMissingFontAliases (systemFontConfig , fontConfig );
@@ -1378,7 +1389,7 @@ private static void init() {
13781389 if (i == 0 ) {
13791390 // The first entry is the default typeface; no sense in
13801391 // duplicating the corresponding FontFamily.
1381- typeface = sDefaultTypeface ;
1392+ typeface = getDefault () ;
13821393 } else {
13831394 android .graphics .FontFamily fontFamily
13841395 = makeFamilyFromParsed (f , bufferForPath );
@@ -1416,20 +1427,13 @@ private static void init() {
14161427 /** @hide */
14171428 public static void recreateDefaults () {
14181429 sDynamicTypefaceCache .evictAll ();
1419- sSystemFontMap .clear ();
14201430 sStyledTypefaceCache .clear ();
14211431 init ();
1422- DEFAULT_BOLD_INTERNAL = create ((String ) null , Typeface .BOLD );
1423- SANS_SERIF_INTERNAL = create ("sans-serif" , 0 );
1424- SERIF_INTERNAL = create ("serif" , 0 );
1425- MONOSPACE_INTERNAL = create ("monospace" , 0 );
14261432 DEFAULT .native_instance = DEFAULT_INTERNAL .native_instance ;
14271433 DEFAULT_BOLD .native_instance = DEFAULT_BOLD_INTERNAL .native_instance ;
14281434 SANS_SERIF .native_instance = SANS_SERIF_INTERNAL .native_instance ;
14291435 SERIF .native_instance = SERIF_INTERNAL .native_instance ;
14301436 MONOSPACE .native_instance = MONOSPACE_INTERNAL .native_instance ;
1431- sDefaults [2 ] = create ((String ) null , Typeface .ITALIC );
1432- sDefaults [3 ] = create ((String ) null , Typeface .BOLD_ITALIC );
14331437 }
14341438
14351439 /**
@@ -1674,22 +1678,6 @@ public static void loadPreinstalledSystemFontMap() {
16741678 }
16751679 }
16761680
1677- private static File getSystemFontConfigLocation () {
1678- return new File ("/system/etc/" );
1679- }
1680-
1681- private static File getSystemFontDirLocation () {
1682- return new File ("/system/fonts/" );
1683- }
1684-
1685- private static File getThemeFontConfigLocation () {
1686- return new File ("/data/system/theme/fonts/" );
1687- }
1688-
1689- private static File getThemeFontDirLocation () {
1690- return new File ("/data/system/theme/fonts/" );
1691- }
1692-
16931681 @ Override
16941682 public boolean equals (Object o ) {
16951683 if (this == o ) return true ;
0 commit comments