Camera2: add static metadata check for maxCaptureStall

Also cleanup the cts code a little bit: Auto-unboxing without a null check is
dangerous, the test could crash by the NPE without telling much details of the
actual failure.

Bug: 20670252
Change-Id: Idaeea2fb16df0c472bf458cc5e701314500d4309
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/CameraTestUtils.java b/tests/tests/hardware/src/android/hardware/camera2/cts/CameraTestUtils.java
index 5ae8a14..9da74d1 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/CameraTestUtils.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/CameraTestUtils.java
@@ -968,6 +968,17 @@
         return value;
     }
 
+    public static <T> T getValueNotNull(CameraCharacteristics characteristics,
+            CameraCharacteristics.Key<T> key) {
+        if (characteristics == null) {
+            throw new IllegalArgumentException("Camera characteristics must not be null");
+        }
+
+        T value = characteristics.get(key);
+        assertNotNull("Value of Key " + key.getName() + "shouldn't be null", value);
+        return value;
+    }
+
     /**
      * Get a crop region for a given zoom factor and center position.
      * <p>
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java
index f3a0cc0..dcfde8a 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java
@@ -2025,12 +2025,6 @@
         validatePipelineDepth(result);
     }
 
-    private <T> T getValueNotNull(CaptureResult result, CaptureResult.Key<T> key) {
-        T value = result.get(key);
-        assertNotNull("Value of Key " + key.getName() + " shouldn't be null", value);
-        return value;
-    }
-
     /**
      * Basic verification for the control mode capture result.
      *
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java
index 06561d4..b1f763d 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java
@@ -358,9 +358,8 @@
         int counter = 0;
         final float SIZE_ERROR_MARGIN = 0.03f;
         for (CameraCharacteristics c : mCharacteristics) {
-            int[] actualCapabilities = c.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);
-            assertNotNull("android.request.availableCapabilities must never be null",
-                    actualCapabilities);
+            int[] actualCapabilities = CameraTestUtils.getValueNotNull(
+                    c, CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);
 
             // Check if the burst capability is defined
             boolean haveBurstCapability = arrayContains(actualCapabilities,
@@ -370,7 +369,8 @@
                     c.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
             assertNotNull(String.format("No stream configuration map found for: ID %s",
                     mIds[counter]), config);
-            Rect activeRect = c.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
+            Rect activeRect = CameraTestUtils.getValueNotNull(
+                    c, CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
             Size sensorSize = new Size(activeRect.width(), activeRect.height());
 
             // Ensure that max YUV size matches max JPEG size
@@ -389,8 +389,10 @@
                      maxYuvSize.getHeight() >= sensorSize.getHeight() * (1.0 - SIZE_ERROR_MARGIN));
 
             // No need to do null check since framework will generate the key if HAL don't supply
-            boolean haveAeLock = c.get(CameraCharacteristics.CONTROL_AE_LOCK_AVAILABLE);
-            boolean haveAwbLock = c.get(CameraCharacteristics.CONTROL_AWB_LOCK_AVAILABLE);
+            boolean haveAeLock = CameraTestUtils.getValueNotNull(
+                    c, CameraCharacteristics.CONTROL_AE_LOCK_AVAILABLE);
+            boolean haveAwbLock = CameraTestUtils.getValueNotNull(
+                    c, CameraCharacteristics.CONTROL_AWB_LOCK_AVAILABLE);
 
             // Ensure that YUV output is fast enough - needs to be at least 20 fps
 
@@ -402,7 +404,8 @@
 
             // Ensure that there's an FPS range that's fast enough to capture at above
             // minFrameDuration, for full-auto bursts
-            Range[] fpsRanges = c.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
+            Range[] fpsRanges = CameraTestUtils.getValueNotNull(
+                    c, CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
             float minYuvFps = 1.f / maxYuvRate;
 
             boolean haveFastAeTargetFps = false;
@@ -513,6 +516,13 @@
                 assertTrue("PRIVATE input must be supported for OPAQUE reprocessing",
                         !supportOpaque || arrayContains(inputFormats, ImageFormat.PRIVATE));
 
+                // max capture stall must be reported if one of the reprocessing is supported.
+                final int MAX_ALLOWED_STALL_FRAMES = 4;
+                Integer maxCaptureStall = c.get(CameraCharacteristics.REPROCESS_MAX_CAPTURE_STALL);
+                assertTrue("max capture stall must be non-null and no larger than "
+                        + MAX_ALLOWED_STALL_FRAMES,
+                        maxCaptureStall != null && maxCaptureStall <= MAX_ALLOWED_STALL_FRAMES);
+
                 for (int input : inputFormats) {
                     // Verify mandatory output formats are supported
                     int[] outputFormats = configs.getValidOutputFormatsForInput(input);