From 4dc141503517d6f629d49d4593cb1d9c1f19cce3 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 16 Aug 2016 16:50:04 +0200 Subject: [PATCH] document processes in CleanCacheService This breaks out each separate process into its own utility method, and adds javadoc to describe them. --- .../org/fdroid/fdroid/CleanCacheService.java | 21 +++++++++++++++++-- .../java/org/fdroid/fdroid/Preferences.java | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java b/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java index 9089b12c6..9fca46e7d 100644 --- a/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java +++ b/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java @@ -23,7 +23,14 @@ import java.util.concurrent.TimeUnit; * Handles cleaning up caches files that are not going to be used, and do not * block the operation of the app itself. For things that must happen before * F-Droid starts normal operation, that should go into - * {@link FDroidApp#onCreate()} + * {@link FDroidApp#onCreate()}. + *

+ * These files should only be deleted when they are at least an hour-ish old, + * in case they are actively in use while {@code CleanCacheService} is running. + * {@link #clearOldFiles(File, long)} checks the file age using access time from + * {@link StructStat#st_atime} on {@link android.os.Build.VERSION_CODES#LOLLIPOP} + * and newer. On older Android, last modified time from {@link File#lastModified()} + * is used. */ public class CleanCacheService extends IntentService { @@ -58,12 +65,22 @@ public class CleanCacheService extends IntentService { return; } Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST); - clearOldFiles(ApkCache.getApkCacheDir(getBaseContext()), Preferences.get().getKeepCacheTime()); + deleteExpiredApksFromCache(); deleteStrayIndexFiles(); deleteOldInstallerFiles(); deleteOldIcons(); } + /** + * All downloaded APKs will be cached for a certain amount of time, which is + * specified by the user in the "Keep Cache Time" preference. This removes + * any APK in the cache that is older than that preference specifies. + */ + private void deleteExpiredApksFromCache() { + File cacheDir = ApkCache.getApkCacheDir(getBaseContext()); + clearOldFiles(cacheDir, Preferences.get().getKeepCacheTime()); + } + /** * {@link org.fdroid.fdroid.installer.Installer} instances copy the APK into * a safe place before installing. It doesn't clean up them reliably yet. diff --git a/app/src/main/java/org/fdroid/fdroid/Preferences.java b/app/src/main/java/org/fdroid/fdroid/Preferences.java index 3216f4c87..626b44182 100644 --- a/app/src/main/java/org/fdroid/fdroid/Preferences.java +++ b/app/src/main/java/org/fdroid/fdroid/Preferences.java @@ -71,7 +71,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh private static final int DEFAULT_UPD_HISTORY = 14; private static final boolean DEFAULT_PRIVILEGED_INSTALLER = false; //private static final boolean DEFAULT_LOCAL_REPO_BONJOUR = true; - private static final long DEFAULT_KEEP_CACHE_TIME = TimeUnit.DAYS.toMillis(1); // one day + private static final long DEFAULT_KEEP_CACHE_TIME = TimeUnit.DAYS.toMillis(1); private static final boolean DEFAULT_UNSTABLE_UPDATES = false; //private static final boolean DEFAULT_LOCAL_REPO_HTTPS = false; private static final boolean DEFAULT_INCOMP_VER = false;