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

Side by Side Diff: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java

Issue 29524668: Issue 3916 - Supporting Adding filter lists via URL (Closed)
Patch Set: Renamed URLInputPreference and adjusted layout design Created Sept. 15, 2017, 12:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 public static final String USER_FILTERS_TITLE = "__filters"; 67 public static final String USER_FILTERS_TITLE = "__filters";
68 public static final String USER_EXCEPTIONS_TITLE = "__exceptions"; 68 public static final String USER_EXCEPTIONS_TITLE = "__exceptions";
69 69
70 public static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser"; 70 public static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser";
71 public static final String EASYLIST_URL = "https://easylist-downloads.adblockp lus.org/easylist.txt"; 71 public static final String EASYLIST_URL = "https://easylist-downloads.adblockp lus.org/easylist.txt";
72 private static final String ACTION_OPEN_SETTINGS = "com.samsung.android.sbrows er.contentBlocker.ACTION_SETTING"; 72 private static final String ACTION_OPEN_SETTINGS = "com.samsung.android.sbrows er.contentBlocker.ACTION_SETTING";
73 private static final String ACTION_UPDATE = "com.samsung.android.sbrowser.cont entBlocker.ACTION_UPDATE"; 73 private static final String ACTION_UPDATE = "com.samsung.android.sbrowser.cont entBlocker.ACTION_UPDATE";
74 74
75 public static final String SUBSCRIPTIONS_EXCEPTIONSURL = "subscriptions_except ionsurl"; 75 public static final String SUBSCRIPTIONS_EXCEPTIONSURL = "subscriptions_except ionsurl";
76 76
77 public static final HashMap<String, Integer> URL_TO_RES_ID_MAP = new HashMap<> ();
diegocarloslima 2017/09/22 17:43:42 I know that I asked you in the last code review to
jens 2017/09/26 10:25:02 Acknowledged.
78
77 // The value below specifies an interval of [x, 2*x[, where x = 79 // The value below specifies an interval of [x, 2*x[, where x =
78 // INITIAL_UPDATE_CHECK_DELAY 80 // INITIAL_UPDATE_CHECK_DELAY
79 private static final long INITIAL_UPDATE_CHECK_DELAY = 5 * DateUtils.SECOND_IN _MILLIS; 81 private static final long INITIAL_UPDATE_CHECK_DELAY = 5 * DateUtils.SECOND_IN _MILLIS;
80 private static final long UPDATE_CHECK_INTERVAL = 30 * DateUtils.MINUTE_IN_MIL LIS; 82 private static final long UPDATE_CHECK_INTERVAL = 30 * DateUtils.MINUTE_IN_MIL LIS;
81 private static final long BROADCAST_COMBINATION_DELAY = 2500; 83 private static final long BROADCAST_COMBINATION_DELAY = 2500;
82 84
83 private static final int NO_FLAG = 0; 85 private static final int NO_FLAG = 0;
84 private static final int OLDEST_SAMSUNG_INTERNET_5_VERSIONCODE = 500000000; 86 private static final int OLDEST_SAMSUNG_INTERNET_5_VERSIONCODE = 500000000;
85 87
86 private final ReentrantLock accessLock = new ReentrantLock(); 88 private final ReentrantLock accessLock = new ReentrantLock();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 251 }
250 252
251 public void subscriptionStateChanged() 253 public void subscriptionStateChanged()
252 { 254 {
253 if (this.subscriptionUpdateCallback != null) 255 if (this.subscriptionUpdateCallback != null)
254 { 256 {
255 subscriptionUpdateCallback.subscriptionUpdatedApplied(); 257 subscriptionUpdateCallback.subscriptionUpdatedApplied();
256 } 258 }
257 } 259 }
258 260
261 public void createAndAddSubscriptionFromUrl(final String url, final Subscripti onAddedCallback callback) throws IOException
262 {
263 final Subscription sub = Subscription.create(url);
264 sub.putMeta(Subscription.KEY_TITLE, url);
265 sub.setEnabled(true);
266 subscriptions.add(sub);
267 subscriptions.persistSubscription(sub);
268 callback.subscriptionAdded();
269 }
270
271 public void removeSubscriptionById(final String subscriptionId)
272 {
273 subscriptions.remove(subscriptionId);
274 }
275
259 void downloadFinished(final String id, final int responseCode, final String re sponse, 276 void downloadFinished(final String id, final int responseCode, final String re sponse,
260 final Map<String, String> headers) 277 final Map<String, String> headers)
261 { 278 {
262 this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response, headers)); 279 this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response, headers));
263 } 280 }
264 281
265 private void createAndWriteFile() 282 private void createAndWriteFile()
266 { 283 {
267 this.lock(); 284 this.lock();
268 try 285 try
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 sb.append(downloadCount); 621 sb.append(downloadCount);
605 } 622 }
606 else 623 else
607 { 624 {
608 sb.append("4%2B"); // "4+" URL encoded 625 sb.append("4%2B"); // "4+" URL encoded
609 } 626 }
610 627
611 return new URL(sb.toString()); 628 return new URL(sb.toString());
612 } 629 }
613 630
631 public List<SubscriptionInfo> getMoreBlockingPreferenceSubscriptions()
diegocarloslima 2017/09/22 17:43:43 Please read my comment above regarding moving this
jens 2017/09/26 10:25:02 Acknowledged.
632 {
633 List<SubscriptionInfo> moreBlockingPreferenceSubscriptions = new ArrayList<> (5);
634 for (SubscriptionInfo sub : getListedSubscriptions())
635 {
636 final DefaultSubscriptionInfo info = getDefaultSubscriptionInfoForUrl(sub. getUrl());
637 Integer resInt = URL_TO_RES_ID_MAP.get(sub.getUrl());
638
639 if (sub.getType() == SubscriptionInfo.Type.CUSTOM)
640 {
641 moreBlockingPreferenceSubscriptions.add(sub);
642 }
643
644 if (info != null && !info.isComplete() && sub.isEnabled())
645 {
646 moreBlockingPreferenceSubscriptions.add(sub);
647 }
648
649 if ((!(isAcceptableAdsUrl(sub)) || sub.getTitle().startsWith("__"))
650 && resInt != null
651 && (info == null || info.getPrefixes().isEmpty() || sub.getType() != S ubscriptionInfo.Type.ADS))
652 {
653 moreBlockingPreferenceSubscriptions.add(sub);
654 }
655 }
656
657 return moreBlockingPreferenceSubscriptions;
658 }
659
660 private boolean isAcceptableAdsUrl(final SubscriptionInfo subscriptionInfo)
diegocarloslima 2017/09/22 17:43:43 If we move the method above, we should make this p
jens 2017/09/26 10:25:02 Acknowledged.
661 {
662 return getPrefsDefault(SUBSCRIPTIONS_EXCEPTIONSURL).equals(subscriptionInfo. getUrl());
663 }
664
614 private static class EventHandler implements Runnable 665 private static class EventHandler implements Runnable
615 { 666 {
616 private static final String TAG = EventHandler.class.getSimpleName(); 667 private static final String TAG = EventHandler.class.getSimpleName();
617 private final Engine engine; 668 private final Engine engine;
618 669
619 public EventHandler(final Engine engine) 670 public EventHandler(final Engine engine)
620 { 671 {
621 this.engine = engine; 672 this.engine = engine;
622 } 673 }
623 674
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 public void connectivityChanged() 831 public void connectivityChanged()
781 { 832 {
782 this.downloader.connectivityChanged(); 833 this.downloader.connectivityChanged();
783 } 834 }
784 835
785 public interface SubscriptionUpdateCallback 836 public interface SubscriptionUpdateCallback
786 { 837 {
787 void subscriptionUpdateRequested(boolean enabled); 838 void subscriptionUpdateRequested(boolean enabled);
788 void subscriptionUpdatedApplied(); 839 void subscriptionUpdatedApplied();
789 } 840 }
841
842 public interface SubscriptionAddedCallback
843 {
844 void subscriptionAdded();
845 }
790 } 846 }
OLDNEW

Powered by Google App Engine
This is Rietveld