From 8060fa83283a6186cb09b52591ba31f041bf5db3 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Tue, 24 Mar 2020 15:03:36 -0400 Subject: [PATCH] Expose ImageDecoder#createSource(byte[] (, int, int)) Bug: 152322291 Test: Ib50eba48e3557a0147b95dd6ce3e8589ab07c127 These methods are used in various places in the system, and the system will not be able to access them as @hidden APIs once ImageDecoder is part of a mainline module. They were originally hidden to discourage clients from keeping the encoded data allocated in a large buffer, especially for animated images. But this is already possible using a ByteBuffer. Change-Id: If5350d4f2ff88ac634e48b9224d70954fd312d30 --- api/current.txt | 2 ++ .../java/android/graphics/ImageDecoder.java | 22 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/api/current.txt b/api/current.txt index f6a0d02aaea90..6d172499bf269 100644 --- a/api/current.txt +++ b/api/current.txt @@ -14678,6 +14678,8 @@ package android.graphics { method @AnyThread @NonNull public static android.graphics.ImageDecoder.Source createSource(@NonNull android.content.res.Resources, int); method @AnyThread @NonNull public static android.graphics.ImageDecoder.Source createSource(@NonNull android.content.ContentResolver, @NonNull android.net.Uri); method @AnyThread @NonNull public static android.graphics.ImageDecoder.Source createSource(@NonNull android.content.res.AssetManager, @NonNull String); + method @AnyThread @NonNull public static android.graphics.ImageDecoder.Source createSource(@NonNull byte[], int, int) throws java.lang.ArrayIndexOutOfBoundsException; + method @AnyThread @NonNull public static android.graphics.ImageDecoder.Source createSource(@NonNull byte[]); method @AnyThread @NonNull public static android.graphics.ImageDecoder.Source createSource(@NonNull java.nio.ByteBuffer); method @AnyThread @NonNull public static android.graphics.ImageDecoder.Source createSource(@NonNull java.io.File); method @AnyThread @NonNull public static android.graphics.ImageDecoder.Source createSource(@NonNull java.util.concurrent.Callable); diff --git a/graphics/java/android/graphics/ImageDecoder.java b/graphics/java/android/graphics/ImageDecoder.java index 83432c3626724..3ecc0b3565dd7 100644 --- a/graphics/java/android/graphics/ImageDecoder.java +++ b/graphics/java/android/graphics/ImageDecoder.java @@ -944,6 +944,12 @@ public final class ImageDecoder implements AutoCloseable { /** * Create a new {@link Source Source} from a byte array. * + *

Note: If this {@code Source} is passed to {@link #decodeDrawable decodeDrawable}, + * and the encoded image is animated, the returned {@link AnimatedImageDrawable} + * will continue reading from {@code data}, so its contents must not + * be modified, even after the {@code AnimatedImageDrawable} is returned. + * {@code data}'s contents should never be modified during decode.

+ * * @param data byte array of compressed image data. * @param offset offset into data for where the decoder should begin * parsing. @@ -954,7 +960,6 @@ public final class ImageDecoder implements AutoCloseable { * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if offset and length are * not within data. - * @hide */ @AnyThread @NonNull @@ -972,8 +977,19 @@ public final class ImageDecoder implements AutoCloseable { } /** - * See {@link #createSource(byte[], int, int). - * @hide + * Create a new {@link Source Source} from a byte array. + * + *

Note: If this {@code Source} is passed to {@link #decodeDrawable decodeDrawable}, + * and the encoded image is animated, the returned {@link AnimatedImageDrawable} + * will continue reading from {@code data}, so its contents must not + * be modified, even after the {@code AnimatedImageDrawable} is returned. + * {@code data}'s contents should never be modified during decode.

+ * + * @param data byte array of compressed image data. + * @return a new Source object, which can be passed to + * {@link #decodeDrawable decodeDrawable} or + * {@link #decodeBitmap decodeBitmap}. + * @throws NullPointerException if data is null. */ @AnyThread @NonNull