summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2009-07-01 11:06:45 +0800
committerHung-ying Tyan <tyanh@google.com>2009-07-01 11:06:45 +0800
commite5b9e4bddf1aed4f647da3966d831a165a064f80 (patch)
tree3845a3f9f5ff9998cb2e4fa8d188ba9d06a926ac /src/com/android/settings
parent88ec7ebfe935c0541df3289c31574adbc01bd8bb (diff)
downloadpackages_apps_settings-e5b9e4bddf1aed4f647da3966d831a165a064f80.zip
packages_apps_settings-e5b9e4bddf1aed4f647da3966d831a165a064f80.tar.gz
packages_apps_settings-e5b9e4bddf1aed4f647da3966d831a165a064f80.tar.bz2
Add L2tpIpsecPskEditor.
* Changes + Add L2tpIpsecPskEditor.java. + Save profile name in VpnEditor to be used in saveSecrets().
Diffstat (limited to 'src/com/android/settings')
-rw-r--r--src/com/android/settings/vpn/L2tpIpsecPskEditor.java78
-rw-r--r--src/com/android/settings/vpn/VpnEditor.java10
2 files changed, 88 insertions, 0 deletions
diff --git a/src/com/android/settings/vpn/L2tpIpsecPskEditor.java b/src/com/android/settings/vpn/L2tpIpsecPskEditor.java
new file mode 100644
index 0000000..9c1d02c
--- /dev/null
+++ b/src/com/android/settings/vpn/L2tpIpsecPskEditor.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.vpn;
+
+import com.android.settings.R;
+
+import android.content.Context;
+import android.net.vpn.L2tpIpsecPskProfile;
+import android.preference.EditTextPreference;
+import android.preference.Preference;
+import android.preference.PreferenceGroup;
+
+/**
+ * The class for editing {@link L2tpIpsecPskProfile}.
+ */
+class L2tpIpsecPskEditor extends L2tpEditor {
+ private EditTextPreference mPresharedKey;
+
+ public L2tpIpsecPskEditor(L2tpIpsecPskProfile p) {
+ super(p);
+ }
+
+ @Override
+ protected void loadExtraPreferencesTo(PreferenceGroup subpanel) {
+ Context c = subpanel.getContext();
+ subpanel.addPreference(createPresharedKeyPreference(c));
+ super.loadExtraPreferencesTo(subpanel);
+ }
+
+ @Override
+ public String validate() {
+ String result = super.validate();
+
+ return ((result != null)
+ ? result
+ : validate(mPresharedKey, R.string.vpn_ipsec_presharedkey));
+ }
+
+ @Override
+ public void saveSecrets(String originalProfileName) {
+ L2tpIpsecPskProfile profile = (L2tpIpsecPskProfile) getProfile();
+ profile.getPresharedKey();
+ // TODO: fill up the implementation after keystore is available
+ }
+
+ private Preference createPresharedKeyPreference(Context c) {
+ final L2tpIpsecPskProfile profile = (L2tpIpsecPskProfile) getProfile();
+ mPresharedKey = createSecretPreference(c,
+ R.string.vpn_ipsec_presharedkey_title,
+ R.string.vpn_ipsec_presharedkey,
+ profile.getPresharedKey(),
+ new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(
+ Preference pref, Object newValue) {
+ profile.setPresharedKey((String) newValue);
+ setSecretSummary(mPresharedKey,
+ R.string.vpn_ipsec_presharedkey,
+ (String) newValue);
+ return true;
+ }
+ });
+ return mPresharedKey;
+ }
+}
diff --git a/src/com/android/settings/vpn/VpnEditor.java b/src/com/android/settings/vpn/VpnEditor.java
index 9df98a6..e33ce55 100644
--- a/src/com/android/settings/vpn/VpnEditor.java
+++ b/src/com/android/settings/vpn/VpnEditor.java
@@ -22,6 +22,7 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.vpn.L2tpIpsecProfile;
+import android.net.vpn.L2tpIpsecPskProfile;
import android.net.vpn.L2tpProfile;
import android.net.vpn.VpnProfile;
import android.net.vpn.VpnType;
@@ -41,9 +42,11 @@ public class VpnEditor extends PreferenceActivity {
private static final int MENU_SAVE = Menu.FIRST;
private static final int MENU_CANCEL = Menu.FIRST + 1;
private static final String KEY_PROFILE = "profile";
+ private static final String KEY_ORIGINAL_PROFILE_NAME = "orig_profile_name";
private VpnProfileEditor mProfileEditor;
private boolean mAddingProfile;
+ private String mOriginalProfileName;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -51,6 +54,9 @@ public class VpnEditor extends PreferenceActivity {
VpnProfile p = (VpnProfile) ((savedInstanceState == null)
? getIntent().getParcelableExtra(VpnSettings.KEY_VPN_PROFILE)
: savedInstanceState.getParcelable(KEY_PROFILE));
+ mOriginalProfileName = (savedInstanceState == null)
+ ? p.getName()
+ : savedInstanceState.getString(KEY_ORIGINAL_PROFILE_NAME);
mProfileEditor = getEditor(p);
mAddingProfile = TextUtils.isEmpty(p.getName());
@@ -65,6 +71,7 @@ public class VpnEditor extends PreferenceActivity {
if (mProfileEditor == null) return;
outState.putParcelable(KEY_PROFILE, getProfile());
+ outState.putString(KEY_ORIGINAL_PROFILE_NAME, mOriginalProfileName);
}
@Override
@@ -119,6 +126,7 @@ public class VpnEditor extends PreferenceActivity {
return false;
}
+ mProfileEditor.saveSecrets(mOriginalProfileName);
setResult(getProfile());
return true;
}
@@ -136,6 +144,8 @@ public class VpnEditor extends PreferenceActivity {
return new L2tpIpsecEditor((L2tpIpsecProfile) p);
case L2TP_IPSEC_PSK:
+ return new L2tpIpsecPskEditor((L2tpIpsecPskProfile) p);
+
case L2TP:
return new L2tpEditor((L2tpProfile) p);