Eliminating the concept of reserved cache

Bug: 203649806
Test: atest installd_cache_test
Change-Id: I19c64f5677e184dc04a8def3c61e0e71aaede81d
This commit is contained in:
Neharika Jali
2021-10-25 05:34:03 +00:00
parent 41edf7cb95
commit 606aae4242
3 changed files with 32 additions and 23 deletions

View File

@@ -299,13 +299,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

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

View File

@@ -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,10 +2864,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;
@@ -2893,10 +2892,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;
@@ -2922,9 +2923,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;