Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ff30b13 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Create sandboxes for newly installed apps.

Bug: 111890351
Test: manual
Change-Id: I8b47e8a9fd1122b2d55c16189f05f5a32a22d16b
parent f2c5ee59
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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);
}
+24 −0
Original line number Diff line number Diff line
@@ -3803,5 +3803,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);
            }
        }
    }
}
+8 −2
Original line number Diff line number Diff line
@@ -21358,9 +21358,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) {
@@ -22798,6 +22798,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) {