Camera: read exposure value range if possible

To fix the bogus failure on devices support READ_SENSOR_SETTINGS
but does not support MANUAL_SENSOR

Change-Id: Id6aabbaef58f8bf2d85870f72716b92059afa530
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/StillCaptureTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/StillCaptureTest.java
index 5e931fe..e7978c6 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/StillCaptureTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/StillCaptureTest.java
@@ -983,6 +983,8 @@
         CaptureRequest.Builder stillRequest =
                 mCamera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
         boolean canSetAeLock = mStaticInfo.isAeLockSupported();
+        boolean canReadSensorSettings = mStaticInfo.isCapabilitySupported(
+                CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_READ_SENSOR_SETTINGS);
 
         if (canSetAeLock) {
             stillRequest.set(CaptureRequest.CONTROL_AE_LOCK, true);
@@ -991,19 +993,20 @@
         CaptureResult normalResult;
         CaptureResult compensatedResult;
 
-        // The following variables should only be read under the MANUAL_SENSOR capability guard:
+        boolean canReadExposureValueRange = mStaticInfo.areKeysAvailable(
+                CameraCharacteristics.SENSOR_INFO_SENSITIVITY_RANGE,
+                CameraCharacteristics.SENSOR_INFO_EXPOSURE_TIME_RANGE);
+        boolean canVerifyExposureValue = canReadSensorSettings && canReadExposureValueRange;
         long minExposureValue = -1;
-        long maxExposureTimeUs = -1;
         long maxExposureValuePreview = -1;
         long maxExposureValueStill = -1;
-        if (mStaticInfo.isCapabilitySupported(
-                CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR)) {
+        if (canReadExposureValueRange) {
             // Minimum exposure settings is mostly static while maximum exposure setting depends on
             // frame rate range which in term depends on capture request.
             minExposureValue = mStaticInfo.getSensitivityMinimumOrDefault() *
                     mStaticInfo.getExposureMinimumOrDefault() / 1000;
             long maxSensitivity = mStaticInfo.getSensitivityMaximumOrDefault();
-            maxExposureTimeUs = mStaticInfo.getExposureMaximumOrDefault() / 1000;
+            long maxExposureTimeUs = mStaticInfo.getExposureMaximumOrDefault() / 1000;
             maxExposureValuePreview = getMaxExposureValue(previewRequest, maxExposureTimeUs,
                     maxSensitivity);
             maxExposureValueStill = getMaxExposureValue(stillRequest, maxExposureTimeUs,
@@ -1024,8 +1027,7 @@
             normalResult = resultListener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
 
             long normalExposureValue = -1;
-            if (mStaticInfo.isCapabilitySupported(
-                    CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_READ_SENSOR_SETTINGS)) {
+            if (canVerifyExposureValue) {
                 // get and check if current exposure value is valid
                 normalExposureValue = getExposureValue(normalResult);
                 mCollector.expectInRange("Exposure setting out of bound", normalExposureValue,
@@ -1072,8 +1074,7 @@
             compensatedResult = resultListener.getCaptureResultForRequest(
                     request, WAIT_FOR_RESULT_TIMEOUT_MS);
 
-            if (mStaticInfo.isCapabilitySupported(
-                    CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_READ_SENSOR_SETTINGS)) {
+            if (canVerifyExposureValue) {
                 // Verify the exposure value compensates as requested
                 long compensatedExposureValue = getExposureValue(compensatedResult);
                 mCollector.expectInRange("Exposure setting out of bound", compensatedExposureValue,