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

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

Issue 9347203: ABP/Android Manual proxy user notifications (Closed)
Patch Set: Created Feb. 16, 2013, 5:23 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/ProxySettings.java
===================================================================
--- a/src/org/adblockplus/android/ProxySettings.java
+++ b/src/org/adblockplus/android/ProxySettings.java
@@ -31,9 +31,40 @@
{
private static final String TAG = "ProxySettings";
+ public static Object getActiveLinkProxy(ConnectivityManager connectivityManager) throws Exception
+ {
+ /*
+ * LinkProperties lp = connectivityManager.getActiveLinkProperties()
+ */
+ Method method = connectivityManager.getClass().getMethod("getActiveLinkProperties");
+ Object lp = method.invoke(connectivityManager);
+
+ Object pp = ProxySettings.getLinkProxy(lp);
+ return pp;
+ }
+
+ /**
+ * Reads proxy settings from link properties on Android 3.1+ using Java
+ * reflection.
+ *
+ * @param linkProperties
+ * android.net.LinkProperties
+ * @return ProxyProperties
+ * @throws Exception
+ */
+ public static Object getLinkProxy(Object linkProperties) throws Exception
+ {
+ /*
+ * linkProperties.getHttpProxy();
+ */
+ Method method = linkProperties.getClass().getMethod("getHttpProxy");
+ Object pp = method.invoke(linkProperties);
+ return pp;
+ }
+
/**
* Reads system proxy settings on Android 3.1+ using Java reflection.
- *
+ *
* @return string array of host, port and exclusion list
*/
public static String[] getUserProxy(Context context)
@@ -77,7 +108,7 @@
/**
* Reads system proxy settings on Android 3.1+ using Java reflection.
- *
+ *
* @param pp
* ProxyProperties object
* @return string array of host, port and exclusion list
@@ -118,7 +149,7 @@
/**
* Tries to set local proxy in system settings via native call on Android 3.1+
* devices using Java reflection.
- *
+ *
* @return true if device supports native proxy setting
*/
public static boolean setConnectionProxy(Context context, String host, int port, String excl)
@@ -147,7 +178,8 @@
{
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Object lp = method.invoke(connectivityManager);
- if (lp == null) // There is no active link now, but device has native proxy support
+ if (lp == null) // There is no active link now, but device has native
+ // proxy support
return true;
String className = "android.net.ProxyProperties";
@@ -201,6 +233,11 @@
return true;
}
+ catch (SecurityException e)
+ {
+ // This is ok for 4.1.2+, 4.2.2+ and later
+ return false;
+ }
catch (Exception e)
{
// This should not happen

Powered by Google App Engine
This is Rietveld