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

Commit caa1089c 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:4b32b0bd6876ecc25d60d95431763bf618699880
Merged-In: I417cec27697a210416027e862a5e5d207d268b82
Change-Id: I417cec27697a210416027e862a5e5d207d268b82
parent 921a0671
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -916,7 +916,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
        final AndroidPackageInternal pkg = p.getPkg();
        PackageSetting ret = addPackageLPw(name, p.getRealName(), p.getPath(), p.getAppId(),
                    p.getFlags(), p.getPrivateFlags(), mDomainVerificationManager.generateNewId(),
                pkg == null ? false : pkg.isSdkLibrary());
                    pkg == null ? false : pkg.isSdkLibrary(), p.hasSharedUser());
        if (ret != null) {
            ret.setLegacyNativeLibraryPath(p.getLegacyNativeLibraryPath());
            ret.setPrimaryCpuAbi(p.getPrimaryCpuAbiLegacy());
@@ -936,6 +936,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
            ret.setRestrictUpdateHash(p.getRestrictUpdateHash());
            ret.setScannedAsStoppedSystemApp(p.isScannedAsStoppedSystemApp());
            ret.setInstallSource(p.getInstallSource());
            ret.setSharedUserAppId(p.getSharedUserAppId());
        }
        mDisabledSysPackages.remove(name);
        return ret;
@@ -957,7 +958,8 @@ 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, boolean isSdkLibrary) {
            int pkgFlags, int pkgPrivateFlags, @NonNull UUID domainSetId, boolean isSdkLibrary,
            boolean hasSharedUser) {
        PackageSetting p = mPackages.get(name);
        if (p != null) {
            if (p.getAppId() == uid) {
@@ -970,7 +972,8 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
        p = new PackageSetting(name, realName, codePath, pkgFlags, pkgPrivateFlags, domainSetId)
                .setAppId(uid);
        if ((uid == Process.INVALID_UID && isSdkLibrary && Flags.disallowSdkLibsToBeApps())
                || mAppIds.registerExistingAppId(uid, p, name)) {
                || mAppIds.registerExistingAppId(uid, p, name)
                || hasSharedUser) {
            mPackages.put(name, p);
            return p;
        }
@@ -4265,7 +4268,8 @@ 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, isSdkLibrary);
                        appId, pkgFlags, pkgPrivateFlags, domainSetId, isSdkLibrary,
                        /* 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
@@ -167,7 +167,7 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) {
            null
        }
        whenever(mocks.settings.addPackageLPw(nullable(), nullable(), 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