From e5b9e4bddf1aed4f647da3966d831a165a064f80 Mon Sep 17 00:00:00 2001 From: Hung-ying Tyan Date: Wed, 1 Jul 2009 11:06:45 +0800 Subject: [PATCH] Add L2tpIpsecPskEditor. * Changes + Add L2tpIpsecPskEditor.java. + Save profile name in VpnEditor to be used in saveSecrets(). --- res/values/strings.xml | 7 ++ .../android/settings/vpn/L2tpIpsecPskEditor.java | 78 ++++++++++++++++++++++ src/com/android/settings/vpn/VpnEditor.java | 10 +++ 3 files changed, 95 insertions(+) create mode 100644 src/com/android/settings/vpn/L2tpIpsecPskEditor.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 7c6529d9ce..fb806c9349 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1895,6 +1895,11 @@ found in the list of installed applications. L2TP secret + Set IPSec pre-shared key + + IPSec pre-shared key + + Set IPSec pre-shared key IPSec pre-shared key @@ -1961,6 +1966,8 @@ found in the list of installed applications. Confirm new password: You must set a password for credential storage before you can store secure certificates and other credentials in it. + Passwords do not match. + Please fill up all the fields. Emergency tone diff --git a/src/com/android/settings/vpn/L2tpIpsecPskEditor.java b/src/com/android/settings/vpn/L2tpIpsecPskEditor.java new file mode 100644 index 0000000000..9c1d02c390 --- /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 9df98a61e3..e33ce55090 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); -- 2.11.0