Codec2CommonUtils: Restrict encoder usage checks to Android U and above
Bug: 293985442
Test: atest CtsMediaV2TestCases:CodecInfoTest
Change-Id: I55543617d8a9e9765d427b289bd42e667bbcb917
diff --git a/media/codec2/sfplugin/utils/Codec2CommonUtils.cpp b/media/codec2/sfplugin/utils/Codec2CommonUtils.cpp
index f428fce..43533fd 100644
--- a/media/codec2/sfplugin/utils/Codec2CommonUtils.cpp
+++ b/media/codec2/sfplugin/utils/Codec2CommonUtils.cpp
@@ -31,11 +31,19 @@
namespace android {
-bool isAtLeastT() {
+
+static bool isAtLeast(int version, const char *codeName) {
char deviceCodeName[PROP_VALUE_MAX];
__system_property_get("ro.build.version.codename", deviceCodeName);
- return android_get_device_api_level() >= __ANDROID_API_T__ ||
- !strcmp(deviceCodeName, "Tiramisu");
+ return android_get_device_api_level() >= version || !strcmp(deviceCodeName, codeName);
+}
+
+bool isAtLeastT() {
+ return isAtLeast(__ANDROID_API_T__, "Tiramisu");
+}
+
+bool isAtLeastU() {
+ return isAtLeast(__ANDROID_API_U__, "UpsideDownCake");
}
static bool isP010Allowed() {
@@ -127,10 +135,16 @@
.rfu0 = 0,
.rfu1 = 0,
};
-
- return AHardwareBuffer_isSupported(&consumableForDisplayOrGpu)
- && AHardwareBuffer_isSupported(&consumableForHwEncoder)
- && AHardwareBuffer_isSupported(&consumableForSwEncoder);
+ // Some devices running versions prior to Android U aren't guaranteed to advertise support
+ // for some color formats when the consumer is an encoder. Hence limit these checks to
+ // Android U and beyond.
+ if (isAtLeastU()) {
+ return AHardwareBuffer_isSupported(&consumableForDisplayOrGpu)
+ && AHardwareBuffer_isSupported(&consumableForHwEncoder)
+ && AHardwareBuffer_isSupported(&consumableForSwEncoder);
+ } else {
+ return AHardwareBuffer_isSupported(&consumableForDisplayOrGpu);
+ }
}
} // namespace android