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

Unified Diff: src/org/adblockplus/android/AdblockPlus.java

Issue 9437197: ABP/Android Proxy switch (Closed)
Patch Set: ABP/Android Proxy switch Created March 11, 2013, 7:29 a.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
« no previous file with comments | « res/xml/preferences_advanced.xml ('k') | src/org/adblockplus/android/AdvancedPreferences.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/org/adblockplus/android/AdblockPlus.java
===================================================================
--- a/src/org/adblockplus/android/AdblockPlus.java
+++ b/src/org/adblockplus/android/AdblockPlus.java
@@ -50,9 +50,11 @@
import org.json.JSONObject;
import org.xml.sax.SAXException;
+import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
+import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -81,6 +83,10 @@
private final static int MSG_TOAST = 1;
/**
+ * Broadcasted when filtering is enabled or disabled.
+ */
+ public static final String BROADCAST_FILTERING_CHANGE = "org.adblockplus.android.filtering.status";
+ /**
* Broadcasted when subscription status changes.
*/
public final static String BROADCAST_SUBSCRIPTION_STATUS = "org.adblockplus.android.subscription.status";
@@ -99,6 +105,11 @@
*/
private boolean interactive = false;
+ /**
+ * Indicates whether filtering is enabled or not.
+ */
+ private boolean filteringEnabled = false;
+
private static AdblockPlus instance;
/**
@@ -205,6 +216,23 @@
}
return networkInfo == null ? false : networkInfo.isConnected();
}
+
+ /**
+ * Checks if ProxyService is running.
+ *
+ * @return true if service is running
+ */
+ public boolean isServiceRunning()
+ {
+ ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
+ // Actually it returns not only running services, so extra check is required
+ for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
+ {
+ if (ProxyService.class.getCanonicalName().equals(service.service.getClassName()) && service.pid > 0)
+ return true;
+ }
+ return false;
+ }
/**
* Checks if application can write to external storage.
@@ -403,6 +431,9 @@
*/
public String getSelectorsForDomain(final String domain)
{
+ if (!filteringEnabled)
+ return null;
+
Future<String> future = js.submit(new Callable<String>()
{
@Override
@@ -472,6 +503,9 @@
*/
public boolean matches(String url, String query, String reqHost, String refHost, String accept) throws Exception
{
+ if (!filteringEnabled)
+ return false;
+
Callable<Boolean> callable = new MatchesCallable(url, query, reqHost, refHost, accept);
Future<Boolean> future = js.submit(callable);
boolean matches = future.get().booleanValue();
@@ -480,6 +514,23 @@
}
/**
+ * Checks if filtering is enabled.
+ */
+ public boolean isFilteringEnabled()
+ {
+ return filteringEnabled;
+ }
+
+ /**
+ * Enables or disables filtering.
+ */
+ public void setFilteringEnabled(boolean enable)
+ {
+ filteringEnabled = enable;
+ sendBroadcast(new Intent(BROADCAST_FILTERING_CHANGE).putExtra("enabled", filteringEnabled));
+ }
+
+ /**
* Notifies JS code that application entered interactive mode.
*/
public void startInteractive()
@@ -566,6 +617,7 @@
{
if ((implicitly || !interactive) && js != null)
{
+ Log.i(TAG, "stopEngine");
js.stopEngine();
try
{
@@ -575,6 +627,7 @@
{
Log.e(TAG, e.getMessage(), e);
}
+ Log.i(TAG, "Engine stopped");
js = null;
}
}
« no previous file with comments | « res/xml/preferences_advanced.xml ('k') | src/org/adblockplus/android/AdvancedPreferences.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld