Add frequency band control in UI

Change-Id: I5a9fa46af358f363b2fe80a8ba7599d13dea5eb7
This commit is contained in:
Irfan Sheriff
2010-11-04 13:45:32 -07:00
parent 38f8a1d0fa
commit fa37a755b5
4 changed files with 70 additions and 6 deletions

View File

@@ -318,6 +318,28 @@
<item>2</item> <item>2</item>
</string-array> </string-array>
<!-- Wi-Fi settings. Presented as a list dialog to the user to choose the Wi-Fi frequency band. -->
<string-array name="wifi_frequency_band_entries">
<!-- Operation on both 2.4 GHz and 5 GHz [CHAR LIMIT=25]-->
<item>Auto</item>
<!-- Operation on 5 GHz alone [CHAR LIMIT=25]-->
<item>5 GHz only</item>
<!-- Operation on 2.4 GHz alone [CHAR LIMIT=25]-->
<item>2.4 GHz only</item>
</string-array>
<!-- Match with wifi_frequency_band_entries and the values of the settings in WifiManager. -->
<!-- Do not translate. -->
<string-array name="wifi_frequency_band_values">
<!-- Do not translate. -->
<item>0</item>
<!-- Do not translate. -->
<item>1</item>
<!-- Do not translate. -->
<item>2</item>
</string-array>
<!-- Display options for UsageStats class --> <!-- Display options for UsageStats class -->
<string-array name="usage_stats_display_order_types"> <string-array name="usage_stats_display_order_types">
<item>Usage Time</item> <item>Usage Time</item>

View File

@@ -1025,6 +1025,12 @@
<string name="wifi_setting_sleep_policy_summary">Specify when to switch from Wi-Fi to mobile data</string> <string name="wifi_setting_sleep_policy_summary">Specify when to switch from Wi-Fi to mobile data</string>
<!-- Wi-Fi settings screen, generic error message when the sleep policy could not be set. --> <!-- Wi-Fi settings screen, generic error message when the sleep policy could not be set. -->
<string name="wifi_setting_sleep_policy_error">There was a problem setting the sleep policy.</string> <string name="wifi_setting_sleep_policy_error">There was a problem setting the sleep policy.</string>
<!-- Wi-Fi settings screen, setting title for setting the band [CHAR LIMIT=50]-->
<string name="wifi_setting_frequency_band_title">Wi-Fi frequency band</string>
<!-- Wi-Fi settings screen, setting summary for setting the wifi frequency band [CHAR LIMIT=50]-->
<string name="wifi_setting_frequency_band_summary">Specify the frequency range of operation</string>
<!-- Wi-Fi settings screen, error message when the frequency band could not be set [CHAR LIMIT=50]. -->
<string name="wifi_setting_frequency_band_error">There was a problem setting the frequency band.</string>
<!-- Wi-Fi settings screen, advanced, title of the item to show the Wi-Fi device's MAC address. --> <!-- Wi-Fi settings screen, advanced, title of the item to show the Wi-Fi device's MAC address. -->
<string name="wifi_advanced_mac_address_title">MAC address</string> <string name="wifi_advanced_mac_address_title">MAC address</string>
<!-- Title of the screen to adjust IP settings --> <!-- Title of the screen to adjust IP settings -->

View File

@@ -25,6 +25,15 @@
android:entries="@array/wifi_sleep_policy_entries" android:entries="@array/wifi_sleep_policy_entries"
android:entryValues="@array/wifi_sleep_policy_values" android:entryValues="@array/wifi_sleep_policy_values"
/> />
<ListPreference
android:key="frequency_band"
android:title="@string/wifi_setting_frequency_band_title"
android:summary="@string/wifi_setting_frequency_band_summary"
android:persistent="false"
android:entries="@array/wifi_frequency_band_entries"
android:entryValues="@array/wifi_frequency_band_values"
/>
<Preference android:key="mac_address" <Preference android:key="mac_address"
style="?android:attr/preferenceInformationStyle" style="?android:attr/preferenceInformationStyle"

View File

@@ -20,6 +20,7 @@ import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
@@ -29,13 +30,18 @@ import android.preference.Preference;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.Toast; import android.widget.Toast;
import android.util.Log;
public class AdvancedSettings extends SettingsPreferenceFragment public class AdvancedSettings extends SettingsPreferenceFragment
implements Preference.OnPreferenceChangeListener { implements Preference.OnPreferenceChangeListener {
private static final String TAG = "AdvancedSettings";
private static final String KEY_MAC_ADDRESS = "mac_address"; private static final String KEY_MAC_ADDRESS = "mac_address";
private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address"; private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address";
private static final String KEY_SLEEP_POLICY = "sleep_policy"; private static final String KEY_SLEEP_POLICY = "sleep_policy";
private static final String KEY_FREQUENCY_BAND = "frequency_band";
private WifiManager mWifiManager;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@@ -46,22 +52,36 @@ public class AdvancedSettings extends SettingsPreferenceFragment
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
initPreferences();
initSleepPolicyPreference();
refreshWifiInfo(); refreshWifiInfo();
} }
private void initSleepPolicyPreference() { private void initPreferences() {
ListPreference pref = (ListPreference) findPreference(KEY_SLEEP_POLICY); ListPreference pref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
pref.setOnPreferenceChangeListener(this); pref.setOnPreferenceChangeListener(this);
int value = Settings.System.getInt(getContentResolver(), int value = Settings.System.getInt(getContentResolver(),
Settings.System.WIFI_SLEEP_POLICY,Settings. System.WIFI_SLEEP_POLICY_DEFAULT); Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
pref.setValue(String.valueOf(value)); pref.setValue(String.valueOf(value));
pref = (ListPreference) findPreference(KEY_FREQUENCY_BAND);
if (mWifiManager.isDualBandSupported()) {
pref.setOnPreferenceChangeListener(this);
value = mWifiManager.getFrequencyBand();
if (value != -1) {
pref.setValue(String.valueOf(value));
} else {
Log.e(TAG, "Failed to fetch frequency band");
}
} else {
getPreferenceScreen().removePreference(pref);
}
} }
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
@@ -77,14 +97,21 @@ public class AdvancedSettings extends SettingsPreferenceFragment
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
return false; return false;
} }
} else if (key.equals(KEY_FREQUENCY_BAND)) {
try {
mWifiManager.setFrequencyBand(Integer.parseInt(((String) newValue)), true);
} catch (NumberFormatException e) {
Toast.makeText(getActivity(), R.string.wifi_setting_frequency_band_error,
Toast.LENGTH_SHORT).show();
return false;
}
} }
return true; return true;
} }
private void refreshWifiInfo() { private void refreshWifiInfo() {
WifiManager wifiManager = (WifiManager) getSystemService(Activity.WIFI_SERVICE); WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS); Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress(); String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();