summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorChung-yih Wang <cywang@google.com>2009-07-06 17:03:53 +0800
committerChung-yih Wang <cywang@google.com>2009-07-06 17:03:53 +0800
commiteb7836f11ec4e9753db7c6ecd9414e153bb7bdbe (patch)
tree2a3b9005b9dfb299c0370a9105f35061bc41962d /src/com
parent4e45d392ada4e84fbeed06874caebfd3c7759073 (diff)
downloadpackages_apps_settings-eb7836f11ec4e9753db7c6ecd9414e153bb7bdbe.zip
packages_apps_settings-eb7836f11ec4e9753db7c6ecd9414e153bb7bdbe.tar.gz
packages_apps_settings-eb7836f11ec4e9753db7c6ecd9414e153bb7bdbe.tar.bz2
Apply the new keystore and certtool library in Wifi setting.
1. Certificate related APIs were moved to CertTool. Therefore, we have to migrate to CertTool instead. 2. Unlock the keystore if it is not unlocked yet(send the intent out to credential storage) for EAP access points. 3. Add Password field for WPA_EAP and IEEE8021X(this is for phase 2 auth.)
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/settings/wifi/AccessPointDialog.java148
-rw-r--r--src/com/android/settings/wifi/AccessPointState.java22
-rw-r--r--src/com/android/settings/wifi/WifiSettings.java10
3 files changed, 97 insertions, 83 deletions
diff --git a/src/com/android/settings/wifi/AccessPointDialog.java b/src/com/android/settings/wifi/AccessPointDialog.java
index 43081a5..bf2007a 100644
--- a/src/com/android/settings/wifi/AccessPointDialog.java
+++ b/src/com/android/settings/wifi/AccessPointDialog.java
@@ -17,11 +17,14 @@
package com.android.settings.wifi;
import com.android.settings.R;
+import com.android.settings.SecuritySettings;
import android.app.AlertDialog;
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.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
@@ -129,13 +132,13 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
private TextView mSecurityText;
private Spinner mSecuritySpinner;
private Spinner mWepTypeSpinner;
- private Keystore mKeystore;
+ private CertTool mCertTool;
public AccessPointDialog(Context context, WifiLayer wifiLayer) {
super(context);
mWifiLayer = wifiLayer;
- mKeystore = Keystore.getInstance();
+ mCertTool = CertTool.getInstance();
}
@Override
@@ -240,7 +243,7 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
setEnterpriseFieldsVisible(false);
} else if (mMode == MODE_INFO) {
- if (isEnterprise() && !mState.configured) {
+ if (mState.isEnterprise() && !mState.configured) {
setLayout(R.layout.wifi_ap_configure);
defaultPasswordVisibility = false;
setEnterpriseFieldsVisible(true);
@@ -287,16 +290,6 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
setButtons(positiveButtonResId, negativeButtonResId, neutralButtonResId);
}
- private boolean isEnterprise() {
-
- if(AccessPointState.WPA_EAP.equals(mState.security) ||
- AccessPointState.IEEE8021X.equals(mState.security)) {
- return true;
- } else {
- return false;
- }
- }
-
/** Called when we need to set our member variables to point to the views. */
private void onReferenceViews(View view) {
mPasswordText = (TextView) view.findViewById(R.id.password_text);
@@ -322,7 +315,8 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
mTable = (ViewGroup) view.findViewById(R.id.table);
}
/* for enterprise one */
- if (mMode == MODE_CONFIGURE || (isEnterprise() && !mState.configured)) {
+ if (mMode == MODE_CONFIGURE ||
+ (mState.isEnterprise() && !mState.configured)) {
setEnterpriseFields(view);
mEapSpinner.setSelection(getSelectionIndex(
R.array.wifi_eap_entries, mState.getEap()));
@@ -336,15 +330,14 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
}
private String[] getAllCaCertificateKeys() {
- return appendEmptyInSelection(mKeystore.getAllCaCertificateKeys());
+ return appendEmptyInSelection(mCertTool.getAllCaCertificateKeys());
}
private String[] getAllUserCertificateKeys() {
- return appendEmptyInSelection(mKeystore.getAllUserCertificateKeys());
+ return appendEmptyInSelection(mCertTool.getAllUserCertificateKeys());
}
private String[] appendEmptyInSelection(String[] keys) {
- if (keys.length == 0) return keys;
String[] selections = new String[keys.length + 1];
System.arraycopy(keys, 0, selections, 0, keys.length);
selections[keys.length] = NOT_APPLICABLE;
@@ -436,8 +429,9 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
if (!TextUtils.isEmpty(ssid)) {
mSsidEdit.setText(ssid);
}
-
- mPasswordEdit.setHint(R.string.wifi_password_unchanged);
+ if (mState.configured) {
+ mPasswordEdit.setHint(R.string.wifi_password_unchanged);
+ }
}
updatePasswordCaption(mState.security);
@@ -505,15 +499,15 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
Log.w(TAG, "Assuming connecting to a new network.");
}
- if (isEnterprise()) {
+ if (mState.isEnterprise()) {
if(!mState.configured) {
updateEnterpriseFields(
AccessPointState.WPA_EAP.equals(mState.security) ?
SECURITY_WPA_EAP : SECURITY_IEEE8021X);
}
- } else {
- updatePasswordField();
}
+ updatePasswordField();
+
mWifiLayer.connectToNetwork(mState);
}
@@ -558,58 +552,53 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
mState.setSsid(ssid);
int securityType = getSecurityTypeFromSpinner();
-
- if (!TextUtils.isEmpty(password)) {
- switch (securityType) {
-
- case SECURITY_WPA_PERSONAL: {
- mState.setSecurity(AccessPointState.WPA);
- mState.setPassword(password);
- break;
- }
-
- case SECURITY_WPA2_PERSONAL: {
- mState.setSecurity(AccessPointState.WPA2);
- mState.setPassword(password);
- break;
- }
-
- case SECURITY_AUTO: {
- mState.setPassword(password);
- break;
- }
-
- case SECURITY_WEP: {
- mState.setSecurity(AccessPointState.WEP);
- mState.setPassword(password,
- WEP_TYPE_VALUES[mWepTypeSpinner.getSelectedItemPosition()]);
- break;
- }
-
+
+ if (!TextUtils.isEmpty(password) && (securityType != SECURITY_WEP)) {
+ mState.setPassword(password);
+ }
+
+ switch (securityType) {
+ case SECURITY_WPA_PERSONAL: {
+ mState.setSecurity(AccessPointState.WPA);
+ break;
}
- } else {
- switch (securityType) {
- case SECURITY_WPA_EAP:
- mState.setSecurity(AccessPointState.WPA_EAP);
- break;
- case SECURITY_IEEE8021X:
- mState.setSecurity(AccessPointState.IEEE8021X);
- break;
- default:
- mState.setSecurity(AccessPointState.OPEN);
- break;
+
+ case SECURITY_WPA2_PERSONAL: {
+ mState.setSecurity(AccessPointState.WPA2);
+ break;
}
- if (isEnterprise() && !mState.configured) {
- updateEnterpriseFields(
- AccessPointState.WPA_EAP.equals(mState.security) ?
- SECURITY_WPA_EAP : SECURITY_IEEE8021X);
+
+ case SECURITY_AUTO: {
+ break;
}
+
+ case SECURITY_WEP: {
+ mState.setSecurity(AccessPointState.WEP);
+ mState.setPassword(password, WEP_TYPE_VALUES[
+ mWepTypeSpinner.getSelectedItemPosition()]);
+ break;
+ }
+
+ case SECURITY_WPA_EAP:
+ mState.setSecurity(AccessPointState.WPA_EAP);
+ break;
+
+ case SECURITY_IEEE8021X:
+ mState.setSecurity(AccessPointState.IEEE8021X);
+ break;
+
+ case SECURITY_NONE:
+ default:
+ mState.setSecurity(AccessPointState.OPEN);
+ break;
}
-
- if (securityType == SECURITY_NONE) {
- mState.setSecurity(AccessPointState.OPEN);
+
+ if (mState.isEnterprise() && !mState.configured) {
+ updateEnterpriseFields(
+ AccessPointState.WPA_EAP.equals(mState.security) ?
+ SECURITY_WPA_EAP : SECURITY_IEEE8021X);
}
-
+
if (!mWifiLayer.saveNetwork(mState)) {
return;
}
@@ -649,13 +638,13 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
Spinner spinner = mClientCertSpinner;
int index = spinner.getSelectedItemPosition();
if (index != (spinner.getCount() - 1)) {
- String key = getAllUserCertificateKeys()[index];
- value = mKeystore.getUserCertificate(key);
+ String key = (String)spinner.getSelectedItem();
+ value = mCertTool.getUserCertificate(key);
if (!TextUtils.isEmpty(value)) {
mState.setEnterpriseField(AccessPointState.CLIENT_CERT,
value);
}
- value = mKeystore.getUserPrivateKey(key);
+ value = mCertTool.getUserPrivateKey(key);
if (!TextUtils.isEmpty(value)) {
mState.setEnterpriseField(AccessPointState.PRIVATE_KEY,
value);
@@ -664,8 +653,8 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
spinner = mCaCertSpinner;
index = spinner.getSelectedItemPosition();
if (index != (spinner.getCount() - 1)) {
- String key = getAllCaCertificateKeys()[index];
- value = mKeystore.getCaCertificate(key);
+ String key = (String)spinner.getSelectedItem();
+ value = mCertTool.getCaCertificate(key);
if (!TextUtils.isEmpty(value)) {
mState.setEnterpriseField(AccessPointState.CA_CERT,
value);
@@ -738,7 +727,6 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
mEnterpriseView.setVisibility(visibility);
if (visible) {
setWepVisible(false);
- setGenericPasswordVisible(false);
}
if (mMode != MODE_CONFIGURE) {
mSsidText.setVisibility(View.GONE);
@@ -792,7 +780,17 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
}
case SECURITY_WPA_EAP:
case SECURITY_IEEE8021X: {
+ // Unlock the keystore if it is not unlocked yet.
+ if (Keystore.getInstance().getState() != Keystore.UNLOCKED) {
+ getContext().startActivity(new Intent(
+ SecuritySettings.ACTION_UNLOCK_CREDENTIAL_STORAGE));
+ mSecuritySpinner.setSelection(0);
+ return;
+ }
setEnterpriseFieldsVisible(true);
+ setGenericPasswordVisible(true);
+ // Both WPA and WPA2 show the same caption, so either is ok
+ updatePasswordCaption(AccessPointState.WPA);
break;
}
}
diff --git a/src/com/android/settings/wifi/AccessPointState.java b/src/com/android/settings/wifi/AccessPointState.java
index 7ea2dc9..8fb651b 100644
--- a/src/com/android/settings/wifi/AccessPointState.java
+++ b/src/com/android/settings/wifi/AccessPointState.java
@@ -276,7 +276,12 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
requestRefresh();
}
}
-
+
+ public boolean isEnterprise() {
+ return (WPA_EAP.equals(security) ||
+ AccessPointState.IEEE8021X.equals(security));
+ }
+
public void setSecurity(String security) {
if (TextUtils.isEmpty(this.security) || !this.security.equals(security)) {
this.security = security;
@@ -592,14 +597,17 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
} else if (security.equals(OPEN)) {
config.allowedKeyManagement.set(KeyMgmt.NONE);
- } else if (security.equals(WPA_EAP)) {
- config.allowedGroupCiphers.set(GroupCipher.TKIP);
- config.allowedGroupCiphers.set(GroupCipher.CCMP);
- config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
- } else if (security.equals(IEEE8021X)) {
+ } else if (security.equals(WPA_EAP) || security.equals(IEEE8021X)) {
config.allowedGroupCiphers.set(GroupCipher.TKIP);
config.allowedGroupCiphers.set(GroupCipher.CCMP);
- config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
+ if (security.equals(WPA_EAP)) {
+ config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
+ } else {
+ config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
+ }
+ if (!TextUtils.isEmpty(mPassword)) {
+ config.password = convertToQuotedString(mPassword);
+ }
}
}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index d2683c0..a015534 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -18,6 +18,7 @@ package com.android.settings.wifi;
import com.android.settings.ProgressCategory;
import com.android.settings.R;
+import com.android.settings.SecuritySettings;
import android.app.Dialog;
import android.content.DialogInterface;
@@ -29,6 +30,7 @@ import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.preference.CheckBoxPreference;
import android.provider.Settings;
+import android.security.Keystore;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
@@ -259,7 +261,7 @@ public class WifiSettings extends PreferenceActivity implements WifiLayer.Callba
@Override
public boolean onContextItemSelected(MenuItem item) {
-
+
AccessPointState state = getStateFromMenuInfo(item.getMenuInfo());
if (state == null) {
return false;
@@ -352,6 +354,12 @@ 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(
+ SecuritySettings.ACTION_UNLOCK_CREDENTIAL_STORAGE));
+ return;
+ }
AccessPointDialog dialog = new AccessPointDialog(this, mWifiLayer);
dialog.setMode(mode);
dialog.setState(state);