OSDN Git Service

Fix boot loop issue on Android Wear.
authorSeigo Nonaka <nona@google.com>
Fri, 14 Apr 2017 00:30:38 +0000 (17:30 -0700)
committerSeigo Nonaka <nona@google.com>
Fri, 14 Apr 2017 01:58:36 +0000 (18:58 -0700)
The boot loop was seen after I65e220aca823fd815a52437b11c8e6dc952de8e2
but only on Android Wear. On Android Wear, some font files are missing
but are listed in fonts.xml. Before that patch, we created a Typeface
object with an empty FontFamily even if there was no valid font entry
in font-family tag. However, after that patch, FontFamily stopped
creating native objects and holds a null pointer instead. As the
result, SIGSEGV happens.

The right fix is skipping Typeface creation if native code failed to
create the font family object.

Since Typeface.init cannot be called twice, this is hard to test
automatically.

Bug: 37328609
Bug: 37326002
Test: Boot succeeded even after removing CutiveMono.ttf from system.

Change-Id: I125de07343252784986d728c3bbaa46b24ace601

graphics/java/android/graphics/Typeface.java

index 2aca782..aede0a8 100644 (file)
@@ -1112,6 +1112,7 @@ public class Typeface {
             // Treat as system error since reaching here means that a system pre-installed font
             // can't be used by our font stack.
             Log.e(TAG, "Unable to load Family: " + family.getName() + ":" + family.getLanguage());
+            return null;
         }
         return fontFamily;
     }
@@ -1137,7 +1138,10 @@ public class Typeface {
             for (int i = 0; i < fontConfig.getFamilies().length; i++) {
                 FontConfig.Family f = fontConfig.getFamilies()[i];
                 if (i == 0 || f.getName() == null) {
-                    familyList.add(makeFamilyFromParsed(f, bufferForPath));
+                    FontFamily family = makeFamilyFromParsed(f, bufferForPath);
+                    if (family != null) {
+                        familyList.add(family);
+                    }
                 }
             }
             sFallbackFonts = familyList.toArray(new FontFamily[familyList.size()]);
@@ -1154,6 +1158,9 @@ public class Typeface {
                         typeface = sDefaultTypeface;
                     } else {
                         FontFamily fontFamily = makeFamilyFromParsed(f, bufferForPath);
+                        if (fontFamily == null) {
+                            continue;
+                        }
                         FontFamily[] families = { fontFamily };
                         typeface = Typeface.createFromFamiliesWithDefault(families);
                     }