Revision 69ecaf02 F-Droid/src/org/fdroid/fdroid/net/DownloaderFactory.java

View differences:

F-Droid/src/org/fdroid/fdroid/net/DownloaderFactory.java
1 1
package org.fdroid.fdroid.net;
2 2

  
3 3
import android.content.Context;
4
import android.os.Build;
4 5

  
5 6
import java.io.File;
6 7
import java.io.IOException;
8
import java.net.MalformedURLException;
7 9
import java.net.URL;
8 10

  
9 11
public class DownloaderFactory {
......
51 53
        return "bluetooth".equalsIgnoreCase(url.getProtocol());
52 54
    }
53 55

  
56
    public static AsyncDownloader createAsync(Context context, String urlString, File destFile, String title, String id, AsyncDownloader.Listener listener) throws IOException {
57
        return createAsync(context, new URL(urlString), destFile, title, id, listener);
58
    }
59

  
60
    public static AsyncDownloader createAsync(Context context, URL url, File destFile, String title, String id, AsyncDownloader.Listener listener)
61
            throws IOException {
62
        if (canUseDownloadManager(url)) {
63
            return new AsyncDownloaderFromAndroid(context, listener, title, id, url.toString(), destFile);
64
        } else {
65
            return new AsyncDownloader(create(context, url, destFile), listener);
66
        }
67
    }
68

  
54 69
    static boolean isOnionAddress(URL url) {
55 70
        return url.getHost().endsWith(".onion");
56 71
    }
72

  
73
    /**
74
     * Tests to see if we can use Android's DownloadManager to download the APK, instead of
75
     * a downloader returned from DownloadFactory.
76
     */
77
    private static boolean canUseDownloadManager(URL url) {
78
        return Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO && !isOnionAddress(url);
79
    }
80

  
57 81
}

Also available in: Unified diff