[System]: WebRequest.GetSystemProxy(): Return custom proxy for monodroid.
authorMartin Baulig <martin.baulig@xamarin.com>
Fri, 6 Sep 2013 13:58:42 +0000 (15:58 +0200)
committerMartin Baulig <martin.baulig@xamarin.com>
Fri, 6 Sep 2013 22:06:00 +0000 (00:06 +0200)
On ICS and newer, we can use Java.Net.ProxySelector, which supports
per-access point proxy settings.  Fixes #12640.

mcs/class/System/System.Net/WebRequest.cs
mcs/class/System/System/AndroidPlatform.cs

index c6b4ca6ae3ed8130e527eb3e9789818d51a7b604..987b7cc109412087df5c61296ba82c3434d9207a 100644 (file)
@@ -327,6 +327,12 @@ namespace System.Net
 #if MONOTOUCH
                        return CFNetwork.GetDefaultProxy ();
 #else
+#if MONODROID
+                       // Return the system web proxy.  This only works for ICS+.
+                       var androidProxy = AndroidPlatform.GetDefaultProxy ();
+                       if (androidProxy != null)
+                               return androidProxy;
+#endif
 #if !NET_2_1
                        if (IsWindows ()) {
                                int iProxyEnable = (int)Microsoft.Win32.Registry.GetValue ("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyEnable", 0);
index bcc30bd186c9b432508d6caeb7d1b967b282bf92..338a92b63966011d11d3b3c7f13b2c6e0d533aa1 100644 (file)
@@ -31,6 +31,7 @@ extern alias MonoSecurity;
 
 #if MONODROID
 using System;
+using System.Net;
 using System.Net.Security;
 using System.Security.Cryptography.X509Certificates;
 #if SECURITY_DEP
@@ -45,12 +46,13 @@ namespace System {
                static readonly Converter<MSX.X509CertificateCollection, bool> trustEvaluateSsl;
                static readonly Func<MSX.X509CertificateCollection, object, X509Certificate2, X509Chain, SslPolicyErrors, bool> trustEvaluateSsl2;
 #endif  // SECURITY_DEP
+               static readonly Func<IWebProxy> getDefaultProxy;
 
 
                static AndroidPlatform ()
                {
-#if SECURITY_DEP
                        var t = Type.GetType ("Android.Runtime.AndroidEnvironment, Mono.Android", throwOnError:true);
+#if SECURITY_DEP
                        trustEvaluateSsl2 = (Func<MSX.X509CertificateCollection, object, X509Certificate2, X509Chain, SslPolicyErrors, bool>)
                                Delegate.CreateDelegate (
                                                typeof (Func<MSX.X509CertificateCollection, object, X509Certificate2, X509Chain, SslPolicyErrors, bool>),
@@ -66,6 +68,10 @@ namespace System {
                                                        ignoreCase:false,
                                                        throwOnBindFailure:true);
 #endif  // SECURITY_DEP
+                       getDefaultProxy = (Func<IWebProxy>)Delegate.CreateDelegate (
+                               typeof (Func<IWebProxy>), t, "GetDefaultProxy",
+                               ignoreCase:false,
+                               throwOnBindFailure:true);
                }
 
 #if SECURITY_DEP
@@ -76,6 +82,11 @@ namespace System {
                        return trustEvaluateSsl (collection);
                }
 #endif  // SECURITY_DEP
+
+               internal static IWebProxy GetDefaultProxy ()
+               {
+                       return getDefaultProxy ();
+               }
        }
 }
 #endif  // MONODROID