diff --git a/mobile/android/base/updater/UpdateService.java b/mobile/android/base/updater/UpdateService.java index 67f573498aed..ad4cfa629e70 100644 --- a/mobile/android/base/updater/UpdateService.java +++ b/mobile/android/base/updater/UpdateService.java @@ -107,6 +107,11 @@ public class UpdateService extends IntentService { } else if (UpdateServiceHelper.ACTION_CANCEL_DOWNLOAD.equals(intent.getAction())) { mCancelDownload = true; } else { + if (!UpdateServiceHelper.ACTION_APPLY_UPDATE.equals(intent.getAction())) { + // Delete the update package used to install the current version. + deleteUpdatePackage(getLastFileName()); + } + super.onStartCommand(intent, flags, startId); } @@ -412,8 +417,26 @@ public class UpdateService extends IntentService { mNotificationManager.notify(NOTIFICATION_ID, notification); } + private boolean deleteUpdatePackage(String path) { + if (path == null) { + return false; + } + + File pkg = new File(path); + if (!pkg.exists()) { + return false; + } + + pkg.delete(); + Log.i(LOGTAG, "deleted update package: " + path); + + return true; + } + private File downloadUpdatePackage(UpdateInfo info, boolean overwriteExisting) { - File downloadFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), new File(info.url.getFile()).getName()); + File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); + String fileName = new File(info.url.getFile()).getName(); + File downloadFile = new File(path, fileName); if (!overwriteExisting && info.buildID.equals(getLastBuildID()) && downloadFile.exists()) { // The last saved buildID is the same as the one for the current update. We also have a file @@ -533,7 +556,7 @@ public class UpdateService extends IntentService { private void applyUpdate(String updatePath) { if (updatePath == null) { - updatePath = mPrefs.getString(KEY_LAST_FILE_NAME, null); + updatePath = getLastFileName(); } applyUpdate(new File(updatePath)); } @@ -569,6 +592,10 @@ public class UpdateService extends IntentService { return mPrefs.getString(KEY_LAST_HASH_VALUE, null); } + private String getLastFileName() { + return mPrefs.getString(KEY_LAST_FILE_NAME, null); + } + private Calendar getLastAttemptDate() { long lastAttempt = mPrefs.getLong(KEY_LAST_ATTEMPT_DATE, -1); if (lastAttempt < 0)