From 0bf221383b0d02da0d7199cdfc4aee26f85669a0 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Thu, 31 Mar 2016 17:27:15 +0200 Subject: [PATCH] make RepoUpdater's index URL a property for easy use Since the DownloaderService's events are all based on the complete download URLs, and RepoUpdater is where the update URLs are built, this makes the full download URL into a read-only property of RepoUpdater so it can be used wherever there is an instance of RepoUpdater This is also important because having the `final` property highlights the lifecycle of that variable: it does not change during the entire life of a RepoUpdater Instance. --- .../java/org/fdroid/fdroid/RepoUpdater.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java b/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java index a03992450..2c75c06bd 100644 --- a/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java +++ b/app/src/main/java/org/fdroid/fdroid/RepoUpdater.java @@ -21,8 +21,6 @@ import org.xml.sax.XMLReader; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; import java.security.CodeSigner; import java.security.cert.Certificate; import java.security.cert.X509Certificate; @@ -54,6 +52,8 @@ public class RepoUpdater { public static final String PROGRESS_COMMITTING = "committing"; public static final String PROGRESS_DATA_REPO_ADDRESS = "repoAddress"; + public final String indexUrl; + @NonNull private final Context context; @NonNull @@ -75,6 +75,13 @@ public class RepoUpdater { this.context = context; this.repo = repo; this.persister = new RepoPersister(context, repo); + + String url = repo.address + "/index.jar"; + String versionName = Utils.getVersionName(context); + if (versionName != null) { + url += "?client_version=" + versionName; + } + this.indexUrl = url; } public void setProgressListener(@Nullable ProgressListener progressListener) { @@ -85,27 +92,17 @@ public class RepoUpdater { return hasChanged; } - private URL getIndexAddress() throws MalformedURLException { - String urlString = repo.address + "/index.jar"; - String versionName = Utils.getVersionName(context); - if (versionName != null) { - urlString += "?client_version=" + versionName; - } - return new URL(urlString); - } - private Downloader downloadIndex() throws UpdateException { Downloader downloader = null; try { - downloader = DownloaderFactory.create(context, - getIndexAddress(), File.createTempFile("index-", "-downloaded", context.getCacheDir())); + downloader = DownloaderFactory.create(context, indexUrl); downloader.setCacheTag(repo.lastetag); downloader.download(); if (downloader.isCached()) { // The index is unchanged since we last read it. We just mark // everything that came from this repo as being updated. - Utils.debugLog(TAG, "Repo index for " + getIndexAddress() + " is up to date (by etag)"); + Utils.debugLog(TAG, "Repo index for " + indexUrl + " is up to date (by etag)"); } } catch (IOException e) {