Add VPN settings classes to Settings app.
PATCH SET 2: + Add import com.android.settings.R PATCH SET 3: + Remove @Override interface methods to be compilable by Java 1.5. PATCH SET 4: + Add import android.net.vpn.VpnManager PATCH SET 5: + Add license headers. PATCH SET 6: + Remove Constant.java and move the constants to VpnSettings. + Make AuthenticationActor implement DialogInterface's handlers. + Remove trailing spaces. PATCH SET 7: + Remove default username.
This commit is contained in:
138
src/com/android/settings/vpn/L2tpIpsecEditor.java
Normal file
138
src/com/android/settings/vpn/L2tpIpsecEditor.java
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.L2tpIpsecProfile;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.security.Keystore;
|
||||
|
||||
/**
|
||||
* The class for editing {@link L2tpIpsecProfile}.
|
||||
*/
|
||||
class L2tpIpsecEditor extends SingleServerEditor {
|
||||
private static final String TAG = L2tpIpsecEditor.class.getSimpleName();
|
||||
|
||||
private ListPreference mUserCertificate;
|
||||
private ListPreference mCaCertificate;
|
||||
private ListPreference mUserkey;
|
||||
|
||||
private L2tpIpsecProfile mProfile;
|
||||
|
||||
public L2tpIpsecEditor(L2tpIpsecProfile p) {
|
||||
super(p);
|
||||
mProfile = p;
|
||||
}
|
||||
|
||||
//@Override
|
||||
public void loadPreferencesTo(PreferenceGroup subsettings) {
|
||||
super.loadPreferencesTo(subsettings);
|
||||
Context c = subsettings.getContext();
|
||||
subsettings.addPreference(createUserkeyPreference(c));
|
||||
subsettings.addPreference(createUserCertificatePreference(c));
|
||||
subsettings.addPreference(createCaCertificatePreference(c));
|
||||
subsettings.addPreference(createDomainSufficesPreference(c));
|
||||
}
|
||||
|
||||
//@Override
|
||||
public String validate(Context c) {
|
||||
String result = super.validate(c);
|
||||
if (result != null) {
|
||||
return result;
|
||||
} else if (mProfile.isCustomized()) {
|
||||
return null;
|
||||
} else if (Util.isNullOrEmpty(mUserkey.getValue())) {
|
||||
return c.getString(R.string.vpn_error_userkey_not_selected);
|
||||
} else if (Util.isNullOrEmpty(mUserCertificate.getValue())) {
|
||||
return c.getString(R.string.vpn_error_user_certificate_not_selected);
|
||||
} else if (Util.isNullOrEmpty(mCaCertificate.getValue())) {
|
||||
return c.getString(R.string.vpn_error_ca_certificate_not_selected);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Preference createUserCertificatePreference(Context c) {
|
||||
mUserCertificate = createListPreference(c,
|
||||
R.string.vpn_user_certificate_title,
|
||||
mProfile.getUserCertificate(),
|
||||
Keystore.getInstance().getAllCertificateKeys(),
|
||||
new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(
|
||||
Preference pref, Object newValue) {
|
||||
mProfile.setUserCertificate((String) newValue);
|
||||
return onPreferenceChangeCommon(pref, newValue);
|
||||
}
|
||||
});
|
||||
return mUserCertificate;
|
||||
}
|
||||
|
||||
private Preference createCaCertificatePreference(Context c) {
|
||||
mCaCertificate = createListPreference(c,
|
||||
R.string.vpn_ca_certificate_title,
|
||||
mProfile.getCaCertificate(),
|
||||
Keystore.getInstance().getAllCertificateKeys(),
|
||||
new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(
|
||||
Preference pref, Object newValue) {
|
||||
mProfile.setCaCertificate((String) newValue);
|
||||
return onPreferenceChangeCommon(pref, newValue);
|
||||
}
|
||||
});
|
||||
return mCaCertificate;
|
||||
}
|
||||
|
||||
private Preference createUserkeyPreference(Context c) {
|
||||
mUserkey = createListPreference(c,
|
||||
R.string.vpn_userkey_title,
|
||||
mProfile.getUserkey(),
|
||||
Keystore.getInstance().getAllUserkeyKeys(),
|
||||
new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(
|
||||
Preference pref, Object newValue) {
|
||||
mProfile.setUserkey((String) newValue);
|
||||
return onPreferenceChangeCommon(pref, newValue);
|
||||
}
|
||||
});
|
||||
return mUserkey;
|
||||
}
|
||||
|
||||
private ListPreference createListPreference(Context c, int titleResId,
|
||||
String text, String[] keys,
|
||||
Preference.OnPreferenceChangeListener listener) {
|
||||
ListPreference pref = new ListPreference(c);
|
||||
pref.setTitle(titleResId);
|
||||
pref.setDialogTitle(titleResId);
|
||||
pref.setPersistent(true);
|
||||
pref.setEntries(keys);
|
||||
pref.setEntryValues(keys);
|
||||
pref.setValue(text);
|
||||
pref.setSummary(checkNull(text, c));
|
||||
pref.setOnPreferenceChangeListener(listener);
|
||||
return pref;
|
||||
}
|
||||
|
||||
private boolean onPreferenceChangeCommon(Preference pref, Object newValue) {
|
||||
pref.setSummary(checkNull(newValue.toString(), pref.getContext()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user