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

Commit 8a8ec5a5 authored by Patrick Baumann's avatar Patrick Baumann
Browse files

Fixes incorrect delete on app update

This change fixes an incorrect refactor of delete. During the refactor,
deletion of all nonsystem apps for an unspecified user changed from not
uninstalling to uninstalling. This change ensures that that only happens
when a user is specified.

Change-Id: I00f709a3aca09da0357454397da60ea398e28627
Fixes: 121201046
Fixes: 121237029
Test: atest InstantAppUserTest#testReplaceExisting
parent b39b21b7
Loading
Loading
Loading
Loading
+12 −29
Original line number Original line Diff line number Diff line
@@ -325,7 +325,6 @@ import dalvik.system.VMRuntime;
import libcore.io.IoUtils;
import libcore.io.IoUtils;
import libcore.util.EmptyArray;
import libcore.util.EmptyArray;
import libcore.util.HexEncoding;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserException;
@@ -17856,21 +17855,14 @@ public class PackageManagerService extends IPackageManager.Stub
        public final PackageRemovedInfo outInfo;
        public final PackageRemovedInfo outInfo;
        public final int flags;
        public final int flags;
        public final UserHandle user;
        public final UserHandle user;
        /**
         * True if this package is an unupdated system app that may be deleted by the system.
         * When true, disabledPs will be null.
         */
        public final boolean mayDeleteUnupdatedSystemApp;
        private DeletePackageAction(PackageSetting deletingPs, PackageSetting disabledPs,
        private DeletePackageAction(PackageSetting deletingPs, PackageSetting disabledPs,
                PackageRemovedInfo outInfo, int flags, UserHandle user,
                PackageRemovedInfo outInfo, int flags, UserHandle user) {
                boolean mayDeleteUnupdatedSystemApp) {
            this.deletingPs = deletingPs;
            this.deletingPs = deletingPs;
            this.disabledPs = disabledPs;
            this.disabledPs = disabledPs;
            this.outInfo = outInfo;
            this.outInfo = outInfo;
            this.flags = flags;
            this.flags = flags;
            this.user = user;
            this.user = user;
            this.mayDeleteUnupdatedSystemApp = mayDeleteUnupdatedSystemApp;
        }
        }
    }
    }
@@ -17886,24 +17878,22 @@ public class PackageManagerService extends IPackageManager.Stub
        if (ps == null) {
        if (ps == null) {
            return null;
            return null;
        }
        }
        boolean mayDeleteUnupdatedSystemApp = false;
        if (isSystemApp(ps)) {
        if (isSystemApp(ps)) {
            if (ps.parentPackageName != null) {
            if (ps.parentPackageName != null) {
                Slog.w(TAG, "Attempt to delete child system package " + ps.pkg.packageName);
                Slog.w(TAG, "Attempt to delete child system package " + ps.pkg.packageName);
                return null;
                return null;
            }
            }
            if (((flags & PackageManager.DELETE_SYSTEM_APP) != 0) && user != null
            final boolean deleteSystem = (flags & PackageManager.DELETE_SYSTEM_APP) != 0;
                    && user.getIdentifier() != UserHandle.USER_ALL) {
            final boolean deleteAllUsers =
                mayDeleteUnupdatedSystemApp = true;
                    user == null || user.getIdentifier() == UserHandle.USER_ALL;
            } else if (disabledPs == null) {
            if ((!deleteSystem || deleteAllUsers) && disabledPs == null) {
                // Confirmed if the system package has been updated
                // An updated system app can be deleted. This will also have to restore
                // the system pkg from system partition
                // reader
                Slog.w(TAG, "Attempt to delete unknown system package " + ps.pkg.packageName);
                Slog.w(TAG, "Attempt to delete unknown system package " + ps.pkg.packageName);
                return null;
                return null;
            }
            }
            // Confirmed if the system package has been updated
            // An updated system app can be deleted. This will also have to restore
            // the system pkg from system partition reader
        }
        }
        final int parentReferenceCount =
        final int parentReferenceCount =
                (ps.childPackageNames != null) ? ps.childPackageNames.size() : 0;
                (ps.childPackageNames != null) ? ps.childPackageNames.size() : 0;
@@ -17918,8 +17908,7 @@ public class PackageManagerService extends IPackageManager.Stub
                }
                }
            }
            }
        }
        }
        return new DeletePackageAction(ps, disabledPs, outInfo, flags, user,
        return new DeletePackageAction(ps, disabledPs, outInfo, flags, user);
                mayDeleteUnupdatedSystemApp);
    }
    }
    /*
    /*
@@ -17993,8 +17982,8 @@ public class PackageManagerService extends IPackageManager.Stub
        if (ps.getPermissionsState().hasPermission(Manifest.permission.SUSPEND_APPS, userId)) {
        if (ps.getPermissionsState().hasPermission(Manifest.permission.SUSPEND_APPS, userId)) {
            unsuspendForSuspendingPackage(packageName, userId);
            unsuspendForSuspendingPackage(packageName, userId);
        }
        }
        if ((!systemApp || (flags & PackageManager.DELETE_SYSTEM_APP) != 0)
        if (!systemApp || action.mayDeleteUnupdatedSystemApp) {
                && userId != UserHandle.USER_ALL) {
            // The caller is asking that the package only be deleted for a single
            // The caller is asking that the package only be deleted for a single
            // user.  To do this, we just mark its uninstalled state and delete
            // user.  To do this, we just mark its uninstalled state and delete
            // its data. If this is a system app, we only allow this to happen if
            // its data. If this is a system app, we only allow this to happen if
@@ -18017,13 +18006,7 @@ public class PackageManagerService extends IPackageManager.Stub
                        // We need to set it back to 'installed' so the uninstall
                        // We need to set it back to 'installed' so the uninstall
                        // broadcasts will be sent correctly.
                        // broadcasts will be sent correctly.
                        if (DEBUG_REMOVE) Slog.d(TAG, "Not installed by other users, full delete");
                        if (DEBUG_REMOVE) Slog.d(TAG, "Not installed by other users, full delete");
                        if (userId != UserHandle.USER_ALL) {
                        ps.setInstalled(true, userId);
                        ps.setInstalled(true, userId);
                        } else {
                            for (int origUserId : outInfo.origUsers) {
                                ps.setInstalled(true, origUserId);
                            }
                        }
                        mSettings.writeKernelMappingLPr(ps);
                        mSettings.writeKernelMappingLPr(ps);
                    }
                    }
                } else {
                } else {