Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/Engine.java

Issue 29673565: Issue 6066 - Implement 'force update' functionality for subscriptions (Closed)
Left Patch Set: Created Jan. 18, 2018, 1:47 p.m.
Right Patch Set: Fixes Created Jan. 23, 2018, 3:12 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 25 matching lines...) Expand all
36 import java.util.HashMap; 36 import java.util.HashMap;
37 import java.util.List; 37 import java.util.List;
38 import java.util.Map; 38 import java.util.Map;
39 import java.util.Set; 39 import java.util.Set;
40 import java.util.TreeSet; 40 import java.util.TreeSet;
41 import java.util.concurrent.LinkedBlockingQueue; 41 import java.util.concurrent.LinkedBlockingQueue;
42 import java.util.concurrent.TimeUnit; 42 import java.util.concurrent.TimeUnit;
43 import java.util.concurrent.locks.ReentrantLock; 43 import java.util.concurrent.locks.ReentrantLock;
44 44
45 import org.adblockplus.adblockplussbrowser.R; 45 import org.adblockplus.adblockplussbrowser.R;
46 import org.adblockplus.sbrowser.contentblocker.util.ConnectivityUtils;
46 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; 47 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils;
47 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils; 48 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils;
48 49
49 import android.content.Context; 50 import android.content.Context;
50 import android.content.Intent; 51 import android.content.Intent;
51 import android.content.pm.PackageInfo; 52 import android.content.pm.PackageInfo;
52 import android.content.pm.PackageManager; 53 import android.content.pm.PackageManager;
53 import android.content.pm.ResolveInfo; 54 import android.content.pm.ResolveInfo;
54 import android.net.ConnectivityManager; 55 import android.net.ConnectivityManager;
55 import android.net.NetworkInfo; 56 import android.net.NetworkInfo;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 public void run() 191 public void run()
191 { 192 {
192 final Intent intent = new Intent(); 193 final Intent intent = new Intent();
193 intent.setAction(ACTION_UPDATE); 194 intent.setAction(ACTION_UPDATE);
194 intent.setData(Uri.parse("package:" + Engine.this.serviceContext.getPack ageName())); 195 intent.setData(Uri.parse("package:" + Engine.this.serviceContext.getPack ageName()));
195 Engine.this.serviceContext.sendBroadcast(intent); 196 Engine.this.serviceContext.sendBroadcast(intent);
196 } 197 }
197 }); 198 });
198 } 199 }
199 200
200 boolean canUseInternet() 201 boolean canUseInternet(final boolean allowMetered)
201 { 202 {
202 final ConnectivityManager connManager = (ConnectivityManager) this.serviceCo ntext 203 // allow a metered connection to update default subscriptions at the first r un.
203 .getSystemService(Context.CONNECTIVITY_SERVICE); 204 // See https://issues.adblockplus.org/ticket/5237
204 final NetworkInfo current = connManager.getActiveNetworkInfo(); 205 return ConnectivityUtils.canUseInternet(serviceContext, allowMetered || wasF irstRun());
205 if (current == null)
206 {
207 return false;
208 }
209
210 if (wasFirstRun())
211 {
212 return true;
213 }
214
215 final boolean wifiOnly = "1".equals(SharedPrefsUtils.getString(
216 this.serviceContext, R.string.key_automatic_updates , "1"));
217
218 if (wifiOnly)
219 {
220 if (current.isConnected() && !current.isRoaming())
221 {
222 switch (current.getType())
223 {
224 case ConnectivityManager.TYPE_BLUETOOTH:
225 case ConnectivityManager.TYPE_ETHERNET:
226 case ConnectivityManager.TYPE_WIFI:
227 case ConnectivityManager.TYPE_WIMAX:
228 return true;
229 default:
230 return false;
231 }
232 }
233 return false;
234 }
235 return current.isConnected();
236 } 206 }
237 207
238 public void forceUpdateSubscriptions(final boolean allowMetered) 208 public void forceUpdateSubscriptions(final boolean allowMetered)
239 { 209 {
240 try 210 try
241 { 211 {
242 subscriptions.checkForUpdates(true, allowMetered); 212 subscriptions.checkForUpdates(true, allowMetered);
243 Toast.makeText(serviceContext, serviceContext.getText(R.string.updating_su bscriptions), Toast.LENGTH_LONG).show(); 213 Toast.makeText(serviceContext, serviceContext.getText(R.string.updating_su bscriptions), Toast.LENGTH_LONG).show();
244 } 214 }
245 catch (IOException e) 215 catch (IOException e)
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 this.id = id; 753 this.id = id;
784 this.responseCode = responseCode; 754 this.responseCode = responseCode;
785 this.response = response; 755 this.response = response;
786 if (headers != null) 756 if (headers != null)
787 { 757 {
788 this.headers.putAll(headers); 758 this.headers.putAll(headers);
789 } 759 }
790 } 760 }
791 } 761 }
792 762
793 public void enqueueDownload(final Subscription sub, final boolean forced, fina l boolean allowMetered) throws IOException 763 public void enqueueDownload(final Subscription sub, final boolean forced,
anton 2018/01/19 10:53:02 the line seems to be too long
jens 2018/01/19 11:00:28 Acknowledged.
764 final boolean allowMetered) throws IOException
794 { 765 {
795 if (sub.getURL() != null && sub.shouldUpdate(forced)) 766 if (sub.getURL() != null && sub.shouldUpdate(forced))
796 { 767 {
797 final HashMap<String, String> headers = new HashMap<>(); 768 final HashMap<String, String> headers = new HashMap<>();
798 if (sub.isMetaDataValid() && sub.isFiltersValid()) 769 if (sub.isMetaDataValid() && sub.isFiltersValid())
799 { 770 {
800 final String lastModified = sub.getMeta(Subscription.KEY_HTTP_LAST_MODIF IED); 771 final String lastModified = sub.getMeta(Subscription.KEY_HTTP_LAST_MODIF IED);
801 if (!TextUtils.isEmpty(lastModified)) 772 if (!TextUtils.isEmpty(lastModified))
802 { 773 {
803 headers.put("If-Modified-Since", lastModified); 774 headers.put("If-Modified-Since", lastModified);
(...skipping 18 matching lines...) Expand all
822 { 793 {
823 void subscriptionUpdateRequested(boolean enabled); 794 void subscriptionUpdateRequested(boolean enabled);
824 void subscriptionUpdatedApplied(); 795 void subscriptionUpdatedApplied();
825 } 796 }
826 797
827 public interface SubscriptionAddedCallback 798 public interface SubscriptionAddedCallback
828 { 799 {
829 void subscriptionAdded(); 800 void subscriptionAdded();
830 } 801 }
831 } 802 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld