summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AndroidManifest.xml1
-rw-r--r--res/layout/vpn_dialog.xml24
-rw-r--r--res/values/strings.xml2
-rw-r--r--res/values/styles.xml5
-rw-r--r--src/com/android/settings/vpn2/VpnDialog.java11
-rw-r--r--src/com/android/settings/vpn2/VpnSettings.java52
6 files changed, 66 insertions, 29 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5b6d24a..7b246a0 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -23,6 +23,7 @@
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
diff --git a/res/layout/vpn_dialog.xml b/res/layout/vpn_dialog.xml
index a4bb216..ffbfd4d 100644
--- a/res/layout/vpn_dialog.xml
+++ b/res/layout/vpn_dialog.xml
@@ -20,7 +20,7 @@
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
- android:padding="5mm">
+ android:padding="3mm">
<LinearLayout android:id="@+id/editor"
android:layout_width="match_parent"
@@ -30,7 +30,7 @@
<TextView style="@style/vpn_label" android:text="@string/vpn_name"/>
<EditText style="@style/vpn_value" android:id="@+id/name"
- android:singleLine="true"/>
+ android:inputType="textCapWords"/>
<TextView style="@style/vpn_label" android:text="@string/vpn_type"/>
<Spinner style="@style/vpn_value" android:id="@+id/type"
@@ -38,11 +38,11 @@
android:entries="@array/vpn_types"/>
<TextView style="@style/vpn_label" android:text="@string/vpn_server"/>
- <EditText style="@style/vpn_value" android:id="@+id/server"
- android:singleLine="true"/>
+ <EditText style="@style/vpn_value" android:id="@+id/server"/>
<CheckBox style="@style/vpn_value" android:id="@+id/mppe"
android:text="@string/vpn_mppe"
+ android:singleLine="false"
android:visibility="gone"/>
<LinearLayout android:id="@+id/l2tp"
@@ -52,24 +52,27 @@
android:visibility="gone">
<TextView style="@style/vpn_label" android:text="@string/vpn_l2tp_secret"/>
<EditText style="@style/vpn_value" android:id="@+id/l2tp_secret"
- android:singleLine="true"
android:password="true"
android:hint="@string/vpn_not_used"/>
</LinearLayout>
- <LinearLayout android:id="@+id/ipsec_psk"
+ <LinearLayout android:id="@+id/ipsec_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView style="@style/vpn_label" android:text="@string/vpn_ipsec_identifier"/>
<EditText style="@style/vpn_value" android:id="@+id/ipsec_identifier"
- android:singleLine="true"
android:hint="@string/vpn_not_used"/>
+ </LinearLayout>
+ <LinearLayout android:id="@+id/ipsec_psk"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:visibility="gone">
<TextView style="@style/vpn_label" android:text="@string/vpn_ipsec_secret"/>
<EditText style="@style/vpn_value" android:id="@+id/ipsec_secret"
- android:singleLine="true"
android:password="true"/>
</LinearLayout>
@@ -111,15 +114,14 @@
android:visibility="gone">
<TextView style="@style/vpn_label" android:text="@string/vpn_username"/>
- <EditText style="@style/vpn_value" android:id="@+id/username"
- android:singleLine="true"/>
+ <EditText style="@style/vpn_value" android:id="@+id/username"/>
<TextView style="@style/vpn_label" android:text="@string/vpn_password"/>
<EditText style="@style/vpn_value" android:id="@+id/password"
- android:singleLine="true"
android:password="true"/>
<CheckBox style="@style/vpn_value" android:id="@+id/save_login"
+ android:singleLine="false"
android:text="@string/vpn_save_login"/>
</LinearLayout>
</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 364ae3e..2b7ec58 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3447,7 +3447,7 @@ found in the list of installed applications.</string>
<!-- Checkbox label to save the username and the password for a VPN network. [CHAR LIMIT=40] -->
<string name="vpn_save_login">Save account information</string>
- <!-- Hint for an optional input of a VPN network. [CHAR LIMIT=40] -->
+ <!-- Hint for not filling an optional field in a VPN configuration. [CHAR LIMIT=40] -->
<string name="vpn_not_used">(not used)</string>
<!-- Option to not use a CA certificate to verify the VPN server. [CHAR LIMIT=40] -->
<string name="vpn_no_ca_cert">(do not verify server)</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 0f73abf..d7f8d9b 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -143,12 +143,15 @@
<style name="vpn_label">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
- <item name="android:textSize">14sp</item>
+ <item name="android:textSize">16sp</item>
</style>
<style name="vpn_value">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
+ <item name="android:textSize">18sp</item>
+ <item name="android:singleLine">true</item>
+ <item name="android:paddingBottom">1mm</item>
</style>
<style name="InputMethodPreferenceStyle">
diff --git a/src/com/android/settings/vpn2/VpnDialog.java b/src/com/android/settings/vpn2/VpnDialog.java
index b3609a6..4f9d0a2 100644
--- a/src/com/android/settings/vpn2/VpnDialog.java
+++ b/src/com/android/settings/vpn2/VpnDialog.java
@@ -197,6 +197,7 @@ class VpnDialog extends AlertDialog implements TextWatcher, OnItemSelectedListen
// First, hide everything.
mMppe.setVisibility(View.GONE);
mView.findViewById(R.id.l2tp).setVisibility(View.GONE);
+ mView.findViewById(R.id.ipsec_id).setVisibility(View.GONE);
mView.findViewById(R.id.ipsec_psk).setVisibility(View.GONE);
mView.findViewById(R.id.ipsec_user).setVisibility(View.GONE);
mView.findViewById(R.id.ipsec_ca).setVisibility(View.GONE);
@@ -206,11 +207,12 @@ class VpnDialog extends AlertDialog implements TextWatcher, OnItemSelectedListen
case VpnProfile.TYPE_PPTP:
mMppe.setVisibility(View.VISIBLE);
break;
-
case VpnProfile.TYPE_L2TP_IPSEC_PSK:
mView.findViewById(R.id.l2tp).setVisibility(View.VISIBLE);
- // fall through
+ mView.findViewById(R.id.ipsec_psk).setVisibility(View.VISIBLE);
+ break;
case VpnProfile.TYPE_IPSEC_XAUTH_PSK:
+ mView.findViewById(R.id.ipsec_id).setVisibility(View.VISIBLE);
mView.findViewById(R.id.ipsec_psk).setVisibility(View.VISIBLE);
break;
@@ -295,11 +297,12 @@ class VpnDialog extends AlertDialog implements TextWatcher, OnItemSelectedListen
case VpnProfile.TYPE_PPTP:
profile.mppe = mMppe.isChecked();
break;
-
case VpnProfile.TYPE_L2TP_IPSEC_PSK:
profile.l2tpSecret = getSecret(mProfile.l2tpSecret, mL2tpSecret);
- // fall through
+ profile.ipsecSecret = getSecret(mProfile.ipsecSecret, mIpsecSecret);
+ break;
case VpnProfile.TYPE_IPSEC_XAUTH_PSK:
+ profile.ipsecIdentifier = mIpsecIdentifier.getText().toString();
profile.ipsecSecret = getSecret(mProfile.ipsecSecret, mIpsecSecret);
break;
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index 7f6c9f4..f345c22 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -21,6 +21,7 @@ import com.android.settings.R;
import android.content.Context;
import android.content.DialogInterface;
import android.net.IConnectivityManager;
+import android.net.LinkProperties;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -41,6 +42,7 @@ import com.android.internal.net.LegacyVpnInfo;
import com.android.internal.net.VpnConfig;
import com.android.settings.SettingsPreferenceFragment;
+import java.nio.charset.Charsets;
import java.util.Arrays;
import java.util.HashMap;
@@ -198,7 +200,11 @@ public class VpnSettings extends SettingsPreferenceFragment implements
// If we are not editing, connect!
if (!mDialog.isEditing()) {
- connect(profile);
+ try {
+ connect(profile);
+ } catch (Exception e) {
+ Log.e(TAG, "connect", e);
+ }
}
}
}
@@ -314,20 +320,45 @@ public class VpnSettings extends SettingsPreferenceFragment implements
return true;
}
- private void connect(VpnProfile profile) {
+ private void connect(VpnProfile profile) throws Exception {
+ // Get the current active interface.
+ LinkProperties network = mService.getActiveLinkProperties();
+ String interfaze = (network == null) ? null : network.getInterfaceName();
+ if (interfaze == null) {
+ throw new IllegalStateException("Cannot get network interface");
+ }
+
+ // Load certificates.
+ String privateKey = "";
+ String userCert = "";
+ String caCert = "";
+ if (!profile.ipsecUserCert.isEmpty()) {
+ byte[] value = mKeyStore.get(Credentials.USER_PRIVATE_KEY + profile.ipsecUserCert);
+ privateKey = (value == null) ? null : new String(value, Charsets.UTF_8);
+ value = mKeyStore.get(Credentials.USER_CERTIFICATE + profile.ipsecUserCert);
+ userCert = (value == null) ? null : new String(value, Charsets.UTF_8);
+ }
+ if (!profile.ipsecCaCert.isEmpty()) {
+ byte[] value = mKeyStore.get(Credentials.CA_CERTIFICATE + profile.ipsecCaCert);
+ caCert = (value == null) ? null : new String(value, Charsets.UTF_8);
+ }
+ if (privateKey == null || userCert == null || caCert == null) {
+ // TODO: find out a proper way to handle this. Delete these keys?
+ throw new IllegalStateException("Cannot load credentials");
+ }
+ Log.i(TAG, userCert);
+
+ // Prepare arguments for racoon.
String[] racoon = null;
switch (profile.type) {
case VpnProfile.TYPE_L2TP_IPSEC_PSK:
racoon = new String[] {
- profile.server, "1701", profile.ipsecSecret,
+ interfaze, profile.server, "udppsk", "1701", profile.ipsecSecret,
};
break;
case VpnProfile.TYPE_L2TP_IPSEC_RSA:
racoon = new String[] {
- profile.server, "1701",
- Credentials.USER_PRIVATE_KEY + profile.ipsecUserCert,
- Credentials.USER_CERTIFICATE + profile.ipsecUserCert,
- Credentials.CA_CERTIFICATE + profile.ipsecCaCert,
+ interfaze, profile.server, "udprsa", "1701", privateKey, userCert, caCert,
};
break;
case VpnProfile.TYPE_IPSEC_XAUTH_PSK:
@@ -338,6 +369,7 @@ public class VpnSettings extends SettingsPreferenceFragment implements
break;
}
+ // Prepare arguments for mtpd.
String[] mtpd = null;
switch (profile.type) {
case VpnProfile.TYPE_PPTP:
@@ -369,11 +401,7 @@ public class VpnSettings extends SettingsPreferenceFragment implements
config.searchDomains = Arrays.asList(profile.searchDomains.split(" "));
}
- try {
- mService.startLegacyVpn(config, racoon, mtpd);
- } catch (Exception e) {
- Log.e(TAG, "connect", e);
- }
+ mService.startLegacyVpn(config, racoon, mtpd);
}
private void disconnect(String key) {