Emulated volumes above private volumes.

When a private volume is mounted, create an emulated volume above it
hosted at the /media path on that device.  That emulated volume is
automatically torn down when unmounting the private volume.

Add "removed" state for volume, which signals to framework that
media has left the building, send when the volume is destroyed.

Bug: 19993667
Change-Id: I1f82b51de578ac5cfcc5d7b9a6fb44f6f25c775c
diff --git a/PrivateVolume.cpp b/PrivateVolume.cpp
index 6ca5480..2b3b7b6 100644
--- a/PrivateVolume.cpp
+++ b/PrivateVolume.cpp
@@ -16,6 +16,7 @@
 
 #include "Ext4.h"
 #include "PrivateVolume.h"
+#include "EmulatedVolume.h"
 #include "Utils.h"
 #include "VolumeManager.h"
 #include "ResponseCode.h"
@@ -120,6 +121,14 @@
         return -EIO;
     }
 
+    // Create a new emulated volume stacked above us, it will automatically
+    // be destroyed during unmount
+    std::string mediaPath(mPath + "/media");
+    auto vol = std::shared_ptr<VolumeBase>(
+            new EmulatedVolume(mediaPath, mRawDevice, mFsUuid));
+    addVolume(vol);
+    vol->create();
+
     return OK;
 }