diff --git a/src/com/android/settings/vpn2/ConfigDialog.java b/src/com/android/settings/vpn2/ConfigDialog.java index 4e6cc893b8e..12d91ec2042 100644 --- a/src/com/android/settings/vpn2/ConfigDialog.java +++ b/src/com/android/settings/vpn2/ConfigDialog.java @@ -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 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 adapter = new ArrayAdapter( + 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);