Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe9e41e6 authored by Benedict Wong's avatar Benedict Wong Committed by Automerger Merge Worker
Browse files

Merge "Hide IKEv2 VPN options if not supported" am: 806523a7 am: 63a14475...

Merge "Hide IKEv2 VPN options if not supported" am: 806523a7 am: 63a14475 am: 6f7a25ce am: f594281f

Change-Id: I861c3243378fc9780a1ecd6f051d04e262db3f96
parents bc089d41 f594281f
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.internal.net.VpnProfile.isLegacyType;

import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.net.Proxy;
import android.net.ProxyInfo;
import android.os.Bundle;
@@ -43,6 +44,9 @@ import com.android.internal.net.VpnProfile;
import com.android.settings.R;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Dialog showing information about a VPN configuration. The dialog
@@ -129,6 +133,7 @@ class ConfigDialog extends AlertDialog implements TextWatcher,

        // Second, copy values from the profile.
        mName.setText(mProfile.name);
        setTypesByFeature(mType);
        mType.setSelection(mProfile.type);
        mServer.setText(mProfile.server);
        if (mProfile.saveLogin) {
@@ -487,6 +492,25 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
        return true;
    }

    private void setTypesByFeature(Spinner typeSpinner) {
        String[] types = getContext().getResources().getStringArray(R.array.vpn_types);
        if (!getContext().getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_IPSEC_TUNNELS)) {
            final List<String> typesList = new ArrayList<>(Arrays.asList(types));

            // This must be removed from back to front in order to ensure index consistency
            typesList.remove(VpnProfile.TYPE_IKEV2_IPSEC_RSA);
            typesList.remove(VpnProfile.TYPE_IKEV2_IPSEC_PSK);
            typesList.remove(VpnProfile.TYPE_IKEV2_IPSEC_USER_PASS);

            types = typesList.toArray(new String[0]);
        }
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                getContext(), android.R.layout.simple_spinner_item, types);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        typeSpinner.setAdapter(adapter);
    }

    private void loadCertificates(Spinner spinner, String prefix, int firstId, String selected) {
        Context context = getContext();
        String first = (firstId == 0) ? "" : context.getString(firstId);