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

Commit d8e13ad5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update libraries on install"

parents 2a127a77 5f619df3
Loading
Loading
Loading
Loading
+93 −60
Original line number Original line Diff line number Diff line
@@ -2971,7 +2971,7 @@ public class PackageManagerService extends IPackageManager.Stub
            // Now that we know all of the shared libraries, update all clients to have
            // Now that we know all of the shared libraries, update all clients to have
            // the correct library paths.
            // the correct library paths.
            updateAllSharedLibrariesLPw(null);
            updateAllSharedLibrariesLocked(null, Collections.unmodifiableMap(mPackages));
            for (SharedUserSetting setting : mSettings.getAllSharedUsersLPw()) {
            for (SharedUserSetting setting : mSettings.getAllSharedUsersLPw()) {
                // NOTE: We ignore potential failures here during a system scan (like
                // NOTE: We ignore potential failures here during a system scan (like
@@ -10022,11 +10022,11 @@ public class PackageManagerService extends IPackageManager.Stub
    }
    }
    @GuardedBy("mPackages")
    @GuardedBy("mPackages")
    private void updateSharedLibrariesLPr(PackageParser.Package pkg,
    private void updateSharedLibrariesLocked(PackageParser.Package pkg,
            PackageParser.Package changingLib) throws PackageManagerException {
            PackageParser.Package changingLib, Map<String, PackageParser.Package> availablePackages)
                    throws PackageManagerException {
        final ArrayList<SharedLibraryInfo> sharedLibraryInfos =
        final ArrayList<SharedLibraryInfo> sharedLibraryInfos =
                collectSharedLibraryInfos(pkg, Collections.unmodifiableMap(mPackages),
                collectSharedLibraryInfos(pkg, availablePackages, mSharedLibraries, null);
                        mSharedLibraries, null);
        executeSharedLibrariesUpdateLPr(pkg, changingLib, sharedLibraryInfos);
        executeSharedLibrariesUpdateLPr(pkg, changingLib, sharedLibraryInfos);
    }
    }
@@ -10118,7 +10118,6 @@ public class PackageManagerService extends IPackageManager.Stub
                                    + " library " + libName + " version "
                                    + " library " + libName + " version "
                                    + libraryInfo.getLongVersion() + "; failing!");
                                    + libraryInfo.getLongVersion() + "; failing!");
                    }
                    }
                    PackageParser.Package libPkg =
                    PackageParser.Package libPkg =
                            availablePackages.get(libraryInfo.getPackageName());
                            availablePackages.get(libraryInfo.getPackageName());
                    if (libPkg == null) {
                    if (libPkg == null) {
@@ -10126,12 +10125,8 @@ public class PackageManagerService extends IPackageManager.Stub
                                "Package " + packageName + " requires unavailable static shared"
                                "Package " + packageName + " requires unavailable static shared"
                                        + " library; failing!");
                                        + " library; failing!");
                    }
                    }
                    final String[] expectedCertDigests = requiredCertDigests[i];
                    final String[] expectedCertDigests = requiredCertDigests[i];
                    if (expectedCertDigests.length > 1) {
                    if (expectedCertDigests.length > 1) {
                        // For apps targeting O MR1 we require explicit enumeration of all certs.
                        // For apps targeting O MR1 we require explicit enumeration of all certs.
                        final String[] libCertDigests = (targetSdk >= Build.VERSION_CODES.O_MR1)
                        final String[] libCertDigests = (targetSdk >= Build.VERSION_CODES.O_MR1)
                                ? PackageUtils.computeSignaturesSha256Digests(
                                ? PackageUtils.computeSignaturesSha256Digests(
@@ -10163,7 +10158,6 @@ public class PackageManagerService extends IPackageManager.Stub
                            }
                            }
                        }
                        }
                    } else {
                    } else {
                        // lib signing cert could have rotated beyond the one expected, check to see
                        // lib signing cert could have rotated beyond the one expected, check to see
                        // if the new one has been blessed by the old
                        // if the new one has been blessed by the old
                        if (!libPkg.mSigningDetails.hasSha256Certificate(
                        if (!libPkg.mSigningDetails.hasSha256Certificate(
@@ -10175,7 +10169,6 @@ public class PackageManagerService extends IPackageManager.Stub
                        }
                        }
                    }
                    }
                }
                }
                if (outUsedLibraries == null) {
                if (outUsedLibraries == null) {
                    outUsedLibraries = new ArrayList<>();
                    outUsedLibraries = new ArrayList<>();
                }
                }
@@ -10186,7 +10179,7 @@ public class PackageManagerService extends IPackageManager.Stub
    }
    }
    private static boolean hasString(List<String> list, List<String> which) {
    private static boolean hasString(List<String> list, List<String> which) {
        if (list == null) {
        if (list == null || which == null) {
            return false;
            return false;
        }
        }
        for (int i=list.size()-1; i>=0; i--) {
        for (int i=list.size()-1; i>=0; i--) {
@@ -10200,23 +10193,46 @@ public class PackageManagerService extends IPackageManager.Stub
    }
    }
    @GuardedBy("mPackages")
    @GuardedBy("mPackages")
    private ArrayList<PackageParser.Package> updateAllSharedLibrariesLPw(
    private ArrayList<PackageParser.Package> updateAllSharedLibrariesLocked(
            PackageParser.Package changingPkg) {
            PackageParser.Package updatedPkg,
        ArrayList<PackageParser.Package> res = null;
            Map<String, PackageParser.Package> availablePackages) {
        for (PackageParser.Package pkg : mPackages.values()) {
        ArrayList<PackageParser.Package> resultList = null;
        // Set of all descendants of a library; used to eliminate cycles
        ArraySet<String> descendants = null;
        // The current list of packages that need updating
        ArrayList<PackageParser.Package> needsUpdating = null;
        if (updatedPkg != null) {
            needsUpdating = new ArrayList<>(1);
            needsUpdating.add(updatedPkg);
        }
        do {
            final PackageParser.Package changingPkg =
                    (needsUpdating == null) ? null : needsUpdating.remove(0);
            for (int i = mPackages.size() - 1; i >= 0; --i) {
                final PackageParser.Package pkg = mPackages.valueAt(i);
                if (changingPkg != null
                if (changingPkg != null
                        && !hasString(pkg.usesLibraries, changingPkg.libraryNames)
                        && !hasString(pkg.usesLibraries, changingPkg.libraryNames)
                        && !hasString(pkg.usesOptionalLibraries, changingPkg.libraryNames)
                        && !hasString(pkg.usesOptionalLibraries, changingPkg.libraryNames)
                        && !ArrayUtils.contains(pkg.usesStaticLibraries,
                        && !ArrayUtils.contains(pkg.usesStaticLibraries,
                                changingPkg.staticSharedLibName)) {
                                changingPkg.staticSharedLibName)) {
                return null;
                    continue;
                }
                if (resultList == null) {
                    resultList = new ArrayList<>();
                }
                resultList.add(pkg);
                // if we're updating a shared library, all of its descendants must be updated
                if (changingPkg != null) {
                    if (descendants == null) {
                        descendants = new ArraySet<>();
                    }
                    if (!descendants.contains(pkg.packageName)) {
                        descendants.add(pkg.packageName);
                        needsUpdating.add(pkg);
                    }
                    }
            if (res == null) {
                res = new ArrayList<>();
                }
                }
            res.add(pkg);
                try {
                try {
                updateSharedLibrariesLPr(pkg, changingPkg);
                    updateSharedLibrariesLocked(pkg, changingPkg, availablePackages);
                } catch (PackageManagerException e) {
                } catch (PackageManagerException e) {
                    // If a system app update or an app and a required lib missing we
                    // If a system app update or an app and a required lib missing we
                    // delete the package and for updated system apps keep the data as
                    // delete the package and for updated system apps keep the data as
@@ -10232,7 +10248,8 @@ public class PackageManagerService extends IPackageManager.Stub
                    Slog.e(TAG, "updateAllSharedLibrariesLPw failed: " + e.getMessage());
                    Slog.e(TAG, "updateAllSharedLibrariesLPw failed: " + e.getMessage());
                }
                }
            }
            }
        return res;
        } while (needsUpdating != null && needsUpdating.size() > 0);
        return resultList;
    }
    }
    @GuardedBy({"mInstallLock", "mPackages"})
    @GuardedBy({"mInstallLock", "mPackages"})
@@ -11654,19 +11671,19 @@ public class PackageManagerService extends IPackageManager.Stub
                for (SharedLibraryInfo info : reconciledPkg.allowedSharedLibraryInfos) {
                for (SharedLibraryInfo info : reconciledPkg.allowedSharedLibraryInfos) {
                    commitSharedLibraryInfoLocked(info);
                    commitSharedLibraryInfoLocked(info);
                }
                }
                final Map<String, PackageParser.Package> combinedPackages =
                        reconciledPkg.getCombinedPackages();
                try {
                try {
                    // Shared libraries for the package need to be updated.
                    // Shared libraries for the package need to be updated.
                    updateSharedLibrariesLPr(pkg, null);
                    updateSharedLibrariesLocked(pkg, null, combinedPackages);
                } catch (PackageManagerException e) {
                } catch (PackageManagerException e) {
                    Slog.e(TAG, "updateSharedLibrariesLPr failed: ", e);
                    Slog.e(TAG, "updateSharedLibrariesLPr failed: ", e);
                }
                }
                // Update all applications that use this library. Skip when booting
                // since this will be done after all packages are scaned.
                if ((scanFlags & SCAN_BOOTING) == 0) {
                    clientLibPkgs = updateAllSharedLibrariesLocked(pkg, combinedPackages);
                }
                }
            if (reconciledPkg.hasDynamicSharedLibraries() && (scanFlags & SCAN_BOOTING) == 0) {
                // If we are not booting, we need to update any applications
                // that are clients of our shared library.  If we are booting,
                // this will all be done once the scan is complete.
                clientLibPkgs = updateAllSharedLibrariesLPw(pkg);
            }
            }
        }
        }
@@ -15755,6 +15772,7 @@ public class PackageManagerService extends IPackageManager.Stub
     * TODO: move most of the data contained her into a PackageSetting for commit.
     * TODO: move most of the data contained her into a PackageSetting for commit.
     */
     */
    private static class ReconciledPackage {
    private static class ReconciledPackage {
        public final ReconcileRequest request;
        public final PackageSetting pkgSetting;
        public final PackageSetting pkgSetting;
        public final ScanResult scanResult;
        public final ScanResult scanResult;
        // TODO: Remove install-specific details from the reconcile result
        // TODO: Remove install-specific details from the reconcile result
@@ -15768,14 +15786,18 @@ public class PackageManagerService extends IPackageManager.Stub
        public ArrayList<SharedLibraryInfo> collectedSharedLibraryInfos;
        public ArrayList<SharedLibraryInfo> collectedSharedLibraryInfos;
        public final boolean removeAppKeySetData;
        public final boolean removeAppKeySetData;
        private ReconciledPackage(InstallArgs installArgs, PackageSetting pkgSetting,
        private ReconciledPackage(ReconcileRequest request,
                InstallArgs installArgs,
                PackageSetting pkgSetting,
                PackageInstalledInfo installResult,
                PackageInstalledInfo installResult,
                PrepareResult prepareResult, ScanResult scanResult,
                PrepareResult prepareResult,
                ScanResult scanResult,
                DeletePackageAction deletePackageAction,
                DeletePackageAction deletePackageAction,
                List<SharedLibraryInfo> allowedSharedLibraryInfos,
                List<SharedLibraryInfo> allowedSharedLibraryInfos,
                SigningDetails signingDetails,
                SigningDetails signingDetails,
                boolean sharedUserSignaturesChanged,
                boolean sharedUserSignaturesChanged,
                boolean removeAppKeySetData) {
                boolean removeAppKeySetData) {
            this.request = request;
            this.installArgs = installArgs;
            this.installArgs = installArgs;
            this.pkgSetting = pkgSetting;
            this.pkgSetting = pkgSetting;
            this.installResult = installResult;
            this.installResult = installResult;
@@ -15788,9 +15810,20 @@ public class PackageManagerService extends IPackageManager.Stub
            this.removeAppKeySetData = removeAppKeySetData;
            this.removeAppKeySetData = removeAppKeySetData;
        }
        }
        public boolean hasDynamicSharedLibraries() {
        /**
            return !ArrayUtils.isEmpty(allowedSharedLibraryInfos)
         * Returns a combined set of packages containing the packages already installed combined
                    && allowedSharedLibraryInfos.get(0).getType() != SharedLibraryInfo.TYPE_STATIC;
         * with the package(s) currently being installed. The to-be installed packages take
         * precedence and may shadow already installed packages.
         */
        private Map<String, PackageParser.Package> getCombinedPackages() {
            final ArrayMap<String, PackageParser.Package> combinedPackages =
                    new ArrayMap<>(request.allPackages.size() + request.scannedPackages.size());
            combinedPackages.putAll(request.allPackages);
            for (ScanResult scanResult : request.scannedPackages.values()) {
                combinedPackages.put(scanResult.pkgSetting.name, scanResult.request.pkg);
            }
            return combinedPackages;
        }
        }
    }
    }
@@ -15980,7 +16013,7 @@ public class PackageManagerService extends IPackageManager.Stub
            }
            }
            result.put(installPackageName,
            result.put(installPackageName,
                    new ReconciledPackage(installArgs, scanResult.pkgSetting,
                    new ReconciledPackage(request, installArgs, scanResult.pkgSetting,
                            res, request.preparedPackages.get(installPackageName), scanResult,
                            res, request.preparedPackages.get(installPackageName), scanResult,
                            deletePackageAction, allowedSharedLibInfos, signingDetails,
                            deletePackageAction, allowedSharedLibInfos, signingDetails,
                            sharedUserSignaturesChanged, removeAppKeySetData));
                            sharedUserSignaturesChanged, removeAppKeySetData));
@@ -18415,7 +18448,7 @@ public class PackageManagerService extends IPackageManager.Stub
        try {
        try {
            // update shared libraries for the newly re-installed system package
            // update shared libraries for the newly re-installed system package
            updateSharedLibrariesLPr(pkg, null);
            updateSharedLibrariesLocked(pkg, null, Collections.unmodifiableMap(mPackages));
        } catch (PackageManagerException e) {
        } catch (PackageManagerException e) {
            Slog.e(TAG, "updateAllSharedLibrariesLPw failed: " + e.getMessage());
            Slog.e(TAG, "updateAllSharedLibrariesLPw failed: " + e.getMessage());
        }
        }
@@ -20489,7 +20522,7 @@ public class PackageManagerService extends IPackageManager.Stub
                        prepareAppDataAfterInstallLIF(pkg);
                        prepareAppDataAfterInstallLIF(pkg);
                        synchronized (mPackages) {
                        synchronized (mPackages) {
                            try {
                            try {
                                updateSharedLibrariesLPr(pkg, null);
                                updateSharedLibrariesLocked(pkg, null, mPackages);
                            } catch (PackageManagerException e) {
                            } catch (PackageManagerException e) {
                                Slog.e(TAG, "updateAllSharedLibrariesLPw failed: ", e);
                                Slog.e(TAG, "updateAllSharedLibrariesLPw failed: ", e);
                            }
                            }