summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2011-02-16 22:59:44 -0800
committerIrfan Sheriff <isheriff@google.com>2011-02-17 00:39:59 -0800
commitc1a322854d3de2f65adf3231d6919a13728d4862 (patch)
treeedd7b45b70ac33745394cc2d8c531f7569032a9d
parenteb3c23d426d536895db1b6fa6d869bf97cb2f9d2 (diff)
downloadpackages_apps_Settings-c1a322854d3de2f65adf3231d6919a13728d4862.tar.gz
packages_apps_Settings-c1a322854d3de2f65adf3231d6919a13728d4862.tar.bz2
packages_apps_Settings-c1a322854d3de2f65adf3231d6919a13728d4862.zip
Add support for WPA for soft Ap
Bug: 2771935 Change-Id: I2c02b4e686a65e0748f4a4afd27dc49602d6dd98
-rw-r--r--res/values/arrays.xml2
-rw-r--r--src/com/android/settings/wifi/WifiApDialog.java59
-rw-r--r--src/com/android/settings/wifi/WifiApSettings.java13
3 files changed, 43 insertions, 31 deletions
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 8f5f16a8a..4f9eaddcf 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -280,6 +280,8 @@
<string-array name="wifi_ap_security" translatable="false">
<item>Open</item>
<!-- Do not translate. -->
+ <item>WPA PSK</item>
+ <!-- Do not translate. -->
<item>WPA2 PSK</item>
</string-array>
diff --git a/src/com/android/settings/wifi/WifiApDialog.java b/src/com/android/settings/wifi/WifiApDialog.java
index fde6efc69..29c1a5df2 100644
--- a/src/com/android/settings/wifi/WifiApDialog.java
+++ b/src/com/android/settings/wifi/WifiApDialog.java
@@ -46,12 +46,13 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
private final DialogInterface.OnClickListener mListener;
- private static final int OPEN_INDEX = 0;
- private static final int WPA_INDEX = 1;
+ static final int OPEN_INDEX = 0;
+ static final int WPA_INDEX = 1;
+ static final int WPA2_INDEX = 2;
private View mView;
private TextView mSsid;
- private int mSecurityType = AccessPoint.SECURITY_NONE;
+ private int mSecurityTypeIndex = OPEN_INDEX;
private EditText mPassword;
WifiConfiguration mWifiConfig;
@@ -61,8 +62,18 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
super(context);
mListener = listener;
mWifiConfig = wifiConfig;
- if (wifiConfig != null)
- mSecurityType = AccessPoint.getSecurity(wifiConfig);
+ if (wifiConfig != null) {
+ mSecurityTypeIndex = getSecurityTypeIndex(wifiConfig);
+ }
+ }
+
+ public static int getSecurityTypeIndex(WifiConfiguration wifiConfig) {
+ if (wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
+ return WPA_INDEX;
+ } else if (wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA2_PSK)) {
+ return WPA2_INDEX;
+ }
+ return OPEN_INDEX;
}
public WifiConfiguration getConfig() {
@@ -77,12 +88,12 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
*/
config.SSID = mSsid.getText().toString();
- switch (mSecurityType) {
- case AccessPoint.SECURITY_NONE:
+ switch (mSecurityTypeIndex) {
+ case OPEN_INDEX:
config.allowedKeyManagement.set(KeyMgmt.NONE);
return config;
- case AccessPoint.SECURITY_PSK:
+ case WPA_INDEX:
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
if (mPassword.length() != 0) {
@@ -90,6 +101,15 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
config.preSharedKey = password;
}
return config;
+
+ case WPA2_INDEX:
+ config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
+ config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
+ if (mPassword.length() != 0) {
+ String password = mPassword.getText().toString();
+ config.preSharedKey = password;
+ }
+ return config;
}
return null;
}
@@ -116,15 +136,10 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
if (mWifiConfig != null) {
mSsid.setText(mWifiConfig.SSID);
- switch (mSecurityType) {
- case AccessPoint.SECURITY_NONE:
- mSecurity.setSelection(OPEN_INDEX);
- break;
- case AccessPoint.SECURITY_PSK:
- String str = mWifiConfig.preSharedKey;
- mPassword.setText(str);
- mSecurity.setSelection(WPA_INDEX);
- break;
+ mSecurity.setSelection(mSecurityTypeIndex);
+ if (mSecurityTypeIndex == WPA_INDEX ||
+ mSecurityTypeIndex == WPA2_INDEX) {
+ mPassword.setText(mWifiConfig.preSharedKey);
}
}
@@ -141,7 +156,8 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
private void validate() {
if ((mSsid != null && mSsid.length() == 0) ||
- (mSecurityType == AccessPoint.SECURITY_PSK && mPassword.length() < 8)) {
+ (((mSecurityTypeIndex == WPA_INDEX) || (mSecurityTypeIndex == WPA2_INDEX))&&
+ mPassword.length() < 8)) {
getButton(BUTTON_SUBMIT).setEnabled(false);
} else {
getButton(BUTTON_SUBMIT).setEnabled(true);
@@ -167,10 +183,7 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- if(position == OPEN_INDEX)
- mSecurityType = AccessPoint.SECURITY_NONE;
- else
- mSecurityType = AccessPoint.SECURITY_PSK;
+ mSecurityTypeIndex = position;
showSecurityFields();
validate();
}
@@ -180,7 +193,7 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
}
private void showSecurityFields() {
- if (mSecurityType == AccessPoint.SECURITY_NONE) {
+ if (mSecurityTypeIndex == OPEN_INDEX) {
mView.findViewById(R.id.fields).setVisibility(View.GONE);
return;
}
diff --git a/src/com/android/settings/wifi/WifiApSettings.java b/src/com/android/settings/wifi/WifiApSettings.java
index 7336c6c5e..ddc3c5c14 100644
--- a/src/com/android/settings/wifi/WifiApSettings.java
+++ b/src/com/android/settings/wifi/WifiApSettings.java
@@ -41,9 +41,6 @@ public class WifiApSettings extends SettingsPreferenceFragment
private static final String ENABLE_WIFI_AP = "enable_wifi_ap";
private static final int CONFIG_SUBTEXT = R.string.wifi_tether_configure_subtext;
- private static final int OPEN_INDEX = 0;
- private static final int WPA_INDEX = 1;
-
private static final int DIALOG_AP_SETTINGS = 1;
private String[] mSecurityType;
@@ -81,12 +78,12 @@ public class WifiApSettings extends SettingsPreferenceFragment
final String s = activity.getString(
com.android.internal.R.string.wifi_tether_configure_ssid_default);
mCreateNetwork.setSummary(String.format(activity.getString(CONFIG_SUBTEXT),
- s, mSecurityType[OPEN_INDEX]));
+ s, mSecurityType[WifiApDialog.OPEN_INDEX]));
} else {
+ int index = WifiApDialog.getSecurityTypeIndex(mWifiConfig);
mCreateNetwork.setSummary(String.format(activity.getString(CONFIG_SUBTEXT),
mWifiConfig.SSID,
- mWifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK) ?
- mSecurityType[WPA_INDEX] : mSecurityType[OPEN_INDEX]));
+ mSecurityType[index]));
}
}
@@ -138,10 +135,10 @@ public class WifiApSettings extends SettingsPreferenceFragment
} else {
mWifiManager.setWifiApConfiguration(mWifiConfig);
}
+ int index = WifiApDialog.getSecurityTypeIndex(mWifiConfig);
mCreateNetwork.setSummary(String.format(getActivity().getString(CONFIG_SUBTEXT),
mWifiConfig.SSID,
- mWifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK) ?
- mSecurityType[WPA_INDEX] : mSecurityType[OPEN_INDEX]));
+ mSecurityType[index]));
}
}
}