Adding support for different Mapper versions in IComposer VTS tests

Bug: 135139498
Test: build, boot, VtsHalGraphicsComposerV2_<1,2,3>TargetTest,
Change-Id: I05e2832c64d4c06eb4afd64c3323d7edbd19a5f4
Merged-In: I05e2832c64d4c06eb4afd64c3323d7edbd19a5f4
diff --git a/graphics/mapper/3.0/utils/vts/MapperVts.cpp b/graphics/mapper/3.0/utils/vts/MapperVts.cpp
index f2b7594..c94e8db 100644
--- a/graphics/mapper/3.0/utils/vts/MapperVts.cpp
+++ b/graphics/mapper/3.0/utils/vts/MapperVts.cpp
@@ -25,8 +25,13 @@
 namespace V3_0 {
 namespace vts {
 
-Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
-    init(allocatorServiceName, mapperServiceName);
+Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName,
+                 bool errOnFailure) {
+    if (errOnFailure) {
+        init(allocatorServiceName, mapperServiceName);
+    } else {
+        initNoErr(allocatorServiceName, mapperServiceName);
+    }
 }
 
 void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
@@ -38,6 +43,16 @@
     ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
 }
 
+void Gralloc::initNoErr(const std::string& allocatorServiceName,
+                        const std::string& mapperServiceName) {
+    mAllocator = ::testing::VtsHalHidlTargetTestBase::getService<IAllocator>(allocatorServiceName);
+
+    mMapper = ::testing::VtsHalHidlTargetTestBase::getService<IMapper>(mapperServiceName);
+    if (mMapper.get()) {
+        ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
+    }
+}
+
 Gralloc::~Gralloc() {
     for (auto bufferHandle : mClonedBuffers) {
         auto buffer = const_cast<native_handle_t*>(bufferHandle);
diff --git a/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h b/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h
index ba79ca4..1141a88 100644
--- a/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h
+++ b/graphics/mapper/3.0/utils/vts/include/mapper-vts/3.0/MapperVts.h
@@ -36,62 +36,66 @@
 // A wrapper to IAllocator and IMapper.
 class Gralloc {
    public:
-    Gralloc(const std::string& allocatorServiceName = "default",
-            const std::string& mapperServiceName = "default");
-    ~Gralloc();
+     Gralloc(const std::string& allocatorServiceName = "default",
+             const std::string& mapperServiceName = "default", bool errOnFailure = true);
+     ~Gralloc();
 
-    // IAllocator methods
+     // IAllocator methods
 
-    sp<IAllocator> getAllocator() const;
+     sp<IAllocator> getAllocator() const;
 
-    std::string dumpDebugInfo();
+     std::string dumpDebugInfo();
 
-    // When import is false, this simply calls IAllocator::allocate. When import
-    // is true, the returned buffers are also imported into the mapper.
-    //
-    // Either case, the returned buffers must be freed with freeBuffer.
-    std::vector<const native_handle_t*> allocate(const BufferDescriptor& descriptor, uint32_t count,
-                                                 bool import = true, uint32_t* outStride = nullptr);
-    const native_handle_t* allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
-                                    bool import = true, uint32_t* outStride = nullptr);
+     // When import is false, this simply calls IAllocator::allocate. When import
+     // is true, the returned buffers are also imported into the mapper.
+     //
+     // Either case, the returned buffers must be freed with freeBuffer.
+     std::vector<const native_handle_t*> allocate(const BufferDescriptor& descriptor,
+                                                  uint32_t count, bool import = true,
+                                                  uint32_t* outStride = nullptr);
+     const native_handle_t* allocate(const IMapper::BufferDescriptorInfo& descriptorInfo,
+                                     bool import = true, uint32_t* outStride = nullptr);
 
-    // IMapper methods
+     // IMapper methods
 
-    sp<IMapper> getMapper() const;
+     sp<IMapper> getMapper() const;
 
-    BufferDescriptor createDescriptor(const IMapper::BufferDescriptorInfo& descriptorInfo);
+     BufferDescriptor createDescriptor(const IMapper::BufferDescriptorInfo& descriptorInfo);
 
-    const native_handle_t* importBuffer(const hidl_handle& rawHandle);
-    void freeBuffer(const native_handle_t* bufferHandle);
+     const native_handle_t* importBuffer(const hidl_handle& rawHandle);
+     void freeBuffer(const native_handle_t* bufferHandle);
 
-    // We use fd instead of hidl_handle in these functions to pass fences
-    // in and out of the mapper.  The ownership of the fd is always transferred
-    // with each of these functions.
-    void* lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
-               const IMapper::Rect& accessRegion, int acquireFence, int32_t* outBytesPerPixel,
-               int32_t* outBytesPerStride);
-    YCbCrLayout lockYCbCr(const native_handle_t* bufferHandle, uint64_t cpuUsage,
-                          const IMapper::Rect& accessRegion, int acquireFence);
-    int unlock(const native_handle_t* bufferHandle);
+     // We use fd instead of hidl_handle in these functions to pass fences
+     // in and out of the mapper.  The ownership of the fd is always transferred
+     // with each of these functions.
+     void* lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
+                const IMapper::Rect& accessRegion, int acquireFence, int32_t* outBytesPerPixel,
+                int32_t* outBytesPerStride);
+     YCbCrLayout lockYCbCr(const native_handle_t* bufferHandle, uint64_t cpuUsage,
+                           const IMapper::Rect& accessRegion, int acquireFence);
+     int unlock(const native_handle_t* bufferHandle);
 
-    bool validateBufferSize(const native_handle_t* bufferHandle,
-                            const IMapper::BufferDescriptorInfo& descriptorInfo, uint32_t stride);
-    void getTransportSize(const native_handle_t* bufferHandle, uint32_t* outNumFds,
-                          uint32_t* outNumInts);
+     bool validateBufferSize(const native_handle_t* bufferHandle,
+                             const IMapper::BufferDescriptorInfo& descriptorInfo, uint32_t stride);
+     void getTransportSize(const native_handle_t* bufferHandle, uint32_t* outNumFds,
+                           uint32_t* outNumInts);
 
-    bool isSupported(const IMapper::BufferDescriptorInfo& descriptorInfo);
+     bool isSupported(const IMapper::BufferDescriptorInfo& descriptorInfo);
 
    private:
-    void init(const std::string& allocatorServiceName, const std::string& mapperServiceName);
-    const native_handle_t* cloneBuffer(const hidl_handle& rawHandle);
+     void init(const std::string& allocatorServiceName, const std::string& mapperServiceName);
 
-    sp<IAllocator> mAllocator;
-    sp<IMapper> mMapper;
+     // initialize without checking for failure to get service
+     void initNoErr(const std::string& allocatorServiceName, const std::string& mapperServiceName);
+     const native_handle_t* cloneBuffer(const hidl_handle& rawHandle);
 
-    // Keep track of all cloned and imported handles.  When a test fails with
-    // ASSERT_*, the destructor will free the handles for the test.
-    std::unordered_set<const native_handle_t*> mClonedBuffers;
-    std::unordered_set<const native_handle_t*> mImportedBuffers;
+     sp<IAllocator> mAllocator;
+     sp<IMapper> mMapper;
+
+     // Keep track of all cloned and imported handles.  When a test fails with
+     // ASSERT_*, the destructor will free the handles for the test.
+     std::unordered_set<const native_handle_t*> mClonedBuffers;
+     std::unordered_set<const native_handle_t*> mImportedBuffers;
 };
 
 }  // namespace vts