Update method "getRearViewCameraIds".

Add a new util method "getRearViewCameraIds" to return all the available
rear cameras, and add comment for the old "getRearViewCameraId" method.

Test: build and run on Hawk device
Bug: 130246434
Change-Id: Ia8366b2fa2c9b661e75547a8639fc602456bf54b
diff --git a/evs/apps/demo_app_evs_support_lib/evs_app_support_lib.cpp b/evs/apps/demo_app_evs_support_lib/evs_app_support_lib.cpp
index b7ae009..4ce2268 100644
--- a/evs/apps/demo_app_evs_support_lib/evs_app_support_lib.cpp
+++ b/evs/apps/demo_app_evs_support_lib/evs_app_support_lib.cpp
@@ -26,6 +26,7 @@
 using ::android::automotive::evs::support::DisplayUseCase;
 using ::android::automotive::evs::support::Frame;
 using ::android::automotive::evs::support::Utils;
+using ::std::string;
 
 class SimpleRenderCallback : public BaseRenderCallback {
     void render(const Frame& inputFrame, const Frame& outputFrame) {
@@ -60,10 +61,11 @@
 int main() {
     ALOGI("EVS app starting\n");
 
-    std::string cameraId = Utils::getRearCameraId();
+    // Get the default rear view camera from evs support lib
+    string cameraId = Utils::getDefaultRearViewCameraId();
     if (cameraId.empty()) {
         ALOGE("Cannot find a valid camera");
-        return -1;
+        return EXIT_FAILURE;
     }
 
     DisplayUseCase useCase =
diff --git a/evs/support_library/Utils.cpp b/evs/support_library/Utils.cpp
index 5443630..12c3fc3 100644
--- a/evs/support_library/Utils.cpp
+++ b/evs/support_library/Utils.cpp
@@ -27,28 +27,36 @@
 
 using namespace ::android::hardware::automotive::evs::V1_0;
 using ::android::hardware::hidl_vec;
-using ::std::string;
 
-string Utils::getRearCameraId() {
+vector<string> Utils::sCameraIds;
+
+vector<string> Utils::getRearViewCameraIds() {
+    // If we already get the camera list, re-use it.
+    if (!sCameraIds.empty()) {
+        return sCameraIds;
+    }
+
     const char* evsServiceName = "EvsEnumeratorV1_0";
 
     // Load our configuration information
     ConfigManager config;
     if (!config.initialize("/system/etc/automotive/evs_support_lib/camera_config.json")) {
         ALOGE("Missing or improper configuration for the EVS application.  Exiting.");
-        return string();
+        return vector<string>();
     }
 
     ALOGI("Acquiring EVS Enumerator");
     sp<IEvsEnumerator> evs = IEvsEnumerator::getService(evsServiceName);
     if (evs.get() == nullptr) {
         ALOGE("getService(%s) returned NULL.  Exiting.", evsServiceName);
-        return string();
+        return vector<string>();
     }
 
+    // static variable cannot be passed into capture, so we create a local
+    // variable instead.
+    vector<string> cameraIds;
     ALOGD("Requesting camera list");
-    string cameraId;
-    evs->getCameraList([&config, &cameraId](hidl_vec<CameraDesc> cameraList) {
+    evs->getCameraList([&config, &cameraIds](hidl_vec<CameraDesc> cameraList) {
         ALOGI("Camera list callback received %zu cameras", cameraList.size());
         for (auto&& cam : cameraList) {
             ALOGD("Found camera %s", cam.cameraId.c_str());
@@ -61,14 +69,23 @@
                     if (info.function.find("reverse") != std::string::npos) {
                         ALOGD("Camera %s is matched with reverse state",
                               cam.cameraId.c_str());
-                        cameraId = (string)cam.cameraId;
-                        return;
+                        cameraIds.emplace_back(cam.cameraId);
                     }
                 }
             }
         }
     });
-    return cameraId;
+    sCameraIds = cameraIds;
+    return sCameraIds;
+}
+
+string Utils::getDefaultRearViewCameraId() {
+    auto list = getRearViewCameraIds();
+    if (!list.empty()) {
+        return list[0];
+    } else {
+        return string();
+    }
 }
 
 }  // namespace support
diff --git a/evs/support_library/Utils.h b/evs/support_library/Utils.h
index a175407..a059175 100644
--- a/evs/support_library/Utils.h
+++ b/evs/support_library/Utils.h
@@ -17,15 +17,39 @@
 #define CAR_LIB_EVS_SUPPORT_UTILS_H
 
 #include <string>
+#include <vector>
 
 namespace android {
 namespace automotive {
 namespace evs {
 namespace support {
 
+using std::vector;
+using std::string;
+
 class Utils {
-  public:
-    static std::string getRearCameraId();
+public:
+    /**
+     * Gets camera ids for all the available rear view cameras. For
+     * now, we don't support dynamically adding/removing camera. In
+     * other words, the camera list won't be updated after the first
+     * time the camera list is obtained.
+     *
+     * An empty vector is returned if no rear view camera is found.
+     */
+    static vector<string> getRearViewCameraIds();
+
+    /**
+     * Gets camera id for the default rear view camera. For now, we
+     * always assume that the first element in rear view camera list
+     * is the default one.
+     *
+     * An empty string is returned if no rear view camera is found.
+     */
+    static string getDefaultRearViewCameraId();
+
+private:
+    static vector<string> sCameraIds;
 };
 
 }  // namespace support