Revision 69ecaf02 F-Droid/src/org/fdroid/fdroid/net/ApkDownloader.java
F-Droid/src/org/fdroid/fdroid/net/ApkDownloader.java | ||
---|---|---|
47 | 47 |
* If the file has previously been downloaded, it will make use of that |
48 | 48 |
* instead, without going to the network to download a new one. |
49 | 49 |
*/ |
50 |
public class ApkDownloader implements AsyncDownloadWrapper.Listener {
|
|
50 |
public class ApkDownloader implements AsyncDownloader.Listener { |
|
51 | 51 |
|
52 | 52 |
private static final String TAG = "ApkDownloader"; |
53 | 53 |
|
... | ... | |
78 | 78 |
@NonNull private final SanitizedFile potentiallyCachedFile; |
79 | 79 |
|
80 | 80 |
private ProgressListener listener; |
81 |
private AsyncDownloadWrapper dlWrapper = null;
|
|
81 |
private AsyncDownloader dlWrapper = null; |
|
82 | 82 |
private boolean isComplete = false; |
83 | 83 |
|
84 | 84 |
private final long id = ++downloadIdCounter; |
... | ... | |
197 | 197 |
Utils.DebugLog(TAG, "Downloading apk from " + remoteAddress + " to " + localFile); |
198 | 198 |
|
199 | 199 |
try { |
200 |
if (canUseDownloadManager(new URL(remoteAddress))) { |
|
201 |
// If we can use Android's DownloadManager, let's use it, because |
|
202 |
// of better OS integration, reliability, and async ability |
|
203 |
dlWrapper = new AsyncDownloader(context, this, |
|
204 |
app.name + " " + curApk.version, curApk.id, |
|
205 |
remoteAddress, localFile); |
|
206 |
} else { |
|
207 |
Downloader downloader = DownloaderFactory.create(context, remoteAddress, localFile); |
|
208 |
dlWrapper = new AsyncDownloadWrapper(downloader, this); |
|
209 |
} |
|
210 |
|
|
200 |
dlWrapper = DownloaderFactory.createAsync(context, remoteAddress, localFile, app.name + " " + curApk.version, curApk.id, this); |
|
211 | 201 |
dlWrapper.download(); |
212 | 202 |
return true; |
213 | 203 |
} catch (IOException e) { |
... | ... | |
217 | 207 |
return false; |
218 | 208 |
} |
219 | 209 |
|
220 |
/** |
|
221 |
* Tests to see if we can use Android's DownloadManager to download the APK, instead of |
|
222 |
* a downloader returned from DownloadFactory. |
|
223 |
* @param url |
|
224 |
* @return |
|
225 |
*/ |
|
226 |
private boolean canUseDownloadManager(URL url) { |
|
227 |
return Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO |
|
228 |
&& !DownloaderFactory.isOnionAddress(url); |
|
229 |
} |
|
230 |
|
|
231 | 210 |
private void sendMessage(String type) { |
232 | 211 |
sendProgressEvent(new ProgressListener.Event(type)); |
233 | 212 |
} |
Also available in: Unified diff