| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 Loading... | |
| 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 | |
| 79 // The value below specifies an interval of [x, 2*x[, where x = | 77 // The value below specifies an interval of [x, 2*x[, where x = |
| 80 // INITIAL_UPDATE_CHECK_DELAY | 78 // INITIAL_UPDATE_CHECK_DELAY |
| 81 private static final long INITIAL_UPDATE_CHECK_DELAY = 5 * DateUtils.SECOND_IN _MILLIS; | 79 private static final long INITIAL_UPDATE_CHECK_DELAY = 5 * DateUtils.SECOND_IN _MILLIS; |
| 82 private static final long UPDATE_CHECK_INTERVAL = 30 * DateUtils.MINUTE_IN_MIL LIS; | 80 private static final long UPDATE_CHECK_INTERVAL = 30 * DateUtils.MINUTE_IN_MIL LIS; |
| 83 private static final long BROADCAST_COMBINATION_DELAY = 2500; | 81 private static final long BROADCAST_COMBINATION_DELAY = 2500; |
| 84 | 82 |
| 85 private static final int NO_FLAG = 0; | 83 private static final int NO_FLAG = 0; |
| 86 private static final int OLDEST_SAMSUNG_INTERNET_5_VERSIONCODE = 500000000; | 84 private static final int OLDEST_SAMSUNG_INTERNET_5_VERSIONCODE = 500000000; |
| 87 | 85 |
| 88 private final ReentrantLock accessLock = new ReentrantLock(); | 86 private final ReentrantLock accessLock = new ReentrantLock(); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 } | 249 } |
| 252 | 250 |
| 253 public void subscriptionStateChanged() | 251 public void subscriptionStateChanged() |
| 254 { | 252 { |
| 255 if (this.subscriptionUpdateCallback != null) | 253 if (this.subscriptionUpdateCallback != null) |
| 256 { | 254 { |
| 257 subscriptionUpdateCallback.subscriptionUpdatedApplied(); | 255 subscriptionUpdateCallback.subscriptionUpdatedApplied(); |
| 258 } | 256 } |
| 259 } | 257 } |
| 260 | 258 |
| 261 public void createAndAddSubscriptionFromUrl(final String url, final Subscripti onAddedCallback callback) throws IOException | 259 public void createAndAddSubscriptionFromUrl(final String url, |
| 260 final SubscriptionAddedCallback callback) throws IOException | |
| 262 { | 261 { |
| 263 final Subscription sub = Subscription.create(url); | 262 final Subscription sub = Subscription.create(url); |
| 264 sub.putMeta(Subscription.KEY_TITLE, url); | 263 sub.putMeta(Subscription.KEY_TITLE, url); |
| 265 sub.setEnabled(true); | 264 sub.setEnabled(true); |
| 266 subscriptions.add(sub); | 265 subscriptions.add(sub); |
| 267 subscriptions.persistSubscription(sub); | 266 subscriptions.persistSubscription(sub); |
| 268 callback.subscriptionAdded(); | 267 callback.subscriptionAdded(); |
| 269 } | 268 } |
| 270 | 269 |
| 271 public void removeSubscriptionById(final String subscriptionId) | 270 public void removeSubscriptionById(final String subscriptionId) |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 engine.wasFirstRun = engine.subscriptions.wasUnitialized(); | 418 engine.wasFirstRun = engine.subscriptions.wasUnitialized(); |
| 420 if (engine.subscriptions.wasUnitialized()) | 419 if (engine.subscriptions.wasUnitialized()) |
| 421 { | 420 { |
| 422 Log.d(TAG, "Subscription storage was uninitialized, initializing..."); | 421 Log.d(TAG, "Subscription storage was uninitialized, initializing..."); |
| 423 | 422 |
| 424 try (final InputStream easylistTxt = context.getResources().openRawResourc e(R.raw.easylist)) | 423 try (final InputStream easylistTxt = context.getResources().openRawResourc e(R.raw.easylist)) |
| 425 { | 424 { |
| 426 final Subscription easylist = engine.subscriptions.add(Subscription | 425 final Subscription easylist = engine.subscriptions.add(Subscription |
| 427 // Use bundled EasyList as default and update it with locale specifi c list later | 426 // Use bundled EasyList as default and update it with locale specifi c list later |
| 428 // see: https://issues.adblockplus.org/ticket/5237 | 427 // see: https://issues.adblockplus.org/ticket/5237 |
| 429 .create(SubscriptionUtils.chooseDefaultSubscriptionUrl(engine.defaul tSubscriptions.getAdsSubscriptions())) | 428 .create(SubscriptionUtils.chooseDefaultSubscriptionUrl( |
| 429 engine.defaultSubscriptions.getAdsSubscriptions())) | |
| 430 .parseLines(readLines(easylistTxt))); | 430 .parseLines(readLines(easylistTxt))); |
| 431 easylist.putMeta(Subscription.KEY_UPDATE_TIMESTAMP, "0"); | 431 easylist.putMeta(Subscription.KEY_UPDATE_TIMESTAMP, "0"); |
| 432 easylist.setEnabled(true); | 432 easylist.setEnabled(true); |
| 433 } | 433 } |
| 434 Log.d(TAG, "Added and enabled bundled easylist"); | 434 Log.d(TAG, "Added and enabled bundled easylist"); |
| 435 | 435 |
| 436 try (final InputStream exceptionsTxt = context.getResources() | 436 try (final InputStream exceptionsTxt = context.getResources() |
| 437 .openRawResource(R.raw.exceptionrules)) | 437 .openRawResource(R.raw.exceptionrules)) |
| 438 { | 438 { |
| 439 final Subscription exceptions = engine.subscriptions.add(Subscription | 439 final Subscription exceptions = engine.subscriptions.add(Subscription |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 sb.append(downloadCount); | 621 sb.append(downloadCount); |
| 622 } | 622 } |
| 623 else | 623 else |
| 624 { | 624 { |
| 625 sb.append("4%2B"); // "4+" URL encoded | 625 sb.append("4%2B"); // "4+" URL encoded |
| 626 } | 626 } |
| 627 | 627 |
| 628 return new URL(sb.toString()); | 628 return new URL(sb.toString()); |
| 629 } | 629 } |
| 630 | 630 |
| 631 public List<SubscriptionInfo> getMoreBlockingPreferenceSubscriptions() | 631 public boolean isAcceptableAdsUrl(final SubscriptionInfo subscriptionInfo) |
|
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 { | 632 { |
| 662 return getPrefsDefault(SUBSCRIPTIONS_EXCEPTIONSURL).equals(subscriptionInfo. getUrl()); | 633 return getPrefsDefault(SUBSCRIPTIONS_EXCEPTIONSURL).equals(subscriptionInfo. getUrl()); |
| 663 } | 634 } |
| 664 | 635 |
| 665 private static class EventHandler implements Runnable | 636 private static class EventHandler implements Runnable |
| 666 { | 637 { |
| 667 private static final String TAG = EventHandler.class.getSimpleName(); | 638 private static final String TAG = EventHandler.class.getSimpleName(); |
| 668 private final Engine engine; | 639 private final Engine engine; |
| 669 | 640 |
| 670 public EventHandler(final Engine engine) | 641 public EventHandler(final Engine engine) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 837 { | 808 { |
| 838 void subscriptionUpdateRequested(boolean enabled); | 809 void subscriptionUpdateRequested(boolean enabled); |
| 839 void subscriptionUpdatedApplied(); | 810 void subscriptionUpdatedApplied(); |
| 840 } | 811 } |
| 841 | 812 |
| 842 public interface SubscriptionAddedCallback | 813 public interface SubscriptionAddedCallback |
| 843 { | 814 { |
| 844 void subscriptionAdded(); | 815 void subscriptionAdded(); |
| 845 } | 816 } |
| 846 } | 817 } |
| LEFT | RIGHT |