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

Commit 51368785 authored by Song Chun Fan's avatar Song Chun Fan Committed by Android Build Coastguard Worker
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:740256b41ba113708655f82dc5664291bf79edd0
Merged-In: I417cec27697a210416027e862a5e5d207d268b82
Change-Id: I417cec27697a210416027e862a5e5d207d268b82
parent 73ad07fe
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -917,7 +917,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());
@@ -937,6 +937,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;
@@ -958,7 +959,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) {
@@ -971,7 +973,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;
        }
@@ -4266,7 +4269,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
@@ -168,7 +168,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