added app certificate fallback
This commit is contained in:
parent
86e62e1163
commit
6e858b6c91
1 changed files with 40 additions and 9 deletions
|
@ -73,6 +73,7 @@ public class DownloadWorker extends Worker {
|
||||||
int version = -1;
|
int version = -1;
|
||||||
int appversion = -1;
|
int appversion = -1;
|
||||||
String errorCode = null;
|
String errorCode = null;
|
||||||
|
private boolean bHttpDownloadProblem;
|
||||||
|
|
||||||
public DownloadWorker(
|
public DownloadWorker(
|
||||||
@NonNull Context context,
|
@NonNull Context context,
|
||||||
|
@ -255,6 +256,7 @@ public class DownloadWorker extends Worker {
|
||||||
newappversion = meta.minAppVersion;
|
newappversion = meta.minAppVersion;
|
||||||
} else {
|
} else {
|
||||||
String lookupLocation = mServerConfig.getLookupUrl() + fileName;
|
String lookupLocation = mServerConfig.getLookupUrl() + fileName;
|
||||||
|
if (bHttpDownloadProblem) lookupLocation = lookupLocation.replace("https://", "http://");
|
||||||
URL lookupUrl = new URL(lookupLocation);
|
URL lookupUrl = new URL(lookupLocation);
|
||||||
downloadProgressListener.onDownloadStart(fileName, DownloadType.LOOKUP);
|
downloadProgressListener.onDownloadStart(fileName, DownloadType.LOOKUP);
|
||||||
changed = downloadFile(lookupUrl, tmplookupFile, size, false, DownloadType.LOOKUP);
|
changed = downloadFile(lookupUrl, tmplookupFile, size, false, DownloadType.LOOKUP);
|
||||||
|
@ -305,6 +307,7 @@ public class DownloadWorker extends Worker {
|
||||||
//if (profileFile.exists())
|
//if (profileFile.exists())
|
||||||
{
|
{
|
||||||
String profileLocation = mServerConfig.getProfilesUrl() + fileName;
|
String profileLocation = mServerConfig.getProfilesUrl() + fileName;
|
||||||
|
if (bHttpDownloadProblem) profileLocation = profileLocation.replace("https://", "http://");
|
||||||
URL profileUrl = new URL(profileLocation);
|
URL profileUrl = new URL(profileLocation);
|
||||||
int size = (int) (profileFile.exists() ? profileFile.length() : 0);
|
int size = (int) (profileFile.exists() ? profileFile.length() : 0);
|
||||||
|
|
||||||
|
@ -326,6 +329,8 @@ public class DownloadWorker extends Worker {
|
||||||
private void downloadSegment(String segmentBaseUrl, String segmentName) throws IOException, InterruptedException {
|
private void downloadSegment(String segmentBaseUrl, String segmentName) throws IOException, InterruptedException {
|
||||||
File segmentFile = new File(baseDir, SEGMENTS_DIR + segmentName);
|
File segmentFile = new File(baseDir, SEGMENTS_DIR + segmentName);
|
||||||
File segmentFileTemp = new File(segmentFile.getAbsolutePath() + "_tmp");
|
File segmentFileTemp = new File(segmentFile.getAbsolutePath() + "_tmp");
|
||||||
|
if (bHttpDownloadProblem) segmentBaseUrl = segmentBaseUrl.replace("https://", "http://");
|
||||||
|
|
||||||
if (DEBUG) Log.d(LOG_TAG, "Download " + segmentName + " " + version + " " + versionChanged);
|
if (DEBUG) Log.d(LOG_TAG, "Download " + segmentName + " " + version + " " + versionChanged);
|
||||||
try {
|
try {
|
||||||
if (segmentFile.exists()) {
|
if (segmentFile.exists()) {
|
||||||
|
@ -333,6 +338,7 @@ public class DownloadWorker extends Worker {
|
||||||
String md5 = Rd5DiffManager.getMD5(segmentFile);
|
String md5 = Rd5DiffManager.getMD5(segmentFile);
|
||||||
if (DEBUG) Log.d(LOG_TAG, "Calculating local checksum " + md5);
|
if (DEBUG) Log.d(LOG_TAG, "Calculating local checksum " + md5);
|
||||||
String segmentDeltaLocation = segmentBaseUrl + "diff/" + segmentName.replace(SEGMENT_SUFFIX, "/" + md5 + SEGMENT_DIFF_SUFFIX);
|
String segmentDeltaLocation = segmentBaseUrl + "diff/" + segmentName.replace(SEGMENT_SUFFIX, "/" + md5 + SEGMENT_DIFF_SUFFIX);
|
||||||
|
if (bHttpDownloadProblem) segmentDeltaLocation = segmentDeltaLocation.replace("https://", "http://");
|
||||||
URL segmentDeltaUrl = new URL(segmentDeltaLocation);
|
URL segmentDeltaUrl = new URL(segmentDeltaLocation);
|
||||||
if (httpFileExists(segmentDeltaUrl)) {
|
if (httpFileExists(segmentDeltaUrl)) {
|
||||||
File segmentDeltaFile = new File(segmentFile.getAbsolutePath() + "_diff");
|
File segmentDeltaFile = new File(segmentFile.getAbsolutePath() + "_diff");
|
||||||
|
@ -376,13 +382,28 @@ public class DownloadWorker extends Worker {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean httpFileExists(URL downloadUrl) throws IOException {
|
private boolean httpFileExists(URL downloadUrl) throws IOException {
|
||||||
HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection();
|
HttpURLConnection connection = null;
|
||||||
connection.setConnectTimeout(5000);
|
|
||||||
connection.setRequestMethod("HEAD");
|
|
||||||
connection.setDoInput(false);
|
|
||||||
try {
|
try {
|
||||||
|
connection = (HttpURLConnection) downloadUrl.openConnection();
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.setRequestMethod("HEAD");
|
||||||
|
connection.setDoInput(false);
|
||||||
connection.connect();
|
connection.connect();
|
||||||
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
|
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
|
||||||
|
} catch (javax.net.ssl.SSLHandshakeException e) {
|
||||||
|
String url = downloadUrl.toString().replace("https://", "http://");
|
||||||
|
downloadUrl = new URL(url);
|
||||||
|
try {
|
||||||
|
connection = (HttpURLConnection) downloadUrl.openConnection();
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.setRequestMethod("HEAD");
|
||||||
|
connection.setDoInput(false);
|
||||||
|
connection.connect();
|
||||||
|
bHttpDownloadProblem = true;
|
||||||
|
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
|
||||||
|
} finally {
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
|
@ -391,14 +412,24 @@ public class DownloadWorker extends Worker {
|
||||||
|
|
||||||
private boolean downloadFile(URL downloadUrl, File outputFile, int fileSize, boolean limitDownloadSpeed, DownloadType type) throws IOException, InterruptedException {
|
private boolean downloadFile(URL downloadUrl, File outputFile, int fileSize, boolean limitDownloadSpeed, DownloadType type) throws IOException, InterruptedException {
|
||||||
if (DEBUG) Log.d(LOG_TAG, "download " + outputFile.getAbsolutePath());
|
if (DEBUG) Log.d(LOG_TAG, "download " + outputFile.getAbsolutePath());
|
||||||
HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection();
|
HttpURLConnection connection = null;
|
||||||
connection.setConnectTimeout(5000);
|
|
||||||
connection.setDefaultUseCaches(false);
|
|
||||||
|
|
||||||
InputStream input = null;
|
InputStream input = null;
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
try {
|
try {
|
||||||
connection.connect();
|
try {
|
||||||
|
connection = (HttpURLConnection) downloadUrl.openConnection();
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.setDefaultUseCaches(false);
|
||||||
|
connection.connect();
|
||||||
|
} catch (javax.net.ssl.SSLHandshakeException e) {
|
||||||
|
String url = downloadUrl.toString().replace("https://", "http://");
|
||||||
|
downloadUrl = new URL(url);
|
||||||
|
connection = (HttpURLConnection) downloadUrl.openConnection();
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.setDefaultUseCaches(false);
|
||||||
|
connection.connect();
|
||||||
|
bHttpDownloadProblem = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||||
throw new IOException("HTTP Request failed: " + downloadUrl + " returned " + connection.getResponseCode());
|
throw new IOException("HTTP Request failed: " + downloadUrl + " returned " + connection.getResponseCode());
|
||||||
|
|
Loading…
Reference in a new issue