Fix multi-user and multi-storage with FUSE
Up until now, the FUSE mount logic has made two assumptions:
1. The primary external volume is an emulated volume on /data/media
2. Only the primary user is running, as user zero
These assumptions are fixed by the following changes
creating an EmulatedVolume per Android user and changing the
VolumeBase id format to append the user to the id, so
s/emulated/emulated-0/. This allows us mount separate volumes per user
Some additional refactorings to re-use/clean up code.
Test: adb shell sm set-virtual-disk and partition disk operations work
even after setting up a work profile
Bug: 135341433
Change-Id: Ifabaa12368e5a591fbcdce4ee71c83ff35fdac6b
diff --git a/model/PrivateVolume.cpp b/model/PrivateVolume.cpp
index de2a09f..5098e5d 100644
--- a/model/PrivateVolume.cpp
+++ b/model/PrivateVolume.cpp
@@ -155,12 +155,18 @@
return -EIO;
}
- // Create a new emulated volume stacked above us, it will automatically
- // be destroyed during unmount
+ auto vol_manager = VolumeManager::Instance();
std::string mediaPath(mPath + "/media");
- auto vol = std::shared_ptr<VolumeBase>(new EmulatedVolume(mediaPath, mRawDevice, mFsUuid));
- addVolume(vol);
- vol->create();
+
+ // Create a new emulated volume stacked above us for all added users, they will automatically
+ // be destroyed during unmount
+ for (userid_t user : vol_manager->getStartedUsers()) {
+ auto vol = std::shared_ptr<VolumeBase>(
+ new EmulatedVolume(mediaPath, mRawDevice, mFsUuid, user));
+ vol->setMountUserId(user);
+ addVolume(vol);
+ vol->create();
+ }
return OK;
}