Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICS proxy settings-Solution #59

Open
GoogleCodeExporter opened this issue Aug 11, 2015 · 2 comments
Open

Fix ICS proxy settings-Solution #59

GoogleCodeExporter opened this issue Aug 11, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

 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
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant