From ddb3934a3d1f43dd184b3b9534a8e621fabff713 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Mon, 19 Oct 2020 17:29:27 -0700 Subject: [PATCH] Update low FD count hardcoded hardware Bitmap blacklist. PiperOrigin-RevId: 337968955 --- .../resource/bitmap/HardwareConfigState.java | 48 +++++++++++-------- .../bitmap/HardwareConfigStateTest.java | 5 +- 2 files changed, 31 insertions(+), 22 deletions(-) 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 807e4db342..c29cb4c563 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 @@ -251,28 +251,38 @@ private static boolean isHardwareConfigDisallowedByB147430447() { } private static boolean isHardwareConfigDisallowedByB112551574() { - if (Build.MODEL == null || Build.MODEL.length() < 7) { + if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O) { return false; } - switch (Build.MODEL.substring(0, 7)) { - case "SM-N935": - // Fall through - case "SM-J720": - // Fall through - case "SM-G960": - // Fall through - case "SM-G965": - // Fall through - case "SM-G935": - // Fall through - case "SM-G930": - // Fall through - case "SM-A520": - // Fall through - return Build.VERSION.SDK_INT == Build.VERSION_CODES.O; - default: - 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 int getMaxFdCount() { 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 3f755b4547..d1f9f2a8ff 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 @@ -250,9 +250,8 @@ public void setHardwareConfigIfAllowed_withDisallowedSamsungDevices_OMR1_returns @Config(sdk = Build.VERSION_CODES.O) @Test - public void setHardwareConfigIfAllowed_withShortEmptyOrNullModelNames_returnsTrue() { - for (String model : - new String[] {null, ".", "-", "", "S", "SM", "SM-", "SM-G", "SM-G9.", "SM-G93"}) { + public void setHardwareConfigIfAllowed_withShortOrEmptyModelNames_returnsTrue() { + for (String model : new String[] {".", "-", "", "S", "SM", "SM-", "SM-G", "SM-G9.", "SM-G93"}) { ShadowBuild.setModel(model); HardwareConfigState state = new HardwareConfigState(); state.unblockHardwareBitmaps();