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 |
@@ -39,16 +39,17 @@ import java.util.Map; |
import java.util.Set; |
import java.util.TreeSet; |
import java.util.concurrent.LinkedBlockingQueue; |
import java.util.concurrent.TimeUnit; |
import java.util.concurrent.locks.ReentrantLock; |
import org.adblockplus.adblockplussbrowser.R; |
import org.adblockplus.sbrowser.contentblocker.util.SharedPrefsUtils; |
+import org.adblockplus.sbrowser.contentblocker.util.SubscriptionUtils; |
import android.content.Context; |
import android.content.Intent; |
import android.content.pm.PackageInfo; |
import android.content.pm.PackageManager; |
import android.content.pm.ResolveInfo; |
import android.net.ConnectivityManager; |
import android.net.NetworkInfo; |
@@ -62,19 +63,19 @@ import android.util.Log; |
public final class Engine |
{ |
private static final String TAG = Engine.class.getSimpleName(); |
public static final String USER_FILTERS_TITLE = "__filters"; |
public static final String USER_EXCEPTIONS_TITLE = "__exceptions"; |
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"; |
- private static final String EASYLIST_URL = "https://easylist-downloads.adblockplus.org/easylist.txt"; |
public static final String SUBSCRIPTIONS_EXCEPTIONSURL = "subscriptions_exceptionsurl"; |
// 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; |
@@ -200,16 +201,21 @@ public final class Engine |
final ConnectivityManager connManager = (ConnectivityManager) this.serviceContext |
.getSystemService(Context.CONNECTIVITY_SERVICE); |
final NetworkInfo current = connManager.getActiveNetworkInfo(); |
if (current == null) |
{ |
return false; |
} |
+ if (wasFirstRun()) |
+ { |
+ return true; |
+ } |
+ |
final boolean wifiOnly = "1".equals(SharedPrefsUtils.getString( |
this.serviceContext, R.string.key_automatic_updates , "1")); |
if (wifiOnly) |
{ |
if (current.isConnected() && !current.isRoaming()) |
{ |
switch (current.getType()) |
@@ -312,19 +318,34 @@ public final class Engine |
} |
} |
public DefaultSubscriptionInfo getDefaultSubscriptionInfoForUrl(final String url) |
{ |
return this.defaultSubscriptions.getForUrl(url); |
} |
- public boolean wasFirstRun() |
+ /** |
+ * If the user starts the app for the first time, we force to update the subscription which was |
+ * selected as the default, no matter if he has a WIFI connection or not. From the second start |
+ * we only update when the user has a WIFI connection. |
+ * |
+ * @return a boolean that indicated if this is the first start of the app |
+ */ |
+ private boolean wasFirstRun() |
{ |
- return this.wasFirstRun; |
+ if (wasFirstRun) |
+ { |
+ this.wasFirstRun = false; |
+ return true; |
+ } |
+ else |
+ { |
+ return false; |
+ } |
} |
private void migrateFromPreviousVersion(final Context context) |
{ |
try |
{ |
final int versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), |
0).versionCode; |
@@ -381,17 +402,19 @@ public final class Engine |
engine.wasFirstRun = engine.subscriptions.wasUnitialized(); |
if (engine.subscriptions.wasUnitialized()) |
{ |
Log.d(TAG, "Subscription storage was uninitialized, initializing..."); |
try (final InputStream easylistTxt = context.getResources().openRawResource(R.raw.easylist)) |
{ |
final Subscription easylist = engine.subscriptions.add(Subscription |
- .create(EASYLIST_URL) |
+ // Use bundled EasyList as default and update it with locale specific list later |
+ // see: https://issues.adblockplus.org/ticket/5237 |
+ .create(SubscriptionUtils.chooseDefaultSubscriptionUrl(engine.defaultSubscriptions.getAdsSubscriptions())) |
.parseLines(readLines(easylistTxt))); |
easylist.putMeta(Subscription.KEY_UPDATE_TIMESTAMP, "0"); |
easylist.setEnabled(true); |
} |
Log.d(TAG, "Added and enabled bundled easylist"); |
try (final InputStream exceptionsTxt = context.getResources() |
.openRawResource(R.raw.exceptionrules)) |