Search in sources :

Example 6 with VpnProfile

use of com.android.internal.net.VpnProfile in project android_packages_apps_Settings by LineageOS.

the class ConfigDialog method updateUiControls.

/**
 * Updates the UI according to the current configuration entered by the user.
 *
 * These include:
 * "Always-on VPN" checkbox
 * Reason for "Always-on VPN" being disabled, when necessary
 * "Save account information" checkbox
 * "Save" and "Connect" buttons
 */
private void updateUiControls() {
    VpnProfile profile = getProfile();
    // Always-on VPN
    if (profile.isValidLockdownProfile()) {
        mAlwaysOnVpn.setEnabled(true);
        mAlwaysOnInvalidReason.setVisibility(View.GONE);
    } else {
        mAlwaysOnVpn.setChecked(false);
        mAlwaysOnVpn.setEnabled(false);
        if (!profile.isTypeValidForLockdown()) {
            mAlwaysOnInvalidReason.setText(R.string.vpn_always_on_invalid_reason_type);
        } else if (!profile.isServerAddressNumeric()) {
            mAlwaysOnInvalidReason.setText(R.string.vpn_always_on_invalid_reason_server);
        } else if (!profile.hasDns()) {
            mAlwaysOnInvalidReason.setText(R.string.vpn_always_on_invalid_reason_no_dns);
        } else if (!profile.areDnsAddressesNumeric()) {
            mAlwaysOnInvalidReason.setText(R.string.vpn_always_on_invalid_reason_dns);
        } else {
            mAlwaysOnInvalidReason.setText(R.string.vpn_always_on_invalid_reason_other);
        }
        mAlwaysOnInvalidReason.setVisibility(View.VISIBLE);
    }
    // Save account information
    if (mAlwaysOnVpn.isChecked()) {
        mSaveLogin.setChecked(true);
        mSaveLogin.setEnabled(false);
    } else {
        mSaveLogin.setChecked(mProfile.saveLogin);
        mSaveLogin.setEnabled(true);
    }
    // Save or Connect button
    getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(mEditing));
}
Also used : VpnProfile(com.android.internal.net.VpnProfile)

Example 7 with VpnProfile

use of com.android.internal.net.VpnProfile in project android_packages_apps_Settings by LineageOS.

the class ConfigDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();
    VpnProfile profile = (VpnProfile) args.getParcelable(ARG_PROFILE);
    boolean editing = args.getBoolean(ARG_EDITING);
    boolean exists = args.getBoolean(ARG_EXISTS);
    final Dialog dialog = new ConfigDialog(getActivity(), this, profile, editing, exists);
    dialog.setOnShowListener(this);
    return dialog;
}
Also used : VpnProfile(com.android.internal.net.VpnProfile) Bundle(android.os.Bundle) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog)

Example 8 with VpnProfile

use of com.android.internal.net.VpnProfile in project android_packages_apps_Settings by LineageOS.

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();
}
Also used : VpnProfile(com.android.internal.net.VpnProfile) Bundle(android.os.Bundle) RemoteException(android.os.RemoteException) KeyStore(android.security.KeyStore)

Example 9 with VpnProfile

use of com.android.internal.net.VpnProfile in project android_packages_apps_Settings by LineageOS.

the class ConfigDialogFragment method onConfirmLockdown.

@Override
public void onConfirmLockdown(Bundle options, boolean isAlwaysOn, boolean isLockdown) {
    VpnProfile profile = (VpnProfile) options.getParcelable(ARG_PROFILE);
    connect(profile, isAlwaysOn);
    dismiss();
}
Also used : VpnProfile(com.android.internal.net.VpnProfile)

Example 10 with VpnProfile

use of com.android.internal.net.VpnProfile in project android_packages_apps_Settings by LineageOS.

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);
}
Also used : VpnProfile(com.android.internal.net.VpnProfile) LegacyVpnInfo(com.android.internal.net.LegacyVpnInfo) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

VpnProfile (com.android.internal.net.VpnProfile)118 LegacyVpnInfo (com.android.internal.net.LegacyVpnInfo)63 LargeTest (android.test.suitebuilder.annotation.LargeTest)42 SmallTest (android.test.suitebuilder.annotation.SmallTest)21 VpnSettings (com.android.settings.vpn2.VpnSettings)18 Context (android.content.Context)14 Bundle (android.os.Bundle)14 RemoteException (android.os.RemoteException)14 WorkerThread (android.annotation.WorkerThread)7 Activity (android.app.Activity)7 Dialog (android.app.Dialog)7 Intent (android.content.Intent)7 PackageInfo (android.content.pm.PackageInfo)7 PackageManager (android.content.pm.PackageManager)7 UserHandle (android.os.UserHandle)7 KeyStore (android.security.KeyStore)7 AlertDialog (android.app.AlertDialog)6 LockdownVpnTracker (com.android.server.net.LockdownVpnTracker)6 ArgumentMatcher (org.mockito.compat.ArgumentMatcher)6 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)5