Merge "Support VPN Proxy(1/2)" am: 65087f4705 am: ba4a9abe35
am: ff3d9bb029
Change-Id: If9b778dd168efdd8b2df15db375ac654398dd709
diff --git a/core/java/com/android/internal/net/VpnProfile.java b/core/java/com/android/internal/net/VpnProfile.java
index ec02432..940cc36 100644
--- a/core/java/com/android/internal/net/VpnProfile.java
+++ b/core/java/com/android/internal/net/VpnProfile.java
@@ -18,6 +18,8 @@
import android.annotation.UnsupportedAppUsage;
import android.os.Build;
+import android.net.ProxyInfo;
+import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -46,6 +48,10 @@
public static final int TYPE_IPSEC_HYBRID_RSA = 5;
public static final int TYPE_MAX = 5;
+ // Match these constants with R.array.vpn_proxy_settings.
+ public static final int PROXY_NONE = 0;
+ public static final int PROXY_MANUAL = 1;
+
// Entity fields.
@UnsupportedAppUsage
public final String key; // -1
@@ -68,6 +74,7 @@
public String ipsecUserCert = ""; // 12
public String ipsecCaCert = ""; // 13
public String ipsecServerCert = "";// 14
+ public ProxyInfo proxy = null; // 15~18
// Helper fields.
@UnsupportedAppUsage
@@ -96,6 +103,7 @@
ipsecCaCert = in.readString();
ipsecServerCert = in.readString();
saveLogin = in.readInt() != 0;
+ proxy = in.readParcelable(null);
}
@Override
@@ -117,6 +125,7 @@
out.writeString(ipsecCaCert);
out.writeString(ipsecServerCert);
out.writeInt(saveLogin ? 1 : 0);
+ out.writeParcelable(proxy, flags);
}
@UnsupportedAppUsage
@@ -127,8 +136,8 @@
}
String[] values = new String(value, StandardCharsets.UTF_8).split("\0", -1);
- // There can be 14 or 15 values in ICS MR1.
- if (values.length < 14 || values.length > 15) {
+ // There can be 14 - 19 Bytes in values.length.
+ if (values.length < 14 || values.length > 19) {
return null;
}
@@ -151,7 +160,18 @@
profile.ipsecUserCert = values[12];
profile.ipsecCaCert = values[13];
profile.ipsecServerCert = (values.length > 14) ? values[14] : "";
-
+ if (values.length > 15) {
+ String host = (values.length > 15) ? values[15] : "";
+ String port = (values.length > 16) ? values[16] : "";
+ String exclList = (values.length > 17) ? values[17] : "";
+ String pacFileUrl = (values.length > 18) ? values[18] : "";
+ if (pacFileUrl.isEmpty()) {
+ profile.proxy = new ProxyInfo(host, port.isEmpty() ?
+ 0 : Integer.parseInt(port), exclList);
+ } else {
+ profile.proxy = new ProxyInfo(pacFileUrl);
+ }
+ } // else profle.proxy = null
profile.saveLogin = !profile.username.isEmpty() || !profile.password.isEmpty();
return profile;
} catch (Exception e) {
@@ -176,6 +196,13 @@
builder.append('\0').append(ipsecUserCert);
builder.append('\0').append(ipsecCaCert);
builder.append('\0').append(ipsecServerCert);
+ if (proxy != null) {
+ builder.append('\0').append(proxy.getHost() != null ? proxy.getHost() : "");
+ builder.append('\0').append(proxy.getPort());
+ builder.append('\0').append(proxy.getExclusionListAsString() != null ?
+ proxy.getExclusionListAsString() : "");
+ builder.append('\0').append(proxy.getPacFileUrl().toString());
+ }
return builder.toString().getBytes(StandardCharsets.UTF_8);
}
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index 59fffb4..8005dda 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -1842,6 +1842,7 @@
config.interfaze = iface;
config.session = profile.name;
config.isMetered = false;
+ config.proxyInfo = profile.proxy;
config.addLegacyRoutes(profile.routes);
if (!profile.dnsServers.isEmpty()) {