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

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

Issue 9437197: ABP/Android Proxy switch (Closed)
Patch Set: Created Feb. 28, 2013, 1:20 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: src/org/adblockplus/android/ProxyService.java
===================================================================
--- a/src/org/adblockplus/android/ProxyService.java
+++ b/src/org/adblockplus/android/ProxyService.java
@@ -70,9 +70,10 @@
}
private static final String TAG = "ProxyService";
- private static final boolean logRequests = false;
+ private static final boolean logRequests = true;
- private static final int[] portVariants = new int[] {8080, 8888, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 9999, 26571, 0};
+ // Do not use 8080 because it is a "dirty" port, Android uses it if something goes wrong
+ private static final int[] portVariants = new int[] {8888, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 9999, 26571, 0};
private final static int DEFAULT_TIMEOUT = 3000;
private final static int NO_TRAFFIC_TIMEOUT = 5 * 60 * 1000; // 5 minutes
@@ -203,12 +204,16 @@
registerReceiver(connectionReceiver, new IntentFilter(Proxy.PROXY_CHANGE_ACTION));
}
}
-
- // Start engine
- AdblockPlus.getApplication().startEngine();
+
+ // Save current native proxy situation. The service is always started on the first run so
+ // we will always have a correct value from the box
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putBoolean(getString(R.string.pref_proxyautoconfigured), transparent || nativeProxyAutoConfigured);
+ editor.commit();
registerReceiver(proxyReceiver, new IntentFilter(ProxyService.BROADCAST_PROXY_FAILED));
- registerReceiver(matchesReceiver, new IntentFilter(AdblockPlus.BROADCAST_FILTER_MATCHES));
+ registerReceiver(filterReceiver, new IntentFilter(AdblockPlus.BROADCAST_FILTERING_CHANGE));
+ registerReceiver(filterReceiver, new IntentFilter(AdblockPlus.BROADCAST_FILTER_MATCHES));
// Start proxy
if (proxy == null)
@@ -291,7 +296,7 @@
stopNoTrafficCheck();
- unregisterReceiver(matchesReceiver);
+ unregisterReceiver(filterReceiver);
unregisterReceiver(proxyReceiver);
// Stop IP redirecting
@@ -329,6 +334,7 @@
if (proxy != null)
proxy.close();
+ // TODO Do we have to check current state?
// Stop engine if not in interactive mode
AdblockPlus.getApplication().stopEngine(false);
@@ -642,6 +648,7 @@
sendStateChangedBroadcast();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(ONGOING_NOTIFICATION_ID, getNotification());
+ notificationManager.cancel(NOTRAFFIC_NOTIFICATION_ID);
}
notrafficHandler = null;
}
@@ -649,9 +656,11 @@
@SuppressLint("NewApi")
private Notification getNotification()
{
+ boolean filtering = AdblockPlus.getApplication().isFilteringEnabled();
+
int msgId = R.string.notif_waiting;
if (nativeProxyAutoConfigured || proxyManualyConfigured)
- msgId = R.string.notif_wifi;
+ msgId = filtering ? R.string.notif_wifi : R.string.notif_wifi_nofiltering;
if (transparent)
msgId = R.string.notif_all;
@@ -671,6 +680,7 @@
builder.setContentIntent(contentIntent);
builder.setContentTitle(getText(R.string.app_name));
builder.setContentText(getText(msgId));
+ builder.setOngoing(true);
Notification notification = builder.getNotification();
return notification;
@@ -740,11 +750,16 @@
/**
* Stops no traffic check if traffic is detected by proxy service.
*/
- private BroadcastReceiver matchesReceiver = new BroadcastReceiver()
+ private BroadcastReceiver filterReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(final Context context, Intent intent)
{
+ if (intent.getAction().equals(AdblockPlus.BROADCAST_FILTERING_CHANGE))
+ {
+ NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ notificationManager.notify(ONGOING_NOTIFICATION_ID, getNotification());
+ }
if (intent.getAction().equals(AdblockPlus.BROADCAST_FILTER_MATCHES))
{
proxyManualyConfigured = true;

Powered by Google App Engine
This is Rietveld