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.
This commit is contained in:
Hans-Christoph Steiner 2016-03-31 17:27:15 +02:00
parent 8befba0522
commit 0bf221383b

View File

@ -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) {