softAp UI changes

Remove channel settings
Add subtext error handling
Remove WEP, keep WPA2 only for now

Bug: 2413908
Change-Id: Ie867e84a0705f0d2185eeb3a4c86a8227446a338
This commit is contained in:
Irfan Sheriff
2010-03-10 08:27:15 -08:00
parent 233880225a
commit 47ebb78954
6 changed files with 70 additions and 123 deletions

View File

@@ -228,12 +228,11 @@
</string-array>
<!-- Wi-Fi AP settings. The type of security a Wi-Fi AP supports. -->
<!-- Note that adding/removing/moving the items will need wifi settings code change. -->
<string-array name="wifi_ap_security" translatable="false">
<item>Open</item>
<!-- Do not translate. -->
<item>WEP</item>
<!-- Do not translate. -->
<item>WPA/WPA2 PSK</item>
<item>WPA2 PSK</item>
</string-array>
<!-- Match this with the constants in WifiDialog. --> <skip />

View File

@@ -28,11 +28,4 @@
android:title="@string/wifi_tether_configure_ap_text"
android:persistent="false" />
<!-- TODO: Channel setting will go away -->
<ListPreference
android:key="wifi_ap_channel"
android:dependency="enable_wifi_ap"
android:title="Channel"
android:persistent="false" />
</PreferenceScreen>

View File

@@ -26,6 +26,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiConfiguration;
import android.os.Environment;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
@@ -54,6 +56,7 @@ public class TetherSettings extends PreferenceActivity {
private PreferenceScreen mWifiApSettings;
private WifiApEnabler mWifiApEnabler;
private PreferenceScreen mTetherHelp;
private WifiManager mWifiManager;
private BroadcastReceiver mTetherChangeReceiver;
@@ -76,6 +79,8 @@ public class TetherSettings extends PreferenceActivity {
ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
mWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
mUsbRegexs = cm.getTetherableUsbRegexs();
if (mUsbRegexs.length == 0) {
getPreferenceScreen().removePreference(mUsbTether);
@@ -221,6 +226,17 @@ public class TetherSettings extends PreferenceActivity {
mUsbTether.setEnabled(false);
mUsbTether.setChecked(false);
}
if (wifiTethered) {
WifiConfiguration mWifiConfig = mWifiManager.getWifiApConfiguration();
String s = getString(com.android.internal.R.string.wifi_tether_configure_ssid_default);
mEnableWifiAp.setSummary(String.format(getString(R.string.wifi_tether_enabled_subtext),
(mWifiConfig == null) ? s : mWifiConfig.SSID));
}
if (wifiErrored) {
mEnableWifiAp.setSummary(R.string.wifi_error);
}
}
@Override

View File

@@ -49,6 +49,9 @@ 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;
private View mView;
private TextView mSsid;
private int mSecurityType = AccessPoint.SECURITY_NONE;
@@ -76,22 +79,6 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
config.allowedKeyManagement.set(KeyMgmt.NONE);
return config;
case AccessPoint.SECURITY_WEP:
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
if (mPassword.length() != 0) {
int length = mPassword.length();
String password = mPassword.getText().toString();
// WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
if ((length == 10 || length == 26 || length == 58) &&
password.matches("[0-9A-Fa-f]*")) {
config.wepKeys[0] = password;
} else {
config.wepKeys[0] = '"' + password + '"';
}
}
return config;
case AccessPoint.SECURITY_PSK:
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
@@ -130,14 +117,18 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
if (mWifiConfig != null) {
mSsid.setText(mWifiConfig.SSID);
switch (mSecurityType) {
case AccessPoint.SECURITY_WEP:
mPassword.setText(mWifiConfig.wepKeys[0]);
case AccessPoint.SECURITY_NONE:
mSecurity.setSelection(OPEN_INDEX);
break;
case AccessPoint.SECURITY_PSK:
mPassword.setText(mWifiConfig.preSharedKey);
String str = mWifiConfig.preSharedKey;
if (!str.matches("[0-9A-Fa-f]{64}")) {
str = str.substring(1,str.length()-1);
}
mPassword.setText(str);
mSecurity.setSelection(WPA_INDEX);
break;
}
mSecurity.setSelection(mSecurityType);
}
mSsid.addTextChangedListener(this);
@@ -153,7 +144,6 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
private void validate() {
if ((mSsid != null && mSsid.length() == 0) ||
(mSecurityType == AccessPoint.SECURITY_WEP && mPassword.length() == 0) ||
(mSecurityType == AccessPoint.SECURITY_PSK && mPassword.length() < 8)) {
getButton(BUTTON_SUBMIT).setEnabled(false);
} else {
@@ -179,7 +169,10 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
}
public void onItemSelected(AdapterView parent, View view, int position, long id) {
mSecurityType = position;
if(position == OPEN_INDEX)
mSecurityType = AccessPoint.SECURITY_NONE;
else
mSecurityType = AccessPoint.SECURITY_PSK;
showSecurityFields();
validate();
}

View File

@@ -22,7 +22,6 @@ import com.android.settings.WirelessSettings;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.NetworkInfo;
@@ -36,15 +35,13 @@ import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
public class WifiApEnabler implements Preference.OnPreferenceChangeListener,
DialogInterface.OnClickListener {
public class WifiApEnabler implements Preference.OnPreferenceChangeListener {
private final Context mContext;
private final CheckBoxPreference mCheckBox;
private final CharSequence mOriginalSummary;
private final WifiManager mWifiManager;
private WifiManager mWifiManager;
private final IntentFilter mIntentFilter;
private AlertDialog mAlertDialog = null;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
@@ -75,50 +72,20 @@ public class WifiApEnabler implements Preference.OnPreferenceChangeListener,
public void pause() {
mContext.unregisterReceiver(mReceiver);
mCheckBox.setOnPreferenceChangeListener(null);
if (mAlertDialog != null) {
mAlertDialog.dismiss();
mAlertDialog = null;
}
}
public boolean onPreferenceChange(Preference preference, Object value) {
boolean enable = (Boolean) value;
public boolean onPreferenceChange(Preference preference, Object enable) {
if (enable && mWifiManager.isWifiEnabled()) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
/**
* TODO: this alert will go away.
*/
builder.setMessage("Turning off Wifi client. Enabling Wifi tethering")
.setCancelable(false)
.setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, this);
mAlertDialog = builder.create();
mAlertDialog.show();
if (mWifiManager.setWifiApEnabled(null, (Boolean)enable)) {
/* Disable here, enabled on receiving success broadcast */
mCheckBox.setEnabled(false);
} else {
setUpAccessPoint(enable);
mCheckBox.setSummary(R.string.wifi_error);
}
return false;
}
public void onClick(DialogInterface dialog, int id) {
if(id == DialogInterface.BUTTON_POSITIVE ) {
setUpAccessPoint(true);
} else if (id == DialogInterface.BUTTON_NEGATIVE) {
dialog.dismiss();
mAlertDialog = null;
}
}
private void setUpAccessPoint(boolean enable) {
if (mWifiManager.setWifiApEnabled(null, enable)) {
mCheckBox.setEnabled(false);
} else {
mCheckBox.setSummary(R.string.wifi_error);
}
}
private void handleWifiApStateChanged(int state) {
switch (state) {
@@ -127,8 +94,11 @@ public class WifiApEnabler implements Preference.OnPreferenceChangeListener,
mCheckBox.setEnabled(false);
break;
case WifiManager.WIFI_AP_STATE_ENABLED:
/**
* Summary on enable is handled by tether
* broadcast notice
*/
mCheckBox.setChecked(true);
mCheckBox.setSummary(null);
mCheckBox.setEnabled(true);
break;
case WifiManager.WIFI_AP_STATE_DISABLING:

View File

@@ -30,6 +30,8 @@ import android.preference.CheckBoxPreference;
import android.provider.Settings;
import android.util.Log;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiManager;
import android.os.Bundle;
@@ -37,14 +39,17 @@ import android.os.Bundle;
* Displays preferences for Tethering.
*/
public class WifiApSettings extends PreferenceActivity
implements DialogInterface.OnClickListener, Preference.OnPreferenceChangeListener {
implements DialogInterface.OnClickListener {
private static final String WIFI_AP_SSID_AND_SECURITY = "wifi_ap_ssid_and_security";
private static final String WIFI_AP_CHANNEL = "wifi_ap_channel";
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 String[] mSecurityType;
private Preference mCreateNetwork;
private ListPreference mChannel;
private CheckBoxPreference mEnableWifiAp;
private WifiApDialog mDialog;
@@ -57,38 +62,26 @@ public class WifiApSettings extends PreferenceActivity
super.onCreate(savedInstanceState);
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
mWifiConfig = mWifiManager.getWifiApConfiguration();
mSecurityType = getResources().getStringArray(R.array.wifi_ap_security);
addPreferencesFromResource(R.xml.wifi_ap_settings);
mCreateNetwork = findPreference(WIFI_AP_SSID_AND_SECURITY);
mChannel = (ListPreference) findPreference(WIFI_AP_CHANNEL);
mEnableWifiAp = (CheckBoxPreference) findPreference(ENABLE_WIFI_AP);
mWifiApEnabler = new WifiApEnabler(this, mEnableWifiAp);
initChannels();
}
public void initChannels() {
mChannel.setOnPreferenceChangeListener(this);
int numChannels = mWifiManager.getNumAllowedChannels();
String[] entries = new String[numChannels];
String[] entryValues = new String[numChannels];
for (int i = 1; i <= numChannels; i++) {
entries[i-1] = "Channel "+i;
entryValues[i-1] = i+"";
if(mWifiConfig == null) {
String s = getString(com.android.internal.R.string.wifi_tether_configure_ssid_default);
mCreateNetwork.setSummary(String.format(getString(CONFIG_SUBTEXT),
s, mSecurityType[OPEN_INDEX]));
} else {
mCreateNetwork.setSummary(String.format(getString(CONFIG_SUBTEXT),
mWifiConfig.SSID,
mWifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK) ?
mSecurityType[WPA_INDEX] : mSecurityType[OPEN_INDEX]));
}
mChannel.setEntries(entries);
mChannel.setEntryValues(entryValues);
mChannel.setEnabled(true);
/**
* TODO: randomize initial channel chosen
*/
mChannel.setValue("2");
}
@Override
@@ -120,32 +113,15 @@ public class WifiApSettings extends PreferenceActivity
}
public void onClick(DialogInterface dialogInterface, int button) {
/**
* TODO: Needs work
*/
mWifiConfig = mDialog.getConfig();
if(mWifiConfig.SSID != null)
mCreateNetwork.setSummary(mWifiConfig.SSID);
/**
* TODO: set SSID and security
*/
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
/**
* TODO: Needs work
*/
String key = preference.getKey();
if (key == null) return true;
if (key.equals(WIFI_AP_CHANNEL)) {
int chosenChannel = Integer.parseInt((String) newValue);
if(newValue != null)
mChannel.setSummary(newValue.toString());
if (button == DialogInterface.BUTTON_POSITIVE && mWifiConfig != null) {
mWifiManager.setWifiApEnabled(mWifiConfig, true);
mCreateNetwork.setSummary(String.format(getString(CONFIG_SUBTEXT),
mWifiConfig.SSID,
mWifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK) ?
mSecurityType[WPA_INDEX] : mSecurityType[OPEN_INDEX]));
}
return true;
}
}