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 29505565: Issue 5237 - Correct filter lists not applied on other language installation (Closed)
Patch Set: Fixed typo in SubscriptionUtils Created Aug. 15, 2017, 7:31 a.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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 26 matching lines...) Expand all
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.SharedPrefsUtils; 46 import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils;
47 import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils;
47 48
48 import android.content.Context; 49 import android.content.Context;
49 import android.content.Intent; 50 import android.content.Intent;
50 import android.content.pm.PackageInfo; 51 import android.content.pm.PackageInfo;
51 import android.content.pm.PackageManager; 52 import android.content.pm.PackageManager;
52 import android.content.pm.ResolveInfo; 53 import android.content.pm.ResolveInfo;
53 import android.net.ConnectivityManager; 54 import android.net.ConnectivityManager;
54 import android.net.NetworkInfo; 55 import android.net.NetworkInfo;
55 import android.net.Uri; 56 import android.net.Uri;
56 import android.os.Handler; 57 import android.os.Handler;
57 import android.os.Looper; 58 import android.os.Looper;
58 import android.text.TextUtils; 59 import android.text.TextUtils;
59 import android.text.format.DateUtils; 60 import android.text.format.DateUtils;
60 import android.util.Log; 61 import android.util.Log;
61 62
62 public final class Engine 63 public final class Engine
63 { 64 {
64 private static final String TAG = Engine.class.getSimpleName(); 65 private static final String TAG = Engine.class.getSimpleName();
65 66
66 public static final String USER_FILTERS_TITLE = "__filters"; 67 public static final String USER_FILTERS_TITLE = "__filters";
67 public static final String USER_EXCEPTIONS_TITLE = "__exceptions"; 68 public static final String USER_EXCEPTIONS_TITLE = "__exceptions";
68 69
69 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";
70 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";
71 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";
72 private static final String EASYLIST_URL = "https://easylist-downloads.adblock plus.org/easylist.txt";
73 74
74 public static final String SUBSCRIPTIONS_EXCEPTIONSURL = "subscriptions_except ionsurl"; 75 public static final String SUBSCRIPTIONS_EXCEPTIONSURL = "subscriptions_except ionsurl";
75 76
76 // 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 =
77 // INITIAL_UPDATE_CHECK_DELAY 78 // INITIAL_UPDATE_CHECK_DELAY
78 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;
79 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;
80 private static final long BROADCAST_COMBINATION_DELAY = 2500; 81 private static final long BROADCAST_COMBINATION_DELAY = 2500;
81 82
82 private static final int NO_FLAG = 0; 83 private static final int NO_FLAG = 0;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 boolean canUseInternet() 199 boolean canUseInternet()
199 { 200 {
200 final ConnectivityManager connManager = (ConnectivityManager) this.serviceCo ntext 201 final ConnectivityManager connManager = (ConnectivityManager) this.serviceCo ntext
201 .getSystemService(Context.CONNECTIVITY_SERVICE); 202 .getSystemService(Context.CONNECTIVITY_SERVICE);
202 final NetworkInfo current = connManager.getActiveNetworkInfo(); 203 final NetworkInfo current = connManager.getActiveNetworkInfo();
203 if (current == null) 204 if (current == null)
204 { 205 {
205 return false; 206 return false;
206 } 207 }
207 208
209 if (wasFirstRun())
210 {
211 return true;
212 }
213
208 final boolean wifiOnly = "1".equals(SharedPrefsUtils.getString( 214 final boolean wifiOnly = "1".equals(SharedPrefsUtils.getString(
209 this.serviceContext, R.string.key_automatic_updates , "1")); 215 this.serviceContext, R.string.key_automatic_updates , "1"));
210 216
211 if (wifiOnly) 217 if (wifiOnly)
212 { 218 {
213 if (current.isConnected() && !current.isRoaming()) 219 if (current.isConnected() && !current.isRoaming())
214 { 220 {
215 switch (current.getType()) 221 switch (current.getType())
216 { 222 {
217 case ConnectivityManager.TYPE_BLUETOOTH: 223 case ConnectivityManager.TYPE_BLUETOOTH:
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 { 316 {
311 this.unlock(); 317 this.unlock();
312 } 318 }
313 } 319 }
314 320
315 public DefaultSubscriptionInfo getDefaultSubscriptionInfoForUrl(final String u rl) 321 public DefaultSubscriptionInfo getDefaultSubscriptionInfoForUrl(final String u rl)
316 { 322 {
317 return this.defaultSubscriptions.getForUrl(url); 323 return this.defaultSubscriptions.getForUrl(url);
318 } 324 }
319 325
320 public boolean wasFirstRun() 326 /**
327 * If the user starts the app for the first time, we force to update the subsc ription which was
328 * selected as the default, no matter if he has a WIFI connection or not. From the second start
329 * we only update when the user has a WIFI connection.
330 *
331 * @return a boolean that indicated if this is the first start of the app
332 */
333 private boolean wasFirstRun()
321 { 334 {
322 return this.wasFirstRun; 335 if (wasFirstRun)
336 {
337 this.wasFirstRun = false;
338 return true;
339 }
340 else
341 {
342 return false;
343 }
323 } 344 }
324 345
325 private void migrateFromPreviousVersion(final Context context) 346 private void migrateFromPreviousVersion(final Context context)
326 { 347 {
327 try 348 try
328 { 349 {
329 final int versionCode = context.getPackageManager().getPackageInfo(context .getPackageName(), 350 final int versionCode = context.getPackageManager().getPackageInfo(context .getPackageName(),
330 0).versionCode; 351 0).versionCode;
331 352
332 final int previousVersionCode = SharedPrefsUtils.getInt( 353 final int previousVersionCode = SharedPrefsUtils.getInt(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 400
380 // Check if this is a fresh start, if so: initialize bundled easylist. 401 // Check if this is a fresh start, if so: initialize bundled easylist.
381 engine.wasFirstRun = engine.subscriptions.wasUnitialized(); 402 engine.wasFirstRun = engine.subscriptions.wasUnitialized();
382 if (engine.subscriptions.wasUnitialized()) 403 if (engine.subscriptions.wasUnitialized())
383 { 404 {
384 Log.d(TAG, "Subscription storage was uninitialized, initializing..."); 405 Log.d(TAG, "Subscription storage was uninitialized, initializing...");
385 406
386 try (final InputStream easylistTxt = context.getResources().openRawResourc e(R.raw.easylist)) 407 try (final InputStream easylistTxt = context.getResources().openRawResourc e(R.raw.easylist))
387 { 408 {
388 final Subscription easylist = engine.subscriptions.add(Subscription 409 final Subscription easylist = engine.subscriptions.add(Subscription
389 .create(EASYLIST_URL) 410 // Use bundled EasyList as default and update it with locale specifi c list later
411 // see: https://issues.adblockplus.org/ticket/5237
412 .create(SubscriptionUtils.chooseDefaultSubscriptionUrl(engine.defaul tSubscriptions.getAdsSubscriptions()))
390 .parseLines(readLines(easylistTxt))); 413 .parseLines(readLines(easylistTxt)));
391 easylist.putMeta(Subscription.KEY_UPDATE_TIMESTAMP, "0"); 414 easylist.putMeta(Subscription.KEY_UPDATE_TIMESTAMP, "0");
392 easylist.setEnabled(true); 415 easylist.setEnabled(true);
393 } 416 }
394 Log.d(TAG, "Added and enabled bundled easylist"); 417 Log.d(TAG, "Added and enabled bundled easylist");
395 418
396 try (final InputStream exceptionsTxt = context.getResources() 419 try (final InputStream exceptionsTxt = context.getResources()
397 .openRawResource(R.raw.exceptionrules)) 420 .openRawResource(R.raw.exceptionrules))
398 { 421 {
399 final Subscription exceptions = engine.subscriptions.add(Subscription 422 final Subscription exceptions = engine.subscriptions.add(Subscription
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 { 781 {
759 this.downloader.connectivityChanged(); 782 this.downloader.connectivityChanged();
760 } 783 }
761 784
762 public interface SubscriptionUpdateCallback 785 public interface SubscriptionUpdateCallback
763 { 786 {
764 void subscriptionUpdateRequested(boolean enabled); 787 void subscriptionUpdateRequested(boolean enabled);
765 void subscriptionUpdatedApplied(); 788 void subscriptionUpdatedApplied();
766 } 789 }
767 } 790 }
OLDNEW

Powered by Google App Engine
This is Rietveld