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

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

Issue 8946130: android: NullPointerException in clearConnectionProxy (Closed)
Patch Set: Created Nov. 30, 2012, 9:51 a.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 | « no previous file | 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 private final static String IPTABLES_RETURN = " -t nat -m owner --uid-owner {{ UID}} -A OUTPUT -p tcp -j RETURN\n"; 88 private final static String IPTABLES_RETURN = " -t nat -m owner --uid-owner {{ UID}} -A OUTPUT -p tcp -j RETURN\n";
89 private final static String IPTABLES_ADD_HTTP = " -t nat -A OUTPUT -p tcp --dp ort 80 -j REDIRECT --to {{PORT}}\n"; 89 private final static String IPTABLES_ADD_HTTP = " -t nat -A OUTPUT -p tcp --dp ort 80 -j REDIRECT --to {{PORT}}\n";
90 90
91 private Notification ongoingNotification; 91 private Notification ongoingNotification;
92 private PendingIntent contentIntent; 92 private PendingIntent contentIntent;
93 93
94 private Handler notrafficHandler; 94 private Handler notrafficHandler;
95 95
96 protected ProxyServer proxy = null; 96 protected ProxyServer proxy = null;
97 protected int port; 97 protected int port;
98 private Properties proxyConfiguration = new Properties();
98 99
99 /** 100 /**
100 * Indicates that service is working with root privileges. 101 * Indicates that service is working with root privileges.
101 */ 102 */
102 private boolean transparent = false; 103 private boolean transparent = false;
103 /** 104 /**
104 * Indicates that service has autoconfigured Android proxy settings (version 105 * Indicates that service has autoconfigured Android proxy settings (version
105 * 3.1+). 106 * 3.1+).
106 */ 107 */
107 private boolean nativeProxy = false; 108 private boolean nativeProxy = false;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // TODO Add port travel 222 // TODO Add port travel
222 listen = new ServerSocket(port, 1024); 223 listen = new ServerSocket(port, 1024);
223 } 224 }
224 catch (IOException e) 225 catch (IOException e)
225 { 226 {
226 sendBroadcast(new Intent(BROADCAST_PROXY_FAILED).putExtra("msg", e.getMe ssage())); 227 sendBroadcast(new Intent(BROADCAST_PROXY_FAILED).putExtra("msg", e.getMe ssage()));
227 Log.e(TAG, null, e); 228 Log.e(TAG, null, e);
228 return; 229 return;
229 } 230 }
230 231
231 Properties config = new Properties(); 232 proxyConfiguration.put("handler", "main");
232 config.put("handler", "main"); 233 proxyConfiguration.put("main.prefix", "");
233 config.put("main.prefix", ""); 234 proxyConfiguration.put("main.class", "sunlabs.brazil.server.ChainHandler") ;
234 config.put("main.class", "sunlabs.brazil.server.ChainHandler");
235 if (transparent) 235 if (transparent)
236 { 236 {
237 config.put("main.handlers", "urlmodifier adblock"); 237 proxyConfiguration.put("main.handlers", "urlmodifier adblock");
238 config.put("urlmodifier.class", "org.adblockplus.brazil.TransparentProxy Handler"); 238 proxyConfiguration.put("urlmodifier.class", "org.adblockplus.brazil.Tran sparentProxyHandler");
239 } 239 }
240 else 240 else
241 { 241 {
242 config.put("main.handlers", "https adblock"); 242 proxyConfiguration.put("main.handlers", "https adblock");
243 config.put("https.class", "org.adblockplus.brazil.SSLConnectionHandler") ; 243 proxyConfiguration.put("https.class", "org.adblockplus.brazil.SSLConnect ionHandler");
244 } 244 }
245 config.put("adblock.class", "org.adblockplus.brazil.RequestHandler"); 245 proxyConfiguration.put("adblock.class", "org.adblockplus.brazil.RequestHan dler");
246 if (logRequests) 246 if (logRequests)
247 config.put("adblock.proxylog", "yes"); 247 proxyConfiguration.put("adblock.proxylog", "yes");
248 248
249 configureUserProxy(config, proxyHost, proxyPort, proxyExcl, proxyUser, pro xyPass); 249 configureUserProxy(proxyConfiguration, proxyHost, proxyPort, proxyExcl, pr oxyUser, proxyPass);
250 250
251 proxy = new ProxyServer(); 251 proxy = new ProxyServer();
252 proxy.logLevel = Server.LOG_DIAGNOSTIC; 252 proxy.logLevel = Server.LOG_DIAGNOSTIC;
253 proxy.setup(listen, config.getProperty("handler"), config); 253 proxy.setup(listen, proxyConfiguration.getProperty("handler"), proxyConfig uration);
254 proxy.start(); 254 proxy.start();
255 } 255 }
256 256
257 prefs.registerOnSharedPreferenceChangeListener(this); 257 prefs.registerOnSharedPreferenceChangeListener(this);
258 258
259 String msg = getString(transparent ? R.string.notif_all : nativeProxy ? R.st ring.notif_wifi : R.string.notif_waiting); 259 String msg = getString(transparent ? R.string.notif_all : nativeProxy ? R.st ring.notif_wifi : R.string.notif_waiting);
260 if (!transparent && !nativeProxy) 260 if (!transparent && !nativeProxy)
261 { 261 {
262 // Initiate no traffic check 262 // Initiate no traffic check
263 notrafficHandler = new Handler(); 263 notrafficHandler = new Handler();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 336
337 Log.i(TAG, "Service stopped"); 337 Log.i(TAG, "Service stopped");
338 } 338 }
339 339
340 /** 340 /**
341 * Restores system proxy settings via native call on Android 3.1+ devices usin g 341 * Restores system proxy settings via native call on Android 3.1+ devices usin g
342 * Java reflection. 342 * Java reflection.
343 */ 343 */
344 private void clearConnectionProxy() 344 private void clearConnectionProxy()
345 { 345 {
346 String proxyHost = (String) proxy.props.getProperty("adblock.proxyHost"); 346 String proxyHost = (String) proxyConfiguration.getProperty("adblock.proxyHos t");
347 String proxyPort = (String) proxy.props.getProperty("adblock.proxyPort"); 347 String proxyPort = (String) proxyConfiguration.getProperty("adblock.proxyPor t");
348 String proxyExcl = (String) proxy.props.getProperty("adblock.proxyExcl"); 348 String proxyExcl = (String) proxyConfiguration.getProperty("adblock.proxyExc l");
349 int port = 0; 349 int port = 0;
350 try 350 try
351 { 351 {
352 if (proxyHost != null) 352 if (proxyHost != null)
353 port = Integer.valueOf(proxyPort); 353 port = Integer.valueOf(proxyPort);
354 } 354 }
355 catch (NumberFormatException e) 355 catch (NumberFormatException e)
356 { 356 {
357 Log.e(TAG, "Bad port setting", e); 357 Log.e(TAG, "Bad port setting", e);
358 } 358 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 String keyUser = getString(R.string.pref_proxyuser); 462 String keyUser = getString(R.string.pref_proxyuser);
463 String keyPass = getString(R.string.pref_proxypass); 463 String keyPass = getString(R.string.pref_proxypass);
464 if (key.equals(ketHost) || key.equals(keyPort) || key.equals(keyUser) || k ey.equals(keyPass)) 464 if (key.equals(ketHost) || key.equals(keyPort) || key.equals(keyUser) || k ey.equals(keyPass))
465 { 465 {
466 String proxyHost = sharedPreferences.getString(ketHost, null); 466 String proxyHost = sharedPreferences.getString(ketHost, null);
467 String proxyPort = sharedPreferences.getString(keyPort, null); 467 String proxyPort = sharedPreferences.getString(keyPort, null);
468 String proxyUser = sharedPreferences.getString(keyUser, null); 468 String proxyUser = sharedPreferences.getString(keyUser, null);
469 String proxyPass = sharedPreferences.getString(keyPass, null); 469 String proxyPass = sharedPreferences.getString(keyPass, null);
470 if (proxy != null) 470 if (proxy != null)
471 { 471 {
472 configureUserProxy(proxy.props, proxyHost, proxyPort, null, proxyUser, proxyPass); 472 configureUserProxy(proxyConfiguration, proxyHost, proxyPort, null, pro xyUser, proxyPass);
473 proxy.restart(proxy.props.getProperty("handler")); 473 proxy.restart(proxyConfiguration.getProperty("handler"));
474 } 474 }
475 } 475 }
476 } 476 }
477 } 477 }
478 478
479 public boolean isTransparent() 479 public boolean isTransparent()
480 { 480 {
481 return transparent; 481 return transparent;
482 } 482 }
483 483
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 */ 704 */
705 method = lp.getClass().getMethod("getHttpProxy"); 705 method = lp.getClass().getMethod("getHttpProxy");
706 Object pp = method.invoke(lp); 706 Object pp = method.invoke(lp);
707 707
708 String[] userProxy = ProxySettings.getUserProxy(pp); 708 String[] userProxy = ProxySettings.getUserProxy(pp);
709 if (userProxy != null && Integer.valueOf(userProxy[1]) != port) 709 if (userProxy != null && Integer.valueOf(userProxy[1]) != port)
710 { 710 {
711 Log.i(TAG, "User has set new proxy: " + userProxy[0] + ":" + userPro xy[1] + "(" + userProxy[2] + ")"); 711 Log.i(TAG, "User has set new proxy: " + userProxy[0] + ":" + userPro xy[1] + "(" + userProxy[2] + ")");
712 if (proxy != null) 712 if (proxy != null)
713 { 713 {
714 configureUserProxy(proxy.props, userProxy[0], userProxy[1], userPr oxy[2], null, null); 714 configureUserProxy(proxyConfiguration, userProxy[0], userProxy[1], userProxy[2], null, null);
715 proxy.restart(proxy.props.getProperty("handler")); 715 proxy.restart(proxyConfiguration.getProperty("handler"));
716 } 716 }
717 } 717 }
718 } 718 }
719 catch (Exception e) 719 catch (Exception e)
720 { 720 {
721 // This should not happen 721 // This should not happen
722 Log.e(TAG, null, e); 722 Log.e(TAG, null, e);
723 } 723 }
724 724
725 } 725 }
(...skipping 21 matching lines...) Expand all
747 @Override 747 @Override
748 public void log(int level, Object obj, String message) 748 public void log(int level, Object obj, String message)
749 { 749 {
750 if (level <= logLevel) 750 if (level <= logLevel)
751 { 751 {
752 Log.println(7 - level, obj != null ? obj.toString() : TAG, message); 752 Log.println(7 - level, obj != null ? obj.toString() : TAG, message);
753 } 753 }
754 } 754 }
755 } 755 }
756 } 756 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld