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

Commit 8d940a0f authored by Ashwini Oruganti's avatar Ashwini Oruganti
Browse files

Support leaving a sharedUser

This change adds PackageManagerService support for a package to leave
a sharedUser

Test: build + flash + TH
Bug: 179284822
Change-Id: I6c03b1df0a97c4ebb573fe54049ba74507e4a53a
parent 6d8c8bc7
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1207,7 +1207,10 @@ final class InstallParams extends HandlerParams {
                    // Check for shared user id changes
                    String invalidPackageName = null;
                    if (!Objects.equals(oldPackage.getSharedUserId(),
                            parsedPackage.getSharedUserId())) {
                            parsedPackage.getSharedUserId())
                            // Don't mark as invalid if the app is trying to
                            // leave a sharedUserId
                            && parsedPackage.getSharedUserId() != null) {
                        invalidPackageName = parsedPackage.getPackageName();
                    }

+26 −15
Original line number Diff line number Diff line
@@ -13528,10 +13528,6 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    /**
     * Returns the actual scan flags depending upon the state of the other settings.
     * <p>Updated system applications will not have the following flags set
@@ -13699,10 +13695,10 @@ public class PackageManagerService extends IPackageManager.Stub
     */
    boolean optimisticallyRegisterAppId(@NonNull ScanResult result)
            throws PackageManagerException {
        if (!result.mExistingSettingCopied) {
        if (!result.mExistingSettingCopied || result.mNeedsNewAppId) {
            // THROWS: when we can't allocate a user id. add call to check if there's
            // enough space to ensure we won't throw; otherwise, don't modify state
            return mSettings.registerAppIdLPw(result.mPkgSetting);
            return mSettings.registerAppIdLPw(result.mPkgSetting, result.mNeedsNewAppId);
        }
        return false;
    }
@@ -14072,7 +14068,16 @@ public class PackageManagerService extends IPackageManager.Stub
            }
        }
        boolean leavingSharedUser = false;
        if (pkgSetting != null && pkgSetting.sharedUser != sharedUserSetting) {
            if (pkgSetting.sharedUser != null && sharedUserSetting == null) {
                leavingSharedUser = true;
                // Log that something is leaving shareduid and keep going
                Slog.i(TAG,
                        "Package " + parsedPackage.getPackageName() + " shared user changed from "
                        + pkgSetting.sharedUser.name + " to " + "<nothing>.");
            } else {
                PackageManagerService.reportSettingsProblem(Log.WARN,
                        "Package " + parsedPackage.getPackageName() + " shared user changed from "
                                + (pkgSetting.sharedUser != null
@@ -14082,6 +14087,7 @@ public class PackageManagerService extends IPackageManager.Stub
                                + "; replacing with new");
                pkgSetting = null;
            }
        }
        String[] usesStaticLibraries = null;
        if (!parsedPackage.getUsesStaticLibraries().isEmpty()) {
@@ -14356,7 +14362,8 @@ public class PackageManagerService extends IPackageManager.Stub
        }
        return new ScanResult(request, true, pkgSetting, changedAbiCodePath,
                !createNewPackage /* existingSettingCopied */, staticSharedLibraryInfo,
                !createNewPackage /* existingSettingCopied */,
                leavingSharedUser /* needsNewAppId */, staticSharedLibraryInfo,
                dynamicSharedLibraryInfos);
    }
@@ -21735,6 +21742,10 @@ public class PackageManagerService extends IPackageManager.Stub
                continue;
            }
            // TODO@ashfall check ScanResult.mNeedsNewAppId, and if true instead
            // of creating app data, migrate / change ownership of existing
            // data.
            if (ps.getInstalled(user.id)) {
                // TODO: when user data is locked, mark that we're still dirty
                prepareAppData(batch, pkg, user.id, flags).thenRun(() -> {
+7 −0
Original line number Diff line number Diff line
@@ -35,6 +35,11 @@ final class ScanResult {
     * commit.
     */
    public final boolean mExistingSettingCopied;
    /**
     * Whether or not the original PackageSetting needs to be updated with
     * a new uid. Useful when leaving a sharedUserID.
     */
    public final boolean mNeedsNewAppId;
    /**
     * The final package settings. This may be the same object passed in
     * the {@link ScanRequest}, but, with modified values.
@@ -52,6 +57,7 @@ final class ScanResult {
            ScanRequest request, boolean success,
            @Nullable PackageSetting pkgSetting,
            @Nullable List<String> changedAbiCodePath, boolean existingSettingCopied,
            boolean needsNewAppId,
            SharedLibraryInfo staticSharedLibraryInfo,
            List<SharedLibraryInfo> dynamicSharedLibraryInfos) {
        mRequest = request;
@@ -59,6 +65,7 @@ final class ScanResult {
        mPkgSetting = pkgSetting;
        mChangedAbiCodePath = changedAbiCodePath;
        mExistingSettingCopied = existingSettingCopied;
        mNeedsNewAppId = needsNewAppId;
        mStaticSharedLibraryInfo = staticSharedLibraryInfo;
        mDynamicSharedLibraryInfos = dynamicSharedLibraryInfos;
    }
+2 −2
Original line number Diff line number Diff line
@@ -1126,9 +1126,9 @@ public final class Settings implements Watchable, Snappable {
     *         already registered.
     * @throws PackageManagerException If a user ID could not be allocated.
     */
    boolean registerAppIdLPw(PackageSetting p) throws PackageManagerException {
    boolean registerAppIdLPw(PackageSetting p, boolean forceNew) throws PackageManagerException {
        final boolean createdNew;
        if (p.appId == 0) {
        if (p.appId == 0 || forceNew) {
            // Assign new user ID
            p.appId = acquireAndRegisterNewAppIdLPw(p);
            createdNew = true;