Merge "Create sandboxes for newly installed apps."

This commit is contained in:
Sudheer Shanka
2018-08-24 21:06:29 +00:00
committed by Android (Google) Code Review
3 changed files with 46 additions and 2 deletions

View File

@@ -79,4 +79,18 @@ public abstract class StorageManagerInternal {
* @return The mount mode.
*/
public abstract int getExternalStorageMountMode(int uid, String packageName);
/**
* Mount external storage for the given package.
*
* <p> This will involve calling into vold to setup appropriate bind mounts.
*
* @param packageName The package for which external storage will be mounted.
* @param appId The appId for the given package.
* @param sharedUserId The sharedUserId for given package if it specified
* {@code android:sharedUserId} in the manifest, otherwise {@code null}
* @param userId
*/
public abstract void mountExternalStorageForApp(String packageName, int appId,
String sharedUserId, int userId);
}

View File

@@ -3867,5 +3867,29 @@ class StorageManagerService extends IStorageManager.Stub
}
return true;
}
@Override
public void mountExternalStorageForApp(String packageName, int appId, String sharedUserId,
int userId) {
final String sandboxId;
synchronized (mPackagesLock) {
final ArraySet<String> userPackages = getPackagesForUserPL(userId);
// If userPackages is empty, it means the user is not started yet, so no need to
// do anything now.
if (userPackages.isEmpty() || userPackages.contains(packageName)) {
return;
}
userPackages.add(packageName);
mAppIds.put(packageName, appId);
sandboxId = getSandboxId(packageName, sharedUserId);
mSandboxIds.put(appId, sandboxId);
}
try {
mVold.mountExternalStorageForApp(packageName, appId, sandboxId, userId);
} catch (Exception e) {
Slog.wtf(TAG, e);
}
}
}
}

View File

@@ -20026,9 +20026,9 @@ public class PackageManagerService extends IPackageManager.Stub
mDexManager.systemReady();
mPackageDexOptimizer.systemReady();
StorageManagerInternal StorageManagerInternal = LocalServices.getService(
StorageManagerInternal storageManagerInternal = LocalServices.getService(
StorageManagerInternal.class);
StorageManagerInternal.addExternalStoragePolicy(
storageManagerInternal.addExternalStoragePolicy(
new StorageManagerInternal.ExternalStorageMountPolicy() {
@Override
public int getMountMode(int uid, String packageName) {
@@ -21411,6 +21411,12 @@ public class PackageManagerService extends IPackageManager.Stub
}
prepareAppDataContentsLeafLIF(pkg, userId, flags);
final StorageManagerInternal storageManagerInternal
= LocalServices.getService(StorageManagerInternal.class);
if (storageManagerInternal != null) {
storageManagerInternal.mountExternalStorageForApp(
pkg.packageName, appId, pkg.mSharedUserId, userId);
}
}
private void prepareAppDataContentsLIF(PackageParser.Package pkg, int userId, int flags) {