Merge "Don't allow protected buffers in Bitmap#wrapHardwareBuffer"

This commit is contained in:
John Reck
2023-07-01 02:19:56 +00:00
committed by Android (Google) Code Review

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