Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Settings.Secure.HTTP_PROXY deprecated in ICS but no information on replacement

The Android developer docs say the following about Settings.Secure.HTTP_PROXY:

Host name and port for global http proxy. Uses ':' seperator for between host and port TODO - deprecate in favor of global_http_proxy_host, etc

But there is not any information about global_http_proxy_host. Now I always get null when trying to read Settings.Secure.HTTP_PROXY.

Settings.Secure.HTTP_PROXY was working properly in all releases before ICS.

like image 350
Safecoder Avatar asked May 16 '12 02:05

Safecoder


2 Answers

You can use Java Reflection to set the global proxy tested on ICS.

UPDATED CODE

Activity activity = this;


private void setProxtAndPortOnICS(String porxyServer2, int port2)
{
            try
{
  Class jwcjb = Class.forName("android.webkit.JWebCoreJavaBridge");
  Class params[] = new Class[1];
  params[0] = Class.forName("android.net.ProxyProperties");
  Method updateProxyInstance = jwcjb.getDeclaredMethod("updateProxy", params);

  Class wv = Class.forName("android.webkit.WebView");
  Field mWebViewCoreField = wv.getDeclaredField("mWebViewCore");
  Object mWebViewCoreFieldIntance = getFieldValueSafely(mWebViewCoreField, oauthPage);

  Class wvc = Class.forName("android.webkit.WebViewCore");
  Field mBrowserFrameField = wvc.getDeclaredField("mBrowserFrame");
  Object mBrowserFrame = getFieldValueSafely(mBrowserFrameField, mWebViewCoreFieldIntance);

  Class bf = Class.forName("android.webkit.BrowserFrame");
  Field sJavaBridgeField = bf.getDeclaredField("sJavaBridge");
  Object sJavaBridge = getFieldValueSafely(sJavaBridgeField, mBrowserFrame);

  Class ppclass = Class.forName("android.net.ProxyProperties");
 Class pparams[] = new Class[3];
 pparams[0] = String.class;
 pparams[1] = int.class;
 pparams[2] = String.class;
 Constructor ppcont = ppclass.getConstructor(pparams);

 updateProxyInstance.invoke(sJavaBridge, ppcont.newInstance("my.proxy.com", 1234, null)); 
}
catch (Exception ex)
{    
 }


 }


 private Object getFieldValueSafely(Field field, Object classInstance) throws IllegalArgumentException, IllegalAccessException {
   boolean oldAccessibleValue = field.isAccessible();
   field.setAccessible(true);
   Object result = field.get(classInstance);
   field.setAccessible(oldAccessibleValue);
   return result;      
}

NOW you can filter out the urls using proxy server.

OR look at this blog this is in Chinese but you can read the code it is fairly easy to understand.

like image 100
Sunny Avatar answered Oct 13 '22 05:10

Sunny


I'm just going by what the documentation says, but it reads to me that Settings.Secure.HTTP_PROXY isn't currently deprecated. The (sloppy) note in the documentation was just a developer's note that this is something the Android team may consider doing in the future.

like image 1
Tony the Pony Avatar answered Oct 13 '22 06:10

Tony the Pony