mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-02-04 12:12:03 -05:00
clean up cached files in a low priority IntentService
This moves the cache file deletion to a dedicated IntentService that runs at the lowest possible priority. The cache cleanup does not need to happen with any kind of priority, so it shouldn't delay the app start or take any resources away from foreground processes. This also changes the logic around the "Cache packages" preference. The downloader always saves APKs, then if "Cache packages" is disabled, those APKs are deleted when they are older than an hour. This also simplifies Utils.deleteFiles() since the endswith arg is no longer needed.
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
|
||||
package org.fdroid.fdroid;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -137,4 +142,34 @@ public class UtilsTest {
|
||||
}
|
||||
|
||||
// TODO write tests that work with a Certificate
|
||||
|
||||
@Test
|
||||
public void testClearOldFiles() throws IOException, InterruptedException {
|
||||
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
File dir = new File(TestUtils.getWriteableDir(instrumentation), "clearOldFiles");
|
||||
FileUtils.deleteQuietly(dir);
|
||||
dir.mkdirs();
|
||||
assertTrue(dir.isDirectory());
|
||||
|
||||
File first = new File(dir, "first");
|
||||
File second = new File(dir, "second");
|
||||
assertFalse(first.exists());
|
||||
assertFalse(second.exists());
|
||||
|
||||
first.createNewFile();
|
||||
assertTrue(first.exists());
|
||||
|
||||
Thread.sleep(7000);
|
||||
second.createNewFile();
|
||||
assertTrue(second.exists());
|
||||
|
||||
Utils.clearOldFiles(dir, 3);
|
||||
assertFalse(first.exists());
|
||||
assertTrue(second.exists());
|
||||
|
||||
Thread.sleep(7000);
|
||||
Utils.clearOldFiles(dir, 3);
|
||||
assertFalse(first.exists());
|
||||
assertFalse(second.exists());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user