Deprecation of legacy VPN types no longer depends on the Provider Model

Flag

Bug: 204522922
Test: atest -c SettingsUnitTests
Change-Id: If43978a7536e269e2b1130a260fcedb7af6bc363
This commit is contained in:
Jeremy Goldman
2021-11-10 13:54:27 +08:00
parent 5afb04e1b8
commit c525183a40
2 changed files with 23 additions and 31 deletions

View File

@@ -41,7 +41,6 @@ import androidx.appcompat.app.AlertDialog;
import com.android.internal.net.VpnProfile; import com.android.internal.net.VpnProfile;
import com.android.net.module.util.ProxyUtils; import com.android.net.module.util.ProxyUtils;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.utils.AndroidKeystoreAliasLoader; import com.android.settings.utils.AndroidKeystoreAliasLoader;
import java.net.InetAddress; import java.net.InetAddress;
@@ -518,36 +517,31 @@ class ConfigDialog extends AlertDialog implements TextWatcher,
String[] types = getContext().getResources().getStringArray(R.array.vpn_types); String[] types = getContext().getResources().getStringArray(R.array.vpn_types);
mTotalTypes = new ArrayList<>(Arrays.asList(types)); mTotalTypes = new ArrayList<>(Arrays.asList(types));
mAllowedTypes = new ArrayList<>(Arrays.asList(types)); mAllowedTypes = new ArrayList<>(Arrays.asList(types));
// Although FEATURE_IPSEC_TUNNELS should always be present in android S and beyond,
// keep this check here just to be safe.
if (!getContext().getPackageManager().hasSystemFeature( if (!getContext().getPackageManager().hasSystemFeature(
PackageManager.FEATURE_IPSEC_TUNNELS)) { PackageManager.FEATURE_IPSEC_TUNNELS)) {
final List<String> typesList = new ArrayList<>(Arrays.asList(types)); Log.wtf(TAG, "FEATURE_IPSEC_TUNNELS missing from system");
}
// If the vpn is new or is not already a legacy type,
// don't allow the user to set the type to a legacy option.
// This must be removed from back to front in order to ensure index consistency // Set the mProfile.type to TYPE_IKEV2_IPSEC_USER_PASS if the VPN not exist
typesList.remove(VpnProfile.TYPE_IKEV2_IPSEC_RSA); if (!mExists) {
typesList.remove(VpnProfile.TYPE_IKEV2_IPSEC_PSK); mProfile.type = VpnProfile.TYPE_IKEV2_IPSEC_USER_PASS;
typesList.remove(VpnProfile.TYPE_IKEV2_IPSEC_USER_PASS); }
types = typesList.toArray(new String[0]); // Remove all types which are legacy types from the typesList
} else if (Utils.isProviderModelEnabled(getContext())) { if (!VpnProfile.isLegacyType(mProfile.type)) {
// If the provider mode is enabled and the vpn is new or is not already a legacy type, for (int i = mAllowedTypes.size() - 1; i >= 0; i--) {
// don't allow the user to set the type to a legacy option. // This must be removed from back to front in order to ensure index consistency
if (VpnProfile.isLegacyType(i)) {
// Set the mProfile.type to TYPE_IKEV2_IPSEC_USER_PASS if the VPN not exist mAllowedTypes.remove(i);
if (!mExists) {
mProfile.type = VpnProfile.TYPE_IKEV2_IPSEC_USER_PASS;
}
// Remove all types which are legacy types from the typesList
if (!VpnProfile.isLegacyType(mProfile.type)) {
for (int i = mAllowedTypes.size() - 1; i >= 0; i--) {
// This must be removed from back to front in order to ensure index consistency
if (VpnProfile.isLegacyType(i)) {
mAllowedTypes.remove(i);
}
} }
types = mAllowedTypes.toArray(new String[0]);
} }
types = mAllowedTypes.toArray(new String[0]);
} }
final ArrayAdapter<String> adapter = new ArrayAdapter<String>( final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getContext(), android.R.layout.simple_spinner_item, types); getContext(), android.R.layout.simple_spinner_item, types);

View File

@@ -59,7 +59,6 @@ import com.android.internal.net.VpnConfig;
import com.android.internal.net.VpnProfile; import com.android.internal.net.VpnProfile;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment; import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.Utils;
import com.android.settings.widget.GearPreference; import com.android.settings.widget.GearPreference;
import com.android.settings.widget.GearPreference.OnGearClickListener; import com.android.settings.widget.GearPreference.OnGearClickListener;
import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.RestrictedLockUtilsInternal;
@@ -130,12 +129,11 @@ public class VpnSettings extends RestrictedSettingsFragment implements
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
// Although FEATURE_IPSEC_TUNNELS should always be present in android S, // Although FEATURE_IPSEC_TUNNELS should always be present in android S and beyond,
// keep this check here just to be safe. // keep this check here just to be safe.
if (Utils.isProviderModelEnabled(getContext()) if (!getContext().getPackageManager().hasSystemFeature(
&& !getContext().getPackageManager().hasSystemFeature( PackageManager.FEATURE_IPSEC_TUNNELS)) {
PackageManager.FEATURE_IPSEC_TUNNELS)) { Log.wtf(LOG_TAG, "FEATURE_IPSEC_TUNNELS missing from system, cannot create new VPNs");
Log.w(LOG_TAG, "FEATURE_IPSEC_TUNNELS missing from system, cannot create new VPNs");
return; return;
} else { } else {
// By default, we should inflate this menu. // By default, we should inflate this menu.