Code drop from //branches/cupcake/...@124589
This commit is contained in:
@@ -25,6 +25,7 @@ import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.Formatter;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.text.method.TransformationMethod;
|
||||
import android.util.Log;
|
||||
@@ -303,7 +304,7 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
}
|
||||
|
||||
if (mState.primary && mState.ipAddress != 0) {
|
||||
addInfoRow(R.string.ip_address, ipAddressToString(mState.ipAddress));
|
||||
addInfoRow(R.string.ip_address, Formatter.formatIpAddress(mState.ipAddress));
|
||||
}
|
||||
|
||||
} else if (mMode == MODE_CONFIGURE) {
|
||||
@@ -579,14 +580,6 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static String ipAddressToString(int addr) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(addr & 0xff).append('.').
|
||||
append((addr >>>= 8) & 0xff).append('.').
|
||||
append((addr >>>= 8) & 0xff).append('.').
|
||||
append((addr >>>= 8) & 0xff);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
if (v == mShowPasswordCheckBox) {
|
||||
|
@@ -538,7 +538,13 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
|
||||
// If password is empty, it should be left untouched
|
||||
if (!TextUtils.isEmpty(mPassword)) {
|
||||
config.preSharedKey = convertToQuotedString(mPassword);
|
||||
if (mPassword.length() == 64 && isHex(mPassword)) {
|
||||
// Goes unquoted as hex
|
||||
config.preSharedKey = mPassword;
|
||||
} else {
|
||||
// Goes quoted as ASCII
|
||||
config.preSharedKey = convertToQuotedString(mPassword);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (security.equals(OPEN)) {
|
||||
@@ -554,8 +560,12 @@ public final class AccessPointState implements Comparable<AccessPointState>, Par
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = len - 1; i >= 0; i--) {
|
||||
final char c = wepKey.charAt(i);
|
||||
return isHex(wepKey);
|
||||
}
|
||||
|
||||
private static boolean isHex(String key) {
|
||||
for (int i = key.length() - 1; i >= 0; i--) {
|
||||
final char c = key.charAt(i);
|
||||
if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -19,12 +19,16 @@ package com.android.settings.wifi;
|
||||
import com.android.settings.R;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.provider.Settings.System;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@@ -32,8 +36,10 @@ import android.widget.Toast;
|
||||
|
||||
public class IpSettings extends PreferenceActivity implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String KEY_MAC_ADDRESS = "mac_address";
|
||||
private static final String KEY_USE_STATIC_IP = "use_static_ip";
|
||||
|
||||
private static final String KEY_NUM_CHANNELS = "num_channels";
|
||||
|
||||
private String[] mSettingNames = {
|
||||
System.WIFI_STATIC_IP, System.WIFI_STATIC_GATEWAY, System.WIFI_STATIC_NETMASK,
|
||||
System.WIFI_STATIC_DNS1, System.WIFI_STATIC_DNS2
|
||||
@@ -61,12 +67,46 @@ public class IpSettings extends PreferenceActivity implements Preference.OnPrefe
|
||||
preference.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
updateUi();
|
||||
initNumChannelsPreference();
|
||||
refreshMacAddress();
|
||||
}
|
||||
|
||||
private void initNumChannelsPreference() {
|
||||
ListPreference pref = (ListPreference) findPreference(KEY_NUM_CHANNELS);
|
||||
pref.setOnPreferenceChangeListener(this);
|
||||
|
||||
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||
/*
|
||||
* Generate the list of valid channel counts to show in the ListPreference.
|
||||
* The values are numerical, so the only text to be localized is the
|
||||
* "channel_word" resource.
|
||||
*/
|
||||
int[] validChannelCounts = wifiManager.getValidChannelCounts();
|
||||
if (validChannelCounts == null) {
|
||||
Toast.makeText(this, R.string.wifi_setting_num_channels_error,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
String[] entries = new String[validChannelCounts.length];
|
||||
String[] entryValues = new String[validChannelCounts.length];
|
||||
|
||||
for (int i = 0; i < validChannelCounts.length; i++) {
|
||||
entryValues[i] = String.valueOf(validChannelCounts[i]);
|
||||
entries[i] = getString(R.string.wifi_setting_num_channels_channel_phrase,
|
||||
validChannelCounts[i]);
|
||||
}
|
||||
pref.setEntries(entries);
|
||||
pref.setEntryValues(entryValues);
|
||||
int numChannels = wifiManager.getNumAllowedChannels();
|
||||
if (numChannels >= 0) {
|
||||
pref.setValue(String.valueOf(numChannels));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,14 +120,34 @@ public class IpSettings extends PreferenceActivity implements Preference.OnPrefe
|
||||
}
|
||||
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String value = (String) newValue;
|
||||
|
||||
if (!isIpAddress(value)) {
|
||||
Toast.makeText(this, R.string.wifi_ip_settings_invalid_ip, Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
String key = preference.getKey();
|
||||
if (key == null) return true;
|
||||
|
||||
if (key.equals(KEY_NUM_CHANNELS)) {
|
||||
try {
|
||||
int numChannels = Integer.parseInt((String) newValue);
|
||||
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||
if (!wifiManager.setNumAllowedChannels(numChannels)) {
|
||||
Toast.makeText(this, R.string.wifi_setting_num_channels_error,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(this, R.string.wifi_setting_num_channels_error,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
String value = (String) newValue;
|
||||
|
||||
if (!isIpAddress(value)) {
|
||||
Toast.makeText(this, R.string.wifi_ip_settings_invalid_ip, Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
preference.setSummary(value);
|
||||
}
|
||||
|
||||
preference.setSummary(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -177,4 +237,14 @@ public class IpSettings extends PreferenceActivity implements Preference.OnPrefe
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshMacAddress() {
|
||||
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
|
||||
Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
|
||||
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
|
||||
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
|
||||
: getString(R.string.status_unavailable));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -94,7 +94,7 @@ public class WifiLayer {
|
||||
private boolean mIsObtainingAddress;
|
||||
|
||||
/**
|
||||
* See {@link Settings.System#WIFI_NUM_OPEN_NETWORKS_KEPT}.
|
||||
* See {@link android.provider.Settings.Secure#WIFI_NUM_OPEN_NETWORKS_KEPT}.
|
||||
*/
|
||||
private int WIFI_NUM_OPEN_NETWORKS_KEPT;
|
||||
/**
|
||||
@@ -229,8 +229,8 @@ public class WifiLayer {
|
||||
mIntentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
|
||||
mIntentFilter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION);
|
||||
|
||||
WIFI_NUM_OPEN_NETWORKS_KEPT = Settings.System.getInt(mContext.getContentResolver(),
|
||||
Settings.System.WIFI_NUM_OPEN_NETWORKS_KEPT, 10);
|
||||
WIFI_NUM_OPEN_NETWORKS_KEPT = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -134,8 +134,8 @@ public class WifiSettings extends PreferenceActivity implements WifiLayer.Callba
|
||||
|
||||
mOpenNetworkNotificationsEnabled = (CheckBoxPreference) preferenceScreen
|
||||
.findPreference(KEY_OPEN_NETWORK_NOTIFICATIONS_ENABLED);
|
||||
mOpenNetworkNotificationsEnabled.setChecked(Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
|
||||
mOpenNetworkNotificationsEnabled.setChecked(Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
|
||||
|
||||
mAddOtherNetwork = preferenceScreen.findPreference(KEY_ADD_OTHER_NETWORK);
|
||||
|
||||
@@ -323,9 +323,9 @@ public class WifiSettings extends PreferenceActivity implements WifiLayer.Callba
|
||||
if (preference == mAddOtherNetwork) {
|
||||
showAddOtherNetworkDialog();
|
||||
} else if (preference == mOpenNetworkNotificationsEnabled) {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
|
||||
mOpenNetworkNotificationsEnabled.isChecked() ? 1 : 0);
|
||||
Settings.Secure.putInt(getContentResolver(),
|
||||
Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
|
||||
mOpenNetworkNotificationsEnabled.isChecked() ? 1 : 0);
|
||||
} else if (preference instanceof AccessPointPreference) {
|
||||
AccessPointState state = ((AccessPointPreference) preference).getAccessPointState();
|
||||
showAccessPointDialog(state, AccessPointDialog.MODE_INFO);
|
||||
|
Reference in New Issue
Block a user