use of com.android.internal.net.VpnProfile in project android_packages_apps_Settings by DirtyUnicorns.
the class ConfigDialog method getProfile.
VpnProfile getProfile() {
// First, save common fields.
VpnProfile profile = new VpnProfile(mProfile.key);
profile.name = mName.getText().toString();
profile.type = mType.getSelectedItemPosition();
profile.server = mServer.getText().toString().trim();
profile.username = mUsername.getText().toString();
profile.password = mPassword.getText().toString();
profile.searchDomains = mSearchDomains.getText().toString().trim();
profile.dnsServers = mDnsServers.getText().toString().trim();
profile.routes = mRoutes.getText().toString().trim();
// Then, save type-specific fields.
switch(profile.type) {
case VpnProfile.TYPE_PPTP:
profile.mppe = mMppe.isChecked();
break;
case VpnProfile.TYPE_L2TP_IPSEC_PSK:
profile.l2tpSecret = mL2tpSecret.getText().toString();
// fall through
case VpnProfile.TYPE_IPSEC_XAUTH_PSK:
profile.ipsecIdentifier = mIpsecIdentifier.getText().toString();
profile.ipsecSecret = mIpsecSecret.getText().toString();
break;
case VpnProfile.TYPE_L2TP_IPSEC_RSA:
profile.l2tpSecret = mL2tpSecret.getText().toString();
// fall through
case VpnProfile.TYPE_IPSEC_XAUTH_RSA:
if (mIpsecUserCert.getSelectedItemPosition() != 0) {
profile.ipsecUserCert = (String) mIpsecUserCert.getSelectedItem();
}
// fall through
case VpnProfile.TYPE_IPSEC_HYBRID_RSA:
if (mIpsecCaCert.getSelectedItemPosition() != 0) {
profile.ipsecCaCert = (String) mIpsecCaCert.getSelectedItem();
}
if (mIpsecServerCert.getSelectedItemPosition() != 0) {
profile.ipsecServerCert = (String) mIpsecServerCert.getSelectedItem();
}
break;
}
final boolean hasLogin = !profile.username.isEmpty() || !profile.password.isEmpty();
profile.saveLogin = mSaveLogin.isChecked() || (mEditing && hasLogin);
return profile;
}
use of com.android.internal.net.VpnProfile in project android_packages_apps_Settings by DirtyUnicorns.
the class ConfigDialogFragment method onClick.
@Override
public void onClick(DialogInterface dialogInterface, int button) {
ConfigDialog dialog = (ConfigDialog) getDialog();
VpnProfile profile = dialog.getProfile();
if (button == DialogInterface.BUTTON_POSITIVE) {
// Possibly throw up a dialog to explain lockdown VPN.
final boolean shouldLockdown = dialog.isVpnAlwaysOn();
final boolean shouldConnect = shouldLockdown || !dialog.isEditing();
final boolean wasLockdown = VpnUtils.isAnyLockdownActive(mContext);
try {
final boolean replace = VpnUtils.isVpnActive(mContext);
if (shouldConnect && !isConnected(profile) && ConfirmLockdownFragment.shouldShow(replace, wasLockdown, shouldLockdown)) {
final Bundle opts = new Bundle();
opts.putParcelable(ARG_PROFILE, profile);
ConfirmLockdownFragment.show(this, replace, /* alwaysOn */
shouldLockdown, /* from */
wasLockdown, /* to */
shouldLockdown, opts);
} else if (shouldConnect) {
connect(profile, shouldLockdown);
} else {
save(profile, false);
}
} catch (RemoteException e) {
Log.w(TAG, "Failed to check active VPN state. Skipping.", e);
}
} else if (button == DialogInterface.BUTTON_NEUTRAL) {
// Disable profile if connected
if (!disconnect(profile)) {
Log.e(TAG, "Failed to disconnect VPN. Leaving profile in keystore.");
return;
}
// Delete from KeyStore
KeyStore keyStore = KeyStore.getInstance();
keyStore.delete(Credentials.VPN + profile.key, KeyStore.UID_SELF);
updateLockdownVpn(false, profile);
}
dismiss();
}
use of com.android.internal.net.VpnProfile in project android_packages_apps_Settings by crdroidandroid.
the class PreferenceListTest method testConnectedLegacyVpnShownExactlyOnce.
@SmallTest
public void testConnectedLegacyVpnShownExactlyOnce() {
final VpnProfile vpnProfile = new VpnProfile("test-no-duplicates");
final LegacyVpnInfo connectedLegacyVpn = new LegacyVpnInfo();
connectedLegacyVpn.key = new String(vpnProfile.key);
final VpnSettings.UpdatePreferences updater = new VpnSettings.UpdatePreferences(mSettings);
updater.legacyVpns(/* vpnProfiles */
Collections.<VpnProfile>singletonList(vpnProfile), /* connectedLegacyVpns */
new HashMap<String, LegacyVpnInfo>() {
{
put(connectedLegacyVpn.key, connectedLegacyVpn);
}
}, /* lockdownVpnKey */
null);
updater.run();
final ArgumentMatcher<VpnProfile> equalsFake = new ArgumentMatcher<VpnProfile>() {
@Override
public boolean matchesObject(final Object arg) {
if (arg == vpnProfile)
return true;
if (arg == null)
return false;
return TextUtils.equals(((VpnProfile) arg).key, vpnProfile.key);
}
};
// The VPN profile should have been used to create a preference and set up at laest once
// with update=true to fill in all the fields.
verify(mSettings, atLeast(1)).findOrCreatePreference(argThat(equalsFake), eq(true));
// ...But no other VPN profile key should ever have been passed in.
verify(mSettings, never()).findOrCreatePreference(not(argThat(equalsFake)), anyBoolean());
// And so we should still have exactly 1 preference created.
assertEquals(1, mLegacyMocks.size());
assertEquals(0, mAppMocks.size());
}
use of com.android.internal.net.VpnProfile in project android_packages_apps_Settings by crdroidandroid.
the class VpnTests method testIpsecXauthRsaConnection.
/**
* Test IPSec Xauth RSA VPN connection
*/
@LargeTest
public void testIpsecXauthRsaConnection() throws Exception {
mPreviousIpAddress = getIpAddress();
VpnInfo curVpnInfo = mVpnInfoPool.get(VpnProfile.TYPE_IPSEC_XAUTH_RSA);
VpnProfile vpnProfile = curVpnInfo.getVpnProfile();
if (DEBUG) {
printVpnProfile(vpnProfile);
}
String certFile = curVpnInfo.getCertificateFile();
String password = curVpnInfo.getPassword();
installCertificatesFromFile(vpnProfile, certFile, password);
connect(vpnProfile);
validateVpnConnection(vpnProfile);
}
use of com.android.internal.net.VpnProfile in project android_packages_apps_Settings by crdroidandroid.
the class VpnTests method testL2tpIpsecPskConnection.
/**
* Test L2TP/IPSec PSK VPN connection
*/
@LargeTest
public void testL2tpIpsecPskConnection() throws Exception {
mPreviousIpAddress = getIpAddress();
VpnInfo curVpnInfo = mVpnInfoPool.get(VpnProfile.TYPE_L2TP_IPSEC_PSK);
VpnProfile vpnProfile = curVpnInfo.getVpnProfile();
connect(vpnProfile);
validateVpnConnection(vpnProfile);
}
Aggregations