Wider volume mutation lock, move force adoptable.

We eventually should move back to per-disk locks, but use a giant
lock to keep development rolling forward.  Also move force adoptable
flag to framework since, since encrypted devices don't have persisted
properties loaded early during boot.

Bug: 19993667
Change-Id: Ifa3016ef41b038f8f71fc30bc81596cfd21dcd2a
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index e05da4d..cd1017c 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -257,6 +257,7 @@
 
     // Assume that we always have an emulated volume on internal
     // storage; the framework will decide if it should be mounted.
+    CHECK(mInternalEmulated == nullptr);
     mInternalEmulated = std::shared_ptr<android::vold::VolumeBase>(
             new android::vold::EmulatedVolume("/data/media"));
     mInternalEmulated->create();
@@ -265,12 +266,15 @@
 }
 
 int VolumeManager::stop() {
+    CHECK(mInternalEmulated != nullptr);
     mInternalEmulated->destroy();
     mInternalEmulated = nullptr;
     return 0;
 }
 
 void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
+    std::lock_guard<std::mutex> lock(mLock);
+
     if (mDebug) {
         LOG(VERBOSE) << "----------------";
         LOG(VERBOSE) << "handleBlockEvent with action " << (int) evt->getAction();
@@ -433,6 +437,8 @@
 }
 
 int VolumeManager::unmountAll() {
+    std::lock_guard<std::mutex> lock(mLock);
+
     // First, try gracefully unmounting all known devices
     if (mInternalEmulated != nullptr) {
         mInternalEmulated->unmount();