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

Commit e59a942a authored by Song Chun Fan's avatar Song Chun Fan Committed by Nishith Khanna
Browse files

[UidMigration] fix update uninstallation with sharedUserMaxSdkVersion

When a system app is re-enabled after the update is uninstalled, when
the system app has shared uid, the current code doesn't support
directly reusing the disabled package setting. Instead, the preloaded
version is re-scanned and installed as a new app, which can bring
breaking behavior of changed UIDs when the manifest has
sharedUserMaxSdkVersion.

This change fixes the bug where registerExistingAppId fails when it
comes to shared uid, therefore directly reuses the disabled package
setting, consistent with the behavior for non-shared-uid system apps.

FLAG: EXEMPT BUGFIX
Test: manually with system-app-test.sh
BUG: 454062218

(cherry picked from commit 6b5ea2f7fbf50313d46e54e0d8f8c18c398e4869)
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:445138b31bc4a08afa70dcae78850d3958dbae97
Merged-In: I1add6ba4a9c0a30a1c029974e70c21eb7a0fe5d5
Change-Id: I1add6ba4a9c0a30a1c029974e70c21eb7a0fe5d5
parent 1660fbe6
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -910,7 +910,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
        }
        p.getPkgState().setUpdatedSystemApp(false);
        PackageSetting ret = addPackageLPw(name, p.getRealName(), p.getPath(), p.getAppId(),
                p.getFlags(), p.getPrivateFlags(), mDomainVerificationManager.generateNewId());
                p.getFlags(), p.getPrivateFlags(), mDomainVerificationManager.generateNewId(), p.hasSharedUser());
        if (ret != null) {
            ret.setLegacyNativeLibraryPath(p.getLegacyNativeLibraryPath());
            ret.setPrimaryCpuAbi(p.getPrimaryCpuAbiLegacy());
@@ -929,6 +929,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
            ret.setTargetSdkVersion(p.getTargetSdkVersion());
            ret.setRestrictUpdateHash(p.getRestrictUpdateHash());
            ret.setScannedAsStoppedSystemApp(p.isScannedAsStoppedSystemApp());
            ret.setSharedUserAppId(p.getSharedUserAppId());
        }
        mDisabledSysPackages.remove(name);
        return ret;
@@ -950,7 +951,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
    }

    PackageSetting addPackageLPw(String name, String realName, File codePath, int uid, int pkgFlags,
                                 int pkgPrivateFlags, @NonNull UUID domainSetId) {
                                 int pkgPrivateFlags, @NonNull UUID domainSetId, boolean hasSharedUser) {
        PackageSetting p = mPackages.get(name);
        if (p != null) {
            if (p.getAppId() == uid) {
@@ -962,7 +963,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
        }
        p = new PackageSetting(name, realName, codePath, pkgFlags, pkgPrivateFlags, domainSetId)
                .setAppId(uid);
        if (mAppIds.registerExistingAppId(uid, p, name)) {
        if (mAppIds.registerExistingAppId(uid, p, name) || hasSharedUser) {
            mPackages.put(name, p);
            return p;
        }
@@ -4160,7 +4161,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
            } else if (appId > 0 || (appId == Process.INVALID_UID && isSdkLibrary
                    && Flags.disallowSdkLibsToBeApps())) {
                packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr),
                        appId, pkgFlags, pkgPrivateFlags, domainSetId);
                        appId, pkgFlags, pkgPrivateFlags, domainSetId, /* hasSharedUser= */ false);
                if (PackageManagerService.DEBUG_SETTINGS)
                    Log.i(PackageManagerService.TAG, "Reading package " + name + ": appId="
                            + appId + " pkg=" + packageSetting);
+1 −1
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) {
            null
        }
        whenever(mocks.settings.addPackageLPw(nullable(), nullable(), nullable(), nullable(),
                nullable(), nullable(), nullable())) {
                nullable(), nullable(), nullable(), nullable())) {
            val name: String = getArgument(0)
            val pendingAdd = mPendingPackageAdds.firstOrNull { it.first == name }
                    ?: return@whenever null