Merge "Delete package sandbox data when it is uninstalled."
This commit is contained in:
commit
b792c3a210
5 changed files with 99 additions and 15 deletions
|
@ -886,17 +886,28 @@ binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::
|
|||
return translateBool(e4crypt_destroy_user_storage(uuid_, userId, flags));
|
||||
}
|
||||
|
||||
binder::Status VoldNativeService::mountExternalStorageForApp(const std::string& packageName,
|
||||
int32_t appId,
|
||||
const std::string& sandboxId,
|
||||
binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName,
|
||||
int32_t appId, const std::string& sandboxId,
|
||||
int32_t userId) {
|
||||
ENFORCE_UID(AID_SYSTEM);
|
||||
CHECK_ARGUMENT_PACKAGE_NAME(packageName);
|
||||
CHECK_ARGUMENT_SANDBOX_ID(sandboxId);
|
||||
ACQUIRE_LOCK;
|
||||
|
||||
return translate(VolumeManager::Instance()->mountExternalStorageForApp(packageName, appId,
|
||||
sandboxId, userId));
|
||||
return translate(
|
||||
VolumeManager::Instance()->prepareSandboxForApp(packageName, appId, sandboxId, userId));
|
||||
}
|
||||
|
||||
binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName,
|
||||
int32_t appId, const std::string& sandboxId,
|
||||
int32_t userId) {
|
||||
ENFORCE_UID(AID_SYSTEM);
|
||||
CHECK_ARGUMENT_PACKAGE_NAME(packageName);
|
||||
CHECK_ARGUMENT_SANDBOX_ID(sandboxId);
|
||||
ACQUIRE_LOCK;
|
||||
|
||||
return translate(
|
||||
VolumeManager::Instance()->destroySandboxForApp(packageName, appId, sandboxId, userId));
|
||||
}
|
||||
|
||||
binder::Status VoldNativeService::startCheckpoint(int32_t retry, bool* _aidl_return) {
|
||||
|
|
|
@ -116,7 +116,9 @@ class VoldNativeService : public BinderService<VoldNativeService>, public os::Bn
|
|||
binder::Status destroyUserStorage(const std::unique_ptr<std::string>& uuid, int32_t userId,
|
||||
int32_t flags);
|
||||
|
||||
binder::Status mountExternalStorageForApp(const std::string& packageName, int32_t appId,
|
||||
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,
|
||||
const std::string& sandboxId, int32_t userId);
|
||||
|
||||
binder::Status startCheckpoint(int32_t retry, bool* _aidl_return);
|
||||
|
|
|
@ -837,7 +837,7 @@ int VolumeManager::addSandboxIds(const std::vector<int32_t>& appIds,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int VolumeManager::mountExternalStorageForApp(const std::string& packageName, appid_t appId,
|
||||
int VolumeManager::prepareSandboxForApp(const std::string& packageName, appid_t appId,
|
||||
const std::string& sandboxId, userid_t userId) {
|
||||
if (!GetBoolProperty(kIsolatedStorage, false)) {
|
||||
return 0;
|
||||
|
@ -846,7 +846,7 @@ int VolumeManager::mountExternalStorageForApp(const std::string& packageName, ap
|
|||
// be created when the user starts.
|
||||
return 0;
|
||||
}
|
||||
LOG(VERBOSE) << "mountExternalStorageForApp: " << packageName << ", appId=" << appId
|
||||
LOG(VERBOSE) << "prepareSandboxForApp: " << packageName << ", appId=" << appId
|
||||
<< ", sandboxId=" << sandboxId << ", userId=" << userId;
|
||||
mUserPackages[userId].push_back(packageName);
|
||||
mAppIds[packageName] = appId;
|
||||
|
@ -863,6 +863,71 @@ int VolumeManager::mountExternalStorageForApp(const std::string& packageName, ap
|
|||
return prepareSandboxes(userId, {packageName}, visibleVolLabels);
|
||||
}
|
||||
|
||||
int VolumeManager::destroySandboxForApp(const std::string& packageName, appid_t appId,
|
||||
const std::string& sandboxId, userid_t userId) {
|
||||
if (!GetBoolProperty(kIsolatedStorage, false)) {
|
||||
return 0;
|
||||
}
|
||||
LOG(VERBOSE) << "destroySandboxForApp: " << packageName << ", appId=" << appId
|
||||
<< ", 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
|
||||
// corresponding to it from the internal state.
|
||||
bool installedInAnyUser = false;
|
||||
for (auto& it : mUserPackages) {
|
||||
auto& packages = it.second;
|
||||
if (std::find(packages.begin(), packages.end(), packageName) != packages.end()) {
|
||||
installedInAnyUser = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!installedInAnyUser) {
|
||||
mAppIds.erase(packageName);
|
||||
mSandboxIds.erase(appId);
|
||||
}
|
||||
|
||||
std::vector<std::string> visibleVolLabels;
|
||||
for (auto& volId : mVisibleVolumeIds) {
|
||||
auto vol = findVolume(volId);
|
||||
userid_t mountUserId = vol->getMountUserId();
|
||||
if (mountUserId == userId || vol->isEmulated()) {
|
||||
if (destroySandboxForAppOnVol(packageName, sandboxId, userId, vol->getLabel()) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VolumeManager::destroySandboxForAppOnVol(const std::string& packageName,
|
||||
const std::string& sandboxId, userid_t userId,
|
||||
const std::string& volLabel) {
|
||||
LOG(VERBOSE) << "destroySandboxOnVol: " << packageName << ", userId=" << userId
|
||||
<< ", volLabel=" << volLabel;
|
||||
std::string pkgSandboxTarget =
|
||||
StringPrintf("/mnt/user/%d/package/%s", userId, packageName.c_str());
|
||||
if (android::vold::UnmountTree(pkgSandboxTarget)) {
|
||||
PLOG(ERROR) << "UnmountTree failed on " << pkgSandboxTarget;
|
||||
}
|
||||
|
||||
std::string sandboxDir = StringPrintf("/mnt/runtime/write/%s", volLabel.c_str());
|
||||
if (volLabel == mPrimary->getLabel() && mPrimary->isEmulated()) {
|
||||
StringAppendF(&sandboxDir, "/%d", userId);
|
||||
}
|
||||
if (StartsWith(sandboxId, "shared:")) {
|
||||
StringAppendF(&sandboxDir, "/Android/sandbox/shared/%s", sandboxId.substr(7).c_str());
|
||||
} else {
|
||||
StringAppendF(&sandboxDir, "/Android/sandbox/%s", sandboxId.c_str());
|
||||
}
|
||||
|
||||
if (android::vold::DeleteDirContentsAndDir(sandboxDir) < 0) {
|
||||
PLOG(ERROR) << "DeleteDirContentsAndDir failed on " << sandboxDir;
|
||||
return -errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VolumeManager::onSecureKeyguardStateChanged(bool isShowing) {
|
||||
mSecureKeyguardShowing = isShowing;
|
||||
if (!mSecureKeyguardShowing) {
|
||||
|
|
|
@ -96,7 +96,9 @@ class VolumeManager {
|
|||
int addAppIds(const std::vector<std::string>& packageNames, const std::vector<int32_t>& appIds);
|
||||
int addSandboxIds(const std::vector<int32_t>& appIds,
|
||||
const std::vector<std::string>& sandboxIds);
|
||||
int mountExternalStorageForApp(const std::string& packageName, appid_t appId,
|
||||
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 onVolumeMounted(android::vold::VolumeBase* vol);
|
||||
|
@ -162,6 +164,8 @@ class VolumeManager {
|
|||
const std::string& volumeRoot, const std::string& sandboxDirRoot);
|
||||
int mountPkgSpecificDir(const std::string& mntSourceRoot, const std::string& mntTargetRoot,
|
||||
const std::string& packageName, const char* dirName);
|
||||
int destroySandboxForAppOnVol(const std::string& packageName, const std::string& sandboxId,
|
||||
userid_t userId, const std::string& volLabel);
|
||||
|
||||
void handleDiskAdded(const std::shared_ptr<android::vold::Disk>& disk);
|
||||
void handleDiskChanged(dev_t device);
|
||||
|
|
|
@ -99,7 +99,9 @@ interface IVold {
|
|||
int storageFlags);
|
||||
void destroyUserStorage(@nullable @utf8InCpp String uuid, int userId, int storageFlags);
|
||||
|
||||
void mountExternalStorageForApp(in @utf8InCpp String packageName, int appId,
|
||||
void prepareSandboxForApp(in @utf8InCpp String packageName, int appId,
|
||||
in @utf8InCpp String sandboxId, int userId);
|
||||
void destroySandboxForApp(in @utf8InCpp String packageName, int appId,
|
||||
in @utf8InCpp String sandboxId, int userId);
|
||||
|
||||
boolean startCheckpoint(int retry);
|
||||
|
|
Loading…
Reference in a new issue