Loading core/api/test-current.txt +1 −0 Original line number Original line Diff line number Diff line Loading @@ -1039,6 +1039,7 @@ package android.graphics { method @NonNull public static android.util.Pair<java.util.List<android.graphics.Typeface>,java.util.List<android.graphics.Typeface>> changeDefaultFontForTest(@NonNull java.util.List<android.graphics.Typeface>, @NonNull java.util.List<android.graphics.Typeface>); method @NonNull public static android.util.Pair<java.util.List<android.graphics.Typeface>,java.util.List<android.graphics.Typeface>> changeDefaultFontForTest(@NonNull java.util.List<android.graphics.Typeface>, @NonNull java.util.List<android.graphics.Typeface>); method @NonNull public static long[] deserializeFontMap(@NonNull java.nio.ByteBuffer, @NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws java.io.IOException; method @NonNull public static long[] deserializeFontMap(@NonNull java.nio.ByteBuffer, @NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws java.io.IOException; method @Nullable public static android.os.SharedMemory getSystemFontMapSharedMemory(); method @Nullable public static android.os.SharedMemory getSystemFontMapSharedMemory(); method public void releaseNativeObjectForTest(); method @NonNull public static android.os.SharedMemory serializeFontMap(@NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws android.system.ErrnoException, java.io.IOException; method @NonNull public static android.os.SharedMemory serializeFontMap(@NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws android.system.ErrnoException, java.io.IOException; } } Loading core/tests/coretests/src/android/graphics/TypefaceTest.java +16 −10 Original line number Original line Diff line number Diff line Loading @@ -203,6 +203,7 @@ public class TypefaceTest { fallbackMap); fallbackMap); SharedMemory sharedMemory = Typeface.serializeFontMap(systemFontMap); SharedMemory sharedMemory = Typeface.serializeFontMap(systemFontMap); Map<String, Typeface> copiedFontMap = new ArrayMap<>(); Map<String, Typeface> copiedFontMap = new ArrayMap<>(); try { Typeface.deserializeFontMap(sharedMemory.mapReadOnly().order(ByteOrder.BIG_ENDIAN), Typeface.deserializeFontMap(sharedMemory.mapReadOnly().order(ByteOrder.BIG_ENDIAN), copiedFontMap); copiedFontMap); assertEquals(systemFontMap.size(), copiedFontMap.size()); assertEquals(systemFontMap.size(), copiedFontMap.size()); Loading @@ -214,6 +215,11 @@ public class TypefaceTest { assertEquals(original.getWeight(), copied.getWeight()); assertEquals(original.getWeight(), copied.getWeight()); assertEquals(measureText(original, "hello"), measureText(copied, "hello"), 1e-6); assertEquals(measureText(original, "hello"), measureText(copied, "hello"), 1e-6); } } } finally { for (Typeface typeface : copiedFontMap.values()) { typeface.releaseNativeObjectForTest(); } } } } @SmallTest @SmallTest Loading graphics/java/android/graphics/Typeface.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -1207,6 +1207,7 @@ public class Typeface { * It is safe to call this method twice or more on the same instance. * It is safe to call this method twice or more on the same instance. * @hide * @hide */ */ @TestApi public void releaseNativeObjectForTest() { public void releaseNativeObjectForTest() { mCleaner.run(); mCleaner.run(); } } Loading Loading @@ -1294,6 +1295,13 @@ public class Typeface { /** /** * Deserialize the font mapping from the serialized byte buffer. * Deserialize the font mapping from the serialized byte buffer. * * * <p>Warning: the given {@code buffer} must outlive generated Typeface * objects in {@code out}. In production code, this is guaranteed by * storing the buffer in {@link #sSystemFontMapBuffer}. * If you call this method in a test, please make sure to destroy the * generated Typeface objects by calling * {@link #releaseNativeObjectForTest()}. * * @hide * @hide */ */ @TestApi @TestApi Loading Loading
core/api/test-current.txt +1 −0 Original line number Original line Diff line number Diff line Loading @@ -1039,6 +1039,7 @@ package android.graphics { method @NonNull public static android.util.Pair<java.util.List<android.graphics.Typeface>,java.util.List<android.graphics.Typeface>> changeDefaultFontForTest(@NonNull java.util.List<android.graphics.Typeface>, @NonNull java.util.List<android.graphics.Typeface>); method @NonNull public static android.util.Pair<java.util.List<android.graphics.Typeface>,java.util.List<android.graphics.Typeface>> changeDefaultFontForTest(@NonNull java.util.List<android.graphics.Typeface>, @NonNull java.util.List<android.graphics.Typeface>); method @NonNull public static long[] deserializeFontMap(@NonNull java.nio.ByteBuffer, @NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws java.io.IOException; method @NonNull public static long[] deserializeFontMap(@NonNull java.nio.ByteBuffer, @NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws java.io.IOException; method @Nullable public static android.os.SharedMemory getSystemFontMapSharedMemory(); method @Nullable public static android.os.SharedMemory getSystemFontMapSharedMemory(); method public void releaseNativeObjectForTest(); method @NonNull public static android.os.SharedMemory serializeFontMap(@NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws android.system.ErrnoException, java.io.IOException; method @NonNull public static android.os.SharedMemory serializeFontMap(@NonNull java.util.Map<java.lang.String,android.graphics.Typeface>) throws android.system.ErrnoException, java.io.IOException; } } Loading
core/tests/coretests/src/android/graphics/TypefaceTest.java +16 −10 Original line number Original line Diff line number Diff line Loading @@ -203,6 +203,7 @@ public class TypefaceTest { fallbackMap); fallbackMap); SharedMemory sharedMemory = Typeface.serializeFontMap(systemFontMap); SharedMemory sharedMemory = Typeface.serializeFontMap(systemFontMap); Map<String, Typeface> copiedFontMap = new ArrayMap<>(); Map<String, Typeface> copiedFontMap = new ArrayMap<>(); try { Typeface.deserializeFontMap(sharedMemory.mapReadOnly().order(ByteOrder.BIG_ENDIAN), Typeface.deserializeFontMap(sharedMemory.mapReadOnly().order(ByteOrder.BIG_ENDIAN), copiedFontMap); copiedFontMap); assertEquals(systemFontMap.size(), copiedFontMap.size()); assertEquals(systemFontMap.size(), copiedFontMap.size()); Loading @@ -214,6 +215,11 @@ public class TypefaceTest { assertEquals(original.getWeight(), copied.getWeight()); assertEquals(original.getWeight(), copied.getWeight()); assertEquals(measureText(original, "hello"), measureText(copied, "hello"), 1e-6); assertEquals(measureText(original, "hello"), measureText(copied, "hello"), 1e-6); } } } finally { for (Typeface typeface : copiedFontMap.values()) { typeface.releaseNativeObjectForTest(); } } } } @SmallTest @SmallTest Loading
graphics/java/android/graphics/Typeface.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -1207,6 +1207,7 @@ public class Typeface { * It is safe to call this method twice or more on the same instance. * It is safe to call this method twice or more on the same instance. * @hide * @hide */ */ @TestApi public void releaseNativeObjectForTest() { public void releaseNativeObjectForTest() { mCleaner.run(); mCleaner.run(); } } Loading Loading @@ -1294,6 +1295,13 @@ public class Typeface { /** /** * Deserialize the font mapping from the serialized byte buffer. * Deserialize the font mapping from the serialized byte buffer. * * * <p>Warning: the given {@code buffer} must outlive generated Typeface * objects in {@code out}. In production code, this is guaranteed by * storing the buffer in {@link #sSystemFontMapBuffer}. * If you call this method in a test, please make sure to destroy the * generated Typeface objects by calling * {@link #releaseNativeObjectForTest()}. * * @hide * @hide */ */ @TestApi @TestApi Loading