Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/Engine.java

Issue 29445587: Issue 5223 - App is freezing sometimes (Closed)
Patch Set: Added separate texts for adding/removing a subscription Created June 14, 2017, 3:19 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
@@ -38,17 +38,16 @@
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 java.util.regex.Pattern;
import org.adblockplus.adblockplussbrowser.R;
-import org.adblockplus.sbrowser.contentblocker.MainPreferences;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.ConnectivityManager;
@@ -107,16 +106,17 @@
private final ReentrantLock accessLock = new ReentrantLock();
private DefaultSubscriptions defaultSubscriptions;
private Subscriptions subscriptions;
private JSONPrefs jsonPrefs;
private AppInfo appInfo;
private LinkedBlockingQueue<EngineEvent> engineEvents = new LinkedBlockingQueue<EngineEvent>();
private Thread handlerThread;
private Downloader downloader;
+ private SubscriptionUpdateCallback subscriptionUpdateCallback;
private final Context serviceContext;
private boolean wasFirstRun = false;
private long nextUpdateBroadcast = Long.MAX_VALUE;
private Engine(final Context context)
{
this.serviceContext = context;
}
@@ -184,27 +184,23 @@
{
// Should never happen, as checkAAStatusAndProceed() should not be called if the user
// has no compatible SBrowser installed. Nevertheless we have to handle the Exception.
Log.d(TAG, "No compatible Samsung Browser found.", e);
return false;
}
}
+ public void setSubscriptionUpdateCallback(final SubscriptionUpdateCallback subscriptionUpdateCallback) {
+ this.subscriptionUpdateCallback = subscriptionUpdateCallback;
+ }
+
public void requestUpdateBroadcast()
{
- this.lock();
- try
- {
- this.nextUpdateBroadcast = System.currentTimeMillis() + BROADCAST_COMBINATION_DELAY_MILLIS;
- }
- finally
- {
- this.unlock();
- }
+ this.nextUpdateBroadcast = System.currentTimeMillis() + BROADCAST_COMBINATION_DELAY_MILLIS;
}
private void writeFileAndSendUpdateBroadcast()
{
createAndWriteFile();
runOnUiThread(new Runnable()
{
@@ -251,32 +247,35 @@
}
return false;
}
return current.isConnected();
}
public List<SubscriptionInfo> getListedSubscriptions()
{
- this.lock();
- try
- {
- return this.subscriptions.getSubscriptions(this);
- }
- finally
- {
- this.unlock();
- }
+ return this.subscriptions.getSubscriptions(this);
}
public void changeSubscriptionState(final String id, final boolean enabled)
{
+ if (this.subscriptionUpdateCallback != null)
+ {
+ this.subscriptionUpdateCallback.subscriptionUpdateRequested(enabled);
+ }
this.engineEvents.add(new ChangeEnabledStateEvent(id, enabled));
}
+ public void subscriptionStateChanged() {
+ if (this.subscriptionUpdateCallback != null)
+ {
+ this.subscriptionUpdateCallback.subscriptionUpdatedApplied();
+ }
+ }
+
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()
{
@@ -801,9 +800,14 @@
this.downloader.enqueueDownload(this.createDownloadURL(sub), sub.getId(), headers);
}
}
public void connectivityChanged()
{
this.downloader.connectivityChanged();
}
+
+ public interface SubscriptionUpdateCallback {
+ void subscriptionUpdateRequested(boolean enabled);
+ void subscriptionUpdatedApplied();
+ }
}

Powered by Google App Engine
This is Rietveld