VpnProfilepublic class VpnProfile extends Object implements Cloneable, android.os.ParcelableParcel-like entity class for VPN profiles. To keep things simple, all
fields are package private. Methods are provided for serialization, so
storage can be implemented easily. Two rules are set for this class.
First, all fields must be kept non-null. Second, always make a copy
using clone() before modifying. |
Fields Summary |
---|
private static final String | TAG | public static final int | TYPE_PPTP | public static final int | TYPE_L2TP_IPSEC_PSK | public static final int | TYPE_L2TP_IPSEC_RSA | public static final int | TYPE_IPSEC_XAUTH_PSK | public static final int | TYPE_IPSEC_XAUTH_RSA | public static final int | TYPE_IPSEC_HYBRID_RSA | public static final int | TYPE_MAX | public final String | key | public String | name | public int | type | public String | server | public String | username | public String | password | public String | dnsServers | public String | searchDomains | public String | routes | public boolean | mppe | public String | l2tpSecret | public String | ipsecIdentifier | public String | ipsecSecret | public String | ipsecUserCert | public String | ipsecCaCert | public String | ipsecServerCert | public boolean | saveLogin | public static final Creator | CREATOR |
Constructors Summary |
---|
public VpnProfile(String key)
this.key = key;
| public VpnProfile(android.os.Parcel in)
key = in.readString();
name = in.readString();
type = in.readInt();
server = in.readString();
username = in.readString();
password = in.readString();
dnsServers = in.readString();
searchDomains = in.readString();
routes = in.readString();
mppe = in.readInt() != 0;
l2tpSecret = in.readString();
ipsecIdentifier = in.readString();
ipsecSecret = in.readString();
ipsecUserCert = in.readString();
ipsecCaCert = in.readString();
ipsecServerCert = in.readString();
saveLogin = in.readInt() != 0;
|
Methods Summary |
---|
public static com.android.internal.net.VpnProfile | decode(java.lang.String key, byte[] value)
try {
if (key == null) {
return null;
}
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) {
return null;
}
VpnProfile profile = new VpnProfile(key);
profile.name = values[0];
profile.type = Integer.valueOf(values[1]);
if (profile.type < 0 || profile.type > TYPE_MAX) {
return null;
}
profile.server = values[2];
profile.username = values[3];
profile.password = values[4];
profile.dnsServers = values[5];
profile.searchDomains = values[6];
profile.routes = values[7];
profile.mppe = Boolean.valueOf(values[8]);
profile.l2tpSecret = values[9];
profile.ipsecIdentifier = values[10];
profile.ipsecSecret = values[11];
profile.ipsecUserCert = values[12];
profile.ipsecCaCert = values[13];
profile.ipsecServerCert = (values.length > 14) ? values[14] : "";
profile.saveLogin = !profile.username.isEmpty() || !profile.password.isEmpty();
return profile;
} catch (Exception e) {
// ignore
}
return null;
| public int | describeContents()
return 0;
| public byte[] | encode()
StringBuilder builder = new StringBuilder(name);
builder.append('\0").append(type);
builder.append('\0").append(server);
builder.append('\0").append(saveLogin ? username : "");
builder.append('\0").append(saveLogin ? password : "");
builder.append('\0").append(dnsServers);
builder.append('\0").append(searchDomains);
builder.append('\0").append(routes);
builder.append('\0").append(mppe);
builder.append('\0").append(l2tpSecret);
builder.append('\0").append(ipsecIdentifier);
builder.append('\0").append(ipsecSecret);
builder.append('\0").append(ipsecUserCert);
builder.append('\0").append(ipsecCaCert);
builder.append('\0").append(ipsecServerCert);
return builder.toString().getBytes(StandardCharsets.UTF_8);
| public boolean | isValidLockdownProfile()Test if profile is valid for lockdown, which requires IPv4 address for
both server and DNS. Server hostnames would require using DNS before
connection.
try {
InetAddress.parseNumericAddress(server);
for (String dnsServer : dnsServers.split(" +")) {
InetAddress.parseNumericAddress(this.dnsServers);
}
if (TextUtils.isEmpty(dnsServers)) {
Log.w(TAG, "DNS required");
return false;
}
// Everything checked out above
return true;
} catch (IllegalArgumentException e) {
Log.w(TAG, "Invalid address", e);
return false;
}
| public void | writeToParcel(android.os.Parcel out, int flags)
out.writeString(key);
out.writeString(name);
out.writeInt(type);
out.writeString(server);
out.writeString(username);
out.writeString(password);
out.writeString(dnsServers);
out.writeString(searchDomains);
out.writeString(routes);
out.writeInt(mppe ? 1 : 0);
out.writeString(l2tpSecret);
out.writeString(ipsecIdentifier);
out.writeString(ipsecSecret);
out.writeString(ipsecUserCert);
out.writeString(ipsecCaCert);
out.writeString(ipsecServerCert);
out.writeInt(saveLogin ? 1 : 0);
|
|