Revert "Stop using the sim mnc/mcc to set wifi country."
Robert Greenwalt [Thu, 3 Oct 2013 21:14:32 +0000 (21:14 +0000)]
This reverts commit 78d801a78087b6a2419f0820628d0273df53203f.

bug:11064682
Change-Id: I46f5b90de417636d03bfa5932684f0ace68a3f6e

src/java/com/android/internal/telephony/MccTable.java
src/java/com/android/internal/telephony/PhoneBase.java

index d14f10d..c4dd08d 100644 (file)
@@ -190,6 +190,7 @@ public final class MccTable
             if (mcc != 0) {
                 setTimezoneFromMccIfNeeded(context, mcc);
                 setLocaleFromMccIfNeeded(context, mcc);
+                setWifiCountryCodeFromMcc(context, mcc);
             }
             try {
                 Configuration config = ActivityManagerNative.getDefault().getConfiguration();
@@ -294,6 +295,22 @@ public final class MccTable
         setSystemLocale(context, language, country);
     }
 
+    /**
+     * If the number of allowed wifi channels has not been set, set it based on
+     * the MCC of the SIM.
+     * @param context Context to act on.
+     * @param mcc Mobile Country Code of the SIM or SIM-like entity (build prop on CDMA)
+     */
+    private static void setWifiCountryCodeFromMcc(Context context, int mcc) {
+        String country = MccTable.countryCodeForMcc(mcc);
+        if (!country.isEmpty()) {
+            Rlog.d(LOG_TAG, "WIFI_COUNTRY_CODE set to " + country);
+            WifiManager wM = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+            //persist
+            wM.setCountryCode(country, true);
+        }
+    }
+
     static {
         sTable = new ArrayList<MccEntry>(240);
 
index 3aa23ce..2a047c2 100644 (file)
@@ -709,6 +709,18 @@ public abstract class PhoneBase extends Handler implements Phone {
                     country = l.substring(3, 5);
                 }
                 MccTable.setSystemLocale(mContext, language, country);
+
+                if (!country.isEmpty()) {
+                    try {
+                        Settings.Global.getInt(mContext.getContentResolver(),
+                                Settings.Global.WIFI_COUNTRY_CODE);
+                    } catch (Settings.SettingNotFoundException e) {
+                        // note this is not persisting
+                        WifiManager wM = (WifiManager)
+                                mContext.getSystemService(Context.WIFI_SERVICE);
+                        wM.setCountryCode(country, false);
+                    }
+                }
                 return;
             }
         }