OSDN Git Service

wifi: Allow configuration of country code for wifi
authorAndrew Dodd <atd7@cornell.edu>
Thu, 13 Sep 2012 01:59:20 +0000 (21:59 -0400)
committerDan Pasanen <dan.pasanen@gmail.com>
Tue, 14 Feb 2017 17:01:24 +0000 (11:01 -0600)
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.

Cherry-Pick: https://review.cyanogenmod.org/#/c/119667/

JIRA: CML-118

Change-Id: Ia9f5133f61f56d89ccb290e37a393f5de507e1cf

res/values/cm_arrays.xml
res/values/cm_strings.xml
res/xml/wifi_advanced_settings.xml
src/com/android/settings/wifi/AdvancedWifiSettings.java

index 00d8bc1..476b1c2 100644 (file)
         <item>600000</item>
     </string-array>
 
+    <!-- Wi-Fi settings. Presented as a list dialog to the user to choose the Wi-Fi region code. -->
+    <string-array name="wifi_countrycode_entries">
+        <item>United States</item>
+        <item>Canada, Taiwan</item>
+        <item>Germany</item>
+        <item>Europe</item>
+        <item>Japan, Russia</item>
+        <item>Australia</item>
+        <item>China</item>
+        <item>Korea</item>
+        <item>South Africa, Turkey</item>
+        <item>Israel, Singapore</item>
+        <item>Brazil</item>
+        <item>India</item>
+    </string-array>
+
+    <string-array name="wifi_countrycode_values" translatable="false">
+        <item>US</item>
+        <item>CA</item>
+        <item>DE</item>
+        <item>GB</item>
+        <item>JP</item>
+        <item>AU</item>
+        <item>CN</item>
+        <item>KR</item>
+        <item>TR</item>
+        <item>SG</item>
+        <item>BR</item>
+        <item>IN</item>
+    </string-array>
 </resources>
index b5caecf..83dae88 100644 (file)
     <string name="security_settings_fingerprint_sensor_location_left">left side</string>
     <string name="security_settings_fingerprint_sensor_location_right">right side</string>
 
+    <!-- Wi-Fi region code -->
+    <string name="wifi_setting_countrycode_title">Wi\u2011Fi region code</string>
+    <!-- Wi-Fi settings screen, setting summary for setting the wifi frequency band [CHAR LIMIT=50]-->
+    <string name="wifi_setting_countrycode_summary">Specify the region code for Wi\u2011Fi</string>
+    <!-- Wi-Fi settings screen, error message when the frequency band could not be set [CHAR LIMIT=50]. -->
+    <string name="wifi_setting_countrycode_error">There was a problem setting the region code.</string>
+
     <!-- Wake on plug -->
     <string name="wake_when_plugged_or_unplugged_title">Wake on plug</string>
     <string name="wake_when_plugged_or_unplugged_summary">Turn the screen on when connecting or disconnecting a power source</string>
index 2fb5967..757dd5a 100755 (executable)
             android:summary="@string/notify_connect_summary"
             android:persistent="false"/>
 
+    <ListPreference
+            android:key="wifi_countrycode"
+            android:title="@string/wifi_setting_countrycode_title"
+            android:summary="@string/wifi_setting_countrycode_summary"
+            android:persistent="false"
+            android:entries="@array/wifi_countrycode_entries"
+            android:entryValues="@array/wifi_countrycode_values" />
+
     <Preference
             android:key="install_credentials"
             android:title="@string/wifi_install_credentials"
index 00608c7..86dd067 100644 (file)
@@ -20,6 +20,7 @@ import android.app.Dialog;
 import android.app.DialogFragment;
 import android.content.Context;
 import android.content.Intent;
+import android.net.wifi.WifiManager;
 import android.net.wifi.WpsInfo;
 import android.os.Bundle;
 import android.os.UserManager;
@@ -56,6 +57,8 @@ public class AdvancedWifiSettings extends RestrictedSettingsFragment
 
     private static final String KEY_PRIORITY_SETTINGS = "wifi_priority_settings";
 
+    private static final String KEY_COUNTRY_CODE = "wifi_countrycode";
+
     private static final String KEY_AUTO_CONNECT_ENABLE = "auto_connect_type";
     private static final String WIFI_AUTO_CONNECT_TYPE = "wifi_auto_connect_type";
     private static final int AUTO_CONNECT_ENABLED = 0;
@@ -86,6 +89,7 @@ public class AdvancedWifiSettings extends RestrictedSettingsFragment
     private ListPreference mCellularToWlanPref;
 
     private boolean mUnavailable;
+    private WifiManager mWifiManager;
 
     public AdvancedWifiSettings() {
         super(UserManager.DISALLOW_CONFIG_WIFI);
@@ -113,6 +117,8 @@ public class AdvancedWifiSettings extends RestrictedSettingsFragment
         getEmptyTextView().setText(R.string.wifi_advanced_not_available);
         if (mUnavailable) {
             getPreferenceScreen().removeAll();
+        } else {
+            mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
         }
     }
 
@@ -191,6 +197,17 @@ public class AdvancedWifiSettings extends RestrictedSettingsFragment
             Log.d(TAG, "Fail to get priority pref...");
         }
 
+        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");
+            }
+        }
+
         mAutoConnectEnablePref =
                 (CheckBoxPreference) findPreference(KEY_AUTO_CONNECT_ENABLE);
         if (mAutoConnectEnablePref != null) {
@@ -274,6 +291,16 @@ public class AdvancedWifiSettings extends RestrictedSettingsFragment
         final Context context = getActivity();
         String key = preference.getKey();
 
+        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_WLAN_TO_CELLULAR_HINT.equals(key)) {
             boolean checked = ((Boolean) newValue).booleanValue();
             setWlanToCellularHintEnable(checked);