gralloc: add IAllocator/IMapper 4.0 to camera HIDL

Add support for gralloc 4.0 to camera interface.

Bug: 136016160
Test: VtsHalCameraProviderV2_4TargetTest on a pixel
      with a local rev'd version of gralloc 4.0.

Change-Id: I7f2e14c291fbdafcb68c1e9c6e94fed87d810191
diff --git a/camera/provider/2.4/default/Android.bp b/camera/provider/2.4/default/Android.bp
index cb78fcb..313b29b 100644
--- a/camera/provider/2.4/default/Android.bp
+++ b/camera/provider/2.4/default/Android.bp
@@ -13,6 +13,7 @@
         "android.hardware.camera.provider@2.4",
         "android.hardware.graphics.mapper@2.0",
         "android.hardware.graphics.mapper@3.0",
+        "android.hardware.graphics.mapper@4.0",
         "android.hidl.allocator@1.0",
         "android.hidl.memory@1.0",
         "camera.device@1.0-impl",
@@ -52,6 +53,7 @@
         "android.hardware.camera.provider@2.4",
         "android.hardware.graphics.mapper@2.0",
         "android.hardware.graphics.mapper@3.0",
+        "android.hardware.graphics.mapper@4.0",
         "android.hidl.allocator@1.0",
         "android.hidl.memory@1.0",
         "camera.device@3.3-impl",
@@ -95,6 +97,8 @@
         "android.hardware.camera.provider@2.4-external",
         "android.hardware.camera.provider@2.4-legacy",
         "android.hardware.graphics.mapper@2.0",
+        "android.hardware.graphics.mapper@3.0",
+        "android.hardware.graphics.mapper@4.0",
         "android.hidl.allocator@1.0",
         "android.hidl.memory@1.0",
         "camera.device@1.0-impl",
@@ -140,6 +144,8 @@
         "android.hardware.camera.device@3.5",
         "android.hardware.camera.provider@2.4",
         "android.hardware.graphics.mapper@2.0",
+        "android.hardware.graphics.mapper@3.0",
+        "android.hardware.graphics.mapper@4.0",
         "android.hidl.allocator@1.0",
         "android.hidl.memory@1.0",
         "libbinder",
diff --git a/camera/provider/2.4/vts/functional/Android.bp b/camera/provider/2.4/vts/functional/Android.bp
index 2c3ed37..5fe7b19 100644
--- a/camera/provider/2.4/vts/functional/Android.bp
+++ b/camera/provider/2.4/vts/functional/Android.bp
@@ -43,9 +43,11 @@
         "android.hardware.camera.provider@2.5",
         "android.hardware.graphics.allocator@2.0",
         "android.hardware.graphics.allocator@3.0",
+        "android.hardware.graphics.allocator@4.0",
         "android.hardware.graphics.common@1.0",
         "android.hardware.graphics.mapper@2.0",
         "android.hardware.graphics.mapper@3.0",
+        "android.hardware.graphics.mapper@4.0",
         "android.hidl.allocator@1.0",
         "libgrallocusage",
         "libhidlmemory",
diff --git a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
index a5369e7..6f6479d 100644
--- a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
+++ b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
@@ -55,9 +55,11 @@
 
 #include <android/hardware/graphics/allocator/2.0/IAllocator.h>
 #include <android/hardware/graphics/allocator/3.0/IAllocator.h>
+#include <android/hardware/graphics/allocator/4.0/IAllocator.h>
 #include <android/hardware/graphics/mapper/2.0/IMapper.h>
 #include <android/hardware/graphics/mapper/2.0/types.h>
 #include <android/hardware/graphics/mapper/3.0/IMapper.h>
+#include <android/hardware/graphics/mapper/4.0/IMapper.h>
 #include <android/hidl/allocator/1.0/IAllocator.h>
 #include <android/hidl/memory/1.0/IMapper.h>
 #include <android/hidl/memory/1.0/IMemory.h>
@@ -6148,13 +6150,44 @@
         android::hardware::graphics::allocator::V2_0::IAllocator::getService();
     sp<android::hardware::graphics::allocator::V3_0::IAllocator> allocatorV3 =
         android::hardware::graphics::allocator::V3_0::IAllocator::getService();
+    sp<android::hardware::graphics::allocator::V4_0::IAllocator> allocatorV4 =
+            android::hardware::graphics::allocator::V4_0::IAllocator::getService();
 
+    sp<android::hardware::graphics::mapper::V4_0::IMapper> mapperV4 =
+            android::hardware::graphics::mapper::V4_0::IMapper::getService();
     sp<android::hardware::graphics::mapper::V3_0::IMapper> mapperV3 =
         android::hardware::graphics::mapper::V3_0::IMapper::getService();
     sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
         android::hardware::graphics::mapper::V2_0::IMapper::getService();
     ::android::hardware::hidl_vec<uint32_t> descriptor;
-    if (mapperV3 != nullptr && allocatorV3 != nullptr) {
+    if (mapperV4 != nullptr && allocatorV4 != nullptr) {
+        android::hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo descriptorInfo{};
+        descriptorInfo.width = width;
+        descriptorInfo.height = height;
+        descriptorInfo.layerCount = 1;
+        descriptorInfo.format =
+                static_cast<android::hardware::graphics::common::V1_2::PixelFormat>(format);
+        descriptorInfo.usage = usage;
+
+        auto ret = mapperV4->createDescriptor(
+                descriptorInfo, [&descriptor](android::hardware::graphics::mapper::V4_0::Error err,
+                                              ::android::hardware::hidl_vec<uint32_t> desc) {
+                    ASSERT_EQ(err, android::hardware::graphics::mapper::V4_0::Error::NONE);
+                    descriptor = desc;
+                });
+        ASSERT_TRUE(ret.isOk());
+
+        ret = allocatorV4->allocate(
+                descriptor, 1u,
+                [&](android::hardware::graphics::mapper::V4_0::Error err, uint32_t /*stride*/,
+                    const ::android::hardware::hidl_vec<::android::hardware::hidl_handle>&
+                            buffers) {
+                    ASSERT_EQ(android::hardware::graphics::mapper::V4_0::Error::NONE, err);
+                    ASSERT_EQ(buffers.size(), 1u);
+                    *buffer_handle = buffers[0];
+                });
+        ASSERT_TRUE(ret.isOk());
+    } else if (mapperV3 != nullptr && allocatorV3 != nullptr) {
         android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo descriptorInfo {};
         descriptorInfo.width = width;
         descriptorInfo.height = height;