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

Commit 1d892dcb authored by Jeff Hao's avatar Jeff Hao
Browse files

Stop boot dexopt when low on memory.

Bug: 17641843
Change-Id: Ie1967fc2cd9bdd258bfee442968f98200edaf62e
parent 2bb933a5
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -4538,14 +4538,24 @@ public class PackageManagerService extends IPackageManager.Stub {
            filterRecentlyUsedApps(pkgs);
            // Add all remaining apps.
            for (PackageParser.Package pkg : pkgs) {
                if (DEBUG_DEXOPT) {
                    Log.i(TAG, "Adding app " + sortedPkgs.size() + ": " + pkg.packageName);
                }
                sortedPkgs.add(pkg);
            }
            int i = 0;
            int total = sortedPkgs.size();
            File dataDir = Environment.getDataDirectory();
            long lowThreshold = StorageManager.from(mContext).getStorageLowBytes(dataDir);
            if (lowThreshold == 0) {
                throw new IllegalStateException("Invalid low memory threshold");
            }
            for (PackageParser.Package pkg : sortedPkgs) {
                if (DEBUG_DEXOPT) {
                    Log.i(TAG, "Adding app " + sortedPkgs.size() + ": " + pkg.packageName);
                long usableSpace = dataDir.getUsableSpace();
                if (usableSpace < lowThreshold) {
                    Log.w(TAG, "Not running dexopt on remaining apps due to low memory: " + usableSpace);
                    break;
                }
                performBootDexOpt(pkg, ++i, total);
            }