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

Commit ac4ca45f authored by Jiakai Zhang's avatar Jiakai Zhang
Browse files

Optimize primary and secondary dex’es together.

Bug: 218666049
Test: atest FrameworksMockingServicesTests:BackgroundDexOptServiceUnitTest
Change-Id: I1caf66f40c6dd7ef2675ac3b82cd6548dc96e595
parent 043872eb
Loading
Loading
Loading
Loading
+20 −20
Original line number Diff line number Diff line
@@ -585,7 +585,6 @@ public final class BackgroundDexOptService {
    private int idleOptimizePackages(PackageManagerService pm, List<String> pkgs,
            long lowStorageThreshold, boolean isPostBootUpdate) {
        ArraySet<String> updatedPackages = new ArraySet<>();
        ArraySet<String> updatedPackagesDueToSecondaryDex = new ArraySet<>();

        try {
            boolean supportSecondaryDex = mInjector.supportSecondaryDex();
@@ -646,20 +645,7 @@ public final class BackgroundDexOptService {
                }
            }

            @Status int primaryResult = optimizePackages(pkgs, lowStorageThreshold,
                    /*isForPrimaryDex=*/ true, updatedPackages, isPostBootUpdate);
            if (primaryResult != STATUS_OK) {
                return primaryResult;
            }

            if (!supportSecondaryDex) {
                return STATUS_OK;
            }

            @Status int secondaryResult = optimizePackages(pkgs, lowStorageThreshold,
                    /*isForPrimaryDex*/ false, updatedPackagesDueToSecondaryDex,
                    isPostBootUpdate);
            return secondaryResult;
            return optimizePackages(pkgs, lowStorageThreshold, updatedPackages, isPostBootUpdate);
        } finally {
            // Always let the pinner service know about changes.
            notifyPinService(updatedPackages);
@@ -672,7 +658,9 @@ public final class BackgroundDexOptService {

    @Status
    private int optimizePackages(List<String> pkgs, long lowStorageThreshold,
            boolean isForPrimaryDex, ArraySet<String> updatedPackages, boolean isPostBootUpdate) {
            ArraySet<String> updatedPackages, boolean isPostBootUpdate) {
        boolean supportSecondaryDex = mInjector.supportSecondaryDex();

        for (String pkg : pkgs) {
            int abortCode = abortIdleOptimizations(lowStorageThreshold);
            if (abortCode != STATUS_OK) {
@@ -680,11 +668,23 @@ public final class BackgroundDexOptService {
                return abortCode;
            }

            @DexOptResult int result = optimizePackage(pkg, isForPrimaryDex, isPostBootUpdate);
            if (result == PackageDexOptimizer.DEX_OPT_PERFORMED) {
            @DexOptResult int primaryResult =
                    optimizePackage(pkg, true /* isForPrimaryDex */, isPostBootUpdate);
            if (primaryResult == PackageDexOptimizer.DEX_OPT_PERFORMED) {
                updatedPackages.add(pkg);
            } else if (result != PackageDexOptimizer.DEX_OPT_SKIPPED) {
                return convertPackageDexOptimizerStatusToInternal(result);
            } else if (primaryResult != PackageDexOptimizer.DEX_OPT_SKIPPED) {
                return convertPackageDexOptimizerStatusToInternal(primaryResult);
            }

            if (!supportSecondaryDex) {
                continue;
            }

            @DexOptResult int secondaryResult =
                    optimizePackage(pkg, false /* isForPrimaryDex */, isPostBootUpdate);
            if (secondaryResult != PackageDexOptimizer.DEX_OPT_PERFORMED
                    && secondaryResult != PackageDexOptimizer.DEX_OPT_SKIPPED) {
                return convertPackageDexOptimizerStatusToInternal(secondaryResult);
            }
        }
        return STATUS_OK;
+4 −0
Original line number Diff line number Diff line
@@ -115,9 +115,11 @@ public final class BackgroundDexOptServiceUnitTest {
        when(mInjector.getDataDirStorageLowBytes()).thenReturn(STORAGE_LOW_BYTES);
        when(mInjector.getDexOptThermalCutoff()).thenReturn(PowerManager.THERMAL_STATUS_CRITICAL);
        when(mInjector.getCurrentThermalStatus()).thenReturn(PowerManager.THERMAL_STATUS_NONE);
        when(mInjector.supportSecondaryDex()).thenReturn(true);
        when(mDexOptHelper.getOptimizablePackages(any())).thenReturn(DEFAULT_PACKAGE_LIST);
        when(mDexOptHelper.performDexOptWithStatus(any())).thenReturn(
                PackageDexOptimizer.DEX_OPT_PERFORMED);
        when(mDexOptHelper.performDexOpt(any())).thenReturn(true);

        mService = new BackgroundDexOptService(mInjector);
    }
@@ -423,6 +425,8 @@ public final class BackgroundDexOptServiceUnitTest {
            for (String pkg : pkgs) {
                inOrder.verify(mDexOptHelper, times(1)).performDexOptWithStatus(argThat((option) ->
                        option.getPackageName().equals(pkg) && !option.isDexoptOnlySecondaryDex()));
                inOrder.verify(mDexOptHelper, times(1)).performDexOpt(argThat((option) ->
                        option.getPackageName().equals(pkg) && option.isDexoptOnlySecondaryDex()));
            }
        }
    }