[WPA3] Filter unsupported networks from Add network spinner

Filter unsupported networks from Add network spinner. Removed entries
from wifi_dialog.xml, adding them dynamically based on device
capabilities. Adding position-to-security table, that decouples spinner
positions from security values.

Bug: 112195778
Test: atest WifiConfigControllerTest + device functional test
Change-Id: I6a814c4d69fbd8d8076db5dbaa5da807b4da4c32
This commit is contained in:
Hai Shalom
2018-11-13 16:37:24 -08:00
parent f611fe8689
commit 1638168336
5 changed files with 165 additions and 50 deletions

View File

@@ -34,6 +34,7 @@ import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiEnterpriseConfig.Eap;
import android.net.wifi.WifiEnterpriseConfig.Phase2;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.UserManager;
import android.security.Credentials;
import android.security.KeyStore;
@@ -119,9 +120,9 @@ public class WifiConfigController implements TextWatcher,
/* Phase2 methods supported by PEAP are limited */
private final ArrayAdapter<String> mPhase2PeapAdapter;
private ArrayAdapter<String> mPhase2PeapAdapter;
/* Full list of phase2 methods */
private final ArrayAdapter<String> mPhase2FullAdapter;
private ArrayAdapter<String> mPhase2FullAdapter;
// e.g. AccessPoint.SECURITY_NONE
@VisibleForTesting
@@ -174,6 +175,9 @@ public class WifiConfigController implements TextWatcher,
private TextView mSsidView;
private Context mContext;
private Integer mSecurityInPosition[];
private final WifiManager mWifiManager;
public WifiConfigController(WifiConfigUiBase parent, View view, AccessPoint accessPoint,
int mode) {
@@ -181,11 +185,31 @@ public class WifiConfigController implements TextWatcher,
mView = view;
mAccessPoint = accessPoint;
mContext = mConfigUi.getContext();
// Init Wi-Fi manager
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
initWifiConfigController(accessPoint, mode);
}
@VisibleForTesting
public WifiConfigController(WifiConfigUiBase parent, View view, AccessPoint accessPoint,
int mode, WifiManager wifiManager) {
mConfigUi = parent;
mView = view;
mAccessPoint = accessPoint;
mContext = mConfigUi.getContext();
mWifiManager = wifiManager;
initWifiConfigController(accessPoint, mode);
}
private void initWifiConfigController(AccessPoint accessPoint, int mode) {
mAccessPointSecurity = (accessPoint == null) ? AccessPoint.SECURITY_NONE :
accessPoint.getSecurity();
mMode = mode;
mContext = mConfigUi.getContext();
final Resources res = mContext.getResources();
mLevels = res.getStringArray(R.array.wifi_signal);
@@ -234,24 +258,10 @@ public class WifiConfigController implements TextWatcher,
mHiddenSettingsSpinner.getSelectedItemPosition() == NOT_HIDDEN_NETWORK
? View.GONE
: View.VISIBLE);
mSecurityInPosition = new Integer[AccessPoint.SECURITY_MAX_VAL];
if (mAccessPoint == null) { // new network
mConfigUi.setTitle(R.string.wifi_add_network);
mSsidView = (TextView) mView.findViewById(R.id.ssid);
mSsidView.addTextChangedListener(this);
mSecuritySpinner = ((Spinner) mView.findViewById(R.id.security));
mSecuritySpinner.setOnItemSelectedListener(this);
mView.findViewById(R.id.type).setVisibility(View.VISIBLE);
showIpConfigFields();
showProxyFields();
mView.findViewById(R.id.wifi_advanced_toggle).setVisibility(View.VISIBLE);
// Hidden option can be changed only when the user adds a network manually.
mView.findViewById(R.id.hidden_settings_field).setVisibility(View.VISIBLE);
((CheckBox) mView.findViewById(R.id.wifi_advanced_togglebox))
.setOnCheckedChangeListener(this);
configureSecuritySpinner();
mConfigUi.setSubmitButton(res.getString(R.string.wifi_save));
} else {
if (!mAccessPoint.isPasspointConfig()) {
@@ -1414,7 +1424,8 @@ public class WifiConfigController implements TextWatcher,
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (parent == mSecuritySpinner) {
mAccessPointSecurity = position;
// Convert menu position to actual Wi-Fi security type
mAccessPointSecurity = mSecurityInPosition[position];
showSecurityFields();
} else if (parent == mEapMethodSpinner || parent == mEapCaCertSpinner) {
showSecurityFields();
@@ -1459,4 +1470,53 @@ public class WifiConfigController implements TextWatcher,
public AccessPoint getAccessPoint() {
return mAccessPoint;
}
private void configureSecuritySpinner() {
mConfigUi.setTitle(R.string.wifi_add_network);
mSsidView = (TextView) mView.findViewById(R.id.ssid);
mSsidView.addTextChangedListener(this);
mSecuritySpinner = ((Spinner) mView.findViewById(R.id.security));
mSecuritySpinner.setOnItemSelectedListener(this);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(mContext,
android.R.layout.simple_spinner_item, android.R.id.text1);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSecuritySpinner.setAdapter(spinnerAdapter);
int idx = 0;
// Populate the Wi-Fi security spinner with the various supported key management types
spinnerAdapter.add(mContext.getString(R.string.wifi_security_none));
mSecurityInPosition[idx++] = AccessPoint.SECURITY_NONE;
if (mWifiManager.isOweSupported()) {
spinnerAdapter.add(mContext.getString(R.string.wifi_security_owe));
mSecurityInPosition[idx++] = AccessPoint.SECURITY_OWE;
}
spinnerAdapter.add(mContext.getString(R.string.wifi_security_wep));
mSecurityInPosition[idx++] = AccessPoint.SECURITY_WEP;
spinnerAdapter.add(mContext.getString(R.string.wifi_security_wpa_wpa2));
mSecurityInPosition[idx++] = AccessPoint.SECURITY_PSK;
if (mWifiManager.isWpa3SaeSupported()) {
spinnerAdapter.add(mContext.getString(R.string.wifi_security_sae));
mSecurityInPosition[idx++] = AccessPoint.SECURITY_SAE;
}
spinnerAdapter.add(mContext.getString(R.string.wifi_security_eap));
mSecurityInPosition[idx++] = AccessPoint.SECURITY_EAP;
if (mWifiManager.isWpa3SuiteBSupported()) {
spinnerAdapter.add(mContext.getString(R.string.wifi_security_eap_suiteb));
mSecurityInPosition[idx++] = AccessPoint.SECURITY_EAP_SUITE_B;
}
spinnerAdapter.notifyDataSetChanged();
mView.findViewById(R.id.type).setVisibility(View.VISIBLE);
showIpConfigFields();
showProxyFields();
mView.findViewById(R.id.wifi_advanced_toggle).setVisibility(View.VISIBLE);
// Hidden option can be changed only when the user adds a network manually.
mView.findViewById(R.id.hidden_settings_field).setVisibility(View.VISIBLE);
((CheckBox) mView.findViewById(R.id.wifi_advanced_togglebox))
.setOnCheckedChangeListener(this);
}
}