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:
Irfan Sheriff
2013-01-11 14:12:54 -08:00
parent 61298b3fda
commit de11bcec8d
2 changed files with 25 additions and 90 deletions

View File

@@ -63,10 +63,6 @@ import java.util.Iterator;
*/ */
public class WifiConfigController implements TextWatcher, public class WifiConfigController implements TextWatcher,
View.OnClickListener, AdapterView.OnItemSelectedListener { 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 WifiConfigUiBase mConfigUi;
private final View mView; private final View mView;
private final AccessPoint mAccessPoint; private final AccessPoint mAccessPoint;
@@ -79,6 +75,8 @@ public class WifiConfigController implements TextWatcher,
private int mAccessPointSecurity; private int mAccessPointSecurity;
private TextView mPasswordView; private TextView mPasswordView;
private String unspecifiedCert = "unspecified";
private Spinner mSecuritySpinner; private Spinner mSecuritySpinner;
private Spinner mEapMethodSpinner; private Spinner mEapMethodSpinner;
private Spinner mEapCaCertSpinner; private Spinner mEapCaCertSpinner;
@@ -124,22 +122,6 @@ public class WifiConfigController implements TextWatcher,
private final Handler mTextViewChangedHandler; 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( public WifiConfigController(
WifiConfigUiBase parent, View view, AccessPoint accessPoint, boolean edit) { WifiConfigUiBase parent, View view, AccessPoint accessPoint, boolean edit) {
mConfigUi = parent; mConfigUi = parent;
@@ -155,6 +137,7 @@ public class WifiConfigController implements TextWatcher,
final Context context = mConfigUi.getContext(); final Context context = mConfigUi.getContext();
final Resources resources = context.getResources(); final Resources resources = context.getResources();
unspecifiedCert = context.getString(R.string.wifi_unspecified);
mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings); mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings);
mIpSettingsSpinner.setOnItemSelectedListener(this); mIpSettingsSpinner.setOnItemSelectedListener(this);
mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings); mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings);
@@ -356,29 +339,18 @@ public class WifiConfigController implements TextWatcher,
case AccessPoint.SECURITY_EAP: case AccessPoint.SECURITY_EAP:
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP); config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X); config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
config.eap.setValue((String) mEapMethodSpinner.getSelectedItem()); config.enterpriseConfig.setEapMethod(mEapMethodSpinner.getSelectedItemPosition());
config.enterpriseConfig.setPhase2Method(mPhase2Spinner.getSelectedItemPosition());
config.phase2.setValue((mPhase2Spinner.getSelectedItemPosition() == 0) ? "" : String caCert = (String) mEapCaCertSpinner.getSelectedItem();
PHASE2_PREFIX + mPhase2Spinner.getSelectedItem()); if (caCert.equals(unspecifiedCert)) caCert = "";
config.ca_cert.setValue((mEapCaCertSpinner.getSelectedItemPosition() == 0) ? "" : String clientCert = (String) mEapUserCertSpinner.getSelectedItem();
KEYSTORE_SPACE + Credentials.CA_CERTIFICATE + if (clientCert.equals(unspecifiedCert)) clientCert = "";
(String) mEapCaCertSpinner.getSelectedItem()); config.enterpriseConfig.setCaCertificate(caCert);
config.client_cert.setValue((mEapUserCertSpinner.getSelectedItemPosition() == 0) ? config.enterpriseConfig.setClientCertificate(clientCert);
"" : KEYSTORE_SPACE + Credentials.USER_CERTIFICATE + config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
(String) mEapUserCertSpinner.getSelectedItem()); config.enterpriseConfig.setAnonymousIdentity(
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) ? "" :
mEapAnonymousView.getText().toString()); mEapAnonymousView.getText().toString());
if (mPasswordView.length() != 0) { config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
config.password.setValue(mPasswordView.getText().toString());
}
break; break;
default: default:
@@ -549,21 +521,13 @@ public class WifiConfigController implements TextWatcher,
if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) { if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) {
WifiConfiguration config = mAccessPoint.getConfig(); 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(); setSelection(mEapCaCertSpinner, config.enterpriseConfig.getCaCertificate());
if (phase2Method != null && phase2Method.startsWith(PHASE2_PREFIX)) { setSelection(mEapUserCertSpinner, config.enterpriseConfig.getClientCertificate());
setSelection(mPhase2Spinner, phase2Method.substring(PHASE2_PREFIX.length())); mEapIdentityView.setText(config.enterpriseConfig.getIdentity());
} else { mEapAnonymousView.setText(config.enterpriseConfig.getAnonymousIdentity());
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());
} }
} }
@@ -675,14 +639,13 @@ public class WifiConfigController implements TextWatcher,
private void loadCertificates(Spinner spinner, String prefix) { private void loadCertificates(Spinner spinner, String prefix) {
final Context context = mConfigUi.getContext(); final Context context = mConfigUi.getContext();
final String unspecified = context.getString(R.string.wifi_unspecified);
String[] certs = KeyStore.getInstance().saw(prefix); String[] certs = KeyStore.getInstance().saw(prefix);
if (certs == null || certs.length == 0) { if (certs == null || certs.length == 0) {
certs = new String[] {unspecified}; certs = new String[] {unspecifiedCert};
} else { } else {
final String[] array = new String[certs.length + 1]; final String[] array = new String[certs.length + 1];
array[0] = unspecified; array[0] = unspecifiedCert;
System.arraycopy(certs, 0, array, 1, certs.length); System.arraycopy(certs, 0, array, 1, certs.length);
certs = array; certs = array;
} }
@@ -693,12 +656,6 @@ public class WifiConfigController implements TextWatcher,
spinner.setAdapter(adapter); 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) { private void setSelection(Spinner spinner, String value) {
if (value != null) { if (value != null) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@@ -46,7 +46,6 @@ import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.security.Credentials; import android.security.Credentials;
import android.security.KeyStore;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
@@ -135,8 +134,6 @@ public class WifiSettings extends SettingsPreferenceFragment
private AtomicBoolean mConnected = new AtomicBoolean(false); private AtomicBoolean mConnected = new AtomicBoolean(false);
private int mKeyStoreNetworkId = INVALID_NETWORK_ID;
private WifiDialog mDialog; private WifiDialog mDialog;
private TextView mEmptyView; private TextView mEmptyView;
@@ -412,12 +409,6 @@ public class WifiSettings extends SettingsPreferenceFragment
} }
getActivity().registerReceiver(mReceiver, mFilter); getActivity().registerReceiver(mReceiver, mFilter);
if (mKeyStoreNetworkId != INVALID_NETWORK_ID &&
KeyStore.getInstance().state() == KeyStore.State.UNLOCKED) {
mWifiManager.connect(mKeyStoreNetworkId, mConnectListener);
}
mKeyStoreNetworkId = INVALID_NETWORK_ID;
updateAccessPoints(); updateAccessPoints();
} }
@@ -560,10 +551,8 @@ public class WifiSettings extends SettingsPreferenceFragment
switch (item.getItemId()) { switch (item.getItemId()) {
case MENU_ID_CONNECT: { case MENU_ID_CONNECT: {
if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) { if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
if (!requireKeyStore(mSelectedAccessPoint.getConfig())) { mWifiManager.connect(mSelectedAccessPoint.networkId,
mWifiManager.connect(mSelectedAccessPoint.networkId, mConnectListener);
mConnectListener);
}
} else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) { } else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
/** Bypass dialog for unsecured networks */ /** Bypass dialog for unsecured networks */
mSelectedAccessPoint.generateOpenNetworkConfig(); mSelectedAccessPoint.generateOpenNetworkConfig();
@@ -700,16 +689,6 @@ public class WifiSettings extends SettingsPreferenceFragment
&& telephonyManager.getSimState() != TelephonyManager.SIM_STATE_UNKNOWN; && 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 * Shows the latest access points available with supplimental information like
* the strength of network and the security for it. * the strength of network and the security for it.
@@ -971,7 +950,6 @@ public class WifiSettings extends SettingsPreferenceFragment
if (config == null) { if (config == null) {
if (mSelectedAccessPoint != null if (mSelectedAccessPoint != null
&& !requireKeyStore(mSelectedAccessPoint.getConfig())
&& mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) { && mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
mWifiManager.connect(mSelectedAccessPoint.networkId, mWifiManager.connect(mSelectedAccessPoint.networkId,
mConnectListener); mConnectListener);
@@ -981,7 +959,7 @@ public class WifiSettings extends SettingsPreferenceFragment
mWifiManager.save(config, mSaveListener); mWifiManager.save(config, mSaveListener);
} }
} else { } else {
if (configController.isEdit() || requireKeyStore(config)) { if (configController.isEdit()) {
mWifiManager.save(config, mSaveListener); mWifiManager.save(config, mSaveListener);
} else { } else {
mWifiManager.connect(config, mConnectListener); mWifiManager.connect(config, mConnectListener);