Index: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/Downloader.java |
=================================================================== |
--- a/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/Downloader.java |
+++ b/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/Downloader.java |
@@ -104,25 +104,26 @@ final class Downloader |
for (int ch = r.read(); ch != -1; ch = r.read()) |
{ |
sb.append((char) ch); |
} |
job.responseText = sb.toString(); |
} |
} |
- public void enqueueDownload(final URL url, final String id, final Map<String, String> headers) |
+ public void enqueueDownload(final URL url, final String id, final Map<String, String> headers, |
+ final boolean allowMetered) |
{ |
this.lock(); |
try |
{ |
if (!this.enqueuedIds.contains(id)) |
{ |
this.enqueuedIds.add(id); |
- this.downloadJobs.add(new DownloadJob(url, id, headers)); |
+ this.downloadJobs.add(new DownloadJob(url, id, headers, allowMetered)); |
} |
} |
finally |
{ |
this.unlock(); |
} |
} |
@@ -162,17 +163,17 @@ final class Downloader |
if (!this.downloader.downloaderEnabled) |
{ |
Thread.sleep(30000); |
continue; |
} |
job = this.downloader.downloadJobs.poll(5 * 60, TimeUnit.SECONDS); |
if (job != null) |
{ |
- if (this.downloader.engine.canUseInternet()) |
+ if (this.downloader.engine.canUseInternet(job.allowMetered)) |
{ |
Log.d(TAG, "Downloading '" + job.id + "' using " + job.url); |
download(job); |
Log.d(TAG, "Downloading '" + job.id + "' finished with response code " |
+ job.responseCode); |
this.downloader.lock(); |
try |
{ |
@@ -236,26 +237,28 @@ final class Downloader |
Log.d(TAG, "Handler thread finished"); |
} |
} |
private static class DownloadJob |
{ |
private final URL url; |
private final String id; |
+ private final boolean allowMetered; |
private final HashMap<String, String> headers = new HashMap<>(); |
private int retryCount = 0; |
private int responseCode = 0; |
private final HashMap<String, String> responseHeaders = new HashMap<>(); |
private String responseText = null; |
- public DownloadJob(final URL url, final String id, final Map<String, String> headers) |
+ public DownloadJob(final URL url, final String id, final Map<String, String> headers, boolean allowMetered) |
{ |
this.url = url; |
this.id = id; |
+ this.allowMetered = allowMetered; |
if (headers != null) |
{ |
this.headers.putAll(headers); |
} |
} |
} |
} |