gralloc: Move validation of non-blob/gpu_data_buffer down to libui
AIDL gralloc implementations may choose to support this combination.
Existing implementations of HIDL gralloc 2/3/4 do not support it,
and do not reliably reject it due to having been previously protected
by validation at the AHardwareBuffer layer.
Move the check down to the gralloc layer, and defer to the HAL only
in the AIDL case.
Bug: b/195944622
Test: build; real CTS/VTS to land soon after.
Change-Id: I7b0b9de005a9b0f564915f9c71cc8aea3ef0618a
diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp
index e026324..9922d6a 100644
--- a/libs/ui/Gralloc4.cpp
+++ b/libs/ui/Gralloc4.cpp
@@ -41,6 +41,7 @@
using android::hardware::hidl_vec;
using android::hardware::graphics::allocator::V4_0::IAllocator;
using android::hardware::graphics::common::V1_2::BufferUsage;
+using android::hardware::graphics::common::V1_2::PixelFormat;
using android::hardware::graphics::mapper::V4_0::BufferDescriptor;
using android::hardware::graphics::mapper::V4_0::Error;
using android::hardware::graphics::mapper::V4_0::IMapper;
@@ -120,6 +121,16 @@
descriptorInfo->usage & ~validUsageBits);
return BAD_VALUE;
}
+
+ // Combinations that are only allowed with gralloc 4.1.
+ // Previous grallocs must be protected from this.
+ if (!hasIAllocatorAidl() &&
+ descriptorInfo->format != hardware::graphics::common::V1_2::PixelFormat::BLOB &&
+ descriptorInfo->usage & BufferUsage::GPU_DATA_BUFFER) {
+ ALOGE("non-BLOB pixel format with GPU_DATA_BUFFER usage is not supported prior to gralloc 4.1");
+ return BAD_VALUE;
+ }
+
return NO_ERROR;
}