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
This commit is contained in:
John Reck
2023-06-30 12:17:51 -04:00
parent 2ccedbf4f5
commit bc3dac3d04

View File

@@ -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);
}