Logs during cache cleaning

This commit is contained in:
DerGenaue
2024-10-02 16:42:05 +02:00
parent 140fdaa826
commit edcdc77956
2 changed files with 13 additions and 3 deletions

View File

@@ -38,6 +38,7 @@ import java.io.IOException;
public class ApkCache {
private static final String CACHE_DIR = "apks";
public static final String TAG = "ApkCache";
public enum ApkCacheState { MISS_OR_PARTIAL, CACHED, CORRUPTED }
@@ -100,6 +101,7 @@ public class ApkCache {
sanitizedApkFile.delete();
}
Utils.debugLog(TAG, "Copying APK to files temporarily: " + sanitizedApkFile.getAbsolutePath());
FileUtils.copyFile(apkFile, sanitizedApkFile);
// verify copied file's hash with expected hash from Apk class
@@ -109,6 +111,8 @@ public class ApkCache {
}
// 20 minutes the start of the install process, delete the file
// If the thread is killed or some issues occur,
// files are still cleaned up periodically by the CleanCacheWorker
final File apkToDelete = sanitizedApkFile;
new Thread() {
@Override
@@ -118,6 +122,7 @@ public class ApkCache {
Thread.sleep(1200000);
} catch (InterruptedException ignored) {
} finally {
Utils.debugLog(TAG, "Deleting temporary APK from files: "+ apkToDelete.getAbsolutePath());
FileUtils.deleteQuietly(apkToDelete);
}
}

View File

@@ -67,7 +67,7 @@ public class CleanCacheWorker extends Worker {
.setConstraints(constraintsBuilder.build())
.build();
workManager.enqueueUniquePeriodicWork(TAG, ExistingPeriodicWorkPolicy.REPLACE, cleanCache);
Utils.debugLog(TAG, "Scheduled periodic work for cleaning the cache.");
Utils.debugLog(TAG, "Scheduled periodic work for cleaning the cache every " + (interval / (60*60*1000)) + " hours");
}
/**
@@ -87,13 +87,16 @@ public class CleanCacheWorker extends Worker {
public Result doWork() {
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
try {
Utils.debugLog(TAG, "Starting cache cleaning job.");
final Context context = getApplicationContext();
deleteExpiredApksFromCache(context);
deleteStrayIndexFiles(context);
deleteOldInstallerFiles(context);
deleteOldIcons(context);
Utils.debugLog(TAG, "Finished cache cleaning job.");
return Result.success();
} catch (Exception e) {
Utils.debugLog(TAG, "Failed cache cleaning job.");
return Result.failure();
}
}
@@ -209,8 +212,10 @@ public class CleanCacheWorker extends Worker {
}
private static void deleteFileAndLog(final File file) {
file.delete();
Utils.debugLog(TAG, "Deleted file: " + file);
if (file.delete()) {
// Only deletes empty directories
Utils.debugLog(TAG, "Deleted file: " + file);
}
}
private static class Impl21 {