Add L2tpIpsecPskEditor.

* Changes
  + Add L2tpIpsecPskEditor.java.
  + Save profile name in VpnEditor to be used in saveSecrets().
This commit is contained in:
Hung-ying Tyan
2009-07-01 11:06:45 +08:00
parent 88ec7ebfe9
commit e5b9e4bddf
3 changed files with 95 additions and 0 deletions

View File

@@ -1894,6 +1894,11 @@ found in the list of installed applications.</string>
<!-- Complete term -->
<string name="vpn_l2tp_secret">L2TP secret</string>
<!-- Preference title -->
<string name="vpn_ipsec_presharedkey_title">Set IPSec pre-shared key</string>
<!-- Complete term -->
<string name="vpn_ipsec_presharedkey">IPSec pre-shared key</string>
<!-- Preference title -->
<string name="vpn_psk_title">Set IPSec pre-shared key</string>
<!-- Complete term -->
@@ -1961,6 +1966,8 @@ found in the list of installed applications.</string>
<string name="cstor_confirm_password">Confirm new password:</string>
<!-- Description when user set up the storage for the very first time -->
<string name="cstor_first_time_hint">You must set a password for credential storage before you can store secure certificates and other credentials in it.</string>
<string name="cstor_password_error">Passwords do not match.</string>
<string name="cstor_password_empty_error">Please fill up all the fields.</string>
<!-- Sound settings screen, setting check box label -->
<string name="emergency_tone_title">Emergency tone</string>

View File

@@ -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;
}
}

View File

@@ -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);