diff --git a/CommandListener.cpp b/CommandListener.cpp index 74fe3fc..5168de6 100644 --- a/CommandListener.cpp +++ b/CommandListener.cpp @@ -184,13 +184,21 @@ int CommandListener::VolumeCmd::runCommand(SocketClient *cli, // mkdirs [path] return sendGenericOkFail(cli, vm->mkdirs(argv[2])); - } else if (cmd == "start_user" && argc > 2) { - // start_user [user] - return sendGenericOkFail(cli, vm->startUser(atoi(argv[2]))); + } else if (cmd == "user_added" && argc > 3) { + // user_added [user] [serial] + return sendGenericOkFail(cli, vm->onUserAdded(atoi(argv[2]), atoi(argv[3]))); - } else if (cmd == "cleanup_user" && argc > 2) { - // cleanup_user [user] - return sendGenericOkFail(cli, vm->cleanupUser(atoi(argv[2]))); + } else if (cmd == "user_removed" && argc > 2) { + // user_removed [user] + return sendGenericOkFail(cli, vm->onUserRemoved(atoi(argv[2]))); + + } else if (cmd == "user_started" && argc > 2) { + // user_started [user] + return sendGenericOkFail(cli, vm->onUserStarted(atoi(argv[2]))); + + } else if (cmd == "user_stopped" && argc > 2) { + // user_stopped [user] + return sendGenericOkFail(cli, vm->onUserStopped(atoi(argv[2]))); } else if (cmd == "mount" && argc > 2) { // mount [volId] [flags] [user] diff --git a/VolumeManager.cpp b/VolumeManager.cpp index 9306363..6f783a2 100755 --- a/VolumeManager.cpp +++ b/VolumeManager.cpp @@ -426,28 +426,38 @@ int VolumeManager::linkPrimary(userid_t userId) { 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& vol) { mPrimary = vol; - for (userid_t userId : mUsers) { + for (userid_t userId : mStartedUsers) { linkPrimary(userId); } return 0; @@ -462,7 +472,8 @@ int VolumeManager::reset() { disk->destroy(); disk->create(); } - mUsers.clear(); + mAddedUsers.clear(); + mStartedUsers.clear(); return 0; } diff --git a/VolumeManager.h b/VolumeManager.h index f29a7fd..3207de8 100644 --- a/VolumeManager.h +++ b/VolumeManager.h @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include @@ -118,8 +120,10 @@ public: nsecs_t benchmarkVolume(const std::string& id); - int startUser(userid_t userId); - int cleanupUser(userid_t userId); + int onUserAdded(userid_t userId, int userSerialNumber); + int onUserRemoved(userid_t userId); + int onUserStarted(userid_t userId); + int onUserStopped(userid_t userId); int setPrimary(const std::shared_ptr& vol); @@ -198,7 +202,8 @@ private: std::list> mDiskSources; std::list> mDisks; - std::list mUsers; + std::unordered_map mAddedUsers; + std::unordered_set mStartedUsers; std::shared_ptr mInternalEmulated; std::shared_ptr mPrimary;