Tweak IMapper 4.0 VTS to run with AIDL IAllocator

When there is no HIDL IAllocator installed on the device, then these
tests must still run.

Bug: 231982605
Test: VtsHalGraphicsMapperV4_0TargetTest
Change-Id: If7503d398c03086df470971cc2c10029270525f9
diff --git a/graphics/composer/2.1/utils/vts/Android.bp b/graphics/composer/2.1/utils/vts/Android.bp
index 8732d53..c0a0c07 100644
--- a/graphics/composer/2.1/utils/vts/Android.bp
+++ b/graphics/composer/2.1/utils/vts/Android.bp
@@ -32,6 +32,7 @@
         "TestCommandReader.cpp",
     ],
     static_libs: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.composer@2.1",
         "android.hardware.graphics.mapper@2.0-vts",
         "android.hardware.graphics.mapper@3.0-vts",
@@ -39,6 +40,7 @@
         "libgtest",
     ],
     export_static_lib_headers: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.composer@2.1",
         "android.hardware.graphics.mapper@2.0-vts",
         "android.hardware.graphics.mapper@3.0-vts",
diff --git a/graphics/composer/2.1/utils/vts/ComposerVts.cpp b/graphics/composer/2.1/utils/vts/ComposerVts.cpp
index 55aaf12..e777010 100644
--- a/graphics/composer/2.1/utils/vts/ComposerVts.cpp
+++ b/graphics/composer/2.1/utils/vts/ComposerVts.cpp
@@ -318,7 +318,7 @@
     [this] {
         ASSERT_NO_FATAL_FAILURE(mGralloc4 = std::make_shared<Gralloc4>("default", "default",
                                                                        /*errOnFailure=*/false));
-        if (mGralloc4->getAllocator() == nullptr || mGralloc4->getMapper() == nullptr) {
+        if (!mGralloc4->hasAllocator() || mGralloc4->getMapper() == nullptr) {
             mGralloc4 = nullptr;
             ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default",
                                                                            /*errOnFailure=*/false));
diff --git a/graphics/composer/2.1/vts/functional/Android.bp b/graphics/composer/2.1/vts/functional/Android.bp
index 9ffd7d5..502036e 100644
--- a/graphics/composer/2.1/vts/functional/Android.bp
+++ b/graphics/composer/2.1/vts/functional/Android.bp
@@ -32,14 +32,17 @@
     // TODO(b/64437680): Assume these libs are always available on the device.
     shared_libs: [
         "libbase",
+        "libbinder_ndk",
         "libfmq",
         "libsync",
+        "android.hardware.common-V2-ndk",
         "android.hardware.graphics.mapper@2.0",
         "android.hardware.graphics.mapper@2.1",
         "android.hardware.graphics.mapper@3.0",
         "android.hardware.graphics.mapper@4.0",
     ],
     static_libs: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.allocator@2.0",
         "android.hardware.graphics.allocator@3.0",
         "android.hardware.graphics.allocator@4.0",
@@ -49,10 +52,14 @@
         "android.hardware.graphics.mapper@2.1-vts",
         "android.hardware.graphics.mapper@3.0-vts",
         "android.hardware.graphics.mapper@4.0-vts",
+        "libaidlcommonsupport",
     ],
     header_libs: [
         "android.hardware.graphics.composer@2.1-command-buffer",
     ],
     disable_framework: true,
-    test_suites: ["general-tests", "vts"],
+    test_suites: [
+        "general-tests",
+        "vts",
+    ],
 }
diff --git a/graphics/composer/2.2/utils/vts/Android.bp b/graphics/composer/2.2/utils/vts/Android.bp
index aa8e541..cca5323 100644
--- a/graphics/composer/2.2/utils/vts/Android.bp
+++ b/graphics/composer/2.2/utils/vts/Android.bp
@@ -35,6 +35,7 @@
         "libui",
     ],
     static_libs: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.composer@2.1-vts",
         "android.hardware.graphics.composer@2.2",
         "android.hardware.graphics.composer3-V1-ndk",
@@ -52,6 +53,7 @@
         "android.hardware.graphics.mapper@4.0-vts",
     ],
     export_static_lib_headers: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.composer@2.1-vts",
         "android.hardware.graphics.composer@2.2",
         "android.hardware.graphics.mapper@2.1-vts",
diff --git a/graphics/composer/2.2/utils/vts/ComposerVts.cpp b/graphics/composer/2.2/utils/vts/ComposerVts.cpp
index a526137..7de4007 100644
--- a/graphics/composer/2.2/utils/vts/ComposerVts.cpp
+++ b/graphics/composer/2.2/utils/vts/ComposerVts.cpp
@@ -184,7 +184,7 @@
         ALOGD("Attempting to initialize gralloc4");
         ASSERT_NO_FATAL_FAILURE(mGralloc4 = std::make_shared<Gralloc4>("default", "default",
                                                                        /*errOnFailure=*/false));
-        if (mGralloc4->getMapper() == nullptr || mGralloc4->getAllocator() == nullptr) {
+        if (mGralloc4->getMapper() == nullptr || !mGralloc4->hasAllocator()) {
             mGralloc4 = nullptr;
             ALOGD("Failed to initialize gralloc4, initializing gralloc3");
             ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default",
diff --git a/graphics/composer/2.2/vts/functional/Android.bp b/graphics/composer/2.2/vts/functional/Android.bp
index dd519e7..960b62d 100644
--- a/graphics/composer/2.2/vts/functional/Android.bp
+++ b/graphics/composer/2.2/vts/functional/Android.bp
@@ -45,18 +45,21 @@
         "libGLESv1_CM",
         "libGLESv2",
         "libbase",
+        "libbinder_ndk",
         "libfmq",
         "libgui",
         "libhidlbase",
         "libprocessgroup",
         "libsync",
         "libui",
+        "android.hardware.common-V2-ndk",
         "android.hardware.graphics.mapper@2.0",
         "android.hardware.graphics.mapper@2.1",
         "android.hardware.graphics.mapper@3.0",
         "android.hardware.graphics.mapper@4.0",
     ],
     static_libs: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.allocator@2.0",
         "android.hardware.graphics.allocator@3.0",
         "android.hardware.graphics.allocator@4.0",
@@ -70,6 +73,7 @@
         "android.hardware.graphics.mapper@2.1-vts",
         "android.hardware.graphics.mapper@3.0-vts",
         "android.hardware.graphics.mapper@4.0-vts",
+        "libaidlcommonsupport",
         "libgtest",
         "librenderengine",
         "libshaders",
diff --git a/graphics/composer/2.3/vts/functional/Android.bp b/graphics/composer/2.3/vts/functional/Android.bp
index 70384ac..40b77d5 100644
--- a/graphics/composer/2.3/vts/functional/Android.bp
+++ b/graphics/composer/2.3/vts/functional/Android.bp
@@ -32,15 +32,18 @@
     // TODO(b/64437680): Assume these libs are always available on the device.
     shared_libs: [
         "libbase",
+        "libbinder_ndk",
         "libfmq",
         "libhidlbase",
         "libsync",
+        "android.hardware.common-V2-ndk",
         "android.hardware.graphics.mapper@2.0",
         "android.hardware.graphics.mapper@2.1",
         "android.hardware.graphics.mapper@3.0",
         "android.hardware.graphics.mapper@4.0",
     ],
     static_libs: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.allocator@2.0",
         "android.hardware.graphics.allocator@3.0",
         "android.hardware.graphics.allocator@4.0",
@@ -54,6 +57,7 @@
         "android.hardware.graphics.mapper@2.1-vts",
         "android.hardware.graphics.mapper@3.0-vts",
         "android.hardware.graphics.mapper@4.0-vts",
+        "libaidlcommonsupport",
     ],
     header_libs: [
         "android.hardware.graphics.composer@2.1-command-buffer",
@@ -61,5 +65,8 @@
         "android.hardware.graphics.composer@2.3-command-buffer",
     ],
     disable_framework: true,
-    test_suites: ["general-tests", "vts"],
+    test_suites: [
+        "general-tests",
+        "vts",
+    ],
 }
diff --git a/graphics/composer/2.4/utils/vts/Android.bp b/graphics/composer/2.4/utils/vts/Android.bp
index 5ef861c..de31975 100644
--- a/graphics/composer/2.4/utils/vts/Android.bp
+++ b/graphics/composer/2.4/utils/vts/Android.bp
@@ -32,6 +32,7 @@
         "TestCommandReader.cpp",
     ],
     static_libs: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.composer@2.1",
         "android.hardware.graphics.composer@2.2",
         "android.hardware.graphics.composer@2.3-vts",
diff --git a/graphics/composer/2.4/vts/functional/Android.bp b/graphics/composer/2.4/vts/functional/Android.bp
index 22ae7c4..b73ea94 100644
--- a/graphics/composer/2.4/vts/functional/Android.bp
+++ b/graphics/composer/2.4/vts/functional/Android.bp
@@ -32,14 +32,17 @@
     // TODO(b/64437680): Assume these libs are always available on the device.
     shared_libs: [
         "libbase",
+        "libbinder_ndk",
         "libfmq",
         "libsync",
+        "android.hardware.common-V2-ndk",
         "android.hardware.graphics.mapper@2.0",
         "android.hardware.graphics.mapper@2.1",
         "android.hardware.graphics.mapper@3.0",
         "android.hardware.graphics.mapper@4.0",
     ],
     static_libs: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.allocator@2.0",
         "android.hardware.graphics.allocator@3.0",
         "android.hardware.graphics.allocator@4.0",
@@ -55,6 +58,7 @@
         "android.hardware.graphics.mapper@2.1-vts",
         "android.hardware.graphics.mapper@3.0-vts",
         "android.hardware.graphics.mapper@4.0-vts",
+        "libaidlcommonsupport",
     ],
     header_libs: [
         "android.hardware.graphics.composer@2.1-command-buffer",
@@ -63,5 +67,8 @@
         "android.hardware.graphics.composer@2.4-command-buffer",
     ],
     disable_framework: true,
-    test_suites: ["general-tests", "vts"],
+    test_suites: [
+        "general-tests",
+        "vts",
+    ],
 }
diff --git a/graphics/mapper/4.0/utils/vts/Android.bp b/graphics/mapper/4.0/utils/vts/Android.bp
index 6331498..7abf5db 100644
--- a/graphics/mapper/4.0/utils/vts/Android.bp
+++ b/graphics/mapper/4.0/utils/vts/Android.bp
@@ -32,14 +32,21 @@
         "-g",
     ],
     static_libs: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.allocator@4.0",
+        "android.hardware.graphics.common-V3-ndk",
         "android.hardware.graphics.mapper@4.0",
+        "libaidlcommonsupport",
     ],
     shared_libs: [
+        "libbinder_ndk",
         "libgralloctypes",
+        "libvndksupport",
     ],
     export_static_lib_headers: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.allocator@4.0",
+        "android.hardware.graphics.common-V3-ndk",
         "android.hardware.graphics.mapper@4.0",
     ],
     export_include_dirs: ["include"],
diff --git a/graphics/mapper/4.0/utils/vts/MapperVts.cpp b/graphics/mapper/4.0/utils/vts/MapperVts.cpp
index 4a6f68d..e4a2535 100644
--- a/graphics/mapper/4.0/utils/vts/MapperVts.cpp
+++ b/graphics/mapper/4.0/utils/vts/MapperVts.cpp
@@ -14,7 +14,9 @@
  * limitations under the License.
  */
 
+#include <aidlcommonsupport/NativeHandle.h>
 #include <android-base/properties.h>
+#include <android/binder_manager.h>
 #include <gralloctypes/Gralloc4.h>
 #include <mapper-vts/4.0/MapperVts.h>
 
@@ -35,8 +37,14 @@
 }
 
 void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
-    mAllocator = IAllocator::getService(allocatorServiceName);
-    ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service";
+    mAidlAllocator = aidl::android::hardware::graphics::allocator::IAllocator::fromBinder(
+            ndk::SpAIBinder(AServiceManager_checkService(allocatorServiceName.c_str())));
+
+    if (mAidlAllocator == nullptr) {
+        mHidlAllocator = IAllocator::getService(allocatorServiceName);
+    }
+    ASSERT_TRUE(nullptr != mAidlAllocator || mHidlAllocator != nullptr)
+            << "failed to get allocator service";
 
     mMapper = IMapper::getService(mapperServiceName);
     ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service";
@@ -45,7 +53,12 @@
 
 void Gralloc::initNoErr(const std::string& allocatorServiceName,
                         const std::string& mapperServiceName) {
-    mAllocator = IAllocator::getService(allocatorServiceName);
+    mAidlAllocator = aidl::android::hardware::graphics::allocator::IAllocator::fromBinder(
+            ndk::SpAIBinder(AServiceManager_checkService(allocatorServiceName.c_str())));
+
+    if (mAidlAllocator == nullptr) {
+        mHidlAllocator = IAllocator::getService(allocatorServiceName);
+    }
 
     mMapper = IMapper::getService(mapperServiceName);
     if (mMapper.get()) {
@@ -68,10 +81,6 @@
     mImportedBuffers.clear();
 }
 
-sp<IAllocator> Gralloc::getAllocator() const {
-    return mAllocator;
-}
-
 const native_handle_t* Gralloc::cloneBuffer(const hidl_handle& rawHandle,
                                             enum Tolerance /*tolerance*/) {
     const native_handle_t* bufferHandle = native_handle_clone(rawHandle.getNativeHandle());
@@ -90,40 +99,40 @@
                                                       uint32_t* outStride) {
     std::vector<const native_handle_t*> bufferHandles;
     bufferHandles.reserve(count);
-    mAllocator->allocate(descriptor, count,
-                         [&](const auto& tmpError, const auto& tmpStride, const auto& tmpBuffers) {
-                             if (canTolerate(tolerance, tmpError)) {
-                                 return;
-                             }
 
-                             if (tmpError != Error::NONE) {
-                                 if (base::GetIntProperty("ro.vendor.build.version.sdk", 0, 0,
-                                                          INT_MAX) < 33) {
-                                     GTEST_SKIP() << "Old vendor grallocs may not support P010";
-                                 } else {
-                                     GTEST_FAIL() << "failed to allocate buffers";
-                                 }
-                             }
-                             ASSERT_EQ(count, tmpBuffers.size()) << "invalid buffer array";
+    auto callback = [&](Error error, uint32_t stride,
+                        const hidl_vec<hidl_handle>& buffers) -> void {
+        if (canTolerate(tolerance, error)) {
+            return;
+        }
 
-                             for (uint32_t i = 0; i < count; i++) {
-                                 const native_handle_t* bufferHandle = nullptr;
-                                 if (import) {
-                                     ASSERT_NO_FATAL_FAILURE(
-                                             bufferHandle = importBuffer(tmpBuffers[i], tolerance));
-                                 } else {
-                                     ASSERT_NO_FATAL_FAILURE(
-                                             bufferHandle = cloneBuffer(tmpBuffers[i], tolerance));
-                                 }
-                                 if (bufferHandle) {
-                                     bufferHandles.push_back(bufferHandle);
-                                 }
-                             }
+        if (error != Error::NONE) {
+            if (base::GetIntProperty("ro.vendor.build.version.sdk", 0, 0, INT_MAX) < 33) {
+                GTEST_SKIP() << "Old vendor grallocs may not support P010";
+            } else {
+                GTEST_FAIL() << "failed to allocate buffers";
+            }
+        }
+        ASSERT_EQ(count, buffers.size()) << "invalid buffer array";
 
-                             if (outStride) {
-                                 *outStride = tmpStride;
-                             }
-                         });
+        for (uint32_t i = 0; i < count; i++) {
+            const native_handle_t* bufferHandle = nullptr;
+            if (import) {
+                ASSERT_NO_FATAL_FAILURE(bufferHandle = importBuffer(buffers[i], tolerance));
+            } else {
+                ASSERT_NO_FATAL_FAILURE(bufferHandle = cloneBuffer(buffers[i], tolerance));
+            }
+            if (bufferHandle) {
+                bufferHandles.push_back(bufferHandle);
+            }
+        }
+
+        if (outStride) {
+            *outStride = stride;
+        }
+    };
+
+    rawAllocate(descriptor, count, callback);
 
     if (::testing::Test::HasFatalFailure()) {
         bufferHandles.clear();
@@ -147,6 +156,23 @@
     return buffers[0];
 }
 
+void Gralloc::rawAllocate(
+        const BufferDescriptor& descriptor, uint32_t count,
+        std::function<void(Error, uint32_t, const hidl_vec<hidl_handle>&)> callback) {
+    if (mAidlAllocator) {
+        aidl::android::hardware::graphics::allocator::AllocationResult result;
+        auto status = mAidlAllocator->allocate(descriptor, count, &result);
+        const Error error = toHidlError(status);
+        std::vector<hidl_handle> handles;
+        for (const auto& aidlHandle : result.buffers) {
+            handles.push_back(hidl_handle(makeFromAidl(aidlHandle)));
+        }
+        callback(error, result.stride, handles);
+    } else {
+        mHidlAllocator->allocate(descriptor, count, callback);
+    }
+}
+
 sp<IMapper> Gralloc::getMapper() const {
     return mMapper;
 }
diff --git a/graphics/mapper/4.0/utils/vts/include/mapper-vts/4.0/MapperVts.h b/graphics/mapper/4.0/utils/vts/include/mapper-vts/4.0/MapperVts.h
index c5406c9..b956e49 100644
--- a/graphics/mapper/4.0/utils/vts/include/mapper-vts/4.0/MapperVts.h
+++ b/graphics/mapper/4.0/utils/vts/include/mapper-vts/4.0/MapperVts.h
@@ -20,6 +20,8 @@
 #include <unordered_set>
 #include <vector>
 
+#include <aidl/android/hardware/graphics/allocator/AllocationError.h>
+#include <aidl/android/hardware/graphics/allocator/IAllocator.h>
 #include <android/hardware/graphics/allocator/4.0/IAllocator.h>
 #include <android/hardware/graphics/mapper/4.0/IMapper.h>
 #include <gtest/gtest.h>
@@ -51,9 +53,33 @@
             const std::string& mapperServiceName = "default", bool errOnFailure = true);
     ~Gralloc();
 
+    static Error toHidlError(aidl::android::hardware::graphics::allocator::AllocationError error) {
+        switch (error) {
+            case aidl::android::hardware::graphics::allocator::AllocationError::BAD_DESCRIPTOR:
+                return Error::BAD_DESCRIPTOR;
+            case aidl::android::hardware::graphics::allocator::AllocationError::NO_RESOURCES:
+                return Error::NO_RESOURCES;
+            case aidl::android::hardware::graphics::allocator::AllocationError::UNSUPPORTED:
+                return Error::UNSUPPORTED;
+        }
+    }
+    static Error toHidlError(const ndk::ScopedAStatus& status) {
+        if (status.isOk()) {
+            return Error::NONE;
+        }
+
+        if (status.getExceptionCode() != EX_SERVICE_SPECIFIC) {
+            return Error::NO_RESOURCES;
+        }
+
+        return toHidlError(
+                static_cast<aidl::android::hardware::graphics::allocator::AllocationError>(
+                        status.getServiceSpecificError()));
+    }
+
     // IAllocator methods
 
-    sp<IAllocator> getAllocator() const;
+    bool hasAllocator() { return mHidlAllocator != nullptr || mAidlAllocator != nullptr; }
 
     // When import is false, this simply calls IAllocator::allocate. When import
     // is true, the returned buffers are also imported into the mapper.
@@ -81,6 +107,10 @@
         return allocate(descriptorInfo, import, Tolerance::kToleranceStrict, outStride);
     }
 
+    // Dispatches directly to the allocator
+    void rawAllocate(const BufferDescriptor& descriptor, uint32_t count,
+                     std::function<void(Error, uint32_t, const hidl_vec<hidl_handle>&)> callback);
+
     // IMapper methods
 
     sp<IMapper> getMapper() const;
@@ -143,7 +173,8 @@
         return cloneBuffer(rawHandle, Tolerance::kToleranceStrict);
     }
 
-    sp<IAllocator> mAllocator;
+    sp<IAllocator> mHidlAllocator;
+    std::shared_ptr<aidl::android::hardware::graphics::allocator::IAllocator> mAidlAllocator;
     sp<IMapper> mMapper;
 
     // Keep track of all cloned and imported handles.  When a test fails with
diff --git a/graphics/mapper/4.0/vts/functional/Android.bp b/graphics/mapper/4.0/vts/functional/Android.bp
index 65bc380..e830633 100644
--- a/graphics/mapper/4.0/vts/functional/Android.bp
+++ b/graphics/mapper/4.0/vts/functional/Android.bp
@@ -25,20 +25,27 @@
 
 cc_test {
     name: "VtsHalGraphicsMapperV4_0TargetTest",
-    defaults: ["VtsHalTargetTestDefaults"],
+    defaults: [
+        "VtsHalTargetTestDefaults",
+        "use_libaidlvintf_gtest_helper_static",
+    ],
     srcs: ["VtsHalGraphicsMapperV4_0TargetTest.cpp"],
     static_libs: [
         "android.hardware.graphics.common-V3-ndk",
         "android.hardware.graphics.mapper@4.0-vts",
+        "libaidlcommonsupport",
         "libgralloctypes",
         "libsync",
     ],
     shared_libs: [
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.allocator@4.0",
         "android.hardware.graphics.common@1.0",
         "android.hardware.graphics.common@1.1",
         "android.hardware.graphics.common@1.2",
         "android.hardware.graphics.mapper@4.0",
+        "libbinder_ndk",
+        "libvndksupport",
     ],
     header_libs: [
         "libsystem_headers",
diff --git a/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp b/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp
index 2aac337..5a450e3 100644
--- a/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp
+++ b/graphics/mapper/4.0/vts/functional/VtsHalGraphicsMapperV4_0TargetTest.cpp
@@ -21,8 +21,12 @@
 #include <thread>
 #include <vector>
 
+#include <aidl/Vintf.h>
+#include <aidl/android/hardware/graphics/allocator/AllocationError.h>
+#include <aidl/android/hardware/graphics/allocator/AllocationResult.h>
 #include <aidl/android/hardware/graphics/common/PixelFormat.h>
 #include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
+#include <aidlcommonsupport/NativeHandle.h>
 
 #include <android-base/logging.h>
 #include <android-base/unique_fd.h>
@@ -72,7 +76,7 @@
     void SetUp() override {
         ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>(std::get<0>(GetParam()),
                                                                      std::get<1>(GetParam())));
-        ASSERT_NE(nullptr, mGralloc->getAllocator().get());
+        ASSERT_TRUE(mGralloc->hasAllocator());
         ASSERT_NE(nullptr, mGralloc->getMapper().get());
 
         mDummyDescriptorInfo.name = "dummy";
@@ -504,10 +508,10 @@
 TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNegative) {
     // this assumes any valid descriptor is non-empty
     BufferDescriptor descriptor;
-    mGralloc->getAllocator()->allocate(descriptor, 1,
-                                       [&](const auto& tmpError, const auto&, const auto&) {
-                                           EXPECT_EQ(Error::BAD_DESCRIPTOR, tmpError);
-                                       });
+
+    mGralloc->rawAllocate(descriptor, 1, [&](const auto& tmpError, const auto&, const auto&) {
+        EXPECT_EQ(Error::BAD_DESCRIPTOR, tmpError);
+    });
 }
 
 /**
@@ -535,9 +539,9 @@
     std::atomic<uint64_t> allocationCount(0);
     auto threadLoop = [&]() {
         while (!timeUp) {
-            mGralloc->getAllocator()->allocate(
-                    descriptor, 1,
-                    [&](const auto&, const auto&, const auto&) { allocationCount++; });
+            mGralloc->rawAllocate(descriptor, 1, [&](const auto&, const auto&, const auto&) {
+                allocationCount++;
+            });
         }
     };
 
@@ -2755,8 +2759,9 @@
         BufferDescriptor descriptor;
         ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(info));
 
-        Error err;
-        mGralloc->getAllocator()->allocate(
+        Error err = Error::NONE;
+
+        mGralloc->rawAllocate(
                 descriptor, 1, [&](const auto& tmpError, const auto&, const auto& tmpBuffers) {
                     err = tmpError;
                     if (err == Error::NONE) {
@@ -2827,11 +2832,27 @@
 }
 
 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsMapperHidlTest);
+
+namespace {
+std::vector<std::string> getAllocatorInstances() {
+    std::vector<std::string> instances;
+    for (auto halInstance : android::hardware::getAllHalInstanceNames(IAllocator::descriptor)) {
+        instances.emplace_back(std::move(halInstance));
+    }
+
+    for (auto aidlInstance : getAidlHalInstanceNames(
+                 aidl::android::hardware::graphics::allocator::IAllocator::descriptor)) {
+        instances.emplace_back(std::move(aidlInstance));
+    }
+
+    return instances;
+}
+}  // namespace
+
 INSTANTIATE_TEST_CASE_P(
         PerInstance, GraphicsMapperHidlTest,
         testing::Combine(
-                testing::ValuesIn(
-                        android::hardware::getAllHalInstanceNames(IAllocator::descriptor)),
+                testing::ValuesIn(getAllocatorInstances()),
                 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IMapper::descriptor))),
         android::hardware::PrintInstanceTupleNameToString<>);