diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/settings/wifi/WifiConfigController.java | 87 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiSettings.java | 26 |
2 files changed, 25 insertions, 88 deletions
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java index 2598a0e25..bf5f6423d 100644 --- a/src/com/android/settings/wifi/WifiConfigController.java +++ b/src/com/android/settings/wifi/WifiConfigController.java @@ -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()); - - final String phase2Method = config.phase2.value(); - if (phase2Method != null && phase2Method.startsWith(PHASE2_PREFIX)) { - setSelection(mPhase2Spinner, phase2Method.substring(PHASE2_PREFIX.length())); - } else { - setSelection(mPhase2Spinner, phase2Method); - } + mEapMethodSpinner.setSelection(config.enterpriseConfig.getEapMethod()); + mPhase2Spinner.setSelection(config.enterpriseConfig.getPhase2Method()); - 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") diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java index e6079309c..274d49ee0 100644 --- a/src/com/android/settings/wifi/WifiSettings.java +++ b/src/com/android/settings/wifi/WifiSettings.java @@ -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,11 +409,6 @@ public class WifiSettings extends SettingsPreferenceFragment } getActivity().registerReceiver(mReceiver, mFilter); - if (mKeyStoreNetworkId != INVALID_NETWORK_ID && KeyStore.getInstance().isUnlocked()) { - mWifiManager.connect(mKeyStoreNetworkId, mConnectListener); - } - mKeyStoreNetworkId = INVALID_NETWORK_ID; - updateAccessPoints(); } @@ -559,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); - } + mWifiManager.connect(mSelectedAccessPoint.networkId, + mConnectListener); } else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) { /** Bypass dialog for unsecured networks */ mSelectedAccessPoint.generateOpenNetworkConfig(); @@ -699,15 +689,6 @@ public class WifiSettings extends SettingsPreferenceFragment && telephonyManager.getSimState() != TelephonyManager.SIM_STATE_UNKNOWN; } - private boolean requireKeyStore(WifiConfiguration config) { - if (WifiConfigController.requireKeyStore(config) && !KeyStore.getInstance().isUnlocked()) { - 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. @@ -974,7 +955,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); @@ -984,7 +964,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); |