release-request-447544c9-42cd-4c45-a7c6-4f09361c94db-for-git_oc-dr1-release-4277755 snap-temp-L90500000093605838

Change-Id: Ic6a7c317b4b2ba27573698c651542b98986b1ab1
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
index e85119b..ce64254 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
@@ -558,9 +558,13 @@
         try {
             File logFile = null;
             if (mCompressLogs) {
-                logFile = mTestLogSaver.saveAndGZipLogData(name, type, stream.createInputStream());
+                try (InputStream inputStream = stream.createInputStream()) {
+                    logFile = mTestLogSaver.saveAndGZipLogData(name, type, inputStream);
+                }
             } else {
-                logFile = mTestLogSaver.saveLogData(name, type, stream.createInputStream());
+                try (InputStream inputStream = stream.createInputStream()) {
+                    logFile = mTestLogSaver.saveLogData(name, type, inputStream);
+                }
             }
             debug("Saved logs for %s in %s", name, logFile.getAbsolutePath());
         } catch (IOException e) {
diff --git a/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java b/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java
index 010d992..72838e5 100644
--- a/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java
+++ b/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java
@@ -264,13 +264,10 @@
             public int getHeight() {
                 return super.getHeight() + OFFSET;
             }
+
             @Override
-            public int getMaxHeight() {
-                return super.getHeight() * 2 + OFFSET;
-            }
-            @Override
-            public int getMaxWidth() {
-                return super.getWidth() * 2 + OFFSET;
+            public boolean isAbrEnabled() {
+                return true;
             }
         };
     }
@@ -281,13 +278,10 @@
             public int getWidth() {
                 return super.getWidth() + OFFSET;
             }
+
             @Override
-            public int getMaxHeight() {
-                return super.getHeight() * 2 + OFFSET;
-            }
-            @Override
-            public int getMaxWidth() {
-                return super.getWidth() * 2 + OFFSET;
+            public boolean isAbrEnabled() {
+                return true;
             }
         };
     }
diff --git a/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java b/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java
index 0e92e3d..58f1607 100644
--- a/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java
+++ b/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java
@@ -20,6 +20,7 @@
 import static org.junit.Assert.assertNotNull;
 
 import com.android.compatibility.common.util.ApiLevelUtil;
+import com.android.compatibility.common.util.MediaUtils;
 
 import android.annotation.TargetApi;
 import android.annotation.SuppressLint;
@@ -38,6 +39,7 @@
 import android.media.MediaCodec;
 import android.media.MediaCodec.BufferInfo;
 import android.media.MediaCodec.CodecException;
+import android.media.MediaCodecInfo.VideoCapabilities;
 import android.media.MediaCodecList;
 import android.media.MediaExtractor;
 import android.media.MediaFormat;
@@ -480,10 +482,27 @@
             if (ApiLevelUtil.isBefore(Build.VERSION_CODES.KITKAT)) {
                 return;
             }
-            if (videoFormat.getMaxWidth() != VideoFormat.INT_UNSET
-                && videoFormat.getMaxHeight() != VideoFormat.INT_UNSET) {
-                mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, videoFormat.getMaxWidth());
-                mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, videoFormat.getMaxHeight());
+            // Set KEY_MAX_WIDTH and KEY_MAX_HEIGHT when isAbrEnabled() is set.
+            if (videoFormat.isAbrEnabled()) {
+                try {
+                    // Check for max resolution supported by the codec.
+                    final MediaCodec decoder = MediaUtils.getDecoder(mediaFormat);
+                    final VideoCapabilities videoCapabilities = MediaUtils.getVideoCapabilities(
+                            decoder.getName(), videoFormat.getMimeType());
+                    decoder.release();
+                    final int maxWidth = videoCapabilities.getSupportedWidths().getUpper();
+                    final int maxHeight =
+                            videoCapabilities.getSupportedHeightsFor(maxWidth).getUpper();
+                    if (maxWidth >= videoFormat.getWidth() && maxHeight >= videoFormat.getHeight()) {
+                        mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, maxWidth);
+                        mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, maxHeight);
+                        return;
+                    }
+                } catch (NullPointerException exception) { /* */ }
+                // Set max width/height to current size if can't get codec's max supported
+                // width/height or max is not greater than the current size.
+                mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, videoFormat.getWidth());
+                mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, videoFormat.getHeight());
             }
         }
 
@@ -1591,6 +1610,10 @@
         return getParsedName().getHeight();
     }
 
+    public boolean isAbrEnabled() {
+        return false;
+    }
+
     public String getOriginalSize() {
         if (width == INT_UNSET || height == INT_UNSET) {
             return getParsedName().getSize();
diff --git a/tools/cts-tradefed/res/config/cts-known-failures.xml b/tools/cts-tradefed/res/config/cts-known-failures.xml
index a4134bc..9ecf71a 100644
--- a/tools/cts-tradefed/res/config/cts-known-failures.xml
+++ b/tools/cts-tradefed/res/config/cts-known-failures.xml
@@ -210,4 +210,6 @@
     <option name="compatibility:exclude-filter" value="CtsSensorTestCases android.hardware.cts.SensorDirectReportTest#testRegisterMultipleChannels" />
     <option name="compatibility:exclude-filter" value="CtsSensorTestCases android.hardware.cts.SensorDirectReportTest#testReconfigure" />
 
+    <!-- b/64690009 -->
+    <option name="compatibility:exclude-filter" value="CtsPermission2TestCases android.permission2.cts.PrivappPermissionsTest" />
 </configuration>