From cceba134b520252aaf899c285203ced480d0a817 Mon Sep 17 00:00:00 2001 From: Sergey Eremin Date: Fri, 19 May 2017 12:08:19 +0300 Subject: [PATCH] Background updater will not redownload existing apks anymore --- .../yeriomin/yalpstore/UpdateChecker.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/yeriomin/yalpstore/UpdateChecker.java b/app/src/main/java/com/github/yeriomin/yalpstore/UpdateChecker.java index 0248fef94..1ae9fb6ee 100644 --- a/app/src/main/java/com/github/yeriomin/yalpstore/UpdateChecker.java +++ b/app/src/main/java/com/github/yeriomin/yalpstore/UpdateChecker.java @@ -50,7 +50,7 @@ public class UpdateChecker extends BroadcastReceiver { return; } if (explicitCheck || PreferenceActivity.getBoolean(context, PreferenceActivity.PREFERENCE_BACKGROUND_UPDATE_DOWNLOAD)) { - download(context, updatableApps); + process(context, updatableApps); } else { createNotification(context, updatesCount); } @@ -61,16 +61,27 @@ public class UpdateChecker extends BroadcastReceiver { return task; } - private void download(Context context, List apps) { + private void process(Context context, List apps) { + boolean canInstallInBackground = PreferenceActivity.canInstallInBackground(context); for (App app: apps) { - Log.i(getClass().getName(), "Starting download of update for " + app.getPackageName()); - DownloadState state = DownloadState.get(app.getPackageName()); - state.setExplicitInstall(context instanceof Activity); - state.setApp(app); - getPurchaseTask(context, app).execute(); + if (!Downloader.getApkPath(app.getPackageName(), app.getVersionCode()).exists()) { + download(context, app); + } else if (canInstallInBackground) { + // Not passing context because it might be an activity + // and we want it to run in background + InstallerFactory.get(context.getApplicationContext()).verifyAndInstall(app); + } } } + private void download(Context context, App app) { + Log.i(getClass().getName(), "Starting download of update for " + app.getPackageName()); + DownloadState state = DownloadState.get(app.getPackageName()); + state.setExplicitInstall(context instanceof Activity); + state.setApp(app); + getPurchaseTask(context, app).execute(); + } + private PurchaseTask getPurchaseTask(Context context, App app) { PurchaseTask task = new PurchaseTask(); task.setApp(app);