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> </string-array>
<!-- Wi-Fi AP settings. The type of security a Wi-Fi AP supports. --> <!-- 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"> <string-array name="wifi_ap_security" translatable="false">
<item>Open</item> <item>Open</item>
<!-- Do not translate. --> <!-- Do not translate. -->
<item>WEP</item> <item>WPA2 PSK</item>
<!-- Do not translate. -->
<item>WPA/WPA2 PSK</item>
</string-array> </string-array>
<!-- Match this with the constants in WifiDialog. --> <skip /> <!-- Match this with the constants in WifiDialog. --> <skip />

View File

@@ -28,11 +28,4 @@
android:title="@string/wifi_tether_configure_ap_text" android:title="@string/wifi_tether_configure_ap_text"
android:persistent="false" /> 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> </PreferenceScreen>

View File

@@ -26,6 +26,8 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiConfiguration;
import android.os.Environment; import android.os.Environment;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
@@ -54,6 +56,7 @@ public class TetherSettings extends PreferenceActivity {
private PreferenceScreen mWifiApSettings; private PreferenceScreen mWifiApSettings;
private WifiApEnabler mWifiApEnabler; private WifiApEnabler mWifiApEnabler;
private PreferenceScreen mTetherHelp; private PreferenceScreen mTetherHelp;
private WifiManager mWifiManager;
private BroadcastReceiver mTetherChangeReceiver; private BroadcastReceiver mTetherChangeReceiver;
@@ -76,6 +79,8 @@ public class TetherSettings extends PreferenceActivity {
ConnectivityManager cm = ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
mWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
mUsbRegexs = cm.getTetherableUsbRegexs(); mUsbRegexs = cm.getTetherableUsbRegexs();
if (mUsbRegexs.length == 0) { if (mUsbRegexs.length == 0) {
getPreferenceScreen().removePreference(mUsbTether); getPreferenceScreen().removePreference(mUsbTether);
@@ -221,6 +226,17 @@ public class TetherSettings extends PreferenceActivity {
mUsbTether.setEnabled(false); mUsbTether.setEnabled(false);
mUsbTether.setChecked(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 @Override

View File

@@ -49,6 +49,9 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
private final DialogInterface.OnClickListener mListener; private final DialogInterface.OnClickListener mListener;
private static final int OPEN_INDEX = 0;
private static final int WPA_INDEX = 1;
private View mView; private View mView;
private TextView mSsid; private TextView mSsid;
private int mSecurityType = AccessPoint.SECURITY_NONE; private int mSecurityType = AccessPoint.SECURITY_NONE;
@@ -76,22 +79,6 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
config.allowedKeyManagement.set(KeyMgmt.NONE); config.allowedKeyManagement.set(KeyMgmt.NONE);
return config; 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: case AccessPoint.SECURITY_PSK:
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK); config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN); config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
@@ -130,14 +117,18 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
if (mWifiConfig != null) { if (mWifiConfig != null) {
mSsid.setText(mWifiConfig.SSID); mSsid.setText(mWifiConfig.SSID);
switch (mSecurityType) { switch (mSecurityType) {
case AccessPoint.SECURITY_WEP: case AccessPoint.SECURITY_NONE:
mPassword.setText(mWifiConfig.wepKeys[0]); mSecurity.setSelection(OPEN_INDEX);
break; break;
case AccessPoint.SECURITY_PSK: 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; break;
} }
mSecurity.setSelection(mSecurityType);
} }
mSsid.addTextChangedListener(this); mSsid.addTextChangedListener(this);
@@ -153,7 +144,6 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
private void validate() { private void validate() {
if ((mSsid != null && mSsid.length() == 0) || if ((mSsid != null && mSsid.length() == 0) ||
(mSecurityType == AccessPoint.SECURITY_WEP && mPassword.length() == 0) ||
(mSecurityType == AccessPoint.SECURITY_PSK && mPassword.length() < 8)) { (mSecurityType == AccessPoint.SECURITY_PSK && mPassword.length() < 8)) {
getButton(BUTTON_SUBMIT).setEnabled(false); getButton(BUTTON_SUBMIT).setEnabled(false);
} else { } else {
@@ -179,7 +169,10 @@ class WifiApDialog extends AlertDialog implements View.OnClickListener,
} }
public void onItemSelected(AdapterView parent, View view, int position, long id) { 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(); showSecurityFields();
validate(); validate();
} }

View File

@@ -22,7 +22,6 @@ import com.android.settings.WirelessSettings;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.net.NetworkInfo; import android.net.NetworkInfo;
@@ -36,15 +35,13 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
public class WifiApEnabler implements Preference.OnPreferenceChangeListener, public class WifiApEnabler implements Preference.OnPreferenceChangeListener {
DialogInterface.OnClickListener {
private final Context mContext; private final Context mContext;
private final CheckBoxPreference mCheckBox; private final CheckBoxPreference mCheckBox;
private final CharSequence mOriginalSummary; private final CharSequence mOriginalSummary;
private final WifiManager mWifiManager; private WifiManager mWifiManager;
private final IntentFilter mIntentFilter; private final IntentFilter mIntentFilter;
private AlertDialog mAlertDialog = null;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() { private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override @Override
@@ -75,50 +72,20 @@ public class WifiApEnabler implements Preference.OnPreferenceChangeListener,
public void pause() { public void pause() {
mContext.unregisterReceiver(mReceiver); mContext.unregisterReceiver(mReceiver);
mCheckBox.setOnPreferenceChangeListener(null); mCheckBox.setOnPreferenceChangeListener(null);
if (mAlertDialog != null) {
mAlertDialog.dismiss();
mAlertDialog = null;
}
} }
public boolean onPreferenceChange(Preference preference, Object value) { public boolean onPreferenceChange(Preference preference, Object enable) {
boolean enable = (Boolean) value;
if (enable && mWifiManager.isWifiEnabled()) { if (mWifiManager.setWifiApEnabled(null, (Boolean)enable)) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext); /* Disable here, enabled on receiving success broadcast */
/** mCheckBox.setEnabled(false);
* 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();
} else { } else {
setUpAccessPoint(enable); mCheckBox.setSummary(R.string.wifi_error);
} }
return false; 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) { private void handleWifiApStateChanged(int state) {
switch (state) { switch (state) {
@@ -127,8 +94,11 @@ public class WifiApEnabler implements Preference.OnPreferenceChangeListener,
mCheckBox.setEnabled(false); mCheckBox.setEnabled(false);
break; break;
case WifiManager.WIFI_AP_STATE_ENABLED: case WifiManager.WIFI_AP_STATE_ENABLED:
/**
* Summary on enable is handled by tether
* broadcast notice
*/
mCheckBox.setChecked(true); mCheckBox.setChecked(true);
mCheckBox.setSummary(null);
mCheckBox.setEnabled(true); mCheckBox.setEnabled(true);
break; break;
case WifiManager.WIFI_AP_STATE_DISABLING: case WifiManager.WIFI_AP_STATE_DISABLING:

View File

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