From 795acaa8b79d8b60cc334db0149cadd2f4ffddf4 Mon Sep 17 00:00:00 2001 From: Andrew Dodd Date: Wed, 12 Sep 2012 21:59:20 -0400 Subject: wifi: Allow configuration of country code for wifi Wifi country code handling is a nightmare - Most retail devices have region customization in /system for each country a device is shipped to. This doesn't work very well for a firmware like Cyanogenmod, where we try to support all target countries with one firmware package. For whatever reason, with newer Broadcom drivers/ firmware blobs, the old trick of using a universal region code (ccode=ALL in nvram_net.txt) does not seem to work. Who knows what the deal is for other wifi chipsets. The good thing is that wpa_supplicant has a standardized cross-chipset method for setting the region code, and we use that here. Change-Id: Ia9f5133f61f56d89ccb290e37a393f5de507e1cf --- .../settings/wifi/AdvancedWifiSettings.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') diff --git a/src/com/android/settings/wifi/AdvancedWifiSettings.java b/src/com/android/settings/wifi/AdvancedWifiSettings.java index 809496a..99b2f10 100644 --- a/src/com/android/settings/wifi/AdvancedWifiSettings.java +++ b/src/com/android/settings/wifi/AdvancedWifiSettings.java @@ -42,6 +42,7 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment 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_FREQUENCY_BAND = "frequency_band"; + private static final String KEY_COUNTRY_CODE = "wifi_countrycode"; private static final String KEY_NOTIFY_OPEN_NETWORKS = "notify_open_networks"; private static final String KEY_SLEEP_POLICY = "sleep_policy"; private static final String KEY_POOR_NETWORK_DETECTION = "wifi_poor_network_detection"; @@ -110,6 +111,17 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment } } + ListPreference ccodePref = (ListPreference) findPreference(KEY_COUNTRY_CODE); + if (ccodePref != null) { + ccodePref.setOnPreferenceChangeListener(this); + String value = mWifiManager.getCountryCode(); + if (value != null) { + ccodePref.setValue(value); + } else { + Log.e(TAG, "Failed to fetch country code"); + } + } + ListPreference sleepPolicyPref = (ListPreference) findPreference(KEY_SLEEP_POLICY); if (sleepPolicyPref != null) { if (Utils.isWifiOnly(getActivity())) { @@ -181,6 +193,16 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment } } + if (KEY_COUNTRY_CODE.equals(key)) { + try { + mWifiManager.setCountryCode((String) newValue, true); + } catch (IllegalArgumentException e) { + Toast.makeText(getActivity(), R.string.wifi_setting_countrycode_error, + Toast.LENGTH_SHORT).show(); + return false; + } + } + if (KEY_SLEEP_POLICY.equals(key)) { try { String stringValue = (String) newValue; -- cgit v1.1