diff --git a/src/com/android/settings/wifi/AccessPointDialog.java b/src/com/android/settings/wifi/AccessPointDialog.java index f2443669439..bb5ee6f451c 100644 --- a/src/com/android/settings/wifi/AccessPointDialog.java +++ b/src/com/android/settings/wifi/AccessPointDialog.java @@ -23,8 +23,8 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; -import android.security.CertTool; -import android.security.Keystore; +import android.security.Credentials; +import android.security.KeyStore; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Bundle; @@ -128,13 +128,13 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On private TextView mSecurityText; private Spinner mSecuritySpinner; private Spinner mWepTypeSpinner; - private CertTool mCertTool; + private KeyStore mKeyStore; public AccessPointDialog(Context context, WifiLayer wifiLayer) { super(context); mWifiLayer = wifiLayer; - mCertTool = CertTool.getInstance(); + mKeyStore = KeyStore.getInstance(); } @Override @@ -342,18 +342,22 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On } private String[] getAllCaCertificateKeys() { - return appendEmptyInSelection(mCertTool.getAllCaCertificateKeys()); + return appendEmptyInSelection(mKeyStore.saw(Credentials.CA_CERTIFICATE)); } private String[] getAllUserCertificateKeys() { - return appendEmptyInSelection(mCertTool.getAllUserCertificateKeys()); + return appendEmptyInSelection(mKeyStore.saw(Credentials.USER_CERTIFICATE)); } private String[] appendEmptyInSelection(String[] keys) { - String[] selections = new String[keys.length + 1]; - System.arraycopy(keys, 0, selections, 0, keys.length); - selections[keys.length] = NOT_APPLICABLE; - return selections; + if (keys == null) { + return new String[] {NOT_APPLICABLE}; + } else { + String[] selections = new String[keys.length + 1]; + System.arraycopy(keys, 0, selections, 0, keys.length); + selections[keys.length] = NOT_APPLICABLE; + return selections; + } } private void setEnterpriseFields(View view) { @@ -635,31 +639,22 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On Spinner spinner = mClientCertSpinner; int index = spinner.getSelectedItemPosition(); if (index != (spinner.getCount() - 1)) { - String key = (String)spinner.getSelectedItem(); - value = mCertTool.getUserCertificate(key); - if (!TextUtils.isEmpty(value)) { - mState.setEnterpriseField(AccessPointState.CLIENT_CERT, - BLOB_HEADER + value); - } - value = mCertTool.getUserPrivateKey(key); - if (!TextUtils.isEmpty(value)) { - mState.setEnterpriseField(AccessPointState.PRIVATE_KEY, - BLOB_HEADER + value); - } + String key = (String) spinner.getSelectedItem(); + mState.setEnterpriseField(AccessPointState.CLIENT_CERT, + BLOB_HEADER + Credentials.USER_CERTIFICATE + key); + mState.setEnterpriseField(AccessPointState.PRIVATE_KEY, + BLOB_HEADER + Credentials.USER_PRIVATE_KEY + key); } spinner = mCaCertSpinner; index = spinner.getSelectedItemPosition(); if (index != (spinner.getCount() - 1)) { - String key = (String)spinner.getSelectedItem(); - value = mCertTool.getCaCertificate(key); - if (!TextUtils.isEmpty(value)) { - mState.setEnterpriseField(AccessPointState.CA_CERT, - BLOB_HEADER + value); - } + String key = (String) spinner.getSelectedItem(); + mState.setEnterpriseField(AccessPointState.CA_CERT, + BLOB_HEADER + Credentials.CA_CERTIFICATE + key); } mState.setSecurity(AccessPointState.EAP); mState.setEap(mEapSpinner.getSelectedItemPosition()); - mState.setPhase2((String)mPhase2Spinner.getSelectedItem()); + mState.setPhase2((String) mPhase2Spinner.getSelectedItem()); } /** @@ -765,9 +760,8 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On } case SECURITY_EAP: { // Unlock the keystore if it is not unlocked yet. - if (Keystore.getInstance().getState() != Keystore.UNLOCKED) { - getContext().startActivity(new Intent( - Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE)); + if (mKeyStore.test() != KeyStore.NO_ERROR) { + Credentials.getInstance().unlock(getContext()); return; } enableEnterpriseFields(); diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java index 4aa5dc35191..361f159ea9a 100644 --- a/src/com/android/settings/wifi/WifiSettings.java +++ b/src/com/android/settings/wifi/WifiSettings.java @@ -29,7 +29,8 @@ import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; import android.preference.CheckBoxPreference; import android.provider.Settings; -import android.security.Keystore; +import android.security.Credentials; +import android.security.KeyStore; import android.util.Log; import android.view.ContextMenu; import android.view.Menu; @@ -86,6 +87,7 @@ public class WifiSettings extends PreferenceActivity implements WifiLayer.Callba private WeakHashMap mAps; + private KeyStore mKeyStore = KeyStore.getInstance(); private AccessPointState mResumeState = null; private int mResumeMode; @@ -156,14 +158,14 @@ public class WifiSettings extends PreferenceActivity implements WifiLayer.Callba mWifiEnabler.resume(); // do what we should have after keystore is unlocked. if (mResumeState != null) { - if (Keystore.getInstance().getState() == Keystore.UNLOCKED) { + if (mKeyStore.test() == KeyStore.NO_ERROR) { showAccessPointDialog(mResumeState, mResumeMode); } mResumeMode = -1; mResumeState = null; } else { if (mResumeMode == AccessPointDialog.MODE_CONFIGURE) { - if (Keystore.getInstance().getState() == Keystore.UNLOCKED) { + if (mKeyStore.test() == KeyStore.NO_ERROR) { ((AccessPointDialog) mDialog).enableEnterpriseFields(); } } @@ -372,10 +374,8 @@ public class WifiSettings extends PreferenceActivity implements WifiLayer.Callba } public void showAccessPointDialog(AccessPointState state, int mode) { - if (state.isEnterprise() && - Keystore.getInstance().getState() != Keystore.UNLOCKED) { - startActivity(new Intent( - Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE)); + if (state.isEnterprise() && mKeyStore.test() != KeyStore.NO_ERROR) { + Credentials.getInstance().unlock(this); mResumeState = state; mResumeMode = mode; return;