Add support for WPA for soft Ap
Bug: 2771935 Change-Id: I2c02b4e686a65e0748f4a4afd27dc49602d6dd98
This commit is contained in:
@@ -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>
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user