Merge "Eliminating the concept of reserved cache"

This commit is contained in:
Neharika Jali
2021-11-11 10:46:40 +00:00
committed by Android (Google) Code Review
3 changed files with 32 additions and 22 deletions

View File

@@ -169,13 +169,15 @@ final class InstallParams extends HandlerParams {
final long sizeBytes = PackageManagerServiceUtils.calculateInstalledSize(
mOriginInfo.mResolvedPath, mPackageAbiOverride);
if (sizeBytes >= 0) {
try {
mPm.mInstaller.freeCache(null, sizeBytes + lowThreshold, 0, 0);
pkgLite = PackageManagerServiceUtils.getMinimalPackageInfo(mPm.mContext,
mPackageLite, mOriginInfo.mResolvedPath, mInstallFlags,
mPackageAbiOverride);
} catch (Installer.InstallerException e) {
Slog.w(TAG, "Failed to free cache", e);
synchronized (mPm.mInstallLock) {
try {
mPm.mInstaller.freeCache(null, sizeBytes + lowThreshold, 0);
pkgLite = PackageManagerServiceUtils.getMinimalPackageInfo(mPm.mContext,
mPackageLite, mOriginInfo.mResolvedPath, mInstallFlags,
mPackageAbiOverride);
} catch (Installer.InstallerException e) {
Slog.w(TAG, "Failed to free cache", e);
}
}
}

View File

@@ -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);
}

View File

@@ -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,10 +2925,11 @@ public class PackageManagerService extends IPackageManager.Stub
}
// 4. Consider cached app data (above quotas)
try {
mInstaller.freeCache(volumeUuid, bytes, reservedBytes,
Installer.FLAG_FREE_CACHE_V2);
} catch (InstallerException ignored) {
synchronized (mInstallLock) {
try {
mInstaller.freeCache(volumeUuid, bytes, Installer.FLAG_FREE_CACHE_V2);
} catch (InstallerException ignored) {
}
}
if (file.getUsableSpace() >= bytes) return;
@@ -2953,10 +2953,12 @@ public class PackageManagerService extends IPackageManager.Stub
}
// 8. Consider cached app data (below quotas)
try {
mInstaller.freeCache(volumeUuid, bytes, reservedBytes,
Installer.FLAG_FREE_CACHE_V2 | Installer.FLAG_FREE_CACHE_V2_DEFY_QUOTA);
} catch (InstallerException ignored) {
synchronized (mInstallLock) {
try {
mInstaller.freeCache(volumeUuid, bytes,
Installer.FLAG_FREE_CACHE_V2 | Installer.FLAG_FREE_CACHE_V2_DEFY_QUOTA);
} catch (InstallerException ignored) {
}
}
if (file.getUsableSpace() >= bytes) return;
@@ -2982,9 +2984,11 @@ public class PackageManagerService extends IPackageManager.Stub
// 12. Clear temp install session files
mInstallerService.freeStageDirs(volumeUuid);
} else {
try {
mInstaller.freeCache(volumeUuid, bytes, 0, 0);
} catch (InstallerException ignored) {
synchronized (mInstallLock) {
try {
mInstaller.freeCache(volumeUuid, bytes, 0);
} catch (InstallerException ignored) {
}
}
}
if (file.getUsableSpace() >= bytes) return;