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

Commit ace80c56 authored by David Brazdil's avatar David Brazdil
Browse files

Retry compiling a previously failing package after update

BackgroundDexOptimizer (BDOS) keeps a list of packages it attempted
to compile but dexopt failed. Once such a package is put on the list,
it is never removed from it until reboot.

This CL modifies BDOS to accept notificiations from
PackageManagerService on recently installed packages and removes
their names from the list.

Bug: 28082762
Change-Id: I0c3d3f657bd3ff5f0a61dfeef1d8174ed7be0b74
parent 726959bf
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -89,6 +89,15 @@ public class BackgroundDexOptService extends JobService {
        }
    }

    public static void notifyPackageChanged(String packageName) {
        // The idle maintanance job skips packages which previously failed to
        // compile. The given package has changed and may successfully compile
        // now. Remove it from the list of known failing packages.
        synchronized (sFailedPackageNames) {
            sFailedPackageNames.remove(packageName);
        }
    }

    // Returns the current battery level as a 0-100 integer.
    private int getBatteryLevel() {
        IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
@@ -170,7 +179,9 @@ public class BackgroundDexOptService extends JobService {
                    }
                    // Conservatively add package to the list of failing ones in case performDexOpt
                    // never returns.
                    synchronized (sFailedPackageNames) {
                        sFailedPackageNames.add(pkg);
                    }
                    // Optimize package if needed. Note that there can be no race between
                    // concurrent jobs because PackageDexOptimizer.performDexOpt is synchronized.
                    if (pm.performDexOpt(pkg,
@@ -179,9 +190,11 @@ public class BackgroundDexOptService extends JobService {
                            PackageManagerService.REASON_BACKGROUND_DEXOPT,
                            /* force */ false)) {
                        // Dexopt succeeded, remove package from the list of failing ones.
                        synchronized (sFailedPackageNames) {
                            sFailedPackageNames.remove(pkg);
                        }
                    }
                }
                // Ran to completion, so we abandon our timeslice and do not reschedule.
                jobFinished(jobParams, /* reschedule */ false);
            }
+6 −2
Original line number Diff line number Diff line
@@ -14516,7 +14516,6 @@ public class PackageManagerService extends IPackageManager.Stub {
                return;
            }
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
            // Do not run PackageDexOptimizer through the local performDexOpt
            // method because `pkg` is not in `mPackages` yet.
@@ -14524,10 +14523,15 @@ public class PackageManagerService extends IPackageManager.Stub {
                    false /* checkProfiles */, getCompilerFilterForReason(REASON_INSTALL));
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            if (result == PackageDexOptimizer.DEX_OPT_FAILED) {
                String msg = "Extracking package failed for " + pkgName;
                String msg = "Extracting package failed for " + pkgName;
                res.setError(INSTALL_FAILED_DEXOPT, msg);
                return;
            }
            // Notify BackgroundDexOptService that the package has been changed.
            // If this is an update of a package which used to fail to compile,
            // BDOS will remove it from its blacklist.
            BackgroundDexOptService.notifyPackageChanged(pkg.packageName);
        }
        if (!args.doRename(res.returnCode, pkg, oldCodePath)) {