diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2014-05-29 15:37:24 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-29 15:37:24 +0000 |
commit | 2cb50d45a8ad5534c089e9ae016a855377067bfe (patch) | |
tree | 4b46f2cfc98de7ba34386a73fc8464f82bafcc04 /tools | |
parent | 1a5b0de877c0392e07c023b6facd12ce8622cce7 (diff) | |
parent | 9113968f9570b0c8ada2dec34fa6cf893da7c022 (diff) | |
download | frameworks_base-2cb50d45a8ad5534c089e9ae016a855377067bfe.zip frameworks_base-2cb50d45a8ad5534c089e9ae016a855377067bfe.tar.gz frameworks_base-2cb50d45a8ad5534c089e9ae016a855377067bfe.tar.bz2 |
Merge "Layoutlib: Fix FontFamily_Delegate use after unref" into lmp-preview-dev
Diffstat (limited to 'tools')
-rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java | 2 | ||||
-rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java | 14 |
2 files changed, 10 insertions, 6 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java index 5e7543a..9ea4538 100644 --- a/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/FontFamily_Delegate.java @@ -146,6 +146,8 @@ public class FontFamily_Delegate { @LayoutlibDelegate /*package*/ static void nUnrefFamily(long nativePtr) { + // Removing the java reference for the object doesn't mean that it's freed for garbage + // collection. Typeface_Delegate may still hold a reference for it. sManager.removeJavaReferenceFor(nativePtr); } diff --git a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java index ed8f3b4..9746b48 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java @@ -54,7 +54,7 @@ public final class Typeface_Delegate { // ---- delegate data ---- - private final long[] mFontFamilies; // the reference to FontFamily_Delegate. + private final FontFamily_Delegate[] mFontFamilies; // the reference to FontFamily_Delegate. private int mStyle; private static long sDefaultTypeface; @@ -71,8 +71,7 @@ public final class Typeface_Delegate { public List<Font> getFonts(boolean compact) { List<Font> fonts = new ArrayList<Font>(mFontFamilies.length); - for (long fontFamily : mFontFamilies) { - FontFamily_Delegate ffd = FontFamily_Delegate.getDelegate(fontFamily); + for (FontFamily_Delegate ffd : mFontFamilies) { if (ffd != null) { Font font = ffd.getFont(mStyle, compact); if (font != null) { @@ -122,7 +121,11 @@ public final class Typeface_Delegate { @LayoutlibDelegate /*package*/ static synchronized long nativeCreateFromArray(long[] familyArray) { - Typeface_Delegate delegate = new Typeface_Delegate(familyArray, Typeface.NORMAL); + FontFamily_Delegate[] fontFamilies = new FontFamily_Delegate[familyArray.length]; + for (int i = 0; i < familyArray.length; i++) { + fontFamilies[i] = FontFamily_Delegate.getDelegate(familyArray[i]); + } + Typeface_Delegate delegate = new Typeface_Delegate(fontFamilies, Typeface.NORMAL); return sManager.addNewDelegate(delegate); } @@ -153,9 +156,8 @@ public final class Typeface_Delegate { // ---- Private delegate/helper methods ---- - private Typeface_Delegate(long[] fontFamilies, int style) { + private Typeface_Delegate(FontFamily_Delegate[] fontFamilies, int style) { mFontFamilies = fontFamilies; mStyle = style; } - } |