Camera: Add hotplug support (for fixed # of cameras)

* Minor: also change addListener to fire the current status upon subscription
* Minor: STATUS_AVAILABLE is now an alias for STATUS_PRESENT and deprecated

Change-Id: I254608a7332095e3ef201ffea64cff156cfc1b3e
diff --git a/camera/tests/ProCameraTests.cpp b/camera/tests/ProCameraTests.cpp
index ecc0854..5f8f772 100644
--- a/camera/tests/ProCameraTests.cpp
+++ b/camera/tests/ProCameraTests.cpp
@@ -587,14 +587,19 @@
     sp<ServiceListener> listener = new ServiceListener();
     EXPECT_OK(ProCamera::addServiceListener(listener));
 
-    ServiceListener::Status currentStatus = ServiceListener::STATUS_AVAILABLE;
+    ServiceListener::Status currentStatus;
+
+    // when subscribing a new listener,
+    // we immediately get a callback to the current status
+    while (listener->waitForStatusChange(/*out*/currentStatus) != OK);
+    EXPECT_EQ(ServiceListener::STATUS_PRESENT, currentStatus);
 
     dout << "Will now stream and resume infinitely..." << std::endl;
     while (true) {
 
-        if (currentStatus == ServiceListener::STATUS_AVAILABLE) {
+        if (currentStatus == ServiceListener::STATUS_PRESENT) {
 
-            EXPECT_OK(mCamera->createStream(mDisplayW, mDisplayH, mDisplayFmt,
+            ASSERT_OK(mCamera->createStream(mDisplayW, mDisplayH, mDisplayFmt,
                                             surface,
                                             &depthStreamId));
             EXPECT_NE(-1, depthStreamId);
@@ -613,12 +618,15 @@
         while (listener->waitForStatusChange(/*out*/stat) != OK);
 
         if (currentStatus != stat) {
-            if (stat == ServiceListener::STATUS_AVAILABLE) {
+            if (stat == ServiceListener::STATUS_PRESENT) {
                 dout << "Reconnecting to camera" << std::endl;
                 mCamera = ProCamera::connect(CAMERA_ID);
             } else if (stat == ServiceListener::STATUS_NOT_AVAILABLE) {
                 dout << "Disconnecting from camera" << std::endl;
                 mCamera->disconnect();
+            } else if (stat == ServiceListener::STATUS_NOT_PRESENT) {
+                dout << "Camera unplugged" << std::endl;
+                mCamera = NULL;
             } else {
                 dout << "Unknown status change "
                      << std::hex << stat << std::endl;
@@ -1216,7 +1224,7 @@
     }
 
     EXPECT_OK(listener->waitForStatusChange(/*out*/stat));
-    EXPECT_EQ(ServiceListener::STATUS_AVAILABLE, stat);
+    EXPECT_EQ(ServiceListener::STATUS_PRESENT, stat);
 
     EXPECT_OK(ProCamera::removeServiceListener(listener));
 }