|
18 | 18 |
|
19 | 19 | import android.os.Parcel; |
20 | 20 | import android.os.Parcelable; |
| 21 | +import android.text.TextUtils; |
| 22 | +import android.util.Log; |
21 | 23 |
|
| 24 | +import java.net.InetAddress; |
22 | 25 | import java.nio.charset.Charsets; |
23 | 26 |
|
24 | 27 | /** |
|
31 | 34 | * @hide |
32 | 35 | */ |
33 | 36 | public class VpnProfile implements Cloneable, Parcelable { |
| 37 | + private static final String TAG = "VpnProfile"; |
| 38 | + |
34 | 39 | // Match these constants with R.array.vpn_types. |
35 | 40 | public static final int TYPE_PPTP = 0; |
36 | 41 | public static final int TYPE_L2TP_IPSEC_PSK = 1; |
@@ -124,6 +129,32 @@ public byte[] encode() { |
124 | 129 | return builder.toString().getBytes(Charsets.UTF_8); |
125 | 130 | } |
126 | 131 |
|
| 132 | + /** |
| 133 | + * Test if profile is valid for lockdown, which requires IPv4 address for |
| 134 | + * both server and DNS. Server hostnames would require using DNS before |
| 135 | + * connection. |
| 136 | + */ |
| 137 | + public boolean isValidLockdownProfile() { |
| 138 | + try { |
| 139 | + InetAddress.parseNumericAddress(server); |
| 140 | + |
| 141 | + for (String dnsServer : dnsServers.split(" +")) { |
| 142 | + InetAddress.parseNumericAddress(this.dnsServers); |
| 143 | + } |
| 144 | + if (TextUtils.isEmpty(dnsServers)) { |
| 145 | + Log.w(TAG, "DNS required"); |
| 146 | + return false; |
| 147 | + } |
| 148 | + |
| 149 | + // Everything checked out above |
| 150 | + return true; |
| 151 | + |
| 152 | + } catch (IllegalArgumentException e) { |
| 153 | + Log.w(TAG, "Invalid address", e); |
| 154 | + return false; |
| 155 | + } |
| 156 | + } |
| 157 | + |
127 | 158 | @Override |
128 | 159 | public void writeToParcel(Parcel out, int flags) { |
129 | 160 | out.writeString(key); |
|
0 commit comments