| Index: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
| =================================================================== |
| --- a/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
| +++ b/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java |
| @@ -69,16 +69,18 @@ public final class Engine |
| public static final String SBROWSER_APP_ID = "com.sec.android.app.sbrowser"; |
| public static final String EASYLIST_URL = "https://easylist-downloads.adblockplus.org/easylist.txt"; |
| private static final String ACTION_OPEN_SETTINGS = "com.samsung.android.sbrowser.contentBlocker.ACTION_SETTING"; |
| private static final String ACTION_UPDATE = "com.samsung.android.sbrowser.contentBlocker.ACTION_UPDATE"; |
| public static final String SUBSCRIPTIONS_EXCEPTIONSURL = "subscriptions_exceptionsurl"; |
| + 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.
|
| + |
| // The value below specifies an interval of [x, 2*x[, where x = |
| // INITIAL_UPDATE_CHECK_DELAY |
| private static final long INITIAL_UPDATE_CHECK_DELAY = 5 * DateUtils.SECOND_IN_MILLIS; |
| private static final long UPDATE_CHECK_INTERVAL = 30 * DateUtils.MINUTE_IN_MILLIS; |
| private static final long BROADCAST_COMBINATION_DELAY = 2500; |
| private static final int NO_FLAG = 0; |
| private static final int OLDEST_SAMSUNG_INTERNET_5_VERSIONCODE = 500000000; |
| @@ -251,16 +253,31 @@ public final class Engine |
| public void subscriptionStateChanged() |
| { |
| if (this.subscriptionUpdateCallback != null) |
| { |
| subscriptionUpdateCallback.subscriptionUpdatedApplied(); |
| } |
| } |
| + public void createAndAddSubscriptionFromUrl(final String url, final SubscriptionAddedCallback callback) throws IOException |
| + { |
| + final Subscription sub = Subscription.create(url); |
| + sub.putMeta(Subscription.KEY_TITLE, url); |
| + sub.setEnabled(true); |
| + subscriptions.add(sub); |
| + subscriptions.persistSubscription(sub); |
| + callback.subscriptionAdded(); |
| + } |
| + |
| + public void removeSubscriptionById(final String subscriptionId) |
| + { |
| + subscriptions.remove(subscriptionId); |
| + } |
| + |
| void downloadFinished(final String id, final int responseCode, final String response, |
| final Map<String, String> headers) |
| { |
| this.engineEvents.add(new DownloadFinishedEvent(id, responseCode, response, headers)); |
| } |
| private void createAndWriteFile() |
| { |
| @@ -606,16 +623,50 @@ public final class Engine |
| else |
| { |
| sb.append("4%2B"); // "4+" URL encoded |
| } |
| return new URL(sb.toString()); |
| } |
| + 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.
|
| + { |
| + List<SubscriptionInfo> moreBlockingPreferenceSubscriptions = new ArrayList<>(5); |
| + for (SubscriptionInfo sub : getListedSubscriptions()) |
| + { |
| + final DefaultSubscriptionInfo info = getDefaultSubscriptionInfoForUrl(sub.getUrl()); |
| + Integer resInt = URL_TO_RES_ID_MAP.get(sub.getUrl()); |
| + |
| + if (sub.getType() == SubscriptionInfo.Type.CUSTOM) |
| + { |
| + moreBlockingPreferenceSubscriptions.add(sub); |
| + } |
| + |
| + if (info != null && !info.isComplete() && sub.isEnabled()) |
| + { |
| + moreBlockingPreferenceSubscriptions.add(sub); |
| + } |
| + |
| + if ((!(isAcceptableAdsUrl(sub)) || sub.getTitle().startsWith("__")) |
| + && resInt != null |
| + && (info == null || info.getPrefixes().isEmpty() || sub.getType() != SubscriptionInfo.Type.ADS)) |
| + { |
| + moreBlockingPreferenceSubscriptions.add(sub); |
| + } |
| + } |
| + |
| + return moreBlockingPreferenceSubscriptions; |
| + } |
| + |
| + 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.
|
| + { |
| + return getPrefsDefault(SUBSCRIPTIONS_EXCEPTIONSURL).equals(subscriptionInfo.getUrl()); |
| + } |
| + |
| private static class EventHandler implements Runnable |
| { |
| private static final String TAG = EventHandler.class.getSimpleName(); |
| private final Engine engine; |
| public EventHandler(final Engine engine) |
| { |
| this.engine = engine; |
| @@ -782,9 +833,14 @@ public final class Engine |
| this.downloader.connectivityChanged(); |
| } |
| public interface SubscriptionUpdateCallback |
| { |
| void subscriptionUpdateRequested(boolean enabled); |
| void subscriptionUpdatedApplied(); |
| } |
| + |
| + public interface SubscriptionAddedCallback |
| + { |
| + void subscriptionAdded(); |
| + } |
| } |