Merge "Support VPN Proxy(1/2)"
This commit is contained in:
@@ -18,6 +18,8 @@ package com.android.internal.net;
|
|||||||
|
|
||||||
import android.annotation.UnsupportedAppUsage;
|
import android.annotation.UnsupportedAppUsage;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.net.ProxyInfo;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -46,6 +48,10 @@ public class VpnProfile implements Cloneable, Parcelable {
|
|||||||
public static final int TYPE_IPSEC_HYBRID_RSA = 5;
|
public static final int TYPE_IPSEC_HYBRID_RSA = 5;
|
||||||
public static final int TYPE_MAX = 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.
|
// Entity fields.
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
public final String key; // -1
|
public final String key; // -1
|
||||||
@@ -68,6 +74,7 @@ public class VpnProfile implements Cloneable, Parcelable {
|
|||||||
public String ipsecUserCert = ""; // 12
|
public String ipsecUserCert = ""; // 12
|
||||||
public String ipsecCaCert = ""; // 13
|
public String ipsecCaCert = ""; // 13
|
||||||
public String ipsecServerCert = "";// 14
|
public String ipsecServerCert = "";// 14
|
||||||
|
public ProxyInfo proxy = null; // 15~18
|
||||||
|
|
||||||
// Helper fields.
|
// Helper fields.
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
@@ -96,6 +103,7 @@ public class VpnProfile implements Cloneable, Parcelable {
|
|||||||
ipsecCaCert = in.readString();
|
ipsecCaCert = in.readString();
|
||||||
ipsecServerCert = in.readString();
|
ipsecServerCert = in.readString();
|
||||||
saveLogin = in.readInt() != 0;
|
saveLogin = in.readInt() != 0;
|
||||||
|
proxy = in.readParcelable(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -117,6 +125,7 @@ public class VpnProfile implements Cloneable, Parcelable {
|
|||||||
out.writeString(ipsecCaCert);
|
out.writeString(ipsecCaCert);
|
||||||
out.writeString(ipsecServerCert);
|
out.writeString(ipsecServerCert);
|
||||||
out.writeInt(saveLogin ? 1 : 0);
|
out.writeInt(saveLogin ? 1 : 0);
|
||||||
|
out.writeParcelable(proxy, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
@@ -127,8 +136,8 @@ public class VpnProfile implements Cloneable, Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String[] values = new String(value, StandardCharsets.UTF_8).split("\0", -1);
|
String[] values = new String(value, StandardCharsets.UTF_8).split("\0", -1);
|
||||||
// There can be 14 or 15 values in ICS MR1.
|
// There can be 14 - 19 Bytes in values.length.
|
||||||
if (values.length < 14 || values.length > 15) {
|
if (values.length < 14 || values.length > 19) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +160,18 @@ public class VpnProfile implements Cloneable, Parcelable {
|
|||||||
profile.ipsecUserCert = values[12];
|
profile.ipsecUserCert = values[12];
|
||||||
profile.ipsecCaCert = values[13];
|
profile.ipsecCaCert = values[13];
|
||||||
profile.ipsecServerCert = (values.length > 14) ? values[14] : "";
|
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();
|
profile.saveLogin = !profile.username.isEmpty() || !profile.password.isEmpty();
|
||||||
return profile;
|
return profile;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -176,6 +196,13 @@ public class VpnProfile implements Cloneable, Parcelable {
|
|||||||
builder.append('\0').append(ipsecUserCert);
|
builder.append('\0').append(ipsecUserCert);
|
||||||
builder.append('\0').append(ipsecCaCert);
|
builder.append('\0').append(ipsecCaCert);
|
||||||
builder.append('\0').append(ipsecServerCert);
|
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);
|
return builder.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1840,6 +1840,7 @@ public class Vpn {
|
|||||||
config.interfaze = iface;
|
config.interfaze = iface;
|
||||||
config.session = profile.name;
|
config.session = profile.name;
|
||||||
config.isMetered = false;
|
config.isMetered = false;
|
||||||
|
config.proxyInfo = profile.proxy;
|
||||||
|
|
||||||
config.addLegacyRoutes(profile.routes);
|
config.addLegacyRoutes(profile.routes);
|
||||||
if (!profile.dnsServers.isEmpty()) {
|
if (!profile.dnsServers.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user