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

Commit 5067ae3d authored by Alan Stokes's avatar Alan Stokes
Browse files

Add more packages to Settings#mInstallerPackages.

We rely on this set to tell us if a package being uninstalled might be
mentioned in an InstallSource object so we can remove the dangling
references. We have code to correctly clean up initiating and
originating package names, but we need to add them to the set to make
sure that clean up is called.

Includes some light refactoring. As a happy side-effect, ensures that
the strings added to the set are all interned.

Test: atest PackageManagerTests PackageVerifierTest
Bug: 134746019
Bug: 146555198
Change-Id: Iffc08d94a5dc9cb8f0d1acbbcdbd6d1be1d69eb1
parent 53af5b24
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -13452,9 +13452,7 @@ public class PackageManagerService extends IPackageManager.Stub
            // Okay!
            targetPackageSetting.setInstallerPackageName(installerPackageName);
            if (installerPackageName != null) {
                mSettings.mInstallerPackages.add(installerPackageName);
            }
            mSettings.addInstallerPackageNames(targetPackageSetting.installSource);
            scheduleWriteSettingsLocked();
        }
    }
@@ -15160,7 +15158,8 @@ public class PackageManagerService extends IPackageManager.Stub
        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "updateSettings");
        final String pkgName = pkg.getPackageName();
        final String installerPackageName = installArgs.installSource.installerPackageName;
        final InstallSource installSource = installArgs.installSource;
        final String installerPackageName = installSource.installerPackageName;
        final int[] installedForUsers = res.origUsers;
        final int installReason = installArgs.installReason;
@@ -15171,7 +15170,7 @@ public class PackageManagerService extends IPackageManager.Stub
            // For system-bundled packages, we assume that installing an upgraded version
            // of the package implies that the user actually wants to run that new code,
            // so we enable the package.
            PackageSetting ps = mSettings.mPackages.get(pkgName);
            final PackageSetting ps = mSettings.mPackages.get(pkgName);
            final int userId = installArgs.user.getIdentifier();
            if (ps != null) {
                if (isSystemApp(pkg)) {
@@ -15208,8 +15207,8 @@ public class PackageManagerService extends IPackageManager.Stub
                    ps.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, userId, installerPackageName);
                }
                ps.setInstallSource(installArgs.installSource);
                ps.setInstallSource(installSource);
                mSettings.addInstallerPackageNames(installSource);
                // When replacing an existing package, preserve the original install reason for all
                // users that had the package installed before.
@@ -15239,7 +15238,6 @@ public class PackageManagerService extends IPackageManager.Stub
            res.name = pkgName;
            res.uid = pkg.getUid();
            res.pkg = pkg;
            mSettings.setInstallerPackageName(pkgName, installerPackageName);
            res.setReturnCode(PackageManager.INSTALL_SUCCEEDED);
            //to update install status
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "writeSettings");
+20 −16
Original line number Diff line number Diff line
@@ -280,8 +280,11 @@ public final class Settings {
    /** Map from package name to settings */
    final ArrayMap<String, PackageSetting> mPackages = new ArrayMap<>();

    /** List of packages that installed other packages */
    final ArraySet<String> mInstallerPackages = new ArraySet<>();
    /**
     * List of packages that were involved in installing other packages, i.e. are listed
     * in at least one app's InstallSource.
     */
    private final ArraySet<String> mInstallerPackages = new ArraySet<>();

    /** Map from package name to appId and excluded userids */
    private final ArrayMap<String, KernelPackageState> mKernelMapping = new ArrayMap<>();
@@ -441,16 +444,6 @@ public final class Settings {
        return mPermissions.canPropagatePermissionToInstantApp(permName);
    }

    void setInstallerPackageName(String pkgName, String installerPkgName) {
        PackageSetting p = mPackages.get(pkgName);
        if (p != null) {
            p.setInstallerPackageName(installerPkgName);
            if (installerPkgName != null) {
                mInstallerPackages.add(installerPkgName);
            }
        }
    }

    /** Gets and optionally creates a new shared user id. */
    SharedUserSetting getSharedUserLPw(String name, int pkgFlags, int pkgPrivateFlags,
            boolean create) throws PackageManagerException {
@@ -3777,9 +3770,10 @@ public final class Settings {
        }
        if (packageSetting != null) {
            packageSetting.uidError = "true".equals(uidError);
            packageSetting.installSource = InstallSource.create(
            InstallSource installSource = InstallSource.create(
                    installInitiatingPackageName, installOriginatingPackageName,
                    installerPackageName, "true".equals(isOrphaned));
            packageSetting.installSource = installSource;
            packageSetting.volumeUuid = volumeUuid;
            packageSetting.categoryHint = categoryHint;
            packageSetting.legacyNativeLibraryPathString = legacyNativeLibraryPathStr;
@@ -3809,9 +3803,7 @@ public final class Settings {
                packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null);
            }

            if (installerPackageName != null) {
                mInstallerPackages.add(installerPackageName);
            }
            addInstallerPackageNames(installSource);

            int outerDepth = parser.getDepth();
            int type;
@@ -3870,6 +3862,18 @@ public final class Settings {
        }
    }

    void addInstallerPackageNames(InstallSource installSource) {
        if (installSource.installerPackageName != null) {
            mInstallerPackages.add(installSource.installerPackageName);
        }
        if (installSource.initiatingPackageName != null) {
            mInstallerPackages.add(installSource.initiatingPackageName);
        }
        if (installSource.originatingPackageName != null) {
            mInstallerPackages.add(installSource.originatingPackageName);
        }
    }

    private void readDisabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser,
            int userId) throws IOException, XmlPullParserException {
        int outerDepth = parser.getDepth();