Merge cherrypicks of ['googleplex-android-review.googlesource.com/25841016'] into 24Q1-release.

Change-Id: I9f8b6c783ae7492366112d8b57e297ef59aa7d1c
diff --git a/gralloc4/service/aidl/Android.bp b/gralloc4/service/aidl/Android.bp
index ea6e461..a3d7a87 100644
--- a/gralloc4/service/aidl/Android.bp
+++ b/gralloc4/service/aidl/Android.bp
@@ -3,7 +3,7 @@
 }
 
 cc_binary {
-    name: "android.hardware.graphics.allocator-V2-service",
+    name: "android.hardware.graphics.allocator-V1-service",
     proprietary: true,
     relative_install_path: "hw",
     srcs: [
@@ -17,7 +17,7 @@
         "libgralloc_headers",
     ],
     shared_libs: [
-        "android.hardware.graphics.allocator-V2-ndk",
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.allocator-aidl-impl",
         "libbinder_ndk",
         "liblog",
diff --git a/gralloc4/service/aidl/android.hardware.graphics.allocator-aidl-service.rc b/gralloc4/service/aidl/android.hardware.graphics.allocator-aidl-service.rc
index 723fab6..e86b68d 100644
--- a/gralloc4/service/aidl/android.hardware.graphics.allocator-aidl-service.rc
+++ b/gralloc4/service/aidl/android.hardware.graphics.allocator-aidl-service.rc
@@ -1,4 +1,4 @@
-service vendor.graphics.allocator-default /vendor/bin/hw/android.hardware.graphics.allocator-V2-service
+service vendor.graphics.allocator-default /vendor/bin/hw/android.hardware.graphics.allocator-V1-service
     class hal animation
     user system
     group graphics drmrpc
diff --git a/gralloc4/service/aidl/manifest_gralloc_aidl.xml b/gralloc4/service/aidl/manifest_gralloc_aidl.xml
index c29d370..6848a99 100644
--- a/gralloc4/service/aidl/manifest_gralloc_aidl.xml
+++ b/gralloc4/service/aidl/manifest_gralloc_aidl.xml
@@ -1,7 +1,6 @@
 <manifest version="1.0" type="device">
     <hal format="aidl">
         <name>android.hardware.graphics.allocator</name>
-        <version>2</version>
         <fqname>IAllocator/default</fqname>
     </hal>
 </manifest>
diff --git a/gralloc4/src/aidl/Android.bp b/gralloc4/src/aidl/Android.bp
index 3c0fc26..e2d9d04 100644
--- a/gralloc4/src/aidl/Android.bp
+++ b/gralloc4/src/aidl/Android.bp
@@ -10,7 +10,7 @@
         "arm_gralloc_api_4x_defaults",
     ],
     shared_libs: [
-        "android.hardware.graphics.allocator-V2-ndk",
+        "android.hardware.graphics.allocator-V1-ndk",
         "android.hardware.graphics.allocator@4.0",
         "android.hardware.graphics.mapper@4.0",
         "libbinder_ndk",
diff --git a/gralloc4/src/aidl/GrallocAllocator.cpp b/gralloc4/src/aidl/GrallocAllocator.cpp
index 2b01b80..fb1d5b7 100644
--- a/gralloc4/src/aidl/GrallocAllocator.cpp
+++ b/gralloc4/src/aidl/GrallocAllocator.cpp
@@ -7,6 +7,7 @@
 #include <cutils/android_filesystem_config.h>
 #include <hidl/HidlSupport.h>
 
+#include "allocator/mali_gralloc_ion.h"
 #include "hidl_common/Allocator.h"
 
 namespace pixel::allocator {
@@ -87,95 +88,6 @@
     return ndk::ScopedAStatus::ok();
 }
 
-buffer_descriptor_t decodeBufferDescriptorInfo(
-        const AidlAllocator::BufferDescriptorInfo& descriptor) {
-    buffer_descriptor_t bufferDescriptor;
-    bufferDescriptor.width = descriptor.width;
-    bufferDescriptor.height = descriptor.height;
-    bufferDescriptor.layer_count = descriptor.layerCount;
-    bufferDescriptor.hal_format = static_cast<uint64_t>(descriptor.format);
-    bufferDescriptor.producer_usage = static_cast<uint64_t>(descriptor.usage);
-    bufferDescriptor.consumer_usage = bufferDescriptor.producer_usage;
-    bufferDescriptor.format_type = MALI_GRALLOC_FORMAT_TYPE_USAGE;
-    bufferDescriptor.signature = sizeof(buffer_descriptor_t);
-    bufferDescriptor.reserved_size = descriptor.reservedSize;
-    const char *str = (const char*) descriptor.name.data();
-    bufferDescriptor.name = std::string(str);
-    return bufferDescriptor;
-}
-
-ndk::ScopedAStatus GrallocAllocator::allocate2(
-        const AidlAllocator::BufferDescriptorInfo& descriptor, int32_t count,
-        AidlAllocator::AllocationResult* result) {
-    MALI_GRALLOC_LOGV("Allocation request from process: %lu", callingPid());
-
-    buffer_descriptor_t bufferDescriptor = decodeBufferDescriptorInfo(descriptor);
-
-    HidlError error = HidlError::NONE;
-    auto hidl_cb = [&](HidlError _error, int _stride, hidl_vec<hidl_handle> _buffers) {
-        if (_error != HidlError::NONE) {
-            error = _error;
-            return;
-        }
-
-        const uint32_t size = _buffers.size();
-
-        result->stride = _stride;
-        result->buffers.resize(size);
-        for (uint32_t i = 0; i < size; i++) {
-            // Dup here is necessary. After this callback returns common::allocate
-            // will free the buffer which will destroy the older fd.
-            result->buffers[i] = android::dupToAidl(static_cast<const native_handle*>(_buffers[i]));
-        }
-    };
-
-    arm::allocator::common::allocate(bufferDescriptor, count, hidl_cb);
-
-    switch (error) {
-        case HidlError::NONE:
-            break;
-
-        case HidlError::BAD_DESCRIPTOR:
-            return ndk::ScopedAStatus::fromServiceSpecificError(
-                    static_cast<int32_t>(AidlAllocator::AllocationError::BAD_DESCRIPTOR));
-
-        case HidlError::NO_RESOURCES:
-            return ndk::ScopedAStatus::fromServiceSpecificError(
-                    static_cast<int32_t>(AidlAllocator::AllocationError::NO_RESOURCES));
-
-        case HidlError::UNSUPPORTED:
-            return ndk::ScopedAStatus::fromServiceSpecificError(
-                    static_cast<int32_t>(AidlAllocator::AllocationError::UNSUPPORTED));
-
-        default:
-            return ndk::ScopedAStatus::fromStatus(STATUS_UNKNOWN_ERROR);
-    }
-
-    return ndk::ScopedAStatus::ok();
-}
-
-// TODO(b/315883761): isSupported should return false for unknown-to-HAL usage
-ndk::ScopedAStatus GrallocAllocator::isSupported(
-        const AidlAllocator::BufferDescriptorInfo& descriptor, bool* result) {
-    buffer_descriptor_t bufferDescriptor = decodeBufferDescriptorInfo(descriptor);
-
-    int isBufferDescriptorSupported = arm::allocator::common::isSupported(&bufferDescriptor);
-    *result = (isBufferDescriptorSupported == 0);
-
-    if (isBufferDescriptorSupported) {
-        MALI_GRALLOC_LOGV("Allocation for the given description will not succeed. error %d",
-                          isBufferDescriptorSupported);
-        return ndk::ScopedAStatus::fromServiceSpecificError(
-                static_cast<int32_t>(AidlAllocator::AllocationError::UNSUPPORTED));
-    }
-    return ndk::ScopedAStatus::ok();
-}
-
-ndk::ScopedAStatus GrallocAllocator::getIMapperLibrarySuffix(std::string* result) {
-    *result = "";
-    return ndk::ScopedAStatus::fromStatus(STATUS_UNKNOWN_ERROR);
-}
-
 binder_status_t GrallocAllocator::dump(int fd, const char** /* args */, uint32_t numArgs) {
     if (callingUid() != AID_ROOT) {
         const std::string permission_denied = "Permission Denied\n";
diff --git a/gralloc4/src/aidl/GrallocAllocator.h b/gralloc4/src/aidl/GrallocAllocator.h
index 91655a7..dadd4b9 100644
--- a/gralloc4/src/aidl/GrallocAllocator.h
+++ b/gralloc4/src/aidl/GrallocAllocator.h
@@ -2,11 +2,9 @@
 
 #include <aidl/android/hardware/graphics/allocator/AllocationResult.h>
 #include <aidl/android/hardware/graphics/allocator/BnAllocator.h>
-#include <aidl/android/hardware/graphics/allocator/BufferDescriptorInfo.h>
 #include <aidlcommonsupport/NativeHandle.h>
 
 #include <cstdint>
-#include <string>
 #include <vector>
 
 namespace pixel {
@@ -23,15 +21,6 @@
     virtual ndk::ScopedAStatus allocate(const std::vector<uint8_t>& descriptor, int32_t count,
                                         AidlAllocator::AllocationResult* result) override;
 
-    virtual ndk::ScopedAStatus allocate2(const AidlAllocator::BufferDescriptorInfo& descriptor,
-                                         int32_t count,
-                                         AidlAllocator::AllocationResult* result) override;
-
-    virtual ndk::ScopedAStatus isSupported(const AidlAllocator::BufferDescriptorInfo& descriptor,
-                                           bool* result) override;
-
-    virtual ndk::ScopedAStatus getIMapperLibrarySuffix(std::string* result) override;
-
     virtual binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
 };
 
diff --git a/gralloc4/src/hidl_common/Allocator.cpp b/gralloc4/src/hidl_common/Allocator.cpp
index 08f2e8e..d854255 100644
--- a/gralloc4/src/hidl_common/Allocator.cpp
+++ b/gralloc4/src/hidl_common/Allocator.cpp
@@ -245,11 +245,6 @@
 	return ss.str();
 }
 
-int isSupported(buffer_descriptor_t *const bufDescriptor) {
-        // this is used as the criteria to determine which allocations succeed.
-        return mali_gralloc_derive_format_and_size(bufDescriptor);
-}
-
 } // namespace common
 } // namespace allocator
 } // namespace arm
diff --git a/gralloc4/src/hidl_common/Allocator.h b/gralloc4/src/hidl_common/Allocator.h
index e5ce174..079457c 100644
--- a/gralloc4/src/hidl_common/Allocator.h
+++ b/gralloc4/src/hidl_common/Allocator.h
@@ -56,8 +56,6 @@
 
 const std::string dump();
 
-int isSupported(buffer_descriptor_t *const bufDescriptor);
-
 } // namespace common
 } // namespace allocator
 } // namespace arm