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

Commit e523aa4f authored by Shubham Ajmera's avatar Shubham Ajmera Committed by Andreas Gampe
Browse files

Compile secondary dex at boot after OTA

(cherry picked from commit ce543973)

Bug: 38413085
Test: build successful
Merged-In: If080281fb3147fea625bcafce91167e8c1439736
Change-Id: If080281fb3147fea625bcafce91167e8c1439736
parent 1285cfd4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -321,6 +321,10 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
                mPackageManagerService.getDexManager().isUsedByOtherApps(pkg.packageName),
                true /* bootComplete */);

        mPackageManagerService.getDexManager().dexoptSecondaryDex(pkg.packageName,
                getCompilerFilterForReason(compilationReason),
                false /* force */,
                false /* compileOnlySharedDex */);
        return commands;
    }

+31 −16
Original line number Diff line number Diff line
@@ -9392,12 +9392,24 @@ public class PackageManagerService extends IPackageManager.Stub
            // 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.
            int dexOptStatus = performDexOptTraced(pkg.packageName,
            int primaryDexOptStaus = performDexOptTraced(pkg.packageName,
                    false /* checkProfiles */,
                    compilerFilter,
                    false /* force */,
                    bootComplete);
            switch (dexOptStatus) {
            boolean secondaryDexOptStatus = true;
            if (pkg.isSystemApp()) {
                // Only dexopt shared secondary dex files belonging to system apps to not slow down
                // too much boot after an OTA.
                secondaryDexOptStatus = mDexManager.dexoptSecondaryDex(pkg.packageName,
                        compilerFilter,
                        false /* force */,
                        true /* compileOnlySharedDex */);
            }
            if (secondaryDexOptStatus) {
                switch (primaryDexOptStaus) {
                    case PackageDexOptimizer.DEX_OPT_PERFORMED:
                        numberOfPackagesOptimized++;
                        break;
@@ -9408,9 +9420,12 @@ public class PackageManagerService extends IPackageManager.Stub
                        numberOfPackagesFailed++;
                        break;
                    default:
                    Log.e(TAG, "Unexpected dexopt return code " + dexOptStatus);
                        Log.e(TAG, "Unexpected dexopt return code " + primaryDexOptStaus);
                        break;
                }
            } else {
                numberOfPackagesFailed++;
            }
        }
        return new int[] { numberOfPackagesOptimized, numberOfPackagesSkipped,
@@ -9611,8 +9626,8 @@ public class PackageManagerService extends IPackageManager.Stub
        } else if (isInstantApp(packageName, UserHandle.getCallingUserId())) {
            return false;
        }
        mDexManager.reconcileSecondaryDexFiles(packageName);
        return mDexManager.dexoptSecondaryDex(packageName, compilerFilter, force);
        return mDexManager.dexoptSecondaryDex(packageName, compilerFilter, force,
                /* compileOnlySharedDex*/ false);
    }
    public boolean performDexOptSecondary(String packageName, int compileReason,
+6 −2
Original line number Diff line number Diff line
@@ -307,7 +307,7 @@ public class DexManager {
    public boolean dexoptSecondaryDex(String packageName, int compilerReason, boolean force) {
        return dexoptSecondaryDex(packageName,
                PackageManagerServiceCompilerMapping.getCompilerFilterForReason(compilerReason),
                force);
                force, /* compileOnlySharedDex */ false);
    }

    /**
@@ -315,7 +315,8 @@ public class DexManager {
     * @return true if all secondary dex files were processed successfully (compiled or skipped
     *         because they don't need to be compiled)..
     */
    public boolean dexoptSecondaryDex(String packageName, String compilerFilter, boolean force) {
    public boolean dexoptSecondaryDex(String packageName, String compilerFilter, boolean force,
            boolean compileOnlySharedDex) {
        // Select the dex optimizer based on the force parameter.
        // Forced compilation is done through ForcedUpdatePackageDexOptimizer which will adjust
        // the necessary dexopt flags to make sure that compilation is not skipped. This avoid
@@ -337,6 +338,9 @@ public class DexManager {
        for (Map.Entry<String, DexUseInfo> entry : useInfo.getDexUseInfoMap().entrySet()) {
            String dexPath = entry.getKey();
            DexUseInfo dexUseInfo = entry.getValue();
            if (compileOnlySharedDex && !dexUseInfo.isUsedByOtherApps()) {
                continue;
            }
            PackageInfo pkg = null;
            try {
                pkg = mPackageManager.getPackageInfo(packageName, /*flags*/0,