diff --git a/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java b/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java index 2feb9d73d..1f817f03e 100644 --- a/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java +++ b/app/src/main/java/org/fdroid/fdroid/CleanCacheService.java @@ -7,7 +7,6 @@ import android.content.Context; import android.content.Intent; import android.os.Process; import android.os.SystemClock; -import android.util.Log; import org.apache.commons.io.FileUtils; @@ -20,7 +19,6 @@ import java.io.File; * {@link FDroidApp#onCreate()} */ public class CleanCacheService extends IntentService { - private static final String TAG = "CleanCacheService"; /** * Schedule or cancel this service to update the app index, according to the @@ -33,7 +31,6 @@ public class CleanCacheService extends IntentService { if (keepTime < interval) { interval = keepTime * 1000; } - Log.i(TAG, "schedule " + keepTime + " " + interval); Intent intent = new Intent(context, CleanCacheService.class); PendingIntent pending = PendingIntent.getService(context, 0, intent, 0); @@ -53,6 +50,29 @@ public class CleanCacheService extends IntentService { Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST); Utils.clearOldFiles(Utils.getApkCacheDir(this), Preferences.get().getKeepCacheTime()); deleteStrayIndexFiles(); + deleteOldInstallerFiles(); + } + + /** + * {@link org.fdroid.fdroid.installer.Installer} instances copy the APK into + * a safe place before installing. It doesn't clean up them reliably yet. + */ + private void deleteOldInstallerFiles() { + File filesDir = getFilesDir(); + if (filesDir == null) { + return; + } + + final File[] files = filesDir.listFiles(); + if (files == null) { + return; + } + + for (File f : files) { + if (f.getName().startsWith("install-")) { + FileUtils.deleteQuietly(f); + } + } } /** diff --git a/app/src/main/java/org/fdroid/fdroid/installer/Installer.java b/app/src/main/java/org/fdroid/fdroid/installer/Installer.java index daf27221d..8f4011190 100644 --- a/app/src/main/java/org/fdroid/fdroid/installer/Installer.java +++ b/app/src/main/java/org/fdroid/fdroid/installer/Installer.java @@ -170,7 +170,7 @@ public abstract class Installer { */ public void installPackage(File apkFile, String packageName, String urlString) throws InstallFailedException { - SanitizedFile apkToInstall; + SanitizedFile apkToInstall = null; try { Map attributes = AndroidXMLDecompress.getManifestHeaderAttributes(apkFile.getAbsolutePath()); @@ -232,6 +232,22 @@ public abstract class Installer { throw new InstallFailedException(e); } catch (ClassCastException e) { throw new InstallFailedException("F-Droid Privileged can only be updated using an activity!"); + } finally { + // 20 minutes the start of the install process, delete the file + final File apkToDelete = apkToInstall; + new Thread() { + @Override + public void run() { + android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LOWEST); + try { + Thread.sleep(1200000); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + FileUtils.deleteQuietly(apkToDelete); + } + } + }.start(); } }