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

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

Merge "Cherry-pick changes 3496fd and 4ec026 to goog/master."

parents 35d9e569 612dc02f
Loading
Loading
Loading
Loading
+45 −23
Original line number Diff line number Diff line
@@ -7168,42 +7168,61 @@ public class PackageManagerService extends IPackageManager.Stub {
            pkgs = PackageManagerServiceUtils.getPackagesForDexopt(mPackages.values(), this);
        }
        int curr = 0;
        int total = pkgs.size();
        int numberOfPackagesVisited = 0;
        int numberOfPackagesOptimized = 0;
        int numberOfPackagesSkipped = 0;
        int numberOfPackagesFailed = 0;
        final int numberOfPackagesToDexopt = pkgs.size();
        final long startTime = System.nanoTime();
        for (PackageParser.Package pkg : pkgs) {
            curr++;
            numberOfPackagesVisited++;
            if (!PackageDexOptimizer.canOptimizePackage(pkg)) {
                if (DEBUG_DEXOPT) {
                    Log.i(TAG, "Skipping update of of non-optimizable app " + pkg.packageName);
                }
                numberOfPackagesSkipped++;
                continue;
            }
            if (DEBUG_DEXOPT) {
                Log.i(TAG, "Extracting app " + curr + " of " + total + ": " + pkg.packageName);
                Log.i(TAG, "Updating app " + numberOfPackagesVisited + " of " +
                        numberOfPackagesToDexopt + ": " + pkg.packageName);
            }
            if (mIsPreNUpgrade) {
                try {
                    ActivityManagerNative.getDefault().showBootMessage(
                            mContext.getResources().getString(R.string.android_upgrading_apk,
                                    curr, total), true);
                                    numberOfPackagesVisited, numberOfPackagesToDexopt), true);
                } catch (RemoteException e) {
                }
            }
            // checkProfiles is false to avoid merging profiles during boot which
            // might interfere with background compilation (b/28612421).
            // Unfortunately this will also means that "pm.dexopt.boot=speed-profile" will
            // behave differently than "pm.dexopt.bg-dexopt=speed-profile" but that's a
            // trade-off worth doing to save boot time work.
            performDexOpt(pkg.packageName,
            int dexOptStatus = performDexOptTraced(pkg.packageName,
                    null /* instructionSet */,
                    false /* checkProfiles */,
                    causeFirstBoot ? REASON_FIRST_BOOT : REASON_BOOT,
                    true /* checkProfiles */,
                    getCompilerFilterForReason(causeFirstBoot ? REASON_FIRST_BOOT : REASON_BOOT),
                    false /* force */);
            switch (dexOptStatus) {
                case PackageDexOptimizer.DEX_OPT_PERFORMED:
                    numberOfPackagesOptimized++;
                    break;
                case PackageDexOptimizer.DEX_OPT_SKIPPED:
                    numberOfPackagesSkipped++;
                    break;
                case PackageDexOptimizer.DEX_OPT_FAILED:
                    numberOfPackagesFailed++;
                    break;
                default:
                    Log.e(TAG, "Unexpected dexopt return code " + dexOptStatus);
                    break;
            }
        }
        final int elapsedTime = (int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        // TODO: Log events using MetricsLogger.histogram / MetricsLogger.count
    }
    @Override
@@ -7220,25 +7239,28 @@ public class PackageManagerService extends IPackageManager.Stub {
    // TODO: this is not used nor needed. Delete it.
    @Override
    public boolean performDexOptIfNeeded(String packageName, String instructionSet) {
        return performDexOptTraced(packageName, instructionSet, false /* checkProfiles */,
                getFullCompilerFilter(), false /* force */);
        int dexOptStatus = performDexOptTraced(packageName, instructionSet,
                false /* checkProfiles */, getFullCompilerFilter(), false /* force */);
        return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
    }
    @Override
    public boolean performDexOpt(String packageName, String instructionSet,
            boolean checkProfiles, int compileReason, boolean force) {
        return performDexOptTraced(packageName, instructionSet, checkProfiles,
        int dexOptStatus = performDexOptTraced(packageName, instructionSet, checkProfiles,
                getCompilerFilterForReason(compileReason), force);
        return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
    }
    @Override
    public boolean performDexOptMode(String packageName, String instructionSet,
            boolean checkProfiles, String targetCompilerFilter, boolean force) {
        return performDexOptTraced(packageName, instructionSet, checkProfiles,
        int dexOptStatus = performDexOptTraced(packageName, instructionSet, checkProfiles,
                targetCompilerFilter, force);
        return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
    }
    private boolean performDexOptTraced(String packageName, String instructionSet,
    private int performDexOptTraced(String packageName, String instructionSet,
                boolean checkProfiles, String targetCompilerFilter, boolean force) {
        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
        try {
@@ -7251,14 +7273,15 @@ public class PackageManagerService extends IPackageManager.Stub {
    // Run dexopt on a given package. Returns true if dexopt did not fail, i.e.
    // if the package can now be considered up to date for the given filter.
    private boolean performDexOptInternal(String packageName, String instructionSet,
    private int performDexOptInternal(String packageName, String instructionSet,
                boolean checkProfiles, String targetCompilerFilter, boolean force) {
        PackageParser.Package p;
        final String targetInstructionSet;
        synchronized (mPackages) {
            p = mPackages.get(packageName);
            if (p == null) {
                return false;
                // Package could not be found. Report failure.
                return PackageDexOptimizer.DEX_OPT_FAILED;
            }
            mPackageUsage.write(false);
@@ -7269,9 +7292,8 @@ public class PackageManagerService extends IPackageManager.Stub {
        try {
            synchronized (mInstallLock) {
                final String[] instructionSets = new String[] { targetInstructionSet };
                int result = performDexOptInternalWithDependenciesLI(p, instructionSets,
                        checkProfiles, targetCompilerFilter, force);
                return result != PackageDexOptimizer.DEX_OPT_FAILED;
                return performDexOptInternalWithDependenciesLI(p, instructionSets, checkProfiles,
                        targetCompilerFilter, force);
            }
        } finally {
            Binder.restoreCallingIdentity(callingId);