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

Commit 0e889e42 authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[pm/archive] allow changing sharedUserId on unarchive

BUG: 361558423
Test: manually by b&r with pre-archive and verified that Firefox and ColorNote can be unarchived successfully with this change.
FLAG: EXEMPT bug fix

Change-Id: I31eecf40e7199661f8d17222fca00936e831b4da
parent 078b7fac
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -1851,11 +1851,17 @@ final class InstallPackageHelper {
                    }

                    if (!oldSharedUid.equals(newSharedUid)) {
                        if (!(oldSharedUid.equals("<nothing>") && ps.getPkg() == null
                                && ps.isArchivedOnAnyUser(allUsers))) {
                            // Only allow changing sharedUserId if unarchiving
                            // TODO(b/361558423): remove this check after pre-archiving installs
                            // accept a sharedUserId param in the API
                            throw new PrepareFailure(INSTALL_FAILED_UID_CHANGED,
                                    "Package " + parsedPackage.getPackageName()
                                            + " shared user changed from "
                                            + oldSharedUid + " to " + newSharedUid);
                        }
                    }

                    // APK should not re-join shared UID
                    if (oldPackageState.isLeavingSharedUser()
+12 −0
Original line number Diff line number Diff line
@@ -924,6 +924,18 @@ public class PackageSetting extends SettingBase implements PackageStateInternal
        return PackageArchiver.isArchived(readUserState(userId));
    }

    /**
     * @return if the package is archived in any of the users
     */
    boolean isArchivedOnAnyUser(int[] userIds) {
        for (int user : userIds) {
            if (isArchived(user)) {
                return true;
            }
        }
        return false;
    }

    int getInstallReason(int userId) {
        return readUserState(userId).getInstallReason();
    }