Index: adblock-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java |
diff --git a/adblock-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java b/adblock-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java |
index 8cf6ab829fd3c032965aab4fe0e9792be8ece934..94198f33816dbc600051604113a41f9a69f50b41 100644 |
--- a/adblock-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java |
+++ b/adblock-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java |
@@ -39,6 +39,7 @@ import org.adblockplus.libadblockplus.ShowNotificationCallback; |
import org.adblockplus.libadblockplus.Subscription; |
import org.adblockplus.libadblockplus.UpdateAvailableCallback; |
import org.adblockplus.libadblockplus.UpdateCheckDoneCallback; |
+import org.adblockplus.libadblockplus.Updater; |
import org.adblockplus.libadblockplus.WebRequest; |
import android.content.Context; |
@@ -67,6 +68,7 @@ public final class AdblockEngine |
*/ |
private volatile Platform platform; |
private volatile FilterEngine filterEngine; |
+ private volatile Updater updater; |
private volatile LogSystem logSystem; |
private volatile WebRequest webRequest; |
private volatile UpdateAvailableCallback updateAvailableCallback; |
@@ -230,9 +232,9 @@ public final class AdblockEngine |
private void initCallbacks() |
{ |
- if (engine.updateAvailableCallback != null) |
+ if (engine.updater != null && engine.updateAvailableCallback != null) |
{ |
- engine.filterEngine.setUpdateAvailableCallback(engine.updateAvailableCallback); |
+ engine.updater.setUpdateAvailableCallback(engine.updateAvailableCallback); |
} |
if (engine.showNotificationCallback != null) |
@@ -247,11 +249,21 @@ public final class AdblockEngine |
} |
public AdblockEngine build() |
+ { |
+ return build(false); |
+ } |
+ |
+ public AdblockEngine buildWithUpdateCheck() |
+ { |
+ return build(true); |
+ } |
+ |
+ private AdblockEngine build(boolean updateCheckEnabled) |
{ |
initRequests(); |
// webRequest should be ready to be used passed right after JsEngine is created |
- createEngines(); |
+ createEngines(updateCheckEnabled); |
initCallbacks(); |
@@ -263,7 +275,7 @@ public final class AdblockEngine |
return engine; |
} |
- private void createEngines() |
+ private void createEngines(boolean updateCheckEnabled) |
{ |
engine.logSystem = new AndroidLogSystem(); |
engine.platform = new Platform(engine.logSystem, engine.webRequest, basePath); |
@@ -277,6 +289,10 @@ public final class AdblockEngine |
} |
engine.platform.setUpFilterEngine(isAllowedConnectionCallback); |
engine.filterEngine = engine.platform.getFilterEngine(); |
+ if (updateCheckEnabled) |
+ { |
+ engine.updater = engine.platform.getUpdater(); |
+ } |
} |
} |
@@ -289,14 +305,17 @@ public final class AdblockEngine |
{ |
Log.w(TAG, "Dispose"); |
- // engines first |
- if (this.filterEngine != null) |
+ if (this.updater != null) |
{ |
if (this.updateAvailableCallback != null) |
{ |
- this.filterEngine.removeUpdateAvailableCallback(); |
+ this.updater.removeUpdateAvailableCallback(); |
} |
+ } |
+ // engines first |
+ if (this.filterEngine != null) |
+ { |
if (this.filterChangeCallback != null) |
{ |
this.filterEngine.removeFilterChangeCallback(); |
@@ -318,6 +337,12 @@ public final class AdblockEngine |
this.updateAvailableCallback = null; |
} |
+ if (this.updateCheckDoneCallback != null) |
+ { |
+ this.updateCheckDoneCallback.dispose(); |
+ this.updateCheckDoneCallback = null; |
+ } |
+ |
if (this.filterChangeCallback != null) |
{ |
this.filterChangeCallback.dispose(); |
@@ -628,7 +653,8 @@ public final class AdblockEngine |
public void checkForUpdates() |
{ |
- this.filterEngine.forceUpdateCheck(this.updateCheckDoneCallback); |
+ if (updater == null) throw new IllegalStateException(); |
+ this.updater.forceUpdateCheck(this.updateCheckDoneCallback); |
} |
public FilterEngine getFilterEngine() |