Merge change 24646 into eclair
* changes: Aggregate the security settings for WiFi network configuration.
This commit is contained in:
@@ -73,10 +73,8 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
private static final int SECURITY_AUTO = 0;
|
||||
private static final int SECURITY_NONE = 1;
|
||||
private static final int SECURITY_WEP = 2;
|
||||
private static final int SECURITY_WPA_PERSONAL = 3;
|
||||
private static final int SECURITY_WPA2_PERSONAL = 4;
|
||||
private static final int SECURITY_WPA_EAP = 5;
|
||||
private static final int SECURITY_IEEE8021X = 6;
|
||||
private static final int SECURITY_PSK = 3;
|
||||
private static final int SECURITY_EAP = 4;
|
||||
|
||||
private static final int[] WEP_TYPE_VALUES = {
|
||||
AccessPointState.WEP_PASSWORD_AUTO, AccessPointState.WEP_PASSWORD_ASCII,
|
||||
@@ -118,8 +116,6 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
private Spinner mCaCertSpinner;
|
||||
private TextView mClientCertText;
|
||||
private Spinner mClientCertSpinner;
|
||||
private TextView mPrivateKeyPasswdText;
|
||||
private EditText mPrivateKeyPasswdEdit;
|
||||
private EditText[] mEnterpriseTextFields;
|
||||
|
||||
|
||||
@@ -221,7 +217,7 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
updateCertificateSelection();
|
||||
setGenericPasswordVisible(true);
|
||||
// Both WPA and WPA2 show the same caption, so either is ok
|
||||
updatePasswordCaption(AccessPointState.WPA);
|
||||
updatePasswordCaption(AccessPointState.PSK);
|
||||
}
|
||||
|
||||
/** Called after flags are set, the dialog's layout/etc should be set up here */
|
||||
@@ -370,8 +366,6 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
mClientCertText =
|
||||
(TextView) view.findViewById(R.id.client_certificate_text);
|
||||
mCaCertText = (TextView) view.findViewById(R.id.ca_certificate_text);
|
||||
mPrivateKeyPasswdEdit =
|
||||
(EditText) view.findViewById(R.id.private_key_passwd_edit);
|
||||
mEapText = (TextView) view.findViewById(R.id.eap_text);
|
||||
mEapSpinner = (Spinner) view.findViewById(R.id.eap_spinner);
|
||||
mEapSpinner.setOnItemSelectedListener(this);
|
||||
@@ -398,7 +392,7 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
setSpinnerAdapter(mCaCertSpinner, getAllCaCertificateKeys());
|
||||
|
||||
mEnterpriseTextFields = new EditText[] {
|
||||
mIdentityEdit, mAnonymousIdentityEdit, mPrivateKeyPasswdEdit
|
||||
mIdentityEdit, mAnonymousIdentityEdit
|
||||
};
|
||||
|
||||
}
|
||||
@@ -517,9 +511,7 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
|
||||
if (mState.isEnterprise()) {
|
||||
if(!mState.configured) {
|
||||
updateEnterpriseFields(
|
||||
AccessPointState.WPA_EAP.equals(mState.security) ?
|
||||
SECURITY_WPA_EAP : SECURITY_IEEE8021X);
|
||||
updateEnterpriseFields();
|
||||
}
|
||||
}
|
||||
updatePasswordField();
|
||||
@@ -575,13 +567,8 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
}
|
||||
|
||||
switch (securityType) {
|
||||
case SECURITY_WPA_PERSONAL: {
|
||||
mState.setSecurity(AccessPointState.WPA);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECURITY_WPA2_PERSONAL: {
|
||||
mState.setSecurity(AccessPointState.WPA2);
|
||||
case SECURITY_PSK: {
|
||||
mState.setSecurity(AccessPointState.PSK);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -596,12 +583,8 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
break;
|
||||
}
|
||||
|
||||
case SECURITY_WPA_EAP:
|
||||
mState.setSecurity(AccessPointState.WPA_EAP);
|
||||
break;
|
||||
|
||||
case SECURITY_IEEE8021X:
|
||||
mState.setSecurity(AccessPointState.IEEE8021X);
|
||||
case SECURITY_EAP:
|
||||
mState.setSecurity(AccessPointState.EAP);
|
||||
break;
|
||||
|
||||
case SECURITY_NONE:
|
||||
@@ -611,9 +594,7 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
}
|
||||
|
||||
if (mState.isEnterprise() && !mState.configured) {
|
||||
updateEnterpriseFields(
|
||||
AccessPointState.WPA_EAP.equals(mState.security) ?
|
||||
SECURITY_WPA_EAP : SECURITY_IEEE8021X);
|
||||
updateEnterpriseFields();
|
||||
}
|
||||
|
||||
if (!mWifiLayer.saveNetwork(mState)) {
|
||||
@@ -641,14 +622,13 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
getContext().getResources().getStringArray(arrayResId), selection);
|
||||
}
|
||||
|
||||
private void updateEnterpriseFields(int securityType) {
|
||||
private void updateEnterpriseFields() {
|
||||
int i;
|
||||
String value;
|
||||
for (i = AccessPointState.IDENTITY ;
|
||||
i <= AccessPointState.PRIVATE_KEY_PASSWD ; i++) {
|
||||
i <= AccessPointState.ANONYMOUS_IDENTITY ; i++) {
|
||||
value = mEnterpriseTextFields[i].getText().toString();
|
||||
if (!TextUtils.isEmpty(value) ||
|
||||
(i == AccessPointState.PRIVATE_KEY_PASSWD)) {
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
mState.setEnterpriseField(i, value);
|
||||
}
|
||||
}
|
||||
@@ -677,21 +657,9 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
BLOB_HEADER + value);
|
||||
}
|
||||
}
|
||||
switch (securityType) {
|
||||
case SECURITY_IEEE8021X:
|
||||
case SECURITY_WPA_EAP: {
|
||||
if (securityType == SECURITY_WPA_EAP) {
|
||||
mState.setSecurity(AccessPointState.WPA_EAP);
|
||||
} else {
|
||||
mState.setSecurity(AccessPointState.IEEE8021X);
|
||||
}
|
||||
mState.setEap(mEapSpinner.getSelectedItemPosition());
|
||||
mState.setPhase2((String)mPhase2Spinner.getSelectedItem());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
mState.setSecurity(AccessPointState.OPEN);
|
||||
}
|
||||
mState.setSecurity(AccessPointState.EAP);
|
||||
mState.setEap(mEapSpinner.getSelectedItemPosition());
|
||||
mState.setPhase2((String)mPhase2Spinner.getSelectedItem());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -784,20 +752,18 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
setWepVisible(false);
|
||||
setGenericPasswordVisible(mState.hasSecurity());
|
||||
// Shows the generic 'wireless password'
|
||||
updatePasswordCaption(AccessPointState.WPA);
|
||||
updatePasswordCaption(AccessPointState.PSK);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECURITY_WPA_PERSONAL:
|
||||
case SECURITY_WPA2_PERSONAL: {
|
||||
|
||||
case SECURITY_PSK: {
|
||||
setWepVisible(false);
|
||||
setGenericPasswordVisible(true);
|
||||
// Both WPA and WPA2 show the same caption, so either is ok
|
||||
updatePasswordCaption(AccessPointState.WPA);
|
||||
updatePasswordCaption(AccessPointState.PSK);
|
||||
break;
|
||||
}
|
||||
case SECURITY_WPA_EAP:
|
||||
case SECURITY_IEEE8021X: {
|
||||
case SECURITY_EAP: {
|
||||
// Unlock the keystore if it is not unlocked yet.
|
||||
if (Keystore.getInstance().getState() != Keystore.UNLOCKED) {
|
||||
getContext().startActivity(new Intent(
|
||||
|
@@ -38,15 +38,11 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
private static final String TAG = "AccessPointState";
|
||||
|
||||
// Constants used for different security types
|
||||
public static final String WPA2 = "WPA2";
|
||||
public static final String WPA = "WPA";
|
||||
public static final String PSK = "PSK";
|
||||
public static final String WEP = "WEP";
|
||||
public static final String EAP = "EAP";
|
||||
public static final String OPEN = "Open";
|
||||
|
||||
/* For EAP Enterprise fields */
|
||||
public static final String WPA_EAP = "-EAP";
|
||||
public static final String IEEE8021X = "IEEE8021X";
|
||||
|
||||
public static final String[] EAP_METHOD = { "PEAP", "TLS", "TTLS" };
|
||||
|
||||
/** String present in capabilities if the scan result is ad-hoc */
|
||||
@@ -103,11 +99,10 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
/* Enterprise Fields */
|
||||
public static final int IDENTITY = 0;
|
||||
public static final int ANONYMOUS_IDENTITY = 1;
|
||||
public static final int PRIVATE_KEY_PASSWD = 2;
|
||||
public static final int CLIENT_CERT = 3;
|
||||
public static final int CA_CERT = 4;
|
||||
public static final int PRIVATE_KEY = 5;
|
||||
public static final int MAX_ENTRPRISE_FIELD = 6;
|
||||
public static final int CLIENT_CERT = 2;
|
||||
public static final int CA_CERT = 3;
|
||||
public static final int PRIVATE_KEY = 4;
|
||||
public static final int MAX_ENTRPRISE_FIELD = 5;
|
||||
private String mEnterpriseFields[] = new String[MAX_ENTRPRISE_FIELD];
|
||||
private String mEap;
|
||||
private String mPhase2;
|
||||
@@ -278,8 +273,7 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
}
|
||||
|
||||
public boolean isEnterprise() {
|
||||
return (WPA_EAP.equals(security) ||
|
||||
AccessPointState.IEEE8021X.equals(security));
|
||||
return (AccessPointState.EAP.equals(security));
|
||||
}
|
||||
|
||||
public void setSecurity(String security) {
|
||||
@@ -296,10 +290,8 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
public String getHumanReadableSecurity() {
|
||||
if (security.equals(OPEN)) return mContext.getString(R.string.wifi_security_open);
|
||||
else if (security.equals(WEP)) return mContext.getString(R.string.wifi_security_wep);
|
||||
else if (security.equals(WPA)) return mContext.getString(R.string.wifi_security_wpa);
|
||||
else if (security.equals(WPA2)) return mContext.getString(R.string.wifi_security_wpa2);
|
||||
else if (security.equals(WPA_EAP)) return mContext.getString(R.string.wifi_security_wpa_eap);
|
||||
else if (security.equals(IEEE8021X)) return mContext.getString(R.string.wifi_security_ieee8021x);
|
||||
else if (security.equals(PSK)) return mContext.getString(R.string.wifi_security_psk);
|
||||
else if (security.equals(EAP)) return mContext.getString(R.string.wifi_security_eap);
|
||||
|
||||
return mContext.getString(R.string.wifi_security_unknown);
|
||||
}
|
||||
@@ -325,7 +317,7 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
*/
|
||||
public static String getScanResultSecurity(ScanResult scanResult) {
|
||||
final String cap = scanResult.capabilities;
|
||||
final String[] securityModes = { WEP, WPA, WPA2, WPA_EAP, IEEE8021X };
|
||||
final String[] securityModes = { WEP, PSK, EAP };
|
||||
for (int i = securityModes.length - 1; i >= 0; i--) {
|
||||
if (cap.contains(securityModes[i])) {
|
||||
return securityModes[i];
|
||||
@@ -427,31 +419,14 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
* @return The security of a given {@link WifiConfiguration}.
|
||||
*/
|
||||
public static String getWifiConfigurationSecurity(WifiConfiguration wifiConfig) {
|
||||
|
||||
if (wifiConfig.allowedKeyManagement.get(KeyMgmt.NONE)) {
|
||||
// If we never set group ciphers, wpa_supplicant puts all of them.
|
||||
// For open, we don't set group ciphers.
|
||||
// For WEP, we specifically only set WEP40 and WEP104, so CCMP
|
||||
// and TKIP should not be there.
|
||||
if (!wifiConfig.allowedGroupCiphers.get(GroupCipher.CCMP)
|
||||
&& (wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP40)
|
||||
|| wifiConfig.allowedGroupCiphers.get(GroupCipher.WEP104))) {
|
||||
return WEP;
|
||||
} else {
|
||||
return OPEN;
|
||||
}
|
||||
} else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_EAP)) {
|
||||
return WPA_EAP;
|
||||
} else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
|
||||
return IEEE8021X;
|
||||
} else if (wifiConfig.allowedProtocols.get(Protocol.RSN)) {
|
||||
return WPA2;
|
||||
} else if (wifiConfig.allowedProtocols.get(Protocol.WPA)) {
|
||||
return WPA;
|
||||
} else {
|
||||
Log.w(TAG, "Unknown security type from WifiConfiguration, falling back on open.");
|
||||
return OPEN;
|
||||
if (!TextUtils.isEmpty(wifiConfig.eap.value())) {
|
||||
return EAP;
|
||||
} else if (!TextUtils.isEmpty(wifiConfig.preSharedKey)) {
|
||||
return PSK;
|
||||
} else if (!TextUtils.isEmpty(wifiConfig.wepKeys[0])) {
|
||||
return WEP;
|
||||
}
|
||||
return OPEN;
|
||||
}
|
||||
|
||||
public void updateFromWifiInfo(WifiInfo wifiInfo, NetworkInfo.DetailedState state) {
|
||||
@@ -504,51 +479,43 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
config.priority = priority;
|
||||
config.hiddenSSID = hiddenSsid;
|
||||
config.SSID = convertToQuotedString(ssid);
|
||||
/*
|
||||
config.eap = mEap;
|
||||
config.eap.setValue(mEap);
|
||||
|
||||
if (!TextUtils.isEmpty(mPhase2)) {
|
||||
config.phase2 = convertToQuotedString("auth=" + mPhase2);
|
||||
config.phase2.setValue(convertToQuotedString("auth=" + mPhase2));
|
||||
} else {
|
||||
config.phase2 = null;
|
||||
config.phase2.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[IDENTITY])) {
|
||||
config.identity =
|
||||
convertToQuotedString(mEnterpriseFields[IDENTITY]);
|
||||
config.identity.setValue(
|
||||
convertToQuotedString(mEnterpriseFields[IDENTITY]));
|
||||
} else {
|
||||
config.identity = null;
|
||||
config.identity.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[ANONYMOUS_IDENTITY])) {
|
||||
config.anonymousIdentity = convertToQuotedString(
|
||||
mEnterpriseFields[ANONYMOUS_IDENTITY]);
|
||||
config.anonymous_identity.setValue(convertToQuotedString(
|
||||
mEnterpriseFields[ANONYMOUS_IDENTITY]));
|
||||
} else {
|
||||
config.anonymousIdentity = null;
|
||||
config.anonymous_identity.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[CLIENT_CERT])) {
|
||||
config.clientCert = convertToQuotedString(
|
||||
mEnterpriseFields[CLIENT_CERT]);
|
||||
config.client_cert.setValue(convertToQuotedString(
|
||||
mEnterpriseFields[CLIENT_CERT]));
|
||||
} else {
|
||||
config.clientCert = null;
|
||||
config.client_cert.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[CA_CERT])) {
|
||||
config.caCert = convertToQuotedString(
|
||||
mEnterpriseFields[CA_CERT]);
|
||||
config.ca_cert.setValue(convertToQuotedString(
|
||||
mEnterpriseFields[CA_CERT]));
|
||||
} else {
|
||||
config.caCert = null;
|
||||
config.ca_cert.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[PRIVATE_KEY])) {
|
||||
config.privateKey = convertToQuotedString(
|
||||
mEnterpriseFields[PRIVATE_KEY]);
|
||||
config.private_key.setValue(convertToQuotedString(
|
||||
mEnterpriseFields[PRIVATE_KEY]));
|
||||
} else {
|
||||
config.privateKey = null;
|
||||
config.private_key.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[PRIVATE_KEY_PASSWD])) {
|
||||
config.privateKeyPasswd = convertToQuotedString(
|
||||
mEnterpriseFields[PRIVATE_KEY_PASSWD]);
|
||||
} else {
|
||||
config.privateKeyPasswd = null;
|
||||
}
|
||||
*/
|
||||
setupSecurity(config);
|
||||
}
|
||||
|
||||
@@ -565,7 +532,6 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
}
|
||||
|
||||
if (security.equals(WEP)) {
|
||||
|
||||
// If password is empty, it should be left untouched
|
||||
if (!TextUtils.isEmpty(mPassword)) {
|
||||
if (mWepPasswordType == WEP_PASSWORD_AUTO) {
|
||||
@@ -580,28 +546,9 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
: mPassword;
|
||||
}
|
||||
}
|
||||
|
||||
config.wepTxKeyIndex = 0;
|
||||
|
||||
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
|
||||
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
|
||||
|
||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
||||
|
||||
config.allowedGroupCiphers.set(GroupCipher.WEP40);
|
||||
config.allowedGroupCiphers.set(GroupCipher.WEP104);
|
||||
|
||||
} else if (security.equals(WPA) || security.equals(WPA2)){
|
||||
config.allowedGroupCiphers.set(GroupCipher.TKIP);
|
||||
config.allowedGroupCiphers.set(GroupCipher.CCMP);
|
||||
|
||||
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
|
||||
|
||||
config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
|
||||
config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);
|
||||
|
||||
config.allowedProtocols.set(security.equals(WPA2) ? Protocol.RSN : Protocol.WPA);
|
||||
|
||||
config.wepTxKeyIndex = 0;
|
||||
} else if (security.equals(PSK)){
|
||||
// If password is empty, it should be left untouched
|
||||
if (!TextUtils.isEmpty(mPassword)) {
|
||||
if (mPassword.length() == 64 && isHex(mPassword)) {
|
||||
@@ -612,20 +559,14 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
config.preSharedKey = convertToQuotedString(mPassword);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (security.equals(EAP)) {
|
||||
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
|
||||
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
|
||||
if (!TextUtils.isEmpty(mPassword)) {
|
||||
config.password.setValue(convertToQuotedString(mPassword));
|
||||
}
|
||||
} else if (security.equals(OPEN)) {
|
||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
||||
} else if (security.equals(WPA_EAP) || security.equals(IEEE8021X)) {
|
||||
config.allowedGroupCiphers.set(GroupCipher.TKIP);
|
||||
config.allowedGroupCiphers.set(GroupCipher.CCMP);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -827,16 +768,10 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
private String getVerboseSecurity() {
|
||||
if (WEP.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_wep);
|
||||
} else if (WPA.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_wpa);
|
||||
} else if (WPA2.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_wpa2);
|
||||
} else if (OPEN.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_open);
|
||||
} else if (WPA_EAP.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_wpa_eap);
|
||||
} else if (IEEE8021X.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_ieee8021x);
|
||||
} else if (PSK.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_psk);
|
||||
} else if (EAP.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_eap);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user