CodecInfoTest: Re-enable HDRDisplayCapabilities test

testHDRDisplayCapabilities was disabled as there was no way at
codec2 framework level to query HDR display capabilities to list
all supported HDR display types.

Using a system property ro.surface_flinger.has_HDR_display, it is
possible to check if a device has HDR display. With this, we can at
least test that HDR10 and HDR10+ profiles are not advertised
on devices that do not support HDR display.

Test is now re-enabled and tweaked such that a device listing
HDR10 profiles must have HDR10 display and device that lists HDR10+
profiles must have either HDR10 or HDR10+ display.

Once there is a way to list HDR10+ display support at framework level,
the HDR10+ profiles can mandate support for HDR10+ display.

Since HLG profiles and default 10-bit profiles without any
color-transfer can't be distinguished, those profiles are excluded from
this test.

Bug: 228237404
Test: atest CtsMediaV2TestCases:CodecInfoTest

Change-Id: I5c594cc6e5ab8f85f087cc1dcae5e63fb867df4b
(cherry picked from commit b567bb14be42b8f52845dfe7233f7f5b7467f787)
Merged-In: I5c594cc6e5ab8f85f087cc1dcae5e63fb867df4b
diff --git a/tests/media/src/android/mediav2/cts/CodecInfoTest.java b/tests/media/src/android/mediav2/cts/CodecInfoTest.java
index 945a7db..29f3e00 100644
--- a/tests/media/src/android/mediav2/cts/CodecInfoTest.java
+++ b/tests/media/src/android/mediav2/cts/CodecInfoTest.java
@@ -91,40 +91,31 @@
 
     /**
      * Tests if the devices on T or later, if decoder for a mediaType supports HDR profiles then
-     * it should be capable of displaying the same
+     * it should be capable of displaying the same. Since HLG profiles can't be distinguished from
+     * default 10-bit profiles, those are excluded from this test.
      */
     @Test
-    @Ignore("TODO(b/228237404) Enable once display capabilities can be queried at codec2 level")
     public void testHDRDisplayCapabilities() {
         Assume.assumeTrue("Test needs Android 13", IS_AT_LEAST_T);
         Assume.assumeTrue("Test is applicable for video codecs", mMediaType.startsWith("video/"));
-        Assume.assumeTrue("Test is applicable for codecs with HDR profiles",
-                mProfileHdrMap.containsKey(mMediaType));
 
-        int[] HdrProfiles = mProfileHdrMap.get(mMediaType);
+        int[] Hdr10Profiles = mProfileHdr10Map.get(mMediaType);
+        int[] Hdr10PlusProfiles = mProfileHdr10PlusMap.get(mMediaType);
+        Assume.assumeTrue("Test is applicable for codecs with HDR10/HDR10+ profiles",
+                Hdr10Profiles != null || Hdr10PlusProfiles != null);
+
         MediaCodecInfo.CodecCapabilities caps = mCodecInfo.getCapabilitiesForType(mMediaType);
 
         for (CodecProfileLevel pl : caps.profileLevels) {
-            if (IntStream.of(HdrProfiles).anyMatch(x -> x == pl.profile)) {
-                if (pl.profile == AV1ProfileMain10 || pl.profile == AVCProfileHigh10 ||
-                        pl.profile == HEVCProfileMain10 || pl.profile == VP9Profile2) {
-                    assertTrue("Advertises support for HLG technology without HLG display",
-                            IntStream.of(DISPLAY_HDR_TYPES).anyMatch(x -> x == HDR_TYPE_HLG));
-                } else if (pl.profile == AV1ProfileMain10HDR10 ||
-                        pl.profile == HEVCProfileMain10HDR10 || pl.profile == VP9Profile2HDR) {
-                    assertTrue(mCodecInfo.getName() + " Advertises support for HDR10 profile " +
-                                    pl.profile + " without HDR10 display",
-                            IntStream.of(DISPLAY_HDR_TYPES).anyMatch(x -> x == HDR_TYPE_HDR10));
-                } else if (pl.profile == AV1ProfileMain10HDR10Plus ||
-                        pl.profile == HEVCProfileMain10HDR10Plus ||
-                        pl.profile == VP9Profile2HDR10Plus) {
-                    assertTrue(mCodecInfo.getName() + " Advertises support for HDR10+ profile " +
-                                    pl.profile + " without HDR10+ display",
-                            IntStream.of(DISPLAY_HDR_TYPES)
-                                    .anyMatch(x -> x == HDR_TYPE_HDR10_PLUS));
-                } else {
-                    fail("Unhandled HDR profile" + pl.profile + " for type " + mMediaType);
-                }
+            boolean isHdr10Profile = Hdr10Profiles != null &&
+                    IntStream.of(Hdr10Profiles).anyMatch(x -> x == pl.profile);
+            boolean isHdr10PlusProfile = Hdr10PlusProfiles != null &&
+                    IntStream.of(Hdr10PlusProfiles).anyMatch(x -> x == pl.profile);
+            // TODO (b/228237404) Once there is a way to query support for HDR10/HDR10+ display at
+            // native level, separate the following to independent checks for HDR10 and HDR10+
+            if (isHdr10Profile || isHdr10PlusProfile) {
+                assertTrue(mCodecInfo.getName() + " Advertises support for HDR10/HDR10+ profile " +
+                        pl.profile + " without any HDR display", DISPLAY_HDR_TYPES.length > 0);
             }
         }
     }