Jhanay / zirco-browser

Automatically exported from code.google.com/p/zirco-browser
Other
0 stars 0 forks source link

Fix ICS proxy settings-Solution #59

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
 private static boolean setProxy(Context ctx, String host, int port) 
    {
        boolean ret = false;
        try 
        {
            if(Build.VERSION.SDK_INT < 14)
            {
            Object requestQueueObject = getRequestQueue(ctx);
            if (requestQueueObject != null) 
            {
                //Create Proxy config object and set it into request Q
                HttpHost httpHost = new HttpHost("24.245.17.166", 1767, "http");
                setDeclaredField(requestQueueObject, "mProxyHost", httpHost);
                //Log.d("Webkit Setted Proxy to: " + host + ":" + port);
                ret = true;
            }
            }
            else
            {
                ret=setICSProxy(host,port);
            }
        } 
        catch (Exception e) 
        {
            Log.e("ProxySettings","Exception setting WebKit proxy settings: " + e.toString());
        }
        return ret;
    }

    private static boolean setICSProxy(String host, int port) throws ClassNotFoundException,
    NoSuchMethodException, IllegalArgumentException, InstantiationException,
    IllegalAccessException, InvocationTargetException {
Class webViewCoreClass = Class.forName("android.webkit.WebViewCore");
Class proxyPropertiesClass = Class.forName("android.net.ProxyProperties");
if (webViewCoreClass != null && proxyPropertiesClass != null) {
    Method m = webViewCoreClass.getDeclaredMethod("sendStaticMessage", Integer.TYPE,
            Object.class);
    Constructor c = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE,
            String.class);
    m.setAccessible(true);
    c.setAccessible(true);
    Object properties = c.newInstance(host, port, null);
    m.invoke(null, PROXY_CHANGED, properties);
    return true;
}

Original issue reported on code.google.com by tapatal...@gmail.com on 17 May 2012 at 7:34

GoogleCodeExporter commented 9 years ago
Well, this is just modified code I'm using but I'm sure you see how to adapt it 
to the current codebase.

Original comment by tapatal...@gmail.com on 17 May 2012 at 7:36

GoogleCodeExporter commented 9 years ago
private static boolean setProxy(Context ctx, String host, int port) 
    {
        boolean ret = false;
        try 
        {
            if(Build.VERSION.SDK_INT < 14)
            {
            Object requestQueueObject = getRequestQueue(ctx);
            if (requestQueueObject != null) 
            {
                //Create Proxy config object and set it into request Q
                HttpHost httpHost = new HttpHost(host, port, "http");
                setDeclaredField(requestQueueObject, "mProxyHost", httpHost);
                //Log.d("Webkit Setted Proxy to: " + host + ":" + port);
                ret = true;
            }
            }
            else
            {
                ret=setICSProxy(host,port);
            }
        } 
        catch (Exception e) 
        {
            Log.e("ProxySettings","Exception setting WebKit proxy settings: " + e.toString());
        }
        return ret;
    }

    private static boolean setICSProxy(String host, int port) throws ClassNotFoundException,
    NoSuchMethodException, IllegalArgumentException, InstantiationException,
    IllegalAccessException, InvocationTargetException {
Class webViewCoreClass = Class.forName("android.webkit.WebViewCore");
Class proxyPropertiesClass = Class.forName("android.net.ProxyProperties");
if (webViewCoreClass != null && proxyPropertiesClass != null) {
    Method m = webViewCoreClass.getDeclaredMethod("sendStaticMessage", Integer.TYPE,
            Object.class);
    Constructor c = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE,
            String.class);
    m.setAccessible(true);
    c.setAccessible(true);
    Object properties = c.newInstance(host, port, null);
    m.invoke(null, PROXY_CHANGED, properties);
    return true;
}

Original comment by tapatal...@gmail.com on 17 May 2012 at 7:36