From ed2437004160674c1a64e9e99fddaaab5e1bc214 Mon Sep 17 00:00:00 2001 From: falhassen Date: Fri, 2 Feb 2024 11:39:37 -0800 Subject: [PATCH] Fix broken DownsamplerEmulatorTest due to class-not-found regression --- .../bitmap/DownsamplerEmulatorTest.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/instrumentation/src/androidTest/java/com/bumptech/glide/load/resource/bitmap/DownsamplerEmulatorTest.java b/instrumentation/src/androidTest/java/com/bumptech/glide/load/resource/bitmap/DownsamplerEmulatorTest.java index 2e4716a88b..28117bb17c 100644 --- a/instrumentation/src/androidTest/java/com/bumptech/glide/load/resource/bitmap/DownsamplerEmulatorTest.java +++ b/instrumentation/src/androidTest/java/com/bumptech/glide/load/resource/bitmap/DownsamplerEmulatorTest.java @@ -15,13 +15,11 @@ import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.Bitmap.Config; -import android.graphics.Gainmap; import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.util.DisplayMetrics; import androidx.annotation.Nullable; -import androidx.annotation.RequiresApi; import androidx.exifinterface.media.ExifInterface; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -481,8 +479,8 @@ private static String runScaleTest( try { if (VERSION.SDK_INT >= VERSION_CODES.UPSIDE_DOWN_CAKE && (bitmap.getWidth() != expectedWidth - || bitmap.getHeight() != expectedHeight - || bitmap.hasGainmap() != hasGainmap)) { + || bitmap.getHeight() != expectedHeight + || bitmap.hasGainmap() != hasGainmap)) { return "API: " + Build.VERSION.SDK_INT + ", os: " @@ -506,7 +504,7 @@ private static String runScaleTest( + readableDimensAndHasGainmap(expectedWidth, expectedHeight, hasGainmap) + ", but Received " + readableDimensAndHasGainmap( - bitmap.getWidth(), bitmap.getHeight(), bitmap.hasGainmap()); + bitmap.getWidth(), bitmap.getHeight(), bitmap.hasGainmap()); } else if (bitmap.getWidth() != expectedWidth || bitmap.getHeight() != expectedHeight) { return "API: " + Build.VERSION.SDK_INT @@ -600,7 +598,11 @@ private static InputStream openFileStream( Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); if (hasGainmap && VERSION.SDK_INT >= VERSION_CODES.UPSIDE_DOWN_CAKE) { - bitmap.setGainmap(createGainmap(width / 2, height / 2)); + bitmap.setGainmap( + // Intentionally not directly imported due to test failures with class resolution when + // running on SDK levels < 34. Also, do not extract methods with Gainmap in the method + // signature for the same reason. + new android.graphics.Gainmap(Bitmap.createBitmap(width / 2, height / 2, Config.ALPHA_8))); } OutputStream os = null; @@ -640,7 +642,11 @@ private static InputStream openInMemoryStream( CompressFormat format, int width, int height, boolean hasGainmap) { Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); if (hasGainmap && VERSION.SDK_INT >= VERSION_CODES.UPSIDE_DOWN_CAKE) { - bitmap.setGainmap(createGainmap(width / 2, height / 2)); + // Intentionally not directly imported due to test failures with class resolution when + // running on SDK levels < 34. Also, do not extract methods with Gainmap in the method + // signature for the same reason. + bitmap.setGainmap( + new android.graphics.Gainmap(Bitmap.createBitmap(width / 2, height / 2, Config.ALPHA_8))); } ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(format, 100 /*quality*/, os); @@ -649,11 +655,6 @@ private static InputStream openInMemoryStream( return new ByteArrayInputStream(data); } - @RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE) - private static Gainmap createGainmap(int width, int height) { - return new Gainmap(Bitmap.createBitmap(width, height, Config.ALPHA_8)); - } - static final class Tester { private final DownsampleStrategy strategy; private final List testCases = new ArrayList<>(); @@ -900,15 +901,15 @@ static final class Formats { private final CompressFormat[] formats; private static final int[] ALL_EXIF_ORIENTATIONS = new int[] { - ExifInterface.ORIENTATION_UNDEFINED, - ExifInterface.ORIENTATION_NORMAL, - ExifInterface.ORIENTATION_FLIP_HORIZONTAL, - ExifInterface.ORIENTATION_ROTATE_180, - ExifInterface.ORIENTATION_FLIP_VERTICAL, - ExifInterface.ORIENTATION_TRANSPOSE, - ExifInterface.ORIENTATION_ROTATE_90, - ExifInterface.ORIENTATION_TRANSVERSE, - ExifInterface.ORIENTATION_ROTATE_270 + ExifInterface.ORIENTATION_UNDEFINED, + ExifInterface.ORIENTATION_NORMAL, + ExifInterface.ORIENTATION_FLIP_HORIZONTAL, + ExifInterface.ORIENTATION_ROTATE_180, + ExifInterface.ORIENTATION_FLIP_VERTICAL, + ExifInterface.ORIENTATION_TRANSPOSE, + ExifInterface.ORIENTATION_ROTATE_90, + ExifInterface.ORIENTATION_TRANSVERSE, + ExifInterface.ORIENTATION_ROTATE_270 }; private static final int[] UNDEFINED_EXIF_ORIENTATIONS = new int[] {ExifInterface.ORIENTATION_UNDEFINED};