Merge Android 13 QPR1

Bug: 261731544
Merged-In: If952b1a340a98999cbdf90a7b41865926699c1d2
Change-Id: I9a577b867d9ec47e0d560fc6a2fcf751cfef969a
diff --git a/GrallocHAL/src/core/exynos_format_allocation.h b/GrallocHAL/src/core/exynos_format_allocation.h
index 30b2c15..204ed98 100644
--- a/GrallocHAL/src/core/exynos_format_allocation.h
+++ b/GrallocHAL/src/core/exynos_format_allocation.h
@@ -16,8 +16,8 @@
 
 #pragma once
 
-#if __has_include(<video/mfc_macros.h>)
-#include <video/mfc_macros.h>
+#if __has_include(<linux/videodev2_exynos_media.h>)
+#include <linux/videodev2_exynos_media.h>
 #else
 #include "mfc_macros_local.h"
 #endif
diff --git a/gralloc4/src/core/exynos_format_allocation.h b/gralloc4/src/core/exynos_format_allocation.h
index bcaadfb..0abfbd0 100644
--- a/gralloc4/src/core/exynos_format_allocation.h
+++ b/gralloc4/src/core/exynos_format_allocation.h
@@ -16,8 +16,8 @@
 
 #pragma once
 
-#if __has_include(<video/mfc_macros.h>)
-#include <video/mfc_macros.h>
+#if __has_include(<linux/videodev2_exynos_media.h>)
+#include <linux/videodev2_exynos_media.h>
 #else
 #include "mfc_macros_local.h"
 #endif
diff --git a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
index 7656fcf..04bf7ed 100644
--- a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
+++ b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
@@ -476,7 +476,7 @@
  * (matched against `VALID_USAGE`). These should be aligned.
  */
 static bool log_deprecated_usage_flags(uint64_t usage) {
-	if (usage & MALI_GRALLOC_USAGE_FRONTBUFFER) {
+	if (usage & DEPRECATED_MALI_GRALLOC_USAGE_FRONTBUFFER) {
 		MALI_GRALLOC_LOGW("Using deprecated FRONTBUFFER usage bit, please upgrade to BufferUsage::FRONT_BUFFER");
 		return true;
 	}
@@ -980,16 +980,6 @@
 	return 0;
 }
 
-static bool validate_usage(const uint64_t usage) {
-	if (usage & GRALLOC_USAGE_FRONT_BUFFER) {
-		/* TODO(b/218383959): Enable front buffer rendering */
-		MALI_GRALLOC_LOGW("Front buffer rendering is disabled.");
-		return false;
-	}
-
-	return true;
-}
-
 int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescriptor)
 {
 	alloc_type_t alloc_type{};
@@ -998,11 +988,6 @@
 	int alloc_height = bufDescriptor->height;
 	uint64_t usage = bufDescriptor->producer_usage | bufDescriptor->consumer_usage;
 
-	if (!validate_usage(usage)) {
-		MALI_GRALLOC_LOGE("Usage flag validation failed.");
-		return -EINVAL;
-	}
-
 	/*
 	* Select optimal internal pixel format based upon
 	* usage and requested format.
diff --git a/gralloc4/src/hidl_common/Allocator.cpp b/gralloc4/src/hidl_common/Allocator.cpp
index 6ca758a..3b8e62a 100644
--- a/gralloc4/src/hidl_common/Allocator.cpp
+++ b/gralloc4/src/hidl_common/Allocator.cpp
@@ -77,7 +77,17 @@
 			auto hnd = const_cast<private_handle_t *>(reinterpret_cast<const private_handle_t *>(tmpBuffer));
 			hnd->imapper_version = HIDL_MAPPER_VERSION_SCALED;
 
+			// 4k is rougly 7.9 MB with one byte per pixel. We are
+			// assuming that the reserved region might be needed for
+			// dynamic HDR and that represents the largest size.
+			uint64_t max_reserved_region_size = 8ull * 1024 * 1024;
 			hnd->reserved_region_size = bufferDescriptor.reserved_size;
+			if (hnd->reserved_region_size > max_reserved_region_size) {
+				MALI_GRALLOC_LOGE("%s, Requested reserved region size (%" PRIu64 ") is larger than allowed (%" PRIu64 ")",
+						__func__, hnd->reserved_region_size, max_reserved_region_size);
+				error = Error::BAD_VALUE;
+				break;
+			}
 			hnd->attr_size = mapper::common::shared_metadata_size() + hnd->reserved_region_size;
 
 			if (hnd->get_usage() & GRALLOC_USAGE_ROIINFO)
diff --git a/gralloc4/src/mali_gralloc_usages.h b/gralloc4/src/mali_gralloc_usages.h
index fb3b70e..3c5a0fa 100644
--- a/gralloc4/src/mali_gralloc_usages.h
+++ b/gralloc4/src/mali_gralloc_usages.h
@@ -60,7 +60,7 @@
 // TODO(b/183478446): Cleanup usage flags redefinition
 typedef enum
 {
-	MALI_GRALLOC_USAGE_FRONTBUFFER = GRALLOC_USAGE_PRIVATE_12,
+	DEPRECATED_MALI_GRALLOC_USAGE_FRONTBUFFER = GRALLOC_USAGE_PRIVATE_12,
 	MALI_GRALLOC_USAGE_FORCE_BACKBUFFER = GRALLOC_USAGE_PRIVATE_13,
 	MALI_GRALLOC_USAGE_NO_AFBC = GRALLOC_USAGE_PRIVATE_1,
 	MALI_GRALLOC_USAGE_AFBC_PADDING = GRALLOC_USAGE_PRIVATE_14,