Index: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
=================================================================== |
--- a/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
+++ b/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
@@ -54,16 +54,17 @@ import android.content.pm.ResolveInfo; |
import android.net.ConnectivityManager; |
import android.net.NetworkInfo; |
import android.net.Uri; |
import android.os.Handler; |
import android.os.Looper; |
import android.text.TextUtils; |
import android.text.format.DateUtils; |
import android.util.Log; |
+import android.widget.Toast; |
public final class Engine |
{ |
private static final String TAG = Engine.class.getSimpleName(); |
public static final String USER_FILTERS_TITLE = "__filters"; |
public static final String USER_EXCEPTIONS_TITLE = "__exceptions"; |
@@ -229,16 +230,29 @@ public final class Engine |
return false; |
} |
} |
return false; |
} |
return current.isConnected(); |
} |
+ public void forceUpdateSubscriptions(final boolean allowMetered) |
+ { |
+ try |
+ { |
+ subscriptions.checkForUpdates(true, allowMetered); |
+ Toast.makeText(serviceContext, serviceContext.getText(R.string.updating_subscriptions), Toast.LENGTH_LONG).show(); |
+ } |
+ catch (IOException e) |
+ { |
+ Log.e(TAG, "Failed checking for updates", e); |
+ } |
+ } |
+ |
public List<SubscriptionInfo> getListedSubscriptions() |
{ |
return this.subscriptions.getSubscriptions(this); |
} |
public void changeSubscriptionState(final String id, final boolean enabled) |
{ |
if (this.subscriptionUpdateCallback != null) |
@@ -684,17 +698,17 @@ public final class Engine |
} |
} |
final long currentTime = System.currentTimeMillis(); |
if (currentTime > nextUpdateCheck) |
{ |
nextUpdateCheck = currentTime + UPDATE_CHECK_INTERVAL; |
- this.engine.subscriptions.checkForUpdates(); |
+ this.engine.subscriptions.checkForUpdates(false, false); |
} |
if (currentTime > this.engine.nextUpdateBroadcast) |
{ |
this.engine.nextUpdateBroadcast = Long.MAX_VALUE; |
Log.d(TAG, "Sending update broadcast"); |
this.engine.writeFileAndSendUpdateBroadcast(); |
} |
@@ -771,17 +785,17 @@ public final class Engine |
this.response = response; |
if (headers != null) |
{ |
this.headers.putAll(headers); |
} |
} |
} |
- public void enqueueDownload(final Subscription sub, final boolean forced) throws IOException |
+ public void enqueueDownload(final Subscription sub, final boolean forced, final boolean allowMetered) throws IOException |
anton
2018/01/19 10:53:02
the line seems to be too long
jens
2018/01/19 11:00:28
Acknowledged.
|
{ |
if (sub.getURL() != null && sub.shouldUpdate(forced)) |
{ |
final HashMap<String, String> headers = new HashMap<>(); |
if (sub.isMetaDataValid() && sub.isFiltersValid()) |
{ |
final String lastModified = sub.getMeta(Subscription.KEY_HTTP_LAST_MODIFIED); |
if (!TextUtils.isEmpty(lastModified)) |
@@ -790,17 +804,17 @@ public final class Engine |
} |
final String etag = sub.getMeta(Subscription.KEY_HTTP_ETAG); |
if (!TextUtils.isEmpty(etag)) |
{ |
headers.put("If-None-Match", etag); |
} |
} |
Log.d(TAG, headers.toString()); |
- this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), headers); |
+ this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), headers, allowMetered); |
} |
} |
public void connectivityChanged() |
{ |
this.downloader.connectivityChanged(); |
} |