autotest-capability: Add camera detectors

To handle unibuild devices with different caps for models/skus, this CL
enables "usb_camera" and "mipi_camera" detectors which read static
camera information from CrOS config.

BUG=b:166652717
TEST=Run camera_V4L2 and check the parsed caps in the logs.

Change-Id: I16a6aea4079774e82150acba3de6c192ab70d98d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/2484634
Reviewed-by: Shik Chen <shik@chromium.org>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Tested-by: Ren-Pei Zeng <kamesan@chromium.org>
Commit-Queue: Ren-Pei Zeng <kamesan@chromium.org>
diff --git a/client/cros/video/detectors/mipi_camera.py b/client/cros/video/detectors/mipi_camera.py
new file mode 100644
index 0000000..b32c5c2
--- /dev/null
+++ b/client/cros/video/detectors/mipi_camera.py
@@ -0,0 +1,14 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from .utils import detect_camera
+
+
+def detect():
+    """
+    Checks whether the device has a built-in MIPI camera.
+
+    @returns string: 'mipi_camera' if true, '' otherwise.
+    """
+    return 'mipi_camera' if detect_camera('mipi') else ''
diff --git a/client/cros/video/detectors/usb_camera.py b/client/cros/video/detectors/usb_camera.py
new file mode 100644
index 0000000..f8e545e
--- /dev/null
+++ b/client/cros/video/detectors/usb_camera.py
@@ -0,0 +1,14 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from .utils import detect_camera
+
+
+def detect():
+    """
+    Checks whether the device has a built-in USB camera.
+
+    @returns string: 'usb_camera' if true, '' otherwise.
+    """
+    return 'usb_camera' if detect_camera('usb') else ''
diff --git a/client/cros/video/detectors/utils.py b/client/cros/video/detectors/utils.py
new file mode 100644
index 0000000..cd66d1b
--- /dev/null
+++ b/client/cros/video/detectors/utils.py
@@ -0,0 +1,27 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import itertools
+
+from autotest_lib.client.common_lib import utils
+from autotest_lib.client.common_lib.cros import cros_config
+
+
+def detect_camera(iface):
+    """
+    Checks whether the device has a built-in camera of specified interface by
+    CrOS config.
+
+    @param iface: string, either 'usb' or 'mipi', indicating the interface of
+                  camera module.
+    @returns boolean indicating whether there's a matching camera.
+    """
+    for i in itertools.count(0):
+        queried = cros_config.call_cros_config_get_output(
+                '/camera/devices/{} interface'.format(i), utils.run)
+        if queried == '':
+            break
+        if queried == iface:
+            return True
+    return False