Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 020d429d authored by Jason Monk's avatar Jason Monk Committed by Android Git Automerger
Browse files

am 3bf09f77: Merge "Add PAC File support for proxy configuration"

* commit '3bf09f77':
  Add PAC File support for proxy configuration
parents 6888e50d 3bf09f77
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -257,7 +257,8 @@ LOCAL_SRC_FILES += \
	telephony/java/com/android/internal/telephony/ITelephonyRegistry.aidl \
	telephony/java/com/android/internal/telephony/IWapPushManager.aidl \
	wifi/java/android/net/wifi/IWifiManager.aidl \
	wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl
	wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl \
	packages/services/Proxy/com/android/net/IProxyService.aidl \

# FRAMEWORKS_BASE_JAVA_SRC_DIRS comes from build/core/pathmap.mk
LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
+2 −2
Original line number Diff line number Diff line
@@ -793,8 +793,8 @@ public final class ActivityThread {
            InetAddress.clearDnsCache();
        }

        public void setHttpProxy(String host, String port, String exclList) {
            Proxy.setHttpProxySystemProperty(host, port, exclList);
        public void setHttpProxy(String host, String port, String exclList, String pacFileUrl) {
            Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl);
        }

        public void processInBackground() {
+5 −2
Original line number Diff line number Diff line
@@ -338,7 +338,8 @@ public abstract class ApplicationThreadNative extends Binder
            final String proxy = data.readString();
            final String port = data.readString();
            final String exclList = data.readString();
            setHttpProxy(proxy, port, exclList);
            final String pacFileUrl = data.readString();
            setHttpProxy(proxy, port, exclList, pacFileUrl);
            return true;
        }

@@ -1001,12 +1002,14 @@ class ApplicationThreadProxy implements IApplicationThread {
        data.recycle();
    }

    public void setHttpProxy(String proxy, String port, String exclList) throws RemoteException {
    public void setHttpProxy(String proxy, String port, String exclList,
            String pacFileUrl) throws RemoteException {
        Parcel data = Parcel.obtain();
        data.writeInterfaceToken(IApplicationThread.descriptor);
        data.writeString(proxy);
        data.writeString(port);
        data.writeString(exclList);
        data.writeString(pacFileUrl);
        mRemote.transact(SET_HTTP_PROXY_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
        data.recycle();
    }
+2 −1
Original line number Diff line number Diff line
@@ -101,7 +101,8 @@ public interface IApplicationThread extends IInterface {
    void scheduleConfigurationChanged(Configuration config) throws RemoteException;
    void updateTimeZone() throws RemoteException;
    void clearDnsCache() throws RemoteException;
    void setHttpProxy(String proxy, String port, String exclList) throws RemoteException;
    void setHttpProxy(String proxy, String port, String exclList,
            String pacFileUrl) throws RemoteException;
    void processInBackground() throws RemoteException;
    void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args)
            throws RemoteException;
+80 −0
Original line number Diff line number Diff line

package android.net;

import android.os.RemoteException;
import android.os.ServiceManager;

import com.android.net.IProxyService;
import com.google.android.collect.Lists;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.util.List;

/**
 * @hide
 */
public class PacProxySelector extends ProxySelector {
    public static final String PROXY_SERVICE = "com.android.net.IProxyService";
    private IProxyService mProxyService;

    public PacProxySelector() {
        mProxyService = IProxyService.Stub.asInterface(
                ServiceManager.getService(PROXY_SERVICE));
    }

    @Override
    public List<Proxy> select(URI uri) {
        String response = null;
        String urlString;
        try {
            urlString = uri.toURL().toString();
        } catch (MalformedURLException e) {
            urlString = uri.getHost();
        }
        try {
            response = mProxyService.resolvePacFile(uri.getHost(), urlString);
        } catch (RemoteException e) {
            e.printStackTrace();
        }

        return parseResponse(response);
    }

    private static List<Proxy> parseResponse(String response) {
        String[] split = response.split(";");
        List<Proxy> ret = Lists.newArrayList();
        for (String s : split) {
            String trimmed = s.trim();
            if (trimmed.equals("DIRECT")) {
                ret.add(java.net.Proxy.NO_PROXY);
            } else if (trimmed.startsWith("PROXY ")) {
                String[] hostPort = trimmed.substring(6).split(":");
                String host = hostPort[0];
                int port;
                try {
                    port = Integer.parseInt(hostPort[1]);
                } catch (Exception e) {
                    port = 8080;
                }
                ret.add(new Proxy(Type.HTTP, new InetSocketAddress(host, port)));
            }
        }
        if (ret.size() == 0) {
            ret.add(java.net.Proxy.NO_PROXY);
        }
        return ret;
    }

    @Override
    public void connectFailed(URI uri, SocketAddress address, IOException failure) {

    }

}
Loading