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

Commit ce543973 authored by Shubham Ajmera's avatar Shubham Ajmera
Browse files

Compile secondary dex at boot after OTA

Bug: 38413085
Test: build successful
Change-Id: If080281fb3147fea625bcafce91167e8c1439736
parent 08a18210
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -345,6 +345,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
@@ -9340,12 +9340,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;
@@ -9356,9 +9368,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,
@@ -9559,8 +9574,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,