Mount emulated volumes as consistent location.
We really only support a single emulated volume on the device at a
time, either on internal storage, or moved to a private volume. To
avoid kicking off a giant rescan of all media when moved, keep all
the paths the same when mounted as primary.
Also ensure we have /data/media/0 ready on private volumes.
Bug: 20275423
Change-Id: I0c102f430b865ca7536772b1fae56d8c9660a97a
diff --git a/EmulatedVolume.cpp b/EmulatedVolume.cpp
index d8d9198..f1ca97b 100644
--- a/EmulatedVolume.cpp
+++ b/EmulatedVolume.cpp
@@ -54,12 +54,19 @@
}
status_t EmulatedVolume::doMount() {
- mFuseDefault = StringPrintf("/mnt/runtime_default/%s", mLabel.c_str());
- mFuseRead = StringPrintf("/mnt/runtime_read/%s", mLabel.c_str());
- mFuseWrite = StringPrintf("/mnt/runtime_write/%s", mLabel.c_str());
+ // We could have migrated storage to an adopted private volume, so always
+ // call primary storage "emulated" to avoid media rescans.
+ std::string label = mLabel;
+ if (getMountFlags() & MountFlags::kPrimary) {
+ label = "emulated";
+ }
+
+ mFuseDefault = StringPrintf("/mnt/runtime_default/%s", label.c_str());
+ mFuseRead = StringPrintf("/mnt/runtime_read/%s", label.c_str());
+ mFuseWrite = StringPrintf("/mnt/runtime_write/%s", label.c_str());
setInternalPath(mRawPath);
- setPath(StringPrintf("/storage/%s", mLabel.c_str()));
+ setPath(StringPrintf("/storage/%s", label.c_str()));
if (fs_prepare_dir(mFuseDefault.c_str(), 0700, AID_ROOT, AID_ROOT) ||
fs_prepare_dir(mFuseRead.c_str(), 0700, AID_ROOT, AID_ROOT) ||
@@ -77,7 +84,7 @@
"-m",
"-w",
mRawPath.c_str(),
- mLabel.c_str(),
+ label.c_str(),
NULL)) {
PLOG(ERROR) << "Failed to exec";
}