BitmapFactoryTest: Add 10-bit HEF decoding test

Bug: b/220741936
Test: BitmapFactoryTest
Change-Id: I9fa359fd6535ce4ff8af9ac550c3c778f9f67440
(cherry picked from commit 623fe2286b78c4fe1aac5da0b95a67fc61aeb652)
diff --git a/tests/tests/graphics/res/raw/heifimage_10bit.heic b/tests/tests/graphics/res/raw/heifimage_10bit.heic
new file mode 100644
index 0000000..c2e6c4b
--- /dev/null
+++ b/tests/tests/graphics/res/raw/heifimage_10bit.heic
Binary files differ
diff --git a/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java b/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
index 1917b2d..534f492 100644
--- a/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
@@ -38,6 +38,7 @@
 import android.os.Parcel;
 import android.os.ParcelFileDescriptor;
 import android.platform.test.annotations.LargeTest;
+import android.platform.test.annotations.RequiresDevice;
 import android.system.ErrnoException;
 import android.system.Os;
 import android.util.DisplayMetrics;
@@ -1001,6 +1002,63 @@
         return argb;
     }
 
+    @Test
+    @RequiresDevice
+    public void testDecode10BitHEIFTo10BitBitmap() {
+        if (!MediaUtils.hasDecoder(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
+            return;
+        }
+        BitmapFactory.Options opt = new BitmapFactory.Options();
+        opt.inPreferredConfig = Config.RGBA_1010102;
+        Bitmap bm = BitmapFactory.decodeStream(obtainInputStream(R.raw.heifimage_10bit), null, opt);
+        assertNotNull(bm);
+        assertEquals(4096, bm.getWidth());
+        assertEquals(3072, bm.getHeight());
+        assertEquals(Config.RGBA_1010102, bm.getConfig());
+    }
+
+    @Test
+    @RequiresDevice
+    public void testDecode10BitHEIFTo8BitBitmap() {
+        if (!MediaUtils.hasDecoder(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
+            return;
+        }
+        BitmapFactory.Options opt = new BitmapFactory.Options();
+        opt.inPreferredConfig = Config.ARGB_8888;
+        Bitmap bm1 =
+            BitmapFactory.decodeStream(obtainInputStream(R.raw.heifimage_10bit), null, opt);
+        Bitmap bm2 = BitmapFactory.decodeStream(obtainInputStream(R.raw.heifimage_10bit));
+        assertNotNull(bm1);
+        assertEquals(4096, bm1.getWidth());
+        assertEquals(3072, bm1.getHeight());
+        assertEquals(Config.RGBA_1010102, bm1.getConfig());
+        assertNotNull(bm2);
+        assertEquals(4096, bm2.getWidth());
+        assertEquals(3072, bm2.getHeight());
+        assertEquals(Config.RGBA_1010102, bm2.getConfig());
+    }
+
+    @Test
+    @RequiresDevice
+    public void testDecode8BitHEIFTo10BitBitmap() {
+        if (!MediaUtils.hasDecoder(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
+            return;
+        }
+        BitmapFactory.Options opt = new BitmapFactory.Options();
+        opt.inPreferredConfig = Config.RGBA_1010102;
+        Bitmap bm1 =
+            BitmapFactory.decodeStream(obtainInputStream(R.raw.heifwriter_input), null, opt);
+        Bitmap bm2 = BitmapFactory.decodeStream(obtainInputStream(R.raw.heifwriter_input));
+        assertNotNull(bm1);
+        assertEquals(1920, bm1.getWidth());
+        assertEquals(1080, bm1.getHeight());
+        assertEquals(Config.ARGB_8888, bm1.getConfig());
+        assertNotNull(bm2);
+        assertEquals(1920, bm2.getWidth());
+        assertEquals(1080, bm2.getHeight());
+        assertEquals(Config.ARGB_8888, bm2.getConfig());
+    }
+
     private byte[] obtainArray() {
         ByteArrayOutputStream stm = new ByteArrayOutputStream();
         Options opt = new BitmapFactory.Options();