CameraITS: add checks for pixel_pitch, FOV, and hyperfocal distance

Bug: 29535513
Change-Id: I2569fe578b22d4a8ffac7fb9c17d25e52daa3c7b
diff --git a/apps/CameraITS/tests/scene0/test_metadata.py b/apps/CameraITS/tests/scene0/test_metadata.py
index 2914493..ed1426b 100644
--- a/apps/CameraITS/tests/scene0/test_metadata.py
+++ b/apps/CameraITS/tests/scene0/test_metadata.py
@@ -12,11 +12,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import its.image
+import math
+
+import its.caps
 import its.device
 import its.objects
 import its.target
-import its.caps
+
 
 def main():
     """Test the validity of some metadata entries.
@@ -75,6 +77,31 @@
 
     assert(not failed)
 
+    if not its.caps.legacy(props):
+        # Test: pixel_pitch, FOV, and hyperfocal distance are reasonable
+        fmts = props["android.scaler.streamConfigurationMap"]["availableStreamConfigurations"]
+        fmts = sorted(fmts, key=lambda k: k["width"]*k["height"], reverse=True)
+        sensor_size = props["android.sensor.info.physicalSize"]
+        pixel_pitch_h = (sensor_size["height"] / fmts[0]["height"] * 1E3)
+        pixel_pitch_w = (sensor_size["width"] / fmts[0]["width"] * 1E3)
+        print "Assert pixel_pitch WxH: %.2f um, %.2f um" % (pixel_pitch_w,
+                                                            pixel_pitch_h)
+        assert 1.0 <= pixel_pitch_w <= 10
+        assert 1.0 <= pixel_pitch_h <= 10
+        assert 0.333 <= pixel_pitch_w/pixel_pitch_h <= 3.0
+
+        diag = math.sqrt(sensor_size["height"] ** 2 +
+                         sensor_size["width"] ** 2)
+        fl = md["android.lens.focalLength"]
+        fov = 2 * math.degrees(math.atan(diag / (2 * fl)))
+        print "Assert field of view: %.1f degrees" % fov
+        assert 30 <= fov <= 130
+
+        hyperfocal = 1.0 / props["android.lens.info.hyperfocalDistance"]
+        print "Assert hyperfocal distance: %.2f m" % hyperfocal
+        assert 0.02 <= hyperfocal
+
+
 def getval(expr, default=None):
     try:
         return eval(expr)
@@ -82,6 +109,8 @@
         return default
 
 failed = False
+
+
 def check(expr):
     global md, props, failed
     try: