am eb7836f1
: Apply the new keystore and certtool library in Wifi setting.
Merge commit 'eb7836f11ec4e9753db7c6ecd9414e153bb7bdbe' * commit 'eb7836f11ec4e9753db7c6ecd9414e153bb7bdbe': Apply the new keystore and certtool library in Wifi setting.
This commit is contained in:
committed by
The Android Open Source Project
commit
bd7f05701a
@@ -66,7 +66,7 @@
|
||||
<LinearLayout android:id="@+id/enterprise_wrapper"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dip"
|
||||
android:padding="0dip"
|
||||
android:orientation="vertical">
|
||||
<TextView android:id="@+id/eap_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
@@ -87,28 +87,6 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView android:id="@+id/identity_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_type_identity" />
|
||||
<EditText android:id="@+id/identity_edit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true" />
|
||||
<TextView android:id="@+id/anonymous_identity_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_type_anonymous_identity" />
|
||||
<EditText android:id="@+id/anonymous_identity_edit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true" />
|
||||
<TextView android:id="@+id/ca_certificate_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="fill_parent"
|
||||
@@ -138,6 +116,28 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true" />
|
||||
<TextView android:id="@+id/identity_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_type_identity" />
|
||||
<EditText android:id="@+id/identity_edit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true" />
|
||||
<TextView android:id="@+id/anonymous_identity_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_type_anonymous_identity" />
|
||||
<EditText android:id="@+id/anonymous_identity_edit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Password -->
|
||||
|
@@ -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,9 +429,10 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
if (!TextUtils.isEmpty(ssid)) {
|
||||
mSsidEdit.setText(ssid);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -559,56 +553,51 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
|
||||
int securityType = getSecurityTypeFromSpinner();
|
||||
|
||||
if (!TextUtils.isEmpty(password)) {
|
||||
switch (securityType) {
|
||||
if (!TextUtils.isEmpty(password) && (securityType != SECURITY_WEP)) {
|
||||
mState.setPassword(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()]);
|
||||
mState.setPassword(password, WEP_TYPE_VALUES[
|
||||
mWepTypeSpinner.getSelectedItemPosition()]);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
switch (securityType) {
|
||||
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 (isEnterprise() && !mState.configured) {
|
||||
|
||||
if (mState.isEnterprise() && !mState.configured) {
|
||||
updateEnterpriseFields(
|
||||
AccessPointState.WPA_EAP.equals(mState.security) ?
|
||||
SECURITY_WPA_EAP : SECURITY_IEEE8021X);
|
||||
}
|
||||
}
|
||||
|
||||
if (securityType == SECURITY_NONE) {
|
||||
mState.setSecurity(AccessPointState.OPEN);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -277,6 +277,11 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
}
|
||||
}
|
||||
|
||||
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,15 +597,18 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
|
||||
} else if (security.equals(OPEN)) {
|
||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
||||
} else if (security.equals(WPA_EAP)) {
|
||||
} 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 if (security.equals(IEEE8021X)) {
|
||||
config.allowedGroupCiphers.set(GroupCipher.TKIP);
|
||||
config.allowedGroupCiphers.set(GroupCipher.CCMP);
|
||||
} else {
|
||||
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mPassword)) {
|
||||
config.password = convertToQuotedString(mPassword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isHexWepKey(String wepKey) {
|
||||
|
@@ -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;
|
||||
@@ -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);
|
||||
|
Reference in New Issue
Block a user