Update StorageManagerService handling of packages info.

Instead of maintaining local copy of all appIds and sandboxIds,
StorageManagerService will just get required packages info
from PackageManagerService when an user starts and passes it
to vold.

Bug: 117988901
Test: manual
Change-Id: Idab274529e843784c8804929e920c3af63032690
This commit is contained in:
Sudheer Shanka 2018-10-25 11:06:55 -07:00
parent 51a38dada7
commit 69bc40f9a9
5 changed files with 34 additions and 17 deletions

View file

@ -358,12 +358,16 @@ binder::Status VoldNativeService::onUserRemoved(int32_t userId) {
}
binder::Status VoldNativeService::onUserStarted(int32_t userId,
const std::vector<std::string>& packageNames) {
const std::vector<std::string>& packageNames,
const std::vector<int>& appIds,
const std::vector<std::string>& sandboxIds) {
ENFORCE_UID(AID_SYSTEM);
CHECK_ARGUMENT_PACKAGE_NAMES(packageNames);
CHECK_ARGUMENT_SANDBOX_IDS(sandboxIds);
ACQUIRE_LOCK;
return translate(VolumeManager::Instance()->onUserStarted(userId, packageNames));
return translate(
VolumeManager::Instance()->onUserStarted(userId, packageNames, appIds, sandboxIds));
}
binder::Status VoldNativeService::onUserStopped(int32_t userId) {
@ -899,7 +903,7 @@ binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packag
}
binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName,
int32_t appId, const std::string& sandboxId,
const std::string& sandboxId,
int32_t userId) {
ENFORCE_UID(AID_SYSTEM);
CHECK_ARGUMENT_PACKAGE_NAME(packageName);
@ -907,7 +911,7 @@ binder::Status VoldNativeService::destroySandboxForApp(const std::string& packag
ACQUIRE_LOCK;
return translate(
VolumeManager::Instance()->destroySandboxForApp(packageName, appId, sandboxId, userId));
VolumeManager::Instance()->destroySandboxForApp(packageName, sandboxId, userId));
}
binder::Status VoldNativeService::startCheckpoint(int32_t retry) {

View file

@ -39,7 +39,9 @@ class VoldNativeService : public BinderService<VoldNativeService>, public os::Bn
binder::Status onUserAdded(int32_t userId, int32_t userSerial);
binder::Status onUserRemoved(int32_t userId);
binder::Status onUserStarted(int32_t userId, const std::vector<std::string>& packageNames);
binder::Status onUserStarted(int32_t userId, const std::vector<std::string>& packageNames,
const std::vector<int>& appIds,
const std::vector<std::string>& sandboxIds);
binder::Status onUserStopped(int32_t userId);
binder::Status addAppIds(const std::vector<std::string>& packageNames,
@ -118,7 +120,7 @@ class VoldNativeService : public BinderService<VoldNativeService>, public os::Bn
binder::Status prepareSandboxForApp(const std::string& packageName, int32_t appId,
const std::string& sandboxId, int32_t userId);
binder::Status destroySandboxForApp(const std::string& packageName, int32_t appId,
binder::Status destroySandboxForApp(const std::string& packageName,
const std::string& sandboxId, int32_t userId);
binder::Status startCheckpoint(int32_t retry);

View file

@ -761,7 +761,9 @@ int VolumeManager::onUserRemoved(userid_t userId) {
return 0;
}
int VolumeManager::onUserStarted(userid_t userId, const std::vector<std::string>& packageNames) {
int VolumeManager::onUserStarted(userid_t userId, const std::vector<std::string>& packageNames,
const std::vector<int>& appIds,
const std::vector<std::string>& sandboxIds) {
LOG(VERBOSE) << "onUserStarted: " << userId;
// Note that sometimes the system will spin up processes from Zygote
// before actually starting the user, so we're okay if Zygote
@ -771,6 +773,10 @@ int VolumeManager::onUserStarted(userid_t userId, const std::vector<std::string>
mStartedUsers.insert(userId);
mUserPackages[userId] = packageNames;
for (size_t i = 0; i < packageNames.size(); ++i) {
mAppIds[packageNames[i]] = appIds[i];
mSandboxIds[appIds[i]] = sandboxIds[i];
}
if (mPrimary) {
linkPrimary(userId);
}
@ -852,13 +858,13 @@ int VolumeManager::prepareSandboxForApp(const std::string& packageName, appid_t
return prepareSandboxes(userId, {packageName}, visibleVolLabels);
}
int VolumeManager::destroySandboxForApp(const std::string& packageName, appid_t appId,
int VolumeManager::destroySandboxForApp(const std::string& packageName,
const std::string& sandboxId, userid_t userId) {
if (!GetBoolProperty(kIsolatedStorage, false)) {
return 0;
}
LOG(VERBOSE) << "destroySandboxForApp: " << packageName << ", appId=" << appId
<< ", sandboxId=" << sandboxId << ", userId=" << userId;
LOG(VERBOSE) << "destroySandboxForApp: " << packageName << ", sandboxId=" << sandboxId
<< ", userId=" << userId;
auto& userPackages = mUserPackages[userId];
std::remove(userPackages.begin(), userPackages.end(), packageName);
// If the package is not uninstalled in any other users, remove appId and sandboxId
@ -872,8 +878,11 @@ int VolumeManager::destroySandboxForApp(const std::string& packageName, appid_t
}
}
if (!installedInAnyUser) {
mAppIds.erase(packageName);
mSandboxIds.erase(appId);
const auto& entry = mAppIds.find(packageName);
if (entry != mAppIds.end()) {
mSandboxIds.erase(entry->second);
mAppIds.erase(entry);
}
}
std::vector<std::string> visibleVolLabels;

View file

@ -90,7 +90,8 @@ class VolumeManager {
int onUserAdded(userid_t userId, int userSerialNumber);
int onUserRemoved(userid_t userId);
int onUserStarted(userid_t userId, const std::vector<std::string>& packageNames);
int onUserStarted(userid_t userId, const std::vector<std::string>& packageNames,
const std::vector<int>& appIds, const std::vector<std::string>& sandboxIds);
int onUserStopped(userid_t userId);
int addAppIds(const std::vector<std::string>& packageNames, const std::vector<int32_t>& appIds);
@ -98,8 +99,8 @@ class VolumeManager {
const std::vector<std::string>& sandboxIds);
int prepareSandboxForApp(const std::string& packageName, appid_t appId,
const std::string& sandboxId, userid_t userId);
int destroySandboxForApp(const std::string& packageName, appid_t appId,
const std::string& sandboxId, userid_t userId);
int destroySandboxForApp(const std::string& packageName, const std::string& sandboxId,
userid_t userId);
int onVolumeMounted(android::vold::VolumeBase* vol);
int onVolumeUnmounted(android::vold::VolumeBase* vol);

View file

@ -29,7 +29,8 @@ interface IVold {
void onUserAdded(int userId, int userSerial);
void onUserRemoved(int userId);
void onUserStarted(int userId, in @utf8InCpp String[] packageNames);
void onUserStarted(int userId, in @utf8InCpp String[] packageNames, in int[] appIds,
in @utf8InCpp String[] sandboxIds);
void onUserStopped(int userId);
void addAppIds(in @utf8InCpp String[] packageNames, in int[] appIds);
@ -101,7 +102,7 @@ interface IVold {
void prepareSandboxForApp(in @utf8InCpp String packageName, int appId,
in @utf8InCpp String sandboxId, int userId);
void destroySandboxForApp(in @utf8InCpp String packageName, int appId,
void destroySandboxForApp(in @utf8InCpp String packageName,
in @utf8InCpp String sandboxId, int userId);
void startCheckpoint(int retry);