import android.widget.TextView;
class VpnDialog extends AlertDialog implements TextWatcher, OnItemSelectedListener {
- private static final String DUMMY = "\r\r\r\r";
+ private static final String DUMMY = "\r";
private static String getDummy(String secret) {
return secret.isEmpty() ? "" : DUMMY;
}
- private static String getSecret(TextView dummy) {
- String secret = dummy.getText().toString();
- return DUMMY.equals(secret) ? "" : secret;
+ private static String getSecret(String oldSecret, TextView view) {
+ String newSecret = view.getText().toString();
+ return DUMMY.equals(newSecret) ? oldSecret : newSecret;
}
private final KeyStore mKeyStore = KeyStore.getInstance();
mIpsecSecret.setText(getDummy(mProfile.ipsecSecret));
loadCertificates(mIpsecUserCert, Credentials.USER_CERTIFICATE,
0, mProfile.ipsecUserCert);
- loadCertificates(mIpsecUserCert, Credentials.CA_CERTIFICATE,
+ loadCertificates(mIpsecCaCert, Credentials.CA_CERTIFICATE,
R.string.vpn_no_ca_cert, mProfile.ipsecCaCert);
mSaveLogin.setChecked(mProfile.saveLogin);
if (parent == mType) {
changeType(position);
}
- getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(false));
+ getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(mEditing));
}
@Override
private void loadCertificates(Spinner spinner, String prefix, int firstId, String selected) {
Context context = getContext();
String first = (firstId == 0) ? "" : context.getString(firstId);
- String[] certs = mKeyStore.saw(prefix);
+ String[] certificates = mKeyStore.saw(prefix);
- if (certs == null || certs.length == 0) {
- certs = new String[] {first};
+ if (certificates == null || certificates.length == 0) {
+ certificates = new String[] {first};
} else {
- String[] array = new String[certs.length + 1];
+ String[] array = new String[certificates.length + 1];
array[0] = first;
- System.arraycopy(certs, 0, array, 1, certs.length);
- certs = array;
+ System.arraycopy(certificates, 0, array, 1, certificates.length);
+ certificates = array;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
- context, android.R.layout.simple_spinner_item, certs);
+ context, android.R.layout.simple_spinner_item, certificates);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
- for (int i = 1; i < certs.length; ++i) {
- if (certs[i].equals(selected)) {
+ for (int i = 1; i < certificates.length; ++i) {
+ if (certificates[i].equals(selected)) {
spinner.setSelection(i);
break;
}
profile.type = mType.getSelectedItemPosition();
profile.server = mServer.getText().toString().trim();
profile.username = mUsername.getText().toString();
- profile.password = getSecret(mPassword);
+ profile.password = getSecret(mProfile.password, mPassword);
profile.domains = mDomains.getText().toString().trim();
profile.routes = mRoutes.getText().toString().trim();
break;
case VpnProfile.TYPE_L2TP_IPSEC_PSK:
- profile.l2tpSecret = getSecret(mL2tpSecret);
+ profile.l2tpSecret = getSecret(mProfile.l2tpSecret, mL2tpSecret);
// fall through
case VpnProfile.TYPE_IPSEC_XAUTH_PSK:
- profile.ipsecSecret = getSecret(mIpsecSecret);
+ profile.ipsecSecret = getSecret(mProfile.ipsecSecret, mIpsecSecret);
break;
case VpnProfile.TYPE_L2TP_IPSEC_RSA:
- profile.l2tpSecret = getSecret(mL2tpSecret);
+ profile.l2tpSecret = getSecret(mProfile.l2tpSecret, mL2tpSecret);
// fall through
case VpnProfile.TYPE_IPSEC_XAUTH_RSA:
if (mIpsecCaCert.getSelectedItemPosition() != 0) {
import android.content.Context;
import android.content.DialogInterface;
+import android.net.IConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.os.ServiceManager;
import android.preference.Preference;
import android.preference.PreferenceGroup;
import android.security.Credentials;
private HashMap<String, VpnPreference> mPreferences;
private VpnDialog mDialog;
+
+ private Handler mUpdater;
+
+ // The key of the profile for the current ContextMenu.
private String mSelectedKey;
- private Handler mHandler;
@Override
public void onCreate(Bundle savedState) {
}
// Start monitoring.
- if (mHandler == null) {
- mHandler = new Handler(this);
+ if (mUpdater == null) {
+ mUpdater = new Handler(this);
}
- mHandler.sendEmptyMessage(0);
+ mUpdater.sendEmptyMessage(0);
// Register for context menu. Hmmm, getListView() is hidden?
registerForContextMenu(getListView());
// If we are not editing, connect!
if (!mDialog.isEditing()) {
- connect(profile.key);
+ connect(profile);
}
}
}
@Override
public boolean handleMessage(Message message) {
- mHandler.removeMessages(0);
+ mUpdater.removeMessages(0);
if (isResumed()) {
- mHandler.sendEmptyMessageDelayed(0, 1000);
+ mUpdater.sendEmptyMessageDelayed(0, 1000);
}
return true;
}
- private void connect(String key) {
+ private static IConnectivityManager getService() {
+ return IConnectivityManager.Stub.asInterface(
+ ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
+ }
+
+ private void connect(VpnProfile profile) {
+ String[] racoon = null;
+ switch (profile.type) {
+ case VpnProfile.TYPE_L2TP_IPSEC_PSK:
+ racoon = new String[] {
+ profile.server, "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,
+ };
+ break;
+ case VpnProfile.TYPE_IPSEC_XAUTH_PSK:
+ break;
+ case VpnProfile.TYPE_IPSEC_XAUTH_RSA:
+ break;
+ case VpnProfile.TYPE_IPSEC_HYBRID_RSA:
+ break;
+ }
+
+ String[] mtpd = null;
+ switch (profile.type) {
+ case VpnProfile.TYPE_PPTP:
+ mtpd = new String[] {
+ "pptp", profile.server, "1723",
+ "name", profile.username, "password", profile.password,
+ "linkname", "vpn", "refuse-eap", "nodefaultroute",
+ "usepeerdns", "idle", "1800", "mtu", "1400", "mru", "1400",
+ (profile.mppe ? "+mppe" : "nomppe"),
+ };
+ break;
+ case VpnProfile.TYPE_L2TP_IPSEC_PSK:
+ case VpnProfile.TYPE_L2TP_IPSEC_RSA:
+ mtpd = new String[] {
+ "l2tp", profile.server, "1701", profile.l2tpSecret,
+ "name", profile.username, "password", profile.password,
+ "linkname", "vpn", "refuse-eap", "nodefaultroute",
+ "usepeerdns", "idle", "1800", "mtu", "1400", "mru", "1400",
+ };
+ break;
+ }
+
+ try {
+// getService().doLegacyVpn(racoon, mtpd);
+ } catch (Exception e) {
+ Log.e(TAG, "connect", e);
+ }
}
private void disconnect(String key) {
@Override
public int compareTo(Preference preference) {
- int result = 1;
+ int result = -1;
if (preference instanceof VpnPreference) {
VpnPreference another = (VpnPreference) preference;