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

Commit 30a23a5a authored by Todd Kennedy's avatar Todd Kennedy
Browse files

Remove scanPackageInternal()

The final, major refactoring for this release. Replace
scanPackageInternal() with addForInit(). This new method delegates
all modifications of the package setting object to the existing
scanPackageOnly() method.

There is one block of code where we modify the ApplicationInfo
object in the PackageParser.Package. It could be argued [and I would
agree] that the ApplicationInfo doesn't belong in the Pacakge
object at all. But, regardless, updating this info is being done
in addForInit(). It would be ideal if we could push this down to
scanPackageOnly(). Unfortunately, we expect the ApplicationInfo
to be updated correctly prior to scanPackageOnly().

Bug: 63539144
Test: Manual.
Test: w/ base image
Test: 1] upgrade OTA
Test: 2] clean flash
Test: w/ image containing additional applications
Test: 1] add a system application
Test: 2] add a system application w/ version installed on /data. version on /data has greater version code
Test: 3] add a system application w/ version installed on /data. version on /data has lower version code
Test: 4] add a system application w/ version installed on /data. version on /data has signature mis-match
Test: 5] remove a system application
Test: 6] remove a system application w/ upgrade installed on /data
Test: 7] update a system application
Test: 8] update a system application w/ upgrade installed on /data. version on /data has greater version code
Test: 9] update a system application w/ upgrade installed on /data. version on /data has lower version code
Change-Id: I00a6f1cd056d9e5ee81154a522b7d50ea9174273
parent 32308613
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -811,6 +811,8 @@ public class PackageParser {

    public static final int PARSE_MUST_BE_APK = 1 << 0;
    public static final int PARSE_IGNORE_PROCESSES = 1 << 1;
    /** @deprecated forward lock no longer functional. remove. */
    @Deprecated
    public static final int PARSE_FORWARD_LOCK = 1 << 2;
    public static final int PARSE_EXTERNAL_STORAGE = 1 << 3;
    public static final int PARSE_IS_SYSTEM_DIR = 1 << 4;
@@ -6001,6 +6003,8 @@ public class PackageParser {
            }
        }

        /** @deprecated Forward locked apps no longer supported. Resource path not needed. */
        @Deprecated
        public void setApplicationInfoResourcePath(String resourcePath) {
            this.applicationInfo.setResourcePath(resourcePath);
            if (childPackages != null) {
@@ -6011,6 +6015,8 @@ public class PackageParser {
            }
        }

        /** @deprecated Forward locked apps no longer supported. Resource path not needed. */
        @Deprecated
        public void setApplicationInfoBaseResourcePath(String resourcePath) {
            this.applicationInfo.setBaseResourcePath(resourcePath);
            if (childPackages != null) {
@@ -6059,6 +6065,8 @@ public class PackageParser {
            // Children have no splits
        }

        /** @deprecated Forward locked apps no longer supported. Resource path not needed. */
        @Deprecated
        public void setApplicationInfoSplitResourcePaths(String[] resroucePaths) {
            this.applicationInfo.setSplitResourcePaths(resroucePaths);
            // Children have no splits
+227 −274

File changed.

Preview size limit exceeded, changes collapsed.

+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.pm;

import android.content.pm.PackageParser;
import android.content.pm.Signature;
import android.content.pm.PackageParser.SigningDetails;
import android.os.Environment;
import android.util.Slog;
import android.util.Xml;
@@ -451,7 +452,8 @@ final class Policy {
    public String getMatchedSeInfo(PackageParser.Package pkg) {
        // Check for exact signature matches across all certs.
        Signature[] certs = mCerts.toArray(new Signature[0]);
        if (!Signature.areExactMatch(certs, pkg.mSigningDetails.signatures)) {
        if (pkg.mSigningDetails != SigningDetails.UNKNOWN
                && !Signature.areExactMatch(certs, pkg.mSigningDetails.signatures)) {
            return null;
        }

+45 −95
Original line number Diff line number Diff line
@@ -783,11 +783,12 @@ public final class Settings {
     */
    static void updatePackageSetting(@NonNull PackageSetting pkgSetting,
            @Nullable PackageSetting disabledPkg, @Nullable SharedUserSetting sharedUser,
            @NonNull File codePath, @Nullable String legacyNativeLibraryPath,
            @Nullable String primaryCpuAbi, @Nullable String secondaryCpuAbi,
            int pkgFlags, int pkgPrivateFlags, @Nullable List<String> childPkgNames,
            @NonNull UserManagerService userManager, @Nullable String[] usesStaticLibraries,
            @Nullable long[] usesStaticLibrariesVersions) throws PackageManagerException {
            @NonNull File codePath, File resourcePath,
            @Nullable String legacyNativeLibraryPath, @Nullable String primaryCpuAbi,
            @Nullable String secondaryCpuAbi, int pkgFlags, int pkgPrivateFlags,
            @Nullable List<String> childPkgNames, @NonNull UserManagerService userManager,
            @Nullable String[] usesStaticLibraries, @Nullable long[] usesStaticLibrariesVersions)
                    throws PackageManagerException {
        final String pkgName = pkgSetting.name;
        if (pkgSetting.sharedUser != sharedUser) {
            PackageManagerService.reportSettingsProblem(Log.WARN,
@@ -799,29 +800,19 @@ public final class Settings {
        }

        if (!pkgSetting.codePath.equals(codePath)) {
            // Check to see if its a disabled system app
            if ((pkgSetting.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                // This is an updated system app with versions in both system
                // and data partition. Just let the most recent version
                // take precedence.
                Slog.w(PackageManagerService.TAG,
                        "Trying to update system app code path from "
                        + pkgSetting.codePathString + " to " + codePath.toString());
            } else {
                // Just a change in the code path is not an issue, but
                // let's log a message about it.
            final boolean isSystem = pkgSetting.isSystem();
            Slog.i(PackageManagerService.TAG,
                        "Package " + pkgName + " codePath changed from "
                        + pkgSetting.codePath + " to " + codePath
                        + "; Retaining data and using new");

                // The owner user's installed flag is set false
                // when the application was installed by other user
                // and the installed flag is not updated
                // when the application is appended as system app later.
                if ((pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0
                        && disabledPkg == null) {
                    List<UserInfo> allUserInfos = getAllUsers(userManager);
                    "Update" + (isSystem ? " system" : "")
                    + " package " + pkgName
                    + " code path from " + pkgSetting.codePathString
                    + " to " + codePath.toString()
                    + "; Retain data and using new");
            if (!isSystem) {
                // The package isn't considered as installed if the application was
                // first installed by another user. Update the installed flag when the
                // application ever becomes part of the system.
                if ((pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0 && disabledPkg == null) {
                    final List<UserInfo> allUserInfos = getAllUsers(userManager);
                    if (allUserInfos != null) {
                        for (UserInfo userInfo : allUserInfos) {
                            pkgSetting.setInstalled(true, userInfo.id);
@@ -829,14 +820,24 @@ public final class Settings {
                    }
                }

                /*
                 * Since we've changed paths, we need to prefer the new
                 * native library path over the one stored in the
                 * package settings since we might have moved from
                 * internal to external storage or vice versa.
                 */
                // Since we've changed paths, prefer the new native library path over
                // the one stored in the package settings since we might have moved from
                // internal to external storage or vice versa.
                pkgSetting.legacyNativeLibraryPathString = legacyNativeLibraryPath;
            }
            pkgSetting.codePath = codePath;
            pkgSetting.codePathString = codePath.toString();
        }
        if (!pkgSetting.resourcePath.equals(resourcePath)) {
            final boolean isSystem = pkgSetting.isSystem();
            Slog.i(PackageManagerService.TAG,
                    "Update" + (isSystem ? " system" : "")
                    + " package " + pkgName
                    + " resource path from " + pkgSetting.resourcePathString
                    + " to " + resourcePath.toString()
                    + "; Retain data and using new");
            pkgSetting.resourcePath = resourcePath;
            pkgSetting.resourcePathString = resourcePath.toString();
        }
        // If what we are scanning is a system (and possibly privileged) package,
        // then make it so, regardless of whether it was previously installed only
@@ -853,13 +854,14 @@ public final class Settings {
        if (childPkgNames != null) {
            pkgSetting.childPackageNames = new ArrayList<>(childPkgNames);
        }
        if (usesStaticLibraries != null) {
            pkgSetting.usesStaticLibraries = Arrays.copyOf(usesStaticLibraries,
                    usesStaticLibraries.length);
        }
        if (usesStaticLibrariesVersions != null) {
            pkgSetting.usesStaticLibrariesVersions = Arrays.copyOf(usesStaticLibrariesVersions,
                    usesStaticLibrariesVersions.length);
        // Update static shared library dependencies if needed
        if (usesStaticLibraries != null && usesStaticLibrariesVersions != null
                && usesStaticLibraries.length == usesStaticLibrariesVersions.length) {
            pkgSetting.usesStaticLibraries = usesStaticLibraries;
            pkgSetting.usesStaticLibrariesVersions = usesStaticLibrariesVersions;
        } else {
            pkgSetting.usesStaticLibraries = null;
            pkgSetting.usesStaticLibrariesVersions = null;
        }
    }

@@ -912,70 +914,18 @@ public final class Settings {
                userId);
    }

    // TODO: Move to scanPackageOnlyLI() after verifying signatures are setup correctly
    // by that time.
    void insertPackageSettingLPw(PackageSetting p, PackageParser.Package pkg) {
        p.pkg = pkg;
        // pkg.mSetEnabled = p.getEnabled(userId);
        // pkg.mSetStopped = p.getStopped(userId);
        final String volumeUuid = pkg.applicationInfo.volumeUuid;
        final String codePath = pkg.applicationInfo.getCodePath();
        final String resourcePath = pkg.applicationInfo.getResourcePath();
        final String legacyNativeLibraryPath = pkg.applicationInfo.nativeLibraryRootDir;
        // Update volume if needed
        if (!Objects.equals(volumeUuid, p.volumeUuid)) {
            Slog.w(PackageManagerService.TAG, "Volume for " + p.pkg.packageName +
                    " changing from " + p.volumeUuid + " to " + volumeUuid);
            p.volumeUuid = volumeUuid;
        }
        // Update code path if needed
        if (!Objects.equals(codePath, p.codePathString)) {
            Slog.w(PackageManagerService.TAG, "Code path for " + p.pkg.packageName +
                    " changing from " + p.codePathString + " to " + codePath);
            p.codePath = new File(codePath);
            p.codePathString = codePath;
        }
        //Update resource path if needed
        if (!Objects.equals(resourcePath, p.resourcePathString)) {
            Slog.w(PackageManagerService.TAG, "Resource path for " + p.pkg.packageName +
                    " changing from " + p.resourcePathString + " to " + resourcePath);
            p.resourcePath = new File(resourcePath);
            p.resourcePathString = resourcePath;
        }
        // Update the native library paths if needed
        if (!Objects.equals(legacyNativeLibraryPath, p.legacyNativeLibraryPathString)) {
            p.legacyNativeLibraryPathString = legacyNativeLibraryPath;
        }

        // Update the required Cpu Abi
        p.primaryCpuAbiString = pkg.applicationInfo.primaryCpuAbi;
        p.secondaryCpuAbiString = pkg.applicationInfo.secondaryCpuAbi;
        p.cpuAbiOverrideString = pkg.cpuAbiOverride;
        // Update version code if needed
        if (pkg.getLongVersionCode() != p.versionCode) {
            p.versionCode = pkg.getLongVersionCode();
        }
        // Update signatures if needed.
        if (p.signatures.mSignatures == null) {
            p.signatures.assignSignatures(pkg.mSigningDetails);
        }
        // Update flags if needed.
        if (pkg.applicationInfo.flags != p.pkgFlags) {
            p.pkgFlags = pkg.applicationInfo.flags;
        }
        // If this app defines a shared user id initialize
        // the shared user signatures as well.
        if (p.sharedUser != null && p.sharedUser.signatures.mSignatures == null) {
            p.sharedUser.signatures.assignSignatures(pkg.mSigningDetails);
        }
        // Update static shared library dependencies if needed
        if (pkg.usesStaticLibraries != null && pkg.usesStaticLibrariesVersions != null
                && pkg.usesStaticLibraries.size() == pkg.usesStaticLibrariesVersions.length) {
            p.usesStaticLibraries = new String[pkg.usesStaticLibraries.size()];
            pkg.usesStaticLibraries.toArray(p.usesStaticLibraries);
            p.usesStaticLibrariesVersions = pkg.usesStaticLibrariesVersions;
        } else {
            p.usesStaticLibraries = null;
            p.usesStaticLibrariesVersions = null;
        }
        addPackageSettingLPw(p, p.sharedUser);
    }

+3 −0
Original line number Diff line number Diff line
@@ -294,6 +294,7 @@ public class PackageManagerSettingsTests {
                null /*disabledPkg*/,
                null /*sharedUser*/,
                UPDATED_CODE_PATH /*codePath*/,
                null /*resourcePath*/,
                null /*legacyNativeLibraryPath*/,
                "arm64-v8a" /*primaryCpuAbi*/,
                "armeabi" /*secondaryCpuAbi*/,
@@ -327,6 +328,7 @@ public class PackageManagerSettingsTests {
                null /*disabledPkg*/,
                null /*sharedUser*/,
                UPDATED_CODE_PATH /*codePath*/,
                null /*resourcePath*/,
                null /*legacyNativeLibraryPath*/,
                "arm64-v8a" /*primaryCpuAbi*/,
                "armeabi" /*secondaryCpuAbi*/,
@@ -367,6 +369,7 @@ public class PackageManagerSettingsTests {
                    null /*disabledPkg*/,
                    testUserSetting01 /*sharedUser*/,
                    UPDATED_CODE_PATH /*codePath*/,
                    null /*resourcePath*/,
                    null /*legacyNativeLibraryPath*/,
                    "arm64-v8a" /*primaryCpuAbi*/,
                    "armeabi" /*secondaryCpuAbi*/,