Update enterprise API usage
Also, remove the unnecessary keystore lock/unlock checks since these are now controlled at lockscreen Change-Id: If65c4029d4cf2b8377fbc3512c9f691572125995
This commit is contained in:
@@ -63,10 +63,6 @@ import java.util.Iterator;
|
||||
*/
|
||||
public class WifiConfigController implements TextWatcher,
|
||||
View.OnClickListener, AdapterView.OnItemSelectedListener {
|
||||
private static final String KEYSTORE_SPACE = WifiConfiguration.KEYSTORE_URI;
|
||||
|
||||
private static final String PHASE2_PREFIX = "auth=";
|
||||
|
||||
private final WifiConfigUiBase mConfigUi;
|
||||
private final View mView;
|
||||
private final AccessPoint mAccessPoint;
|
||||
@@ -79,6 +75,8 @@ public class WifiConfigController implements TextWatcher,
|
||||
private int mAccessPointSecurity;
|
||||
private TextView mPasswordView;
|
||||
|
||||
private String unspecifiedCert = "unspecified";
|
||||
|
||||
private Spinner mSecuritySpinner;
|
||||
private Spinner mEapMethodSpinner;
|
||||
private Spinner mEapCaCertSpinner;
|
||||
@@ -124,22 +122,6 @@ public class WifiConfigController implements TextWatcher,
|
||||
|
||||
private final Handler mTextViewChangedHandler;
|
||||
|
||||
static boolean requireKeyStore(WifiConfiguration config) {
|
||||
if (config == null) {
|
||||
return false;
|
||||
}
|
||||
if (!TextUtils.isEmpty(config.key_id.value())) {
|
||||
return true;
|
||||
}
|
||||
String values[] = { config.ca_cert.value(), config.client_cert.value() };
|
||||
for (String value : values) {
|
||||
if (value != null && value.startsWith(KEYSTORE_SPACE)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public WifiConfigController(
|
||||
WifiConfigUiBase parent, View view, AccessPoint accessPoint, boolean edit) {
|
||||
mConfigUi = parent;
|
||||
@@ -155,6 +137,7 @@ public class WifiConfigController implements TextWatcher,
|
||||
final Context context = mConfigUi.getContext();
|
||||
final Resources resources = context.getResources();
|
||||
|
||||
unspecifiedCert = context.getString(R.string.wifi_unspecified);
|
||||
mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings);
|
||||
mIpSettingsSpinner.setOnItemSelectedListener(this);
|
||||
mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings);
|
||||
@@ -356,29 +339,18 @@ public class WifiConfigController implements TextWatcher,
|
||||
case AccessPoint.SECURITY_EAP:
|
||||
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
|
||||
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
|
||||
config.eap.setValue((String) mEapMethodSpinner.getSelectedItem());
|
||||
|
||||
config.phase2.setValue((mPhase2Spinner.getSelectedItemPosition() == 0) ? "" :
|
||||
PHASE2_PREFIX + mPhase2Spinner.getSelectedItem());
|
||||
config.ca_cert.setValue((mEapCaCertSpinner.getSelectedItemPosition() == 0) ? "" :
|
||||
KEYSTORE_SPACE + Credentials.CA_CERTIFICATE +
|
||||
(String) mEapCaCertSpinner.getSelectedItem());
|
||||
config.client_cert.setValue((mEapUserCertSpinner.getSelectedItemPosition() == 0) ?
|
||||
"" : KEYSTORE_SPACE + Credentials.USER_CERTIFICATE +
|
||||
(String) mEapUserCertSpinner.getSelectedItem());
|
||||
final boolean isEmptyKeyId = (mEapUserCertSpinner.getSelectedItemPosition() == 0);
|
||||
config.key_id.setValue(isEmptyKeyId ? "" : Credentials.USER_PRIVATE_KEY +
|
||||
(String) mEapUserCertSpinner.getSelectedItem());
|
||||
config.engine.setValue(isEmptyKeyId ? WifiConfiguration.ENGINE_DISABLE :
|
||||
WifiConfiguration.ENGINE_ENABLE);
|
||||
config.engine_id.setValue(isEmptyKeyId ? "" : WifiConfiguration.KEYSTORE_ENGINE_ID);
|
||||
config.identity.setValue((mEapIdentityView.length() == 0) ? "" :
|
||||
mEapIdentityView.getText().toString());
|
||||
config.anonymous_identity.setValue((mEapAnonymousView.length() == 0) ? "" :
|
||||
config.enterpriseConfig.setEapMethod(mEapMethodSpinner.getSelectedItemPosition());
|
||||
config.enterpriseConfig.setPhase2Method(mPhase2Spinner.getSelectedItemPosition());
|
||||
String caCert = (String) mEapCaCertSpinner.getSelectedItem();
|
||||
if (caCert.equals(unspecifiedCert)) caCert = "";
|
||||
String clientCert = (String) mEapUserCertSpinner.getSelectedItem();
|
||||
if (clientCert.equals(unspecifiedCert)) clientCert = "";
|
||||
config.enterpriseConfig.setCaCertificate(caCert);
|
||||
config.enterpriseConfig.setClientCertificate(clientCert);
|
||||
config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
|
||||
config.enterpriseConfig.setAnonymousIdentity(
|
||||
mEapAnonymousView.getText().toString());
|
||||
if (mPasswordView.length() != 0) {
|
||||
config.password.setValue(mPasswordView.getText().toString());
|
||||
}
|
||||
config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -549,21 +521,13 @@ public class WifiConfigController implements TextWatcher,
|
||||
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
WifiConfiguration config = mAccessPoint.getConfig();
|
||||
setSelection(mEapMethodSpinner, config.eap.value());
|
||||
mEapMethodSpinner.setSelection(config.enterpriseConfig.getEapMethod());
|
||||
mPhase2Spinner.setSelection(config.enterpriseConfig.getPhase2Method());
|
||||
|
||||
final String phase2Method = config.phase2.value();
|
||||
if (phase2Method != null && phase2Method.startsWith(PHASE2_PREFIX)) {
|
||||
setSelection(mPhase2Spinner, phase2Method.substring(PHASE2_PREFIX.length()));
|
||||
} else {
|
||||
setSelection(mPhase2Spinner, phase2Method);
|
||||
}
|
||||
|
||||
setCertificate(mEapCaCertSpinner, KEYSTORE_SPACE + Credentials.CA_CERTIFICATE,
|
||||
config.ca_cert.value());
|
||||
setCertificate(mEapUserCertSpinner, Credentials.USER_PRIVATE_KEY,
|
||||
config.key_id.value());
|
||||
mEapIdentityView.setText(config.identity.value());
|
||||
mEapAnonymousView.setText(config.anonymous_identity.value());
|
||||
setSelection(mEapCaCertSpinner, config.enterpriseConfig.getCaCertificate());
|
||||
setSelection(mEapUserCertSpinner, config.enterpriseConfig.getClientCertificate());
|
||||
mEapIdentityView.setText(config.enterpriseConfig.getIdentity());
|
||||
mEapAnonymousView.setText(config.enterpriseConfig.getAnonymousIdentity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,14 +639,13 @@ public class WifiConfigController implements TextWatcher,
|
||||
|
||||
private void loadCertificates(Spinner spinner, String prefix) {
|
||||
final Context context = mConfigUi.getContext();
|
||||
final String unspecified = context.getString(R.string.wifi_unspecified);
|
||||
|
||||
String[] certs = KeyStore.getInstance().saw(prefix);
|
||||
if (certs == null || certs.length == 0) {
|
||||
certs = new String[] {unspecified};
|
||||
certs = new String[] {unspecifiedCert};
|
||||
} else {
|
||||
final String[] array = new String[certs.length + 1];
|
||||
array[0] = unspecified;
|
||||
array[0] = unspecifiedCert;
|
||||
System.arraycopy(certs, 0, array, 1, certs.length);
|
||||
certs = array;
|
||||
}
|
||||
@@ -693,12 +656,6 @@ public class WifiConfigController implements TextWatcher,
|
||||
spinner.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void setCertificate(Spinner spinner, String prefix, String cert) {
|
||||
if (cert != null && cert.startsWith(prefix)) {
|
||||
setSelection(spinner, cert.substring(prefix.length()));
|
||||
}
|
||||
}
|
||||
|
||||
private void setSelection(Spinner spinner, String value) {
|
||||
if (value != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@@ -46,7 +46,6 @@ import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.security.Credentials;
|
||||
import android.security.KeyStore;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
@@ -135,8 +134,6 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
|
||||
private AtomicBoolean mConnected = new AtomicBoolean(false);
|
||||
|
||||
private int mKeyStoreNetworkId = INVALID_NETWORK_ID;
|
||||
|
||||
private WifiDialog mDialog;
|
||||
|
||||
private TextView mEmptyView;
|
||||
@@ -412,12 +409,6 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
getActivity().registerReceiver(mReceiver, mFilter);
|
||||
if (mKeyStoreNetworkId != INVALID_NETWORK_ID &&
|
||||
KeyStore.getInstance().state() == KeyStore.State.UNLOCKED) {
|
||||
mWifiManager.connect(mKeyStoreNetworkId, mConnectListener);
|
||||
}
|
||||
mKeyStoreNetworkId = INVALID_NETWORK_ID;
|
||||
|
||||
updateAccessPoints();
|
||||
}
|
||||
|
||||
@@ -560,10 +551,8 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
switch (item.getItemId()) {
|
||||
case MENU_ID_CONNECT: {
|
||||
if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
if (!requireKeyStore(mSelectedAccessPoint.getConfig())) {
|
||||
mWifiManager.connect(mSelectedAccessPoint.networkId,
|
||||
mConnectListener);
|
||||
}
|
||||
} else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
|
||||
/** Bypass dialog for unsecured networks */
|
||||
mSelectedAccessPoint.generateOpenNetworkConfig();
|
||||
@@ -700,16 +689,6 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
&& telephonyManager.getSimState() != TelephonyManager.SIM_STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
private boolean requireKeyStore(WifiConfiguration config) {
|
||||
if (WifiConfigController.requireKeyStore(config) &&
|
||||
KeyStore.getInstance().state() != KeyStore.State.UNLOCKED) {
|
||||
mKeyStoreNetworkId = config.networkId;
|
||||
Credentials.getInstance().unlock(getActivity());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the latest access points available with supplimental information like
|
||||
* the strength of network and the security for it.
|
||||
@@ -971,7 +950,6 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
|
||||
if (config == null) {
|
||||
if (mSelectedAccessPoint != null
|
||||
&& !requireKeyStore(mSelectedAccessPoint.getConfig())
|
||||
&& mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
mWifiManager.connect(mSelectedAccessPoint.networkId,
|
||||
mConnectListener);
|
||||
@@ -981,7 +959,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
mWifiManager.save(config, mSaveListener);
|
||||
}
|
||||
} else {
|
||||
if (configController.isEdit() || requireKeyStore(config)) {
|
||||
if (configController.isEdit()) {
|
||||
mWifiManager.save(config, mSaveListener);
|
||||
} else {
|
||||
mWifiManager.connect(config, mConnectListener);
|
||||
|
Reference in New Issue
Block a user