Loading services/core/java/com/android/server/pm/BackgroundDexOptService.java +51 −37 Original line number Diff line number Diff line Loading @@ -281,20 +281,7 @@ public class BackgroundDexOptService extends JobService { mAbortIdleOptimization.set(false); long lowStorageThreshold = getLowStorageThreshold(context); // Optimize primary apks. int result = optimizePackages(pm, pkgs, lowStorageThreshold, /*isForPrimaryDex=*/ true); if (result == OPTIMIZE_ABORT_BY_JOB_SCHEDULER) { return result; } if (supportSecondaryDex()) { result = reconcileSecondaryDexFiles(pm.getDexManager()); if (result == OPTIMIZE_ABORT_BY_JOB_SCHEDULER) { return result; } result = optimizePackages(pm, pkgs, lowStorageThreshold, /*isForPrimaryDex=*/ false); } int result = idleOptimizePackages(pm, pkgs, lowStorageThreshold); return result; } Loading Loading @@ -342,11 +329,20 @@ public class BackgroundDexOptService extends JobService { return 0; } private int optimizePackages(PackageManagerService pm, ArraySet<String> pkgs, long lowStorageThreshold, boolean isForPrimaryDex) { private int idleOptimizePackages(PackageManagerService pm, ArraySet<String> pkgs, long lowStorageThreshold) { ArraySet<String> updatedPackages = new ArraySet<>(); try { final boolean supportSecondaryDex = supportSecondaryDex(); if (supportSecondaryDex) { int result = reconcileSecondaryDexFiles(pm.getDexManager()); if (result == OPTIMIZE_ABORT_BY_JOB_SCHEDULER) { return result; } } // Only downgrade apps when space is low on device. // Threshold is selected above the lowStorageThreshold so that we can pro-actively clean // up disk before user hits the actual lowStorageThreshold. Loading @@ -359,23 +355,47 @@ public class BackgroundDexOptService extends JobService { pm.getUnusedPackages(mDowngradeUnusedAppsThresholdInMillis); Log.d(TAG, "Unsused Packages " + String.join(",", unusedPackages)); if (!unusedPackages.isEmpty()) { for (String pkg : unusedPackages) { int abortCode = abortIdleOptimizations(/*lowStorageThreshold*/ -1); if (abortCode != OPTIMIZE_CONTINUE) { // Should be aborted by the scheduler. return abortCode; } if (downgradePackage(pm, pkg, isForPrimaryDex)) { if (downgradePackage(pm, pkg, /*isForPrimaryDex*/ true)) { updatedPackages.add(pkg); } if (supportSecondaryDex) { downgradePackage(pm, pkg, /*isForPrimaryDex*/ false); } } if (!unusedPackages.isEmpty()) { pkgs = new ArraySet<>(pkgs); pkgs.removeAll(unusedPackages); } } int primaryResult = optimizePackages(pm, pkgs, lowStorageThreshold, /*isForPrimaryDex*/ true, updatedPackages); if (primaryResult != OPTIMIZE_PROCESSED) { return primaryResult; } if (!supportSecondaryDex) { return OPTIMIZE_PROCESSED; } int secondaryResult = optimizePackages(pm, pkgs, lowStorageThreshold, /*isForPrimaryDex*/ false, updatedPackages); return secondaryResult; } finally { // Always let the pinner service know about changes. notifyPinService(updatedPackages); } } private int optimizePackages(PackageManagerService pm, ArraySet<String> pkgs, long lowStorageThreshold, boolean isForPrimaryDex, ArraySet<String> updatedPackages) { for (String pkg : pkgs) { int abortCode = abortIdleOptimizations(lowStorageThreshold); if (abortCode != OPTIMIZE_CONTINUE) { Loading @@ -388,14 +408,8 @@ public class BackgroundDexOptService extends JobService { updatedPackages.add(pkg); } } return OPTIMIZE_PROCESSED; } finally { // Always let the pinner service know about changes. notifyPinService(updatedPackages); } } /** * Try to downgrade the package to a smaller compilation filter. Loading Loading
services/core/java/com/android/server/pm/BackgroundDexOptService.java +51 −37 Original line number Diff line number Diff line Loading @@ -281,20 +281,7 @@ public class BackgroundDexOptService extends JobService { mAbortIdleOptimization.set(false); long lowStorageThreshold = getLowStorageThreshold(context); // Optimize primary apks. int result = optimizePackages(pm, pkgs, lowStorageThreshold, /*isForPrimaryDex=*/ true); if (result == OPTIMIZE_ABORT_BY_JOB_SCHEDULER) { return result; } if (supportSecondaryDex()) { result = reconcileSecondaryDexFiles(pm.getDexManager()); if (result == OPTIMIZE_ABORT_BY_JOB_SCHEDULER) { return result; } result = optimizePackages(pm, pkgs, lowStorageThreshold, /*isForPrimaryDex=*/ false); } int result = idleOptimizePackages(pm, pkgs, lowStorageThreshold); return result; } Loading Loading @@ -342,11 +329,20 @@ public class BackgroundDexOptService extends JobService { return 0; } private int optimizePackages(PackageManagerService pm, ArraySet<String> pkgs, long lowStorageThreshold, boolean isForPrimaryDex) { private int idleOptimizePackages(PackageManagerService pm, ArraySet<String> pkgs, long lowStorageThreshold) { ArraySet<String> updatedPackages = new ArraySet<>(); try { final boolean supportSecondaryDex = supportSecondaryDex(); if (supportSecondaryDex) { int result = reconcileSecondaryDexFiles(pm.getDexManager()); if (result == OPTIMIZE_ABORT_BY_JOB_SCHEDULER) { return result; } } // Only downgrade apps when space is low on device. // Threshold is selected above the lowStorageThreshold so that we can pro-actively clean // up disk before user hits the actual lowStorageThreshold. Loading @@ -359,23 +355,47 @@ public class BackgroundDexOptService extends JobService { pm.getUnusedPackages(mDowngradeUnusedAppsThresholdInMillis); Log.d(TAG, "Unsused Packages " + String.join(",", unusedPackages)); if (!unusedPackages.isEmpty()) { for (String pkg : unusedPackages) { int abortCode = abortIdleOptimizations(/*lowStorageThreshold*/ -1); if (abortCode != OPTIMIZE_CONTINUE) { // Should be aborted by the scheduler. return abortCode; } if (downgradePackage(pm, pkg, isForPrimaryDex)) { if (downgradePackage(pm, pkg, /*isForPrimaryDex*/ true)) { updatedPackages.add(pkg); } if (supportSecondaryDex) { downgradePackage(pm, pkg, /*isForPrimaryDex*/ false); } } if (!unusedPackages.isEmpty()) { pkgs = new ArraySet<>(pkgs); pkgs.removeAll(unusedPackages); } } int primaryResult = optimizePackages(pm, pkgs, lowStorageThreshold, /*isForPrimaryDex*/ true, updatedPackages); if (primaryResult != OPTIMIZE_PROCESSED) { return primaryResult; } if (!supportSecondaryDex) { return OPTIMIZE_PROCESSED; } int secondaryResult = optimizePackages(pm, pkgs, lowStorageThreshold, /*isForPrimaryDex*/ false, updatedPackages); return secondaryResult; } finally { // Always let the pinner service know about changes. notifyPinService(updatedPackages); } } private int optimizePackages(PackageManagerService pm, ArraySet<String> pkgs, long lowStorageThreshold, boolean isForPrimaryDex, ArraySet<String> updatedPackages) { for (String pkg : pkgs) { int abortCode = abortIdleOptimizations(lowStorageThreshold); if (abortCode != OPTIMIZE_CONTINUE) { Loading @@ -388,14 +408,8 @@ public class BackgroundDexOptService extends JobService { updatedPackages.add(pkg); } } return OPTIMIZE_PROCESSED; } finally { // Always let the pinner service know about changes. notifyPinService(updatedPackages); } } /** * Try to downgrade the package to a smaller compilation filter. Loading