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

Side by Side Diff: src/org/adblockplus/android/ProxyService.java

Issue 9433005: ABP/Android Port travel (Closed)
Patch Set: Created Feb. 20, 2013, 12:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « res/values/integers.xml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of the Adblock Plus, 2 * This file is part of the Adblock Plus,
3 * Copyright (C) 2006-2012 Eyeo GmbH 3 * Copyright (C) 2006-2012 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 import android.net.ConnectivityManager; 45 import android.net.ConnectivityManager;
46 import android.net.NetworkInfo; 46 import android.net.NetworkInfo;
47 import android.net.Proxy; 47 import android.net.Proxy;
48 import android.os.Binder; 48 import android.os.Binder;
49 import android.os.Build; 49 import android.os.Build;
50 import android.os.Handler; 50 import android.os.Handler;
51 import android.os.IBinder; 51 import android.os.IBinder;
52 import android.preference.PreferenceManager; 52 import android.preference.PreferenceManager;
53 import android.support.v4.app.NotificationCompat; 53 import android.support.v4.app.NotificationCompat;
54 import android.util.Log; 54 import android.util.Log;
55 import android.widget.Toast;
56 55
57 import com.stericson.RootTools.RootTools; 56 import com.stericson.RootTools.RootTools;
58 import com.stericson.RootTools.RootToolsException; 57 import com.stericson.RootTools.RootToolsException;
59 58
60 public class ProxyService extends Service implements OnSharedPreferenceChangeLis tener 59 public class ProxyService extends Service implements OnSharedPreferenceChangeLis tener
61 { 60 {
62 private static final String LOCALHOST = "127.0.0.1"; 61 private static final String LOCALHOST = "127.0.0.1";
63 /** 62 /**
64 * Indicates that system supports native proxy configuration. 63 * Indicates that system supports native proxy configuration.
65 */ 64 */
66 public static boolean hasNativeProxy = Build.VERSION.SDK_INT >= 12; // Honeyco mb 3.1 65 public static boolean hasNativeProxy = Build.VERSION.SDK_INT >= 12; // Honeyco mb 3.1
67 66
68 static 67 static
69 { 68 {
70 RootTools.debugMode = false; 69 RootTools.debugMode = false;
71 } 70 }
72 71
73 private static final String TAG = "ProxyService"; 72 private static final String TAG = "ProxyService";
74 private static final boolean logRequests = false; 73 private static final boolean logRequests = false;
75 74
75 private static final int[] portVariants = new int[] {8080, 8888, 1111, 2222, 3 333, 4444, 5555, 6666, 7777, 9999, 26571, 0};
Felix Dahlke 2013/02/20 12:39:02 Maybe it makes sense to have this in arrays.xml in
Andrey Novikov 2013/02/20 12:44:23 It was there historically - because first versions
Felix Dahlke 2013/02/20 12:50:41 Right, still wondering if we should put magic valu
76
76 private final static int DEFAULT_TIMEOUT = 3000; 77 private final static int DEFAULT_TIMEOUT = 3000;
77 private final static int NO_TRAFFIC_TIMEOUT = 5 * 60 * 1000; // 5 minutes 78 private final static int NO_TRAFFIC_TIMEOUT = 5 * 60 * 1000; // 5 minutes
78 79
79 final static int ONGOING_NOTIFICATION_ID = R.string.app_name; 80 final static int ONGOING_NOTIFICATION_ID = R.string.app_name;
80 private static final long POSITION_RIGHT = Build.VERSION.SDK_INT >= Build.VERS ION_CODES.GINGERBREAD ? Long.MIN_VALUE : Long.MAX_VALUE; 81 private static final long POSITION_RIGHT = Build.VERSION.SDK_INT >= Build.VERS ION_CODES.GINGERBREAD ? Long.MIN_VALUE : Long.MAX_VALUE;
81 private final static int NOTRAFFIC_NOTIFICATION_ID = R.string.app_name + 3; 82 private final static int NOTRAFFIC_NOTIFICATION_ID = R.string.app_name + 3;
82 83
83 /** 84 /**
84 * Broadcasted when service starts or stops. 85 * Broadcasted when service starts or stops.
85 */ 86 */
(...skipping 30 matching lines...) Expand all
116 117
117 @Override 118 @Override
118 public void onCreate() 119 public void onCreate()
119 { 120 {
120 super.onCreate(); 121 super.onCreate();
121 122
122 // Get port for local proxy 123 // Get port for local proxy
123 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this ); 124 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this );
124 Resources resources = getResources(); 125 Resources resources = getResources();
125 126
126 String p = prefs.getString(getString(R.string.pref_port), null);
127 try
128 {
129 port = p != null ? Integer.valueOf(p) : resources.getInteger(R.integer.def _port);
130 }
131 catch (NumberFormatException e)
132 {
133 Toast.makeText(this, getString(R.string.msg_badport) + ": " + p, Toast.LEN GTH_LONG).show();
134 port = resources.getInteger(R.integer.def_port);
135 }
136
137 // Try to read user proxy settings 127 // Try to read user proxy settings
138 String proxyHost = null; 128 String proxyHost = null;
139 String proxyPort = null; 129 String proxyPort = null;
140 String proxyExcl = null; 130 String proxyExcl = null;
141 String proxyUser = null; 131 String proxyUser = null;
142 String proxyPass = null; 132 String proxyPass = null;
143 133
144 if (hasNativeProxy) 134 if (hasNativeProxy)
145 { 135 {
146 // Read system settings 136 // Read system settings
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // Start engine 207 // Start engine
218 AdblockPlus.getApplication().startEngine(); 208 AdblockPlus.getApplication().startEngine();
219 209
220 registerReceiver(proxyReceiver, new IntentFilter(ProxyService.BROADCAST_PROX Y_FAILED)); 210 registerReceiver(proxyReceiver, new IntentFilter(ProxyService.BROADCAST_PROX Y_FAILED));
221 registerReceiver(matchesReceiver, new IntentFilter(AdblockPlus.BROADCAST_FIL TER_MATCHES)); 211 registerReceiver(matchesReceiver, new IntentFilter(AdblockPlus.BROADCAST_FIL TER_MATCHES));
222 212
223 // Start proxy 213 // Start proxy
224 if (proxy == null) 214 if (proxy == null)
225 { 215 {
226 ServerSocket listen = null; 216 ServerSocket listen = null;
227 try 217 String msg = null;
218 for (int p : portVariants)
228 { 219 {
229 // TODO Add port travel 220 try
230 listen = new ServerSocket(port, 1024); 221 {
222 listen = new ServerSocket(p, 1024);
223 port = p;
224 break;
225 }
226 catch (IOException e)
227 {
228 Log.e(TAG, null, e);
229 msg = e.getMessage();
230 }
231 } 231 }
232 catch (IOException e) 232 if (listen == null)
233 { 233 {
234 sendBroadcast(new Intent(BROADCAST_PROXY_FAILED).putExtra("msg", e.getMe ssage())); 234 sendBroadcast(new Intent(BROADCAST_PROXY_FAILED).putExtra("msg", msg));
235 Log.e(TAG, null, e);
236 return; 235 return;
237 } 236 }
238 237
239 proxyConfiguration.put("handler", "main"); 238 proxyConfiguration.put("handler", "main");
240 proxyConfiguration.put("main.prefix", ""); 239 proxyConfiguration.put("main.prefix", "");
241 proxyConfiguration.put("main.class", "sunlabs.brazil.server.ChainHandler") ; 240 proxyConfiguration.put("main.class", "sunlabs.brazil.server.ChainHandler") ;
242 if (transparent) 241 if (transparent)
243 { 242 {
244 proxyConfiguration.put("main.handlers", "urlmodifier adblock"); 243 proxyConfiguration.put("main.handlers", "urlmodifier adblock");
245 proxyConfiguration.put("urlmodifier.class", "org.adblockplus.brazil.Tran sparentProxyHandler"); 244 proxyConfiguration.put("urlmodifier.class", "org.adblockplus.brazil.Tran sparentProxyHandler");
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 648
650 @SuppressLint("NewApi") 649 @SuppressLint("NewApi")
651 private Notification getNotification() 650 private Notification getNotification()
652 { 651 {
653 int msgId = R.string.notif_waiting; 652 int msgId = R.string.notif_waiting;
654 if (nativeProxy || proxyManualyConfigured) 653 if (nativeProxy || proxyManualyConfigured)
655 msgId = R.string.notif_wifi; 654 msgId = R.string.notif_wifi;
656 if (transparent) 655 if (transparent)
657 msgId = R.string.notif_all; 656 msgId = R.string.notif_all;
658 657
659 Log.e(TAG, "V: " + nativeProxy + " " + proxyManualyConfigured + " " + transp arent);
Felix Dahlke 2013/02/20 12:39:02 Is this change related?
Andrey Novikov 2013/02/20 12:44:23 Of course not, just forgot to remove it before pre
660 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 658 NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
661 if (hideIcon && msgId != R.string.notif_waiting) 659 if (hideIcon && msgId != R.string.notif_waiting)
662 { 660 {
663 builder.setWhen(POSITION_RIGHT); 661 builder.setWhen(POSITION_RIGHT);
664 builder.setSmallIcon(R.drawable.transparent); 662 builder.setSmallIcon(R.drawable.transparent);
665 //builder.setContent(new RemoteViews(getPackageName(), R.layout.notif_hidd en)); 663 //builder.setContent(new RemoteViews(getPackageName(), R.layout.notif_hidd en));
666 } 664 }
667 else 665 else
668 { 666 {
669 builder.setWhen(0); 667 builder.setWhen(0);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 @Override 855 @Override
858 public void log(int level, Object obj, String message) 856 public void log(int level, Object obj, String message)
859 { 857 {
860 if (level <= logLevel) 858 if (level <= logLevel)
861 { 859 {
862 Log.println(7 - level, obj != null ? obj.toString() : TAG, message); 860 Log.println(7 - level, obj != null ? obj.toString() : TAG, message);
863 } 861 }
864 } 862 }
865 } 863 }
866 } 864 }
OLDNEW
« no previous file with comments | « res/values/integers.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld