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

Commit 18622d3d authored by Irina Dumitrescu's avatar Irina Dumitrescu
Browse files

Add API for proxy configuration over VPN.

Test: runtest -x
frameworks/base/tests/net/java/com/android/server/ConnectivityServiceTest.java
&& atest HostsideVpnTests
Bug: 76001058
Change-Id: Id4dde4a4103fd93bfbbacc52d0e5ade56ae67a6a
parent 2499cc2f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29138,6 +29138,7 @@ package android.net {
    method public android.os.ParcelFileDescriptor establish();
    method public android.net.VpnService.Builder setBlocking(boolean);
    method public android.net.VpnService.Builder setConfigureIntent(android.app.PendingIntent);
    method public android.net.VpnService.Builder setHttpProxy(android.net.ProxyInfo);
    method public android.net.VpnService.Builder setMtu(int);
    method public android.net.VpnService.Builder setSession(java.lang.String);
    method public android.net.VpnService.Builder setUnderlyingNetworks(android.net.Network[]);
+3 −11
Original line number Diff line number Diff line
@@ -77,9 +77,7 @@ import android.graphics.ImageDecoder;
import android.hardware.display.DisplayManagerGlobal;
import android.net.ConnectivityManager;
import android.net.IConnectivityManager;
import android.net.Network;
import android.net.Proxy;
import android.net.ProxyInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Binder;
@@ -1033,15 +1031,10 @@ public final class ActivityThread extends ClientTransactionHandler {
            NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged();
        }

        public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) {
        public void updateHttpProxy() {
            final ConnectivityManager cm = ConnectivityManager.from(
                    getApplication() != null ? getApplication() : getSystemContext());
            final Network network = cm.getBoundNetworkForProcess();
            if (network != null) {
            Proxy.setHttpProxySystemProperty(cm.getDefaultProxy());
            } else {
                Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl);
            }
        }

        public void processInBackground() {
@@ -5955,8 +5948,7 @@ public final class ActivityThread extends ClientTransactionHandler {
            // crash if we can't get it.
            final IConnectivityManager service = IConnectivityManager.Stub.asInterface(b);
            try {
                final ProxyInfo proxyInfo = service.getProxyForNetwork(null);
                Proxy.setHttpProxySystemProperty(proxyInfo);
                Proxy.setHttpProxySystemProperty(service.getProxyForNetwork(null));
            } catch (RemoteException e) {
                Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                throw e.rethrowFromSystemServer();
+1 −2
Original line number Diff line number Diff line
@@ -100,8 +100,7 @@ oneway interface IApplicationThread {
    void dumpActivity(in ParcelFileDescriptor fd, IBinder servicetoken, in String prefix,
            in String[] args);
    void clearDnsCache();
    void setHttpProxy(in String proxy, in String port, in String exclList,
            in Uri pacFileUrl);
    void updateHttpProxy();
    void setCoreSettings(in Bundle coreSettings);
    void updatePackageCompatibilityInfo(in String pkg, in CompatibilityInfo info);
    void scheduleTrimMemory(int level);
+31 −26
Original line number Diff line number Diff line
@@ -39,12 +39,12 @@ import java.util.Locale;
 */
public class ProxyInfo implements Parcelable {

    private String mHost;
    private int mPort;
    private String mExclusionList;
    private String[] mParsedExclusionList;
    private final String mHost;
    private final int mPort;
    private final String mExclusionList;
    private final String[] mParsedExclusionList;
    private final Uri mPacFileUrl;

    private Uri mPacFileUrl;
    /**
     *@hide
     */
@@ -96,7 +96,8 @@ public class ProxyInfo implements Parcelable {
    public ProxyInfo(String host, int port, String exclList) {
        mHost = host;
        mPort = port;
        setExclusionList(exclList);
        mExclusionList = exclList;
        mParsedExclusionList = parseExclusionList(mExclusionList);
        mPacFileUrl = Uri.EMPTY;
    }

@@ -107,7 +108,8 @@ public class ProxyInfo implements Parcelable {
    public ProxyInfo(Uri pacFileUrl) {
        mHost = LOCAL_HOST;
        mPort = LOCAL_PORT;
        setExclusionList(LOCAL_EXCL_LIST);
        mExclusionList = LOCAL_EXCL_LIST;
        mParsedExclusionList = parseExclusionList(mExclusionList);
        if (pacFileUrl == null) {
            throw new NullPointerException();
        }
@@ -121,7 +123,8 @@ public class ProxyInfo implements Parcelable {
    public ProxyInfo(String pacFileUrl) {
        mHost = LOCAL_HOST;
        mPort = LOCAL_PORT;
        setExclusionList(LOCAL_EXCL_LIST);
        mExclusionList = LOCAL_EXCL_LIST;
        mParsedExclusionList = parseExclusionList(mExclusionList);
        mPacFileUrl = Uri.parse(pacFileUrl);
    }

@@ -132,13 +135,22 @@ public class ProxyInfo implements Parcelable {
    public ProxyInfo(Uri pacFileUrl, int localProxyPort) {
        mHost = LOCAL_HOST;
        mPort = localProxyPort;
        setExclusionList(LOCAL_EXCL_LIST);
        mExclusionList = LOCAL_EXCL_LIST;
        mParsedExclusionList = parseExclusionList(mExclusionList);
        if (pacFileUrl == null) {
            throw new NullPointerException();
        }
        mPacFileUrl = pacFileUrl;
    }

    private static String[] parseExclusionList(String exclusionList) {
        if (exclusionList == null) {
            return new String[0];
        } else {
            return exclusionList.toLowerCase(Locale.ROOT).split(",");
        }
    }

    private ProxyInfo(String host, int port, String exclList, String[] parsedExclList) {
        mHost = host;
        mPort = port;
@@ -159,6 +171,10 @@ public class ProxyInfo implements Parcelable {
            mExclusionList = source.getExclusionListAsString();
            mParsedExclusionList = source.mParsedExclusionList;
        } else {
            mHost = null;
            mPort = 0;
            mExclusionList = null;
            mParsedExclusionList = null;
            mPacFileUrl = Uri.EMPTY;
        }
    }
@@ -214,16 +230,6 @@ public class ProxyInfo implements Parcelable {
        return mExclusionList;
    }

    // comma separated
    private void setExclusionList(String exclusionList) {
        mExclusionList = exclusionList;
        if (mExclusionList == null) {
            mParsedExclusionList = new String[0];
        } else {
            mParsedExclusionList = exclusionList.toLowerCase(Locale.ROOT).split(",");
        }
    }

    /**
     * @hide
     */
@@ -352,8 +358,7 @@ public class ProxyInfo implements Parcelable {
                }
                String exclList = in.readString();
                String[] parsedExclList = in.readStringArray();
                ProxyInfo proxyProperties =
                        new ProxyInfo(host, port, exclList, parsedExclList);
                ProxyInfo proxyProperties = new ProxyInfo(host, port, exclList, parsedExclList);
                return proxyProperties;
            }

+9 −0
Original line number Diff line number Diff line
@@ -485,6 +485,15 @@ public class VpnService extends Service {
            return this;
        }

        /**
         * Sets an HTTP proxy for the VPN network. This proxy is only a recommendation
         * and it is possible that some apps will ignore it.
         */
        public Builder setHttpProxy(ProxyInfo proxyInfo) {
            mConfig.proxyInfo = proxyInfo;
            return this;
        }

        /**
         * Add a network address to the VPN interface. Both IPv4 and IPv6
         * addresses are supported. At least one address must be set before
Loading