Start tracking added users with serial numbers.

vold will eventually use the serial numbers to clean up stale user
directories when mounting private storage devices.

Bug: 20275572
Change-Id: Ia29cb5da23e969f3087bb5caa5dc8f4e88f07613
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index 9306363..6f783a2 100755
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -426,28 +426,38 @@
     return 0;
 }
 
-int VolumeManager::startUser(userid_t userId) {
+int VolumeManager::onUserAdded(userid_t userId, int userSerialNumber) {
+    mAddedUsers[userId] = userSerialNumber;
+    return 0;
+}
+
+int VolumeManager::onUserRemoved(userid_t userId) {
+    mAddedUsers.erase(userId);
+    return 0;
+}
+
+int VolumeManager::onUserStarted(userid_t userId) {
     // Note that sometimes the system will spin up processes from Zygote
     // before actually starting the user, so we're okay if Zygote
     // already created this directory.
     std::string path(StringPrintf("%s/%d", kUserMountPath, userId));
     fs_prepare_dir(path.c_str(), 0755, AID_ROOT, AID_ROOT);
 
-    mUsers.push_back(userId);
+    mStartedUsers.insert(userId);
     if (mPrimary) {
         linkPrimary(userId);
     }
     return 0;
 }
 
-int VolumeManager::cleanupUser(userid_t userId) {
-    mUsers.remove(userId);
+int VolumeManager::onUserStopped(userid_t userId) {
+    mStartedUsers.erase(userId);
     return 0;
 }
 
 int VolumeManager::setPrimary(const std::shared_ptr<android::vold::VolumeBase>& vol) {
     mPrimary = vol;
-    for (userid_t userId : mUsers) {
+    for (userid_t userId : mStartedUsers) {
         linkPrimary(userId);
     }
     return 0;
@@ -462,7 +472,8 @@
         disk->destroy();
         disk->create();
     }
-    mUsers.clear();
+    mAddedUsers.clear();
+    mStartedUsers.clear();
     return 0;
 }