switch all Downloader subclasses to use Uri instead of URL
java.net.URL barfs on custom URL schemes, and making it handle them is really hard. Basically, there needs to be a Handler stub class, then URL.setURLStreamHandlerFactory() must run when F-Droid starts, since it has to be set before any URL instance is used. This all leaves some weird logic that gives the false impression that URLConnection will handle these custom schemes. Switching to Uri/urlString throughout the code matches the other classes that use urlString as the unique ID, and this doesn't add more lines of code.
This commit is contained in:
parent
195aaae7e5
commit
df08e84e78
@ -60,12 +60,8 @@ import org.fdroid.fdroid.installer.InstallHistoryService;
|
|||||||
import org.fdroid.fdroid.net.ImageLoaderForUIL;
|
import org.fdroid.fdroid.net.ImageLoaderForUIL;
|
||||||
import org.fdroid.fdroid.net.WifiStateChangeService;
|
import org.fdroid.fdroid.net.WifiStateChangeService;
|
||||||
import org.fdroid.fdroid.views.hiding.HidingManager;
|
import org.fdroid.fdroid.views.hiding.HidingManager;
|
||||||
import sun.net.www.protocol.bluetooth.Handler;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLStreamHandler;
|
|
||||||
import java.net.URLStreamHandlerFactory;
|
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -370,16 +366,6 @@ public class FDroidApp extends Application {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// This is added so that the bluetooth:// scheme we use for URLs the BluetoothDownloader
|
|
||||||
// understands is not treated as invalid by the java.net.URL class. The actual Handler does
|
|
||||||
// nothing, but its presence is enough.
|
|
||||||
URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
|
|
||||||
@Override
|
|
||||||
public URLStreamHandler createURLStreamHandler(String protocol) {
|
|
||||||
return TextUtils.equals(protocol, "bluetooth") ? new Handler() : null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final Context context = this;
|
final Context context = this;
|
||||||
Preferences.get().registerUnstableUpdatesChangeListener(new Preferences.ChangeListener() {
|
Preferences.get().registerUnstableUpdatesChangeListener(new Preferences.ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,7 +6,6 @@ import android.net.Uri;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
@ -15,7 +14,6 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.InjectableValues;
|
import com.fasterxml.jackson.databind.InjectableValues;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.fdroid.fdroid.data.Apk;
|
import org.fdroid.fdroid.data.Apk;
|
||||||
import org.fdroid.fdroid.data.App;
|
import org.fdroid.fdroid.data.App;
|
||||||
@ -31,7 +29,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.URL;
|
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -157,7 +154,7 @@ public class IndexV1Updater extends RepoUpdater {
|
|||||||
JarFile jarFile = new JarFile(outputFile, true);
|
JarFile jarFile = new JarFile(outputFile, true);
|
||||||
JarEntry indexEntry = (JarEntry) jarFile.getEntry(DATA_FILE_NAME);
|
JarEntry indexEntry = (JarEntry) jarFile.getEntry(DATA_FILE_NAME);
|
||||||
InputStream indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
|
InputStream indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
|
||||||
processIndexListener, new URL(repo.address), (int) indexEntry.getSize());
|
processIndexListener, repo.address, (int) indexEntry.getSize());
|
||||||
processIndexV1(indexInputStream, indexEntry, cacheTag);
|
processIndexV1(indexInputStream, indexEntry, cacheTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,12 +3,11 @@ package org.fdroid.fdroid;
|
|||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
class ProgressBufferedInputStream extends BufferedInputStream {
|
class ProgressBufferedInputStream extends BufferedInputStream {
|
||||||
|
|
||||||
private final ProgressListener progressListener;
|
private final ProgressListener progressListener;
|
||||||
private final URL sourceUrl;
|
private final String urlString;
|
||||||
private final int totalBytes;
|
private final int totalBytes;
|
||||||
|
|
||||||
private int currentBytes;
|
private int currentBytes;
|
||||||
@ -17,10 +16,10 @@ class ProgressBufferedInputStream extends BufferedInputStream {
|
|||||||
* Reports progress to the specified {@link ProgressListener}, with the
|
* Reports progress to the specified {@link ProgressListener}, with the
|
||||||
* progress based on the {@code totalBytes}.
|
* progress based on the {@code totalBytes}.
|
||||||
*/
|
*/
|
||||||
ProgressBufferedInputStream(InputStream in, ProgressListener progressListener, URL sourceUrl, int totalBytes) {
|
ProgressBufferedInputStream(InputStream in, ProgressListener progressListener, String urlString, int totalBytes) {
|
||||||
super(in);
|
super(in);
|
||||||
this.progressListener = progressListener;
|
this.progressListener = progressListener;
|
||||||
this.sourceUrl = sourceUrl;
|
this.urlString = urlString;
|
||||||
this.totalBytes = totalBytes;
|
this.totalBytes = totalBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ class ProgressBufferedInputStream extends BufferedInputStream {
|
|||||||
* the digits changing because it looks pretty, < 9000 since the reads won't
|
* the digits changing because it looks pretty, < 9000 since the reads won't
|
||||||
* line up exactly */
|
* line up exactly */
|
||||||
if (currentBytes % 333333 < 9000) {
|
if (currentBytes % 333333 < 9000) {
|
||||||
progressListener.onProgress(sourceUrl, currentBytes, totalBytes);
|
progressListener.onProgress(urlString, currentBytes, totalBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.read(buffer, byteOffset, byteCount);
|
return super.read(buffer, byteOffset, byteCount);
|
||||||
|
@ -19,6 +19,6 @@ import java.net.URL;
|
|||||||
*/
|
*/
|
||||||
public interface ProgressListener {
|
public interface ProgressListener {
|
||||||
|
|
||||||
void onProgress(URL sourceUrl, long bytesRead, long totalBytes);
|
void onProgress(String urlString, long bytesRead, long totalBytes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,6 @@ import javax.xml.parsers.SAXParserFactory;
|
|||||||
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.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;
|
||||||
@ -213,7 +212,7 @@ public class RepoUpdater {
|
|||||||
JarFile jarFile = new JarFile(downloadedFile, true);
|
JarFile jarFile = new JarFile(downloadedFile, true);
|
||||||
JarEntry indexEntry = (JarEntry) jarFile.getEntry("index.xml");
|
JarEntry indexEntry = (JarEntry) jarFile.getEntry("index.xml");
|
||||||
indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
|
indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
|
||||||
processIndexListener, new URL(repo.address), (int) indexEntry.getSize());
|
processIndexListener, repo.address, (int) indexEntry.getSize());
|
||||||
|
|
||||||
// Process the index...
|
// Process the index...
|
||||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
@ -251,14 +250,14 @@ public class RepoUpdater {
|
|||||||
|
|
||||||
protected final ProgressListener downloadListener = new ProgressListener() {
|
protected final ProgressListener downloadListener = new ProgressListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(URL sourceUrl, long bytesRead, long totalBytes) {
|
public void onProgress(String urlString, long bytesRead, long totalBytes) {
|
||||||
UpdateService.reportDownloadProgress(context, RepoUpdater.this, bytesRead, totalBytes);
|
UpdateService.reportDownloadProgress(context, RepoUpdater.this, bytesRead, totalBytes);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected final ProgressListener processIndexListener = new ProgressListener() {
|
protected final ProgressListener processIndexListener = new ProgressListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(URL sourceUrl, long bytesRead, long totalBytes) {
|
public void onProgress(String urlString, long bytesRead, long totalBytes) {
|
||||||
UpdateService.reportProcessIndexProgress(context, RepoUpdater.this, bytesRead, totalBytes);
|
UpdateService.reportProcessIndexProgress(context, RepoUpdater.this, bytesRead, totalBytes);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package org.fdroid.fdroid.net;
|
package org.fdroid.fdroid.net;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.apache.commons.io.input.BoundedInputStream;
|
import org.apache.commons.io.input.BoundedInputStream;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.net.bluetooth.BluetoothClient;
|
import org.fdroid.fdroid.net.bluetooth.BluetoothClient;
|
||||||
@ -14,7 +14,6 @@ import org.fdroid.fdroid.net.bluetooth.httpish.Response;
|
|||||||
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.URL;
|
|
||||||
|
|
||||||
public class BluetoothDownloader extends Downloader {
|
public class BluetoothDownloader extends Downloader {
|
||||||
|
|
||||||
@ -24,10 +23,11 @@ public class BluetoothDownloader extends Downloader {
|
|||||||
private FileDetails fileDetails;
|
private FileDetails fileDetails;
|
||||||
private final String sourcePath;
|
private final String sourcePath;
|
||||||
|
|
||||||
public BluetoothDownloader(String macAddress, URL sourceUrl, File destFile) throws IOException {
|
public BluetoothDownloader(Uri uri, File destFile) throws IOException {
|
||||||
super(sourceUrl, destFile);
|
super(uri, destFile);
|
||||||
|
String macAddress = uri.getHost().replace("-", ":");
|
||||||
this.connection = new BluetoothClient(macAddress).openConnection();
|
this.connection = new BluetoothClient(macAddress).openConnection();
|
||||||
this.sourcePath = sourceUrl.getPath();
|
this.sourcePath = uri.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -58,7 +58,7 @@ public class BluetoothDownloader extends Downloader {
|
|||||||
if (fileDetails == null) {
|
if (fileDetails == null) {
|
||||||
Utils.debugLog(TAG, "Going to Bluetooth \"server\" to get file details.");
|
Utils.debugLog(TAG, "Going to Bluetooth \"server\" to get file details.");
|
||||||
try {
|
try {
|
||||||
fileDetails = Request.createHEAD(sourceUrl.getPath(), connection).send().toFileDetails();
|
fileDetails = Request.createHEAD(sourcePath, connection).send().toFileDetails();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "Error getting file details from Bluetooth \"server\"", e);
|
Log.e(TAG, "Error getting file details from Bluetooth \"server\"", e);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.fdroid.fdroid.net;
|
package org.fdroid.fdroid.net;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
import org.fdroid.fdroid.ProgressListener;
|
import org.fdroid.fdroid.ProgressListener;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
|
|
||||||
@ -9,7 +10,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ public abstract class Downloader {
|
|||||||
|
|
||||||
public final File outputFile;
|
public final File outputFile;
|
||||||
|
|
||||||
final URL sourceUrl;
|
final String urlString;
|
||||||
String cacheTag;
|
String cacheTag;
|
||||||
boolean notFound;
|
boolean notFound;
|
||||||
|
|
||||||
@ -52,8 +52,8 @@ public abstract class Downloader {
|
|||||||
|
|
||||||
protected abstract void close();
|
protected abstract void close();
|
||||||
|
|
||||||
Downloader(URL url, File destFile) {
|
Downloader(Uri uri, File destFile) {
|
||||||
this.sourceUrl = url;
|
this.urlString = uri.toString();
|
||||||
outputFile = destFile;
|
outputFile = destFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ public abstract class Downloader {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (downloaderProgressListener != null) {
|
if (downloaderProgressListener != null) {
|
||||||
downloaderProgressListener.onProgress(sourceUrl, bytesRead, totalBytes);
|
downloaderProgressListener.onProgress(urlString, bytesRead, totalBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2,19 +2,15 @@ package org.fdroid.fdroid.net;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
|
||||||
import org.fdroid.fdroid.data.Repo;
|
import org.fdroid.fdroid.data.Repo;
|
||||||
import org.fdroid.fdroid.data.RepoProvider;
|
import org.fdroid.fdroid.data.RepoProvider;
|
||||||
import org.fdroid.fdroid.data.Schema;
|
import org.fdroid.fdroid.data.Schema;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class DownloaderFactory {
|
public class DownloaderFactory {
|
||||||
|
|
||||||
private static LocalBroadcastManager localBroadcastManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads to a temporary file, which *you must delete yourself when
|
* Downloads to a temporary file, which *you must delete yourself when
|
||||||
* you are done. It is stored in {@link Context#getCacheDir()} and starts
|
* you are done. It is stored in {@link Context#getCacheDir()} and starts
|
||||||
@ -34,22 +30,19 @@ public class DownloaderFactory {
|
|||||||
|
|
||||||
public static Downloader create(Context context, String urlString, File destFile)
|
public static Downloader create(Context context, String urlString, File destFile)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
URL url = new URL(urlString);
|
|
||||||
Downloader downloader;
|
Downloader downloader;
|
||||||
if (localBroadcastManager == null) {
|
|
||||||
localBroadcastManager = LocalBroadcastManager.getInstance(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("bluetooth".equalsIgnoreCase(url.getProtocol())) {
|
Uri uri = Uri.parse(urlString);
|
||||||
String macAddress = url.getHost().replace("-", ":");
|
String scheme = uri.getScheme();
|
||||||
downloader = new BluetoothDownloader(macAddress, url, destFile);
|
if ("bluetooth".equals(scheme)) {
|
||||||
|
downloader = new BluetoothDownloader(uri, destFile);
|
||||||
} else {
|
} else {
|
||||||
final String[] projection = {Schema.RepoTable.Cols.USERNAME, Schema.RepoTable.Cols.PASSWORD};
|
final String[] projection = {Schema.RepoTable.Cols.USERNAME, Schema.RepoTable.Cols.PASSWORD};
|
||||||
Repo repo = RepoProvider.Helper.findByUrl(context, Uri.parse(url.toString()), projection);
|
Repo repo = RepoProvider.Helper.findByUrl(context, uri, projection);
|
||||||
if (repo == null) {
|
if (repo == null) {
|
||||||
downloader = new HttpDownloader(url, destFile);
|
downloader = new HttpDownloader(uri, destFile);
|
||||||
} else {
|
} else {
|
||||||
downloader = new HttpDownloader(url, destFile, repo.username, repo.password);
|
downloader = new HttpDownloader(uri, destFile, repo.username, repo.password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return downloader;
|
return downloader;
|
||||||
|
@ -31,7 +31,6 @@ import android.os.PatternMatcher;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.fdroid.fdroid.ProgressListener;
|
import org.fdroid.fdroid.ProgressListener;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
@ -42,7 +41,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DownloaderService is a service that handles asynchronous download requests
|
* DownloaderService is a service that handles asynchronous download requests
|
||||||
@ -199,7 +197,7 @@ public class DownloaderService extends Service {
|
|||||||
downloader = DownloaderFactory.create(this, uri, localFile);
|
downloader = DownloaderFactory.create(this, uri, localFile);
|
||||||
downloader.setListener(new ProgressListener() {
|
downloader.setListener(new ProgressListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(URL sourceUrl, long bytesRead, long totalBytes) {
|
public void onProgress(String urlString, long bytesRead, long totalBytes) {
|
||||||
Intent intent = new Intent(Downloader.ACTION_PROGRESS);
|
Intent intent = new Intent(Downloader.ACTION_PROGRESS);
|
||||||
intent.setData(uri);
|
intent.setData(uri);
|
||||||
intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);
|
intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);
|
||||||
@ -321,7 +319,7 @@ public class DownloaderService extends Service {
|
|||||||
* Check if a URL is actively being downloaded.
|
* Check if a URL is actively being downloaded.
|
||||||
*/
|
*/
|
||||||
private static boolean isActive(String urlString) {
|
private static boolean isActive(String urlString) {
|
||||||
return downloader != null && TextUtils.equals(urlString, downloader.sourceUrl.toString());
|
return downloader != null && TextUtils.equals(urlString, downloader.urlString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setTimeout(int ms) {
|
public static void setTimeout(int ms) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.fdroid.fdroid.net;
|
package org.fdroid.fdroid.net;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
||||||
@ -29,29 +30,30 @@ public class HttpDownloader extends Downloader {
|
|||||||
|
|
||||||
private final String username;
|
private final String username;
|
||||||
private final String password;
|
private final String password;
|
||||||
|
private URL sourceUrl;
|
||||||
private HttpURLConnection connection;
|
private HttpURLConnection connection;
|
||||||
private boolean newFileAvailableOnServer;
|
private boolean newFileAvailableOnServer;
|
||||||
|
|
||||||
HttpDownloader(URL url, File destFile)
|
HttpDownloader(Uri uri, File destFile)
|
||||||
throws FileNotFoundException, MalformedURLException {
|
throws FileNotFoundException, MalformedURLException {
|
||||||
this(url, destFile, null, null);
|
this(uri, destFile, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a downloader that can authenticate via HTTP Basic Auth using the supplied
|
* Create a downloader that can authenticate via HTTP Basic Auth using the supplied
|
||||||
* {@code username} and {@code password}.
|
* {@code username} and {@code password}.
|
||||||
*
|
*
|
||||||
* @param url The file to download
|
* @param uri The file to download
|
||||||
* @param destFile Where the download is saved
|
* @param destFile Where the download is saved
|
||||||
* @param username Username for HTTP Basic Auth, use {@code null} to ignore
|
* @param username Username for HTTP Basic Auth, use {@code null} to ignore
|
||||||
* @param password Password for HTTP Basic Auth, use {@code null} to ignore
|
* @param password Password for HTTP Basic Auth, use {@code null} to ignore
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
*/
|
*/
|
||||||
HttpDownloader(URL url, File destFile, String username, String password)
|
HttpDownloader(Uri uri, File destFile, String username, String password)
|
||||||
throws FileNotFoundException, MalformedURLException {
|
throws FileNotFoundException, MalformedURLException {
|
||||||
super(url, destFile);
|
super(uri, destFile);
|
||||||
|
this.sourceUrl = new URL(urlString);
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
@ -95,7 +97,7 @@ public class HttpDownloader extends Downloader {
|
|||||||
case 200:
|
case 200:
|
||||||
contentLength = tmpConn.getContentLength();
|
contentLength = tmpConn.getContentLength();
|
||||||
if (!TextUtils.isEmpty(etag) && etag.equals(cacheTag)) {
|
if (!TextUtils.isEmpty(etag) && etag.equals(cacheTag)) {
|
||||||
Utils.debugLog(TAG, sourceUrl + " is cached, not downloading");
|
Utils.debugLog(TAG, urlString + " is cached, not downloading");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newFileAvailableOnServer = true;
|
newFileAvailableOnServer = true;
|
||||||
@ -104,7 +106,7 @@ public class HttpDownloader extends Downloader {
|
|||||||
notFound = true;
|
notFound = true;
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
Utils.debugLog(TAG, "HEAD check of " + sourceUrl + " returned " + statusCode + ": "
|
Utils.debugLog(TAG, "HEAD check of " + urlString + " returned " + statusCode + ": "
|
||||||
+ tmpConn.getResponseMessage());
|
+ tmpConn.getResponseMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +120,7 @@ public class HttpDownloader extends Downloader {
|
|||||||
resumable = true;
|
resumable = true;
|
||||||
}
|
}
|
||||||
setupConnection(resumable);
|
setupConnection(resumable);
|
||||||
Utils.debugLog(TAG, "downloading " + sourceUrl + " (is resumable: " + resumable + ")");
|
Utils.debugLog(TAG, "downloading " + urlString + " (is resumable: " + resumable + ")");
|
||||||
downloadFromStream(8192, resumable);
|
downloadFromStream(8192, resumable);
|
||||||
cacheTag = connection.getHeaderField(HEADER_FIELD_ETAG);
|
cacheTag = connection.getHeaderField(HEADER_FIELD_ETAG);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package sun.net.www.protocol.bluetooth;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.net.URLStreamHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is added so that the bluetooth:// scheme we use for the {@link
|
|
||||||
* org.fdroid.fdroid.net.BluetoothDownloader} is not treated as invalid by
|
|
||||||
* the {@link URL} class.
|
|
||||||
*/
|
|
||||||
public class Handler extends URLStreamHandler {
|
|
||||||
@Override
|
|
||||||
protected URLConnection openConnection(URL u) throws IOException {
|
|
||||||
throw new UnsupportedOperationException("openConnection() not supported on bluetooth:// URLs");
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user