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

Delta Between Two Patch Sets: src/org/adblockplus/android/ProxySettings.java

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Left Patch Set: Created April 11, 2014, 1:31 p.m.
Right Patch Set: Even more review issues fixed. Created April 28, 2014, 10:18 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/org/adblockplus/android/ProxyService.java ('k') | src/org/adblockplus/android/RefreshableListPreference.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 11 matching lines...) Expand all
22 22
23 import android.content.Context; 23 import android.content.Context;
24 import android.content.Intent; 24 import android.content.Intent;
25 import android.net.ConnectivityManager; 25 import android.net.ConnectivityManager;
26 import android.net.NetworkInfo; 26 import android.net.NetworkInfo;
27 import android.os.Parcelable; 27 import android.os.Parcelable;
28 import android.util.Log; 28 import android.util.Log;
29 29
30 public class ProxySettings 30 public class ProxySettings
31 { 31 {
32 private final static String TAG = Utils.getTag(ProxySettings.class); 32 private static final String TAG = Utils.getTag(ProxySettings.class);
33 33
34 public static Object getActiveLinkProxy(final ConnectivityManager connectivity Manager) throws Exception 34 public static Object getActiveLinkProxy(final ConnectivityManager connectivity Manager) throws Exception
35 { 35 {
36 // LinkProperties lp = connectivityManager.getActiveLinkProperties() 36 /*
37 * LinkProperties lp = connectivityManager.getActiveLinkProperties()
38 */
37 final Method method = connectivityManager.getClass().getMethod("getActiveLin kProperties"); 39 final Method method = connectivityManager.getClass().getMethod("getActiveLin kProperties");
38 final Object lp = method.invoke(connectivityManager); 40 final Object lp = method.invoke(connectivityManager);
39 41
40 final Object pp = ProxySettings.getLinkProxy(lp); 42 final Object pp = ProxySettings.getLinkProxy(lp);
41 return pp; 43 return pp;
42 } 44 }
43 45
44 /** 46 /**
45 * Reads proxy settings from link properties on Android 3.1+ using Java 47 * Reads proxy settings from link properties on Android 3.1+ using Java
46 * reflection. 48 * reflection.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 84 }
83 catch (final Exception e) 85 catch (final Exception e)
84 { 86 {
85 // This should not happen 87 // This should not happen
86 Log.e(TAG, "getProxy failure", e); 88 Log.e(TAG, "getProxy failure", e);
87 return null; 89 return null;
88 } 90 }
89 91
90 try 92 try
91 { 93 {
92 final ConnectivityManager connectivityManager = (ConnectivityManager)conte xt.getSystemService(Context.CONNECTIVITY_SERVICE); 94 final ConnectivityManager connectivityManager = (ConnectivityManager) cont ext.getSystemService(Context.CONNECTIVITY_SERVICE);
93 final Object pp = method.invoke(connectivityManager); 95 final Object pp = method.invoke(connectivityManager);
94 if (pp == null) 96 if (pp == null)
95 {
96 return null; 97 return null;
97 }
98 98
99 return getUserProxy(pp); 99 return getUserProxy(pp);
100 } 100 }
101 catch (final Exception e) 101 catch (final Exception e)
102 { 102 {
103 // This should not happen 103 // This should not happen
104 Log.e(TAG, "getProxy failure", e); 104 Log.e(TAG, "getProxy failure", e);
105 return null; 105 return null;
106 } 106 }
107 } 107 }
(...skipping 11 matching lines...) Expand all
119 final String[] userProxy = new String[3]; 119 final String[] userProxy = new String[3];
120 120
121 final String className = "android.net.ProxyProperties"; 121 final String className = "android.net.ProxyProperties";
122 final Class<?> c = Class.forName(className); 122 final Class<?> c = Class.forName(className);
123 Method method; 123 Method method;
124 124
125 /* 125 /*
126 * String proxyHost = pp.getHost() 126 * String proxyHost = pp.getHost()
127 */ 127 */
128 method = c.getMethod("getHost"); 128 method = c.getMethod("getHost");
129 userProxy[0] = (String)method.invoke(pp); 129 userProxy[0] = (String) method.invoke(pp);
130 130
131 /* 131 /*
132 * int proxyPort = pp.getPort(); 132 * int proxyPort = pp.getPort();
133 */ 133 */
134 method = c.getMethod("getPort"); 134 method = c.getMethod("getPort");
135 userProxy[1] = String.valueOf(method.invoke(pp)); 135 userProxy[1] = String.valueOf(method.invoke(pp));
136 136
137 /* 137 /*
138 * String proxyEL = pp.getExclusionList() 138 * String proxyEL = pp.getExclusionList()
139 */ 139 */
140 method = c.getMethod("getExclusionList"); 140 method = c.getMethod("getExclusionList");
141 userProxy[2] = (String)method.invoke(pp); 141 userProxy[2] = (String) method.invoke(pp);
142 142
143 if (userProxy[0] != null) 143 if (userProxy[0] != null)
144 {
145 return userProxy; 144 return userProxy;
146 }
147 else 145 else
148 { 146 return null;
149 return null;
150 }
151 } 147 }
152 148
153 /** 149 /**
154 * Tries to set local proxy in system settings via native call on Android 3.1+ 150 * Tries to set local proxy in system settings via native call on Android 3.1+
155 * devices using Java reflection. 151 * devices using Java reflection.
156 * 152 *
157 * @return true if device supports native proxy setting 153 * @return true if device supports native proxy setting
158 */ 154 */
159 public static boolean setConnectionProxy(final Context context, final String h ost, final int port, final String excl) 155 public static boolean setConnectionProxy(final Context context, final String h ost, final int port, final String excl)
160 { 156 {
(...skipping 12 matching lines...) Expand all
173 return false; 169 return false;
174 } 170 }
175 catch (final Exception e) 171 catch (final Exception e)
176 { 172 {
177 // This should not happen 173 // This should not happen
178 Log.e(TAG, "setHttpProxy failure", e); 174 Log.e(TAG, "setHttpProxy failure", e);
179 return false; 175 return false;
180 } 176 }
181 try 177 try
182 { 178 {
183 final ConnectivityManager connectivityManager = (ConnectivityManager)conte xt.getSystemService(Context.CONNECTIVITY_SERVICE); 179 final ConnectivityManager connectivityManager = (ConnectivityManager) cont ext.getSystemService(Context.CONNECTIVITY_SERVICE);
184 final Object lp = method.invoke(connectivityManager); 180 final Object lp = method.invoke(connectivityManager);
185 // There is no active link now, but device has native proxy support 181 // There is no active link now, but device has native proxy support
186 if (lp == null) 182 if (lp == null)
187 {
188 return true; 183 return true;
189 }
190 184
191 final String className = "android.net.ProxyProperties"; 185 final String className = "android.net.ProxyProperties";
192 final Class<?> c = Class.forName(className); 186 final Class<?> c = Class.forName(className);
193 method = lp.getClass().getMethod("setHttpProxy", c); 187 method = lp.getClass().getMethod("setHttpProxy", c);
194 if (host != null) 188 if (host != null)
195 { 189 {
196 /* 190 /*
197 * ProxyProperties pp = new ProxyProperties(host, port, excl); 191 * ProxyProperties pp = new ProxyProperties(host, port, excl);
198 */ 192 */
199 final Class<?>[] parameter = new Class[] { String.class, int.class, Stri ng.class }; 193 final Class<?>[] parameter = new Class[] { String.class, int.class, Stri ng.class };
(...skipping 25 matching lines...) Expand all
225 break; 219 break;
226 case ConnectivityManager.TYPE_MOBILE: 220 case ConnectivityManager.TYPE_MOBILE:
227 // TODO We leave it here for future, it does not work now 221 // TODO We leave it here for future, it does not work now
228 // intent = new Intent("android.intent.action.ANY_DATA_STATE"); 222 // intent = new Intent("android.intent.action.ANY_DATA_STATE");
229 break; 223 break;
230 } 224 }
231 if (intent != null) 225 if (intent != null)
232 { 226 {
233 if (lp != null) 227 if (lp != null)
234 { 228 {
235 intent.putExtra("linkProperties", (Parcelable)lp); 229 intent.putExtra("linkProperties", (Parcelable) lp);
236 } 230 }
237 context.sendBroadcast(intent); 231 context.sendBroadcast(intent);
238 } 232 }
239 233
240 return true; 234 return true;
241 } 235 }
242 catch (final SecurityException e) 236 catch (final SecurityException e)
243 { 237 {
244 // This is ok for 4.1.2+, 4.2.2+ and later 238 // This is ok for 4.1.2+, 4.2.2+ and later
245 return false; 239 return false;
246 } 240 }
247 catch (final Exception e) 241 catch (final Exception e)
248 { 242 {
249 // This should not happen 243 // This should not happen
250 Log.e(TAG, "setHttpProxy failure", e); 244 Log.e(TAG, "setHttpProxy failure", e);
251 return false; 245 return false;
252 } 246 }
253 } 247 }
254 } 248 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld