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

Commit b198c976 authored by Neharika Jali's avatar Neharika Jali Committed by Android (Google) Code Review
Browse files

Merge "Eliminating the concept of reserved cache"

parents c4993d10 606aae42
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -169,8 +169,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);
@@ -178,6 +179,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
@@ -632,11 +632,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 −12
Original line number Diff line number Diff line
@@ -2909,7 +2909,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)
@@ -2926,11 +2925,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
@@ -2953,11 +2953,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
@@ -2982,11 +2984,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);