delete the APK copy that Installer instances make
Installer instances always copy the APK to a safe place to run the install from. That copy needs to be deleted. Until we have the whole lifecycle in InstallManagerService, we need this hack. It should be handled on the broadcast from InstallerService to say that its complete. #611 !300
This commit is contained in:
parent
c35d327fa4
commit
0ab80e4c6a
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<String, Object> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user