Merge "Enumerate camera devices in getCameraList()"
diff --git a/evs/sampleDriver/EvsEnumerator.cpp b/evs/sampleDriver/EvsEnumerator.cpp
index 9838258..96fd067 100644
--- a/evs/sampleDriver/EvsEnumerator.cpp
+++ b/evs/sampleDriver/EvsEnumerator.cpp
@@ -35,9 +35,10 @@
 std::list<EvsEnumerator::CameraRecord>   EvsEnumerator::sCameraList;
 wp<EvsGlDisplay>                           EvsEnumerator::sActiveDisplay;
 
+// Number of trials to open the camera.
+static const unsigned int kMaxRetry = 3;
 
-EvsEnumerator::EvsEnumerator()
-: kMaxRetry(3) {
+EvsEnumerator::EvsEnumerator() {
     ALOGD("EvsEnumerator created");
 
     enumerateDevices();
@@ -80,6 +81,21 @@
 Return<void> EvsEnumerator::getCameraList(getCameraList_cb _hidl_cb)  {
     ALOGD("getCameraList");
 
+    if (sCameraList.size() < 1) {
+        // WAR: this assumes that the device has at least one compatible camera and
+        // therefore keeps trying until it succeeds to open.
+        // TODO: this is required for external USB camera so would be better to
+        // subscribe hot-plug event.
+        unsigned tries = 0;
+        ALOGI("No camera is available; enumerate devices again.");
+        while (sCameraList.size() < 1 && tries++ < kMaxRetry) {
+            enumerateDevices();
+
+            // TODO: remove this.
+            usleep(5000);
+        }
+    }
+
     const unsigned numCameras = sCameraList.size();
 
     // Build up a packed array of CameraDesc for return
@@ -104,19 +120,6 @@
 
     // Is this a recognized camera id?
     CameraRecord *pRecord = findCameraById(cameraId);
-    // WAR: this assumes that the device has at least one compatible camera and
-    // therefore keeps trying until it succeeds to open.
-    // TODO: this is required for external USB camera so would be better to
-    // subscribe hot-plug event.
-    unsigned tries = 0;
-    while (!pRecord && tries++ < kMaxRetry) {
-        ALOGI("Requested camera %s not found, enumerate again, %d", cameraId.c_str(), tries);
-        enumerateDevices();
-        pRecord = findCameraById(cameraId);
-
-        // TODO: remove this.
-        usleep(5000);
-    }
 
     // Has this camera already been instantiated by another caller?
     sp<EvsV4lCamera> pActiveCamera = pRecord->activeInstance.promote();
diff --git a/evs/sampleDriver/EvsEnumerator.h b/evs/sampleDriver/EvsEnumerator.h
index 96c2e91..e7e94d4 100644
--- a/evs/sampleDriver/EvsEnumerator.h
+++ b/evs/sampleDriver/EvsEnumerator.h
@@ -48,8 +48,6 @@
     // Implementation details
     EvsEnumerator();
 
-    const unsigned kMaxRetry;
-
 private:
     struct CameraRecord {
         CameraDesc          desc;