Pass ImageDecoderTest#testUpscale on MEDIUM devices

Bug: 111330679
Test: Run the test on hikey960

The intent of this test is to trick the system into thinking it has a
screen with a (first higher, then lower) density than the only asset
available. With a higher density screen, the asset should not be scaled,
but the Drawable's density will result in drawing it at a larger size as
if it had been scaled (saving memory). With a lower density screen, the
asset should be scaled down at decode time, also saving memory, and
matching the existing behavior. As originally written, the test does not
pass for DisplayMetrics.DENSITY_MEDIUM devices. Even though the test
modifies |densityDpi|, ImageDecoder (correctly) notes that the asset's
density matches |noncompatDensityDpi| (a hidden field) and uses that as
a signal to avoid scaling at decode time. Since ImageDecoder is doing
the right thing, update the test for DENSITY_MEDIUM devices to match the
existing behavior.

Change-Id: I3d6a4b7a317baf2a4b0fc5c255f7ccb0ec124385
(cherry picked from commit 86cb28b8cf27744b4435b6e4e584f843ebc54ea7)
diff --git a/tests/tests/graphics/src/android/graphics/cts/ImageDecoderTest.java b/tests/tests/graphics/src/android/graphics/cts/ImageDecoderTest.java
index 371d6b6..cb214db 100644
--- a/tests/tests/graphics/src/android/graphics/cts/ImageDecoderTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/ImageDecoderTest.java
@@ -1997,16 +1997,31 @@
                 assertTrue(drawable.getIntrinsicHeight() > record.height);
 
                 // Set a low density. This will result in a smaller drawable and
-                // Bitmap.
+                // Bitmap, unless the true density is DENSITY_MEDIUM, which matches
+                // the density of the asset.
                 mRes.getDisplayMetrics().densityDpi = DisplayMetrics.DENSITY_LOW;
                 drawable = decodeBitmapDrawable(resId);
-
                 bm = drawable.getBitmap();
-                assertTrue(bm.getWidth() < record.width);
-                assertTrue(bm.getHeight() < record.height);
 
-                assertEquals(bm.getWidth(), drawable.getIntrinsicWidth());
-                assertEquals(bm.getHeight(), drawable.getIntrinsicHeight());
+                if (originalDensity == DisplayMetrics.DENSITY_MEDIUM) {
+                    // Although we've modified |densityDpi|, ImageDecoder knows the
+                    // true density matches the asset, so it will not downscale at
+                    // decode time.
+                    assertEquals(bm.getWidth(), record.width);
+                    assertEquals(bm.getHeight(), record.height);
+
+                    // The drawable should still be smaller.
+                    assertTrue(bm.getWidth() > drawable.getIntrinsicWidth());
+                    assertTrue(bm.getHeight() > drawable.getIntrinsicHeight());
+                } else {
+                    // The bitmap is scaled down at decode time, so it matches the
+                    // drawable size, and is smaller than the original.
+                    assertTrue(bm.getWidth() < record.width);
+                    assertTrue(bm.getHeight() < record.height);
+
+                    assertEquals(bm.getWidth(), drawable.getIntrinsicWidth());
+                    assertEquals(bm.getHeight(), drawable.getIntrinsicHeight());
+                }
             }
         } finally {
             mRes.getDisplayMetrics().densityDpi = originalDensity;