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

Commit e219aaae authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Delete preloadsFileCache when the cache has expired"

parents 3ec7c359 935618a2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -628,4 +628,6 @@ interface IPackageManager {
    ParceledListSlice getSharedLibraries(int flags, int userId);

    boolean canRequestPackageInstalls(String packageName, int userId);

    void deletePreloadsFileCache();
}
+20 −2
Original line number Diff line number Diff line
@@ -3818,6 +3818,16 @@ public class PackageManagerService extends IPackageManager.Stub {
        return normalizedPackageName != null ? normalizedPackageName : packageName;
    }
    @Override
    public void deletePreloadsFileCache() {
        if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
            throw new SecurityException("Only system or settings may call deletePreloadsFileCache");
        }
        File dir = Environment.getDataPreloadsFileCacheDirectory();
        Slog.i(TAG, "Deleting preloaded file cache " + dir);
        FileUtils.deleteContents(dir);
    }
    @Override
    public void freeStorageAndNotify(final String volumeUuid, final long freeStorageSize,
            final IPackageDataObserver observer) {
@@ -3871,19 +3881,27 @@ public class PackageManagerService extends IPackageManager.Stub {
    public void freeStorage(String volumeUuid, long bytes, int storageFlags) throws IOException {
        final StorageManager storage = mContext.getSystemService(StorageManager.class);
        final File file = storage.findPathForUuid(volumeUuid);
        if (file.getUsableSpace() >= bytes) return;
        if (ENABLE_FREE_CACHE_V2) {
            final boolean aggressive = (storageFlags
                    & StorageManager.FLAG_ALLOCATE_AGGRESSIVE) != 0;
            final boolean internalVolume = Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL,
                    volumeUuid);
            // 1. Pre-flight to determine if we have any chance to succeed
            // 2. Consider preloaded data (after 1w honeymoon, unless aggressive)
            if (internalVolume && (aggressive || SystemProperties
                    .getBoolean("persist.sys.preloads.file_cache_expired", false))) {
                deletePreloadsFileCache();
                if (file.getUsableSpace() >= bytes) return;
            }
            // 3. Consider parsed APK data (aggressive only)
            if (aggressive) {
            if (internalVolume && aggressive) {
                FileUtils.deleteContents(mCacheDir);
            }
                if (file.getUsableSpace() >= bytes) return;
            }
            // 4. Consider cached app data (above quotas)
            try {