diff options
| author | 2023-06-30 12:17:51 -0400 | |
|---|---|---|
| committer | 2023-06-30 12:17:51 -0400 | |
| commit | bc3dac3d048d5fc70123999d09aa1fe56b7b9968 (patch) | |
| tree | 458dc9fc7c21eeedb3e3b68fce141505050042db | |
| parent | 2ccedbf4f5acf650f106c83e8ab75186ba0b62d2 (diff) | |
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
| -rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index b9d3756ac6d2..a4c655c8ce55 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); } |