From bc3dac3d048d5fc70123999d09aa1fe56b7b9968 Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 30 Jun 2023 12:17:51 -0400 Subject: [PATCH] Don't allow protected buffers in Bitmap#wrapHardwareBuffer HWUI doesn't support protected contexts and it's unlikely to do so, so reject the attempt to create a Bitmap from such a buffer. Test: build & boot, existing usages work fine Bug: 279135360 Change-Id: I0d5efc88a089bf69b4e3bd146fdddf49f784f639 --- graphics/java/android/graphics/Bitmap.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index b9d3756ac6d2a..a4c655c8ce55e 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -782,10 +782,13 @@ public final class Bitmap implements Parcelable { @Nullable public static Bitmap wrapHardwareBuffer(@NonNull HardwareBuffer hardwareBuffer, @Nullable ColorSpace colorSpace) { - if ((hardwareBuffer.getUsage() & HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE) == 0) { + final long usage = hardwareBuffer.getUsage(); + if ((usage & HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE) == 0) { throw new IllegalArgumentException("usage flags must contain USAGE_GPU_SAMPLED_IMAGE."); } - int format = hardwareBuffer.getFormat(); + if ((usage & HardwareBuffer.USAGE_PROTECTED_CONTENT) != 0) { + throw new IllegalArgumentException("Bitmap is not compatible with protected buffers"); + } if (colorSpace == null) { colorSpace = ColorSpace.get(ColorSpace.Named.SRGB); }