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

Commit aab8cbfa authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Fix package cleanup when parsed APK missing.

Recently the uninstall logic was changed to require a parsed APK to
succeed, but we need uninstall to succeed when the APK lives on an
ejected storage device.

To fix that case, create a fake parsed package with just enough
information for the delete to proceed.

Fix package movement bug that sent an invalid user ID to installd;
we need to explicitly ask for each user.

Bug: 28658206
Change-Id: Icf417661f07688c7523f0d082528adec2ac70cc6
parent d1f686f5
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -15453,9 +15453,18 @@ public class PackageManagerService extends IPackageManager.Stub {
        removePackageLI(ps, (flags & REMOVE_CHATTY) != 0);
        if ((flags & PackageManager.DELETE_KEEP_DATA) == 0) {
            destroyAppDataLIF(deletedPkg, UserHandle.USER_ALL,
            final PackageParser.Package resolvedPkg;
            if (deletedPkg != null) {
                resolvedPkg = deletedPkg;
            } else {
                // We don't have a parsed package when it lives on an ejected
                // adopted storage device, so fake something together
                resolvedPkg = new PackageParser.Package(ps.name);
                resolvedPkg.setVolumeUuid(ps.volumeUuid);
            }
            destroyAppDataLIF(resolvedPkg, UserHandle.USER_ALL,
                    StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE);
            destroyAppProfilesLIF(deletedPkg);
            destroyAppProfilesLIF(resolvedPkg);
            if (outInfo != null) {
                outInfo.dataRemoved = true;
            }
@@ -19610,6 +19619,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
        final String label;
        final int targetSdkVersion;
        final PackageFreezer freezer;
        final int[] installedUserIds;
        // reader
        synchronized (mPackages) {
@@ -19664,6 +19674,7 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
            label = String.valueOf(pm.getApplicationLabel(pkg.applicationInfo));
            targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
            freezer = new PackageFreezer(packageName, "movePackageInternal");
            installedUserIds = ps.queryInstalledUsers(sUserManager.getUserIds(), true);
        }
        final Bundle extras = new Bundle();
@@ -19701,12 +19712,14 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
        final PackageStats stats = new PackageStats(null, -1);
        synchronized (mInstaller) {
            if (!getPackageSizeInfoLI(packageName, -1, stats)) {
            for (int userId : installedUserIds) {
                if (!getPackageSizeInfoLI(packageName, userId, stats)) {
                    freezer.close();
                    throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,
                            "Failed to measure package size");
                }
            }
        }
        if (DEBUG_INSTALL) Slog.d(TAG, "Measured code size " + stats.codeSize + ", data size "
                + stats.dataSize);