diff --git a/library/src/main/java/com/bumptech/glide/Glide.java b/library/src/main/java/com/bumptech/glide/Glide.java index c0b2ba2b2e..8db27f10c2 100644 --- a/library/src/main/java/com/bumptech/glide/Glide.java +++ b/library/src/main/java/com/bumptech/glide/Glide.java @@ -14,7 +14,6 @@ import androidx.annotation.VisibleForTesting; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; -import com.bumptech.glide.GlideBuilder.DisableHardwareBitmapsOnO; import com.bumptech.glide.load.DecodeFormat; import com.bumptech.glide.load.engine.Engine; import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; @@ -328,13 +327,6 @@ private static void throwIncorrectGlideModule(Exception e) { this.connectivityMonitorFactory = connectivityMonitorFactory; this.defaultRequestOptionsFactory = defaultRequestOptionsFactory; - DisableHardwareBitmapsOnO disableHardwareBitmapsOnO = - experiments.get(DisableHardwareBitmapsOnO.class); - if (disableHardwareBitmapsOnO != null) { - HardwareConfigState.setDisableHardwareBitmapsOnO( - disableHardwareBitmapsOnO.disableHardwareBitmapsOnO); - } - // This has a circular relationship with Glide and GlideContext in that it depends on both, // but it's created by Glide's constructor. In practice this shouldn't matter because the // supplier holding the registry should never be initialized before this constructor finishes. diff --git a/library/src/main/java/com/bumptech/glide/GlideBuilder.java b/library/src/main/java/com/bumptech/glide/GlideBuilder.java index 950e85a80d..c61d6be114 100644 --- a/library/src/main/java/com/bumptech/glide/GlideBuilder.java +++ b/library/src/main/java/com/bumptech/glide/GlideBuilder.java @@ -488,15 +488,11 @@ public GlideBuilder setImageDecoderEnabledForBitmaps(boolean isEnabled) { } /** - * Disables hardware bitmaps if the sdk level is <= O and {@code disableHardwareBitmapsOnO} is - * {@code true}. - * - * @deprecated This method is experimental. It will be hard coded and removed in a future release + * @deprecated This method does nothing. It will be hard coded and removed in a future release * without further warning. */ @Deprecated public GlideBuilder setDisableHardwareBitmapsOnO(boolean disableHardwareBitmapsOnO) { - glideExperimentsBuilder.add(new DisableHardwareBitmapsOnO(disableHardwareBitmapsOnO)); return this; } @@ -595,14 +591,6 @@ Glide build( experiments); } - static final class DisableHardwareBitmapsOnO implements Experiment { - final boolean disableHardwareBitmapsOnO; - - DisableHardwareBitmapsOnO(boolean disableHardwareBitmapsOnO) { - this.disableHardwareBitmapsOnO = disableHardwareBitmapsOnO; - } - } - static final class ManualOverrideHardwareBitmapMaxFdCount implements Experiment { final int fdCount; diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/HardwareConfigState.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/HardwareConfigState.java index 6bbe1f9e7d..476a0a3880 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/HardwareConfigState.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/HardwareConfigState.java @@ -4,7 +4,9 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Build; +import android.os.Build.VERSION_CODES; import android.util.Log; +import androidx.annotation.ChecksSdkIntAtLeast; import androidx.annotation.GuardedBy; import androidx.annotation.VisibleForTesting; import com.bumptech.glide.util.Util; @@ -29,21 +31,9 @@ public final class HardwareConfigState { Build.VERSION.SDK_INT < Build.VERSION_CODES.Q; /** Support for the hardware bitmap config was added in Android O. */ + @ChecksSdkIntAtLeast(api = VERSION_CODES.P) public static final boolean HARDWARE_BITMAPS_SUPPORTED = - Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; - - /** - * The minimum size in pixels a {@link Bitmap} must be in both dimensions to be created with the - * {@link Bitmap.Config#HARDWARE} configuration. - * - *

This is a quick check that lets us skip wasting FDs (see {@link #FD_SIZE_LIST}) on small - * {@link Bitmap}s with relatively low memory costs. - * - * @see #FD_SIZE_LIST - */ - @VisibleForTesting static final int MIN_HARDWARE_DIMENSION_O = 128; - - private static final int MIN_HARDWARE_DIMENSION_P = 0; + Build.VERSION.SDK_INT >= Build.VERSION_CODES.P; /** * Allows us to check to make sure we're not exceeding the FD limit for a process with hardware @@ -65,15 +55,6 @@ public final class HardwareConfigState { * arbitrary. */ private static final int MINIMUM_DECODES_BETWEEN_FD_CHECKS = 50; - - /** - * 700 with an error of 50 Bitmaps in between at two FDs each lets us use up to 800 FDs for - * hardware Bitmaps. - * - *

Prior to P, the limit per process was 1024 FDs. In P, the limit was updated to 32k FDs per - * process. - */ - private static final int MAXIMUM_FDS_FOR_HARDWARE_CONFIGS_O = 700; // 20k. private static final int MAXIMUM_FDS_FOR_HARDWARE_CONFIGS_P = 20000; @@ -90,12 +71,7 @@ public final class HardwareConfigState { private static volatile HardwareConfigState instance; - private static boolean disableHardwareBitmapsOnO; - - private final boolean isHardwareConfigAllowedByDeviceModel; private final int sdkBasedMaxFdCount; - private final int minHardwareDimension; - @GuardedBy("this") private int decodesSinceLastFdCheck; @@ -123,14 +99,7 @@ public static HardwareConfigState getInstance() { @VisibleForTesting HardwareConfigState() { - isHardwareConfigAllowedByDeviceModel = isHardwareConfigAllowedByDeviceModel(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - sdkBasedMaxFdCount = MAXIMUM_FDS_FOR_HARDWARE_CONFIGS_P; - minHardwareDimension = MIN_HARDWARE_DIMENSION_P; - } else { - sdkBasedMaxFdCount = MAXIMUM_FDS_FOR_HARDWARE_CONFIGS_O; - minHardwareDimension = MIN_HARDWARE_DIMENSION_O; - } + sdkBasedMaxFdCount = MAXIMUM_FDS_FOR_HARDWARE_CONFIGS_P; } public void blockHardwareBitmaps() { @@ -143,22 +112,6 @@ public void unblockHardwareBitmaps() { isHardwareConfigAllowedByAppState.set(true); } - /** - * Temporary API to try disabling hardware Bitmaps < Android P. - * - * @deprecated Will be removed in a future version without further warning. This value will be - * hard coded for release. - */ - @Deprecated - public static void setDisableHardwareBitmapsOnO(boolean disableHardwareBitmapsOnO) { - HardwareConfigState.disableHardwareBitmapsOnO = disableHardwareBitmapsOnO; - } - - private boolean areHardwareBitmapsAllowedBySdk() { - return HARDWARE_BITMAPS_SUPPORTED - && (!disableHardwareBitmapsOnO || Build.VERSION.SDK_INT >= Build.VERSION_CODES.P); - } - public boolean isHardwareConfigAllowed( int targetWidth, int targetHeight, @@ -170,13 +123,7 @@ public boolean isHardwareConfigAllowed( } return false; } - if (!isHardwareConfigAllowedByDeviceModel) { - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.v(TAG, "Hardware config disallowed by device model"); - } - return false; - } - if (!areHardwareBitmapsAllowedBySdk()) { + if (!HARDWARE_BITMAPS_SUPPORTED) { if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "Hardware config disallowed by sdk"); } @@ -194,15 +141,9 @@ public boolean isHardwareConfigAllowed( } return false; } - if (targetWidth < minHardwareDimension) { - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.v(TAG, "Hardware config disallowed because width is too small"); - } - return false; - } - if (targetHeight < minHardwareDimension) { + if (targetWidth < 0 || targetHeight < 0) { if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.v(TAG, "Hardware config disallowed because height is too small"); + Log.v(TAG, "Hardware config disallowed because of invalid dimensions"); } return false; } @@ -239,75 +180,6 @@ boolean setHardwareConfigIfAllowed( return result; } - private static boolean isHardwareConfigAllowedByDeviceModel() { - return !isHardwareConfigDisallowedByB112551574() && !isHardwareConfigDisallowedByB147430447(); - } - - private static boolean isHardwareConfigDisallowedByB147430447() { - if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O_MR1) { - return false; - } - // This method will only be called once, so simple iteration is reasonable. - return Arrays.asList( - "LG-M250", - "LG-M320", - "LG-Q710AL", - "LG-Q710PL", - "LGM-K121K", - "LGM-K121L", - "LGM-K121S", - "LGM-X320K", - "LGM-X320L", - "LGM-X320S", - "LGM-X401L", - "LGM-X401S", - "LM-Q610.FG", - "LM-Q610.FGN", - "LM-Q617.FG", - "LM-Q617.FGN", - "LM-Q710.FG", - "LM-Q710.FGN", - "LM-X220PM", - "LM-X220QMA", - "LM-X410PM") - .contains(Build.MODEL); - } - - private static boolean isHardwareConfigDisallowedByB112551574() { - if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O) { - return false; - } - // This method will only be called once, so simple iteration is reasonable. - for (String prefixOrModelName : - // This is sadly a list of prefixes, not models. We no longer have the data that shows us - // all the explicit models, so we have to live with the prefixes. - Arrays.asList( - // Samsung - "SC-04J", - "SM-N935", - "SM-J720", - "SM-G570F", - "SM-G570M", - "SM-G960", - "SM-G965", - "SM-G935", - "SM-G930", - "SM-A520", - "SM-A720F", - // Moto - "moto e5", - "moto e5 play", - "moto e5 plus", - "moto e5 cruise", - "moto g(6) forge", - "moto g(6) play")) { - if (Build.MODEL.startsWith(prefixOrModelName)) { - return true; - } - } - return false; - } - private static boolean isHardwareBitmapCountReducedOnApi28ByB139097735() { if (Build.VERSION.SDK_INT != Build.VERSION_CODES.P) { return false; diff --git a/library/test/src/test/java/com/bumptech/glide/load/resource/bitmap/HardwareConfigStateTest.java b/library/test/src/test/java/com/bumptech/glide/load/resource/bitmap/HardwareConfigStateTest.java index 4022f5c09b..13dd3c7b46 100644 --- a/library/test/src/test/java/com/bumptech/glide/load/resource/bitmap/HardwareConfigStateTest.java +++ b/library/test/src/test/java/com/bumptech/glide/load/resource/bitmap/HardwareConfigStateTest.java @@ -15,8 +15,10 @@ @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class HardwareConfigStateTest { + private static final int VALID_DIMENSION = 100; - @Config(sdk = Build.VERSION_CODES.O) + + @Config(sdk = Build.VERSION_CODES.P) @Test public void setHardwareConfigIfAllowed_withAllowedState_setsInPreferredConfigAndMutable_returnsTrue() { @@ -25,8 +27,8 @@ public class HardwareConfigStateTest { BitmapFactory.Options options = new BitmapFactory.Options(); boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, + /* targetWidth= */ VALID_DIMENSION, + /* targetHeight= */ VALID_DIMENSION, options, /* isHardwareConfigAllowed= */ true, /* isExifOrientationRequired= */ false); @@ -35,7 +37,7 @@ public class HardwareConfigStateTest { assertThat(options.inPreferredConfig).isEqualTo(Bitmap.Config.HARDWARE); } - @Config(sdk = Build.VERSION_CODES.O) + @Config(sdk = Build.VERSION_CODES.P) @Test public void setHardwareConfigIfAllowed_withAllowedState_afterReblock_returnsFalseAndDoesNotSetValues() { @@ -45,8 +47,8 @@ public class HardwareConfigStateTest { BitmapFactory.Options options = new BitmapFactory.Options(); boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, + /* targetWidth= */ VALID_DIMENSION, + /* targetHeight= */ VALID_DIMENSION, options, /* isHardwareConfigAllowed= */ true, /* isExifOrientationRequired= */ false); @@ -55,9 +57,9 @@ public class HardwareConfigStateTest { assertThat(options.inPreferredConfig).isNotEqualTo(Bitmap.Config.HARDWARE); } - @Config(sdk = Build.VERSION_CODES.O) + @Config(sdk = Build.VERSION_CODES.P) @Test - public void setHardwareConfigIfAllowed_withSmallerThanMinWidth_returnsFalse_doesNotSetValues() { + public void setHardwareConfigIfAllowed_withInvalidWidth_returnsFalse_doesNotSetValues() { HardwareConfigState state = new HardwareConfigState(); state.unblockHardwareBitmaps(); BitmapFactory.Options options = new BitmapFactory.Options(); @@ -66,8 +68,8 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinWidth_returnsFalse_does boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O - 1, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, + /* targetWidth= */ -1, + /* targetHeight= */ VALID_DIMENSION, options, /* isHardwareConfigAllowed= */ true, /* isExifOrientationRequired= */ false); @@ -77,9 +79,9 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinWidth_returnsFalse_does assertThat(options.inPreferredConfig).isNull(); } - @Config(sdk = Build.VERSION_CODES.O) + @Config(sdk = Build.VERSION_CODES.P) @Test - public void setHardwareConfigIfAllowed_withSmallerThanMinHeight_returnsFalse_doesNotSetValues() { + public void setHardwareConfigIfAllowed_withInvalidHeight_returnsFalse_doesNotSetValues() { HardwareConfigState state = new HardwareConfigState(); state.unblockHardwareBitmaps(); BitmapFactory.Options options = new BitmapFactory.Options(); @@ -88,8 +90,8 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinHeight_returnsFalse_doe boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O - 1, + /* targetWidth= */ VALID_DIMENSION, + /* targetHeight= */ -1, options, /* isHardwareConfigAllowed= */ true, /* isExifOrientationRequired= */ false); @@ -99,7 +101,7 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinHeight_returnsFalse_doe assertThat(options.inPreferredConfig).isNull(); } - @Config(sdk = Build.VERSION_CODES.O) + @Config(sdk = Build.VERSION_CODES.P) @Test public void setHardwareConfigIfAllowed_withHardwareConfigDisallowed_returnsFalse_doesNotSetValues() { @@ -111,8 +113,8 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinHeight_returnsFalse_doe boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, + /* targetWidth= */ VALID_DIMENSION, + /* targetHeight= */ VALID_DIMENSION, options, /* isHardwareConfigAllowed= */ false, /* isExifOrientationRequired= */ false); @@ -122,7 +124,7 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinHeight_returnsFalse_doe assertThat(options.inPreferredConfig).isNull(); } - @Config(sdk = Build.VERSION_CODES.O) + @Config(sdk = Build.VERSION_CODES.P) @Test public void setHardwareConfigIfAllowed_withExifOrientationRequired_returnsFalse_doesNotSetValues() { @@ -134,8 +136,8 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinHeight_returnsFalse_doe boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, + /* targetWidth= */ VALID_DIMENSION, + /* targetHeight= */ VALID_DIMENSION, options, /* isHardwareConfigAllowed= */ true, /* isExifOrientationRequired= */ true); @@ -156,8 +158,8 @@ public void setHardwareConfigIfAllowed_withOsLessThanO_returnsFalse_doesNotSetVa boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, + /* targetWidth= */ VALID_DIMENSION, + /* targetHeight= */ VALID_DIMENSION, options, /* isHardwareConfigAllowed= */ true, /* isExifOrientationRequired= */ false); @@ -178,8 +180,8 @@ public void setHardwareConfigIfAllowed_withOsLessThanO_returnsFalse_doesNotSetVa boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, + /* targetWidth= */ VALID_DIMENSION, + /* targetHeight= */ VALID_DIMENSION, options, /* isHardwareConfigAllowed= */ true, /* isExifOrientationRequired= */ false); @@ -200,8 +202,8 @@ public void setHardwareConfigIfAllowed_withOsLessThanO_returnsFalse_doesNotSetVa boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, + /* targetWidth= */ VALID_DIMENSION, + /* targetHeight= */ VALID_DIMENSION, options, /* isHardwareConfigAllowed= */ true, /* isExifOrientationRequired= */ false); @@ -211,38 +213,9 @@ public void setHardwareConfigIfAllowed_withOsLessThanO_returnsFalse_doesNotSetVa assertThat(options.inPreferredConfig).isEqualTo(Bitmap.Config.HARDWARE); } - @Config(sdk = Build.VERSION_CODES.O) - @Test - public void - setHardwareConfigIfAllowed_withDisallowedSamsungDevices_returnsFalse_doesNotSetValues() { - for (String model : - new String[] { - "SM-N9351", "SM-J72053", "SM-G9600", "SM-G965ab", "SM-G935.", "SM-G930", "SM-A5204" - }) { - ShadowBuild.setModel(model); - HardwareConfigState state = new HardwareConfigState(); - state.unblockHardwareBitmaps(); - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = null; - options.inMutable = true; - - boolean result = - state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - options, - /* isHardwareConfigAllowed= */ true, - /* isExifOrientationRequired= */ false); - - assertWithMessage("model: " + model).that(result).isFalse(); - assertWithMessage("model: " + model).that(options.inMutable).isTrue(); - assertWithMessage("model: " + model).that(options.inPreferredConfig).isNull(); - } - } - - @Config(sdk = Build.VERSION_CODES.O_MR1) + @Config(sdk = Build.VERSION_CODES.P) @Test - public void setHardwareConfigIfAllowed_withDisallowedSamsungDevices_OMR1_returnsTrue() { + public void setHardwareConfigIfAllowed_withPreviouslyDisallowedSamsungDevices_P_returnsTrue() { for (String model : new String[] { "SM-N9351", "SM-J72053", "SM-G9600", "SM-G965ab", "SM-G935.", "SM-G930", "SM-A5204" @@ -256,8 +229,8 @@ public void setHardwareConfigIfAllowed_withDisallowedSamsungDevices_OMR1_returns boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, + /* targetWidth= */ VALID_DIMENSION, + /* targetHeight= */ VALID_DIMENSION, options, /* isHardwareConfigAllowed= */ true, /* isExifOrientationRequired= */ false); @@ -270,7 +243,7 @@ public void setHardwareConfigIfAllowed_withDisallowedSamsungDevices_OMR1_returns } } - @Config(sdk = Build.VERSION_CODES.O) + @Config(sdk = Build.VERSION_CODES.P) @Test public void setHardwareConfigIfAllowed_withShortOrEmptyModelNames_returnsTrue() { for (String model : new String[] {".", "-", "", "S", "SM", "SM-", "SM-G", "SM-G9.", "SM-G93"}) { @@ -283,8 +256,8 @@ public void setHardwareConfigIfAllowed_withShortOrEmptyModelNames_returnsTrue() boolean result = state.setHardwareConfigIfAllowed( - /* targetWidth= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, - /* targetHeight= */ HardwareConfigState.MIN_HARDWARE_DIMENSION_O, + /* targetWidth= */ VALID_DIMENSION, + /* targetHeight= */ VALID_DIMENSION, options, /* isHardwareConfigAllowed= */ true, /* isExifOrientationRequired= */ false);