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:
parent
8befba0522
commit
0bf221383b
@ -21,8 +21,6 @@ import org.xml.sax.XMLReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.security.CodeSigner;
|
import java.security.CodeSigner;
|
||||||
import java.security.cert.Certificate;
|
import java.security.cert.Certificate;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
@ -54,6 +52,8 @@ public class RepoUpdater {
|
|||||||
public static final String PROGRESS_COMMITTING = "committing";
|
public static final String PROGRESS_COMMITTING = "committing";
|
||||||
public static final String PROGRESS_DATA_REPO_ADDRESS = "repoAddress";
|
public static final String PROGRESS_DATA_REPO_ADDRESS = "repoAddress";
|
||||||
|
|
||||||
|
public final String indexUrl;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Context context;
|
private final Context context;
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -75,6 +75,13 @@ public class RepoUpdater {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.persister = new RepoPersister(context, 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) {
|
public void setProgressListener(@Nullable ProgressListener progressListener) {
|
||||||
@ -85,27 +92,17 @@ public class RepoUpdater {
|
|||||||
return hasChanged;
|
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 {
|
private Downloader downloadIndex() throws UpdateException {
|
||||||
Downloader downloader = null;
|
Downloader downloader = null;
|
||||||
try {
|
try {
|
||||||
downloader = DownloaderFactory.create(context,
|
downloader = DownloaderFactory.create(context, indexUrl);
|
||||||
getIndexAddress(), File.createTempFile("index-", "-downloaded", context.getCacheDir()));
|
|
||||||
downloader.setCacheTag(repo.lastetag);
|
downloader.setCacheTag(repo.lastetag);
|
||||||
downloader.download();
|
downloader.download();
|
||||||
|
|
||||||
if (downloader.isCached()) {
|
if (downloader.isCached()) {
|
||||||
// The index is unchanged since we last read it. We just mark
|
// The index is unchanged since we last read it. We just mark
|
||||||
// everything that came from this repo as being updated.
|
// 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) {
|
} catch (IOException e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user