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

Commit 606aae42 authored by Neharika Jali's avatar Neharika Jali
Browse files

Eliminating the concept of reserved cache

Bug: 203649806
Test: atest installd_cache_test
Change-Id: I19c64f5677e184dc04a8def3c61e0e71aaede81d
parent 41edf7cb
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -299,8 +299,9 @@ final class InstallParams extends HandlerParams {
            final long sizeBytes = PackageManagerServiceUtils.calculateInstalledSize(
                    mOriginInfo.mResolvedPath, mPackageAbiOverride);
            if (sizeBytes >= 0) {
                synchronized (mPm.mInstallLock) {
                    try {
                    mPm.mInstaller.freeCache(null, sizeBytes + lowThreshold, 0, 0);
                        mPm.mInstaller.freeCache(null, sizeBytes + lowThreshold, 0);
                        pkgLite = PackageManagerServiceUtils.getMinimalPackageInfo(mPm.mContext,
                                mPackageLite, mOriginInfo.mResolvedPath, mInstallFlags,
                                mPackageAbiOverride);
@@ -308,6 +309,7 @@ final class InstallParams extends HandlerParams {
                        Slog.w(TAG, "Failed to free cache", e);
                    }
                }
            }

            /*
             * The cache free must have deleted the file we downloaded to install.
+7 −3
Original line number Diff line number Diff line
@@ -655,11 +655,15 @@ public class Installer extends SystemService {
        }
    }

    public void freeCache(String uuid, long targetFreeBytes, long cacheReservedBytes, int flags)
            throws InstallerException {
    /**
     * Deletes cache from specified uuid until targetFreeBytes amount of space is free.
     * flag denotes aggressive or non-aggresive mode where cache under quota is eligible or not
     * respectively for clearing.
     */
    public void freeCache(String uuid, long targetFreeBytes, int flags) throws InstallerException {
        if (!checkBeforeRemote()) return;
        try {
            mInstalld.freeCache(uuid, targetFreeBytes, cacheReservedBytes, flags);
            mInstalld.freeCache(uuid, targetFreeBytes, flags);
        } catch (Exception e) {
            throw InstallerException.from(e);
        }
+16 −13
Original line number Diff line number Diff line
@@ -142,7 +142,6 @@ import android.content.pm.dex.IArtManager;
import android.content.pm.overlay.OverlayPaths;
import android.content.pm.parsing.ParsingPackageUtils;
import android.content.pm.parsing.component.ParsedActivity;
import android.content.pm.parsing.component.ParsedActivityImpl;
import android.content.pm.parsing.component.ParsedInstrumentation;
import android.content.pm.parsing.component.ParsedIntentInfo;
import android.content.pm.parsing.component.ParsedMainComponent;
@@ -2849,7 +2848,6 @@ public class PackageManagerService extends IPackageManager.Stub
                    volumeUuid);
            final boolean aggressive = (storageFlags
                    & StorageManager.FLAG_ALLOCATE_AGGRESSIVE) != 0;
            final long reservedBytes = storage.getStorageCacheBytes(file, storageFlags);

            // 1. Pre-flight to determine if we have any chance to succeed
            // 2. Consider preloaded data (after 1w honeymoon, unless aggressive)
@@ -2866,11 +2864,12 @@ public class PackageManagerService extends IPackageManager.Stub
            }

            // 4. Consider cached app data (above quotas)
            synchronized (mInstallLock) {
                try {
                mInstaller.freeCache(volumeUuid, bytes, reservedBytes,
                        Installer.FLAG_FREE_CACHE_V2);
                    mInstaller.freeCache(volumeUuid, bytes, Installer.FLAG_FREE_CACHE_V2);
                } catch (InstallerException ignored) {
                }
            }
            if (file.getUsableSpace() >= bytes) return;

            // 5. Consider shared libraries with refcount=0 and age>min cache period
@@ -2893,11 +2892,13 @@ public class PackageManagerService extends IPackageManager.Stub
            }

            // 8. Consider cached app data (below quotas)
            synchronized (mInstallLock) {
                try {
                mInstaller.freeCache(volumeUuid, bytes, reservedBytes,
                    mInstaller.freeCache(volumeUuid, bytes,
                            Installer.FLAG_FREE_CACHE_V2 | Installer.FLAG_FREE_CACHE_V2_DEFY_QUOTA);
                } catch (InstallerException ignored) {
                }
            }
            if (file.getUsableSpace() >= bytes) return;

            // 9. Consider DropBox entries
@@ -2922,11 +2923,13 @@ public class PackageManagerService extends IPackageManager.Stub
            // 12. Clear temp install session files
            mInstallerService.freeStageDirs(volumeUuid);
        } else {
            synchronized (mInstallLock) {
                try {
                mInstaller.freeCache(volumeUuid, bytes, 0, 0);
                    mInstaller.freeCache(volumeUuid, bytes, 0);
                } catch (InstallerException ignored) {
                }
            }
        }
        if (file.getUsableSpace() >= bytes) return;

        throw new IOException("Failed to free " + bytes + " on storage device at " + file);