Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0b637db authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Switch from SIM to carrier info for wifi country

Now will also inform when no known country too.

bug:11062898
Change-Id: I4a938119c1c06898b39b3bcc6124031d2f66dd71
parent fb36cdca
Loading
Loading
Loading
Loading
+40 −30
Original line number Original line Diff line number Diff line
@@ -171,8 +171,10 @@ public final class MccTable
     * correct version of resources.  If MCC is 0, MCC and MNC will be ignored (not set).
     * correct version of resources.  If MCC is 0, MCC and MNC will be ignored (not set).
     * @param context Context to act on.
     * @param context Context to act on.
     * @param mccmnc truncated imsi with just the MCC and MNC - MNC assumed to be from 4th to end
     * @param mccmnc truncated imsi with just the MCC and MNC - MNC assumed to be from 4th to end
     * @param fromServiceState true if coming from the radio service state, false if from SIM
     */
     */
    public static void updateMccMncConfiguration(Context context, String mccmnc) {
    public static void updateMccMncConfiguration(Context context, String mccmnc,
            boolean fromServiceState) {
        if (!TextUtils.isEmpty(mccmnc)) {
        if (!TextUtils.isEmpty(mccmnc)) {
            int mcc, mnc;
            int mcc, mnc;


@@ -190,8 +192,11 @@ public final class MccTable
            if (mcc != 0) {
            if (mcc != 0) {
                setTimezoneFromMccIfNeeded(context, mcc);
                setTimezoneFromMccIfNeeded(context, mcc);
                locale = getLocaleFromMcc(context, mcc);
                locale = getLocaleFromMcc(context, mcc);
                setWifiCountryCodeFromMcc(context, mcc);
            }
            }
            if (fromServiceState) {
                setWifiCountryCodeFromMcc(context, mcc);
            } else {
                // from SIM
                try {
                try {
                    Configuration config = new Configuration();
                    Configuration config = new Configuration();
                    boolean updateConfig = false;
                    boolean updateConfig = false;
@@ -214,6 +219,12 @@ public final class MccTable
                    Slog.e(LOG_TAG, "Can't update configuration", e);
                    Slog.e(LOG_TAG, "Can't update configuration", e);
                }
                }
            }
            }
        } else {
            if (fromServiceState) {
                // an empty mccmnc means no signal - tell wifi we don't know
                setWifiCountryCodeFromMcc(context, 0);
            }
        }
    }
    }


    /**
    /**
@@ -342,20 +353,19 @@ public final class MccTable
    }
    }


    /**
    /**
     * If the number of allowed wifi channels has not been set, set it based on
     * Set the country code for wifi.  This sets allowed wifi channels based on the
     * the MCC of the SIM.
     * country of the carrier we see.  If we can't see any, reset to 0 so we don't
     * broadcast on forbidden channels.
     * @param context Context to act on.
     * @param context Context to act on.
     * @param mcc Mobile Country Code of the SIM or SIM-like entity (build prop on CDMA)
     * @param mcc Mobile Country Code of the operator.  0 if not known
     */
     */
    private static void setWifiCountryCodeFromMcc(Context context, int mcc) {
    private static void setWifiCountryCodeFromMcc(Context context, int mcc) {
        String country = MccTable.countryCodeForMcc(mcc);
        String country = MccTable.countryCodeForMcc(mcc);
        if (!country.isEmpty()) {
        Slog.d(LOG_TAG, "WIFI_COUNTRY_CODE set to " + country);
        Slog.d(LOG_TAG, "WIFI_COUNTRY_CODE set to " + country);
        WifiManager wM = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiManager wM = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        //persist
        //persist
        wM.setCountryCode(country, true);
        wM.setCountryCode(country, true);
    }
    }
    }


    static {
    static {
        sTable = new ArrayList<MccEntry>(240);
        sTable = new ArrayList<MccEntry>(240);
+10 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.internal.telephony;
package com.android.internal.telephony;


import android.content.Context;
import android.os.AsyncResult;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
@@ -25,6 +26,7 @@ import android.os.SystemClock;
import android.telephony.CellInfo;
import android.telephony.CellInfo;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SignalStrength;
import android.text.TextUtils;
import android.util.Pair;
import android.util.Pair;
import android.util.TimeUtils;
import android.util.TimeUtils;


@@ -791,4 +793,12 @@ public abstract class ServiceStateTracker extends Handler {
        if (VDBG) log("isCallerOnDifferentThread: " + value);
        if (VDBG) log("isCallerOnDifferentThread: " + value);
        return value;
        return value;
    }
    }

    protected void updateCarrierMccMncConfiguration(String newOp, String oldOp, Context context) {
        // if we have a change in operator, notify wifi (even to/from none)
        if (((newOp == null) && (TextUtils.isEmpty(oldOp) == false)) ||
                ((newOp != null) && (newOp.equals(oldOp) == false))) {
            MccTable.updateMccMncConfiguration(context, newOp, true);
        }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -1580,7 +1580,7 @@ public class CDMAPhone extends PhoneBase {
                getContext().getContentResolver().insert(uri, map);
                getContext().getContentResolver().insert(uri, map);


                // Updates MCC MNC device configuration information
                // Updates MCC MNC device configuration information
                MccTable.updateMccMncConfiguration(mContext, operatorNumeric);
                MccTable.updateMccMncConfiguration(mContext, operatorNumeric, false);


                return true;
                return true;
            } catch (SQLException e) {
            } catch (SQLException e) {
+2 −0
Original line number Original line Diff line number Diff line
@@ -406,6 +406,8 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
                    SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
                    SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
            operatorNumeric = mSS.getOperatorNumeric();
            operatorNumeric = mSS.getOperatorNumeric();
            mPhone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);
            mPhone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);
            updateCarrierMccMncConfiguration(operatorNumeric,
                    prevOperatorNumeric, mPhone.getContext());


            if (operatorNumeric == null) {
            if (operatorNumeric == null) {
                if (DBG) log("operatorNumeric is null");
                if (DBG) log("operatorNumeric is null");
+2 −1
Original line number Original line Diff line number Diff line
@@ -1070,7 +1070,8 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
                    SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
                    SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
            operatorNumeric = mSS.getOperatorNumeric();
            operatorNumeric = mSS.getOperatorNumeric();
            mPhone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);
            mPhone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);

            updateCarrierMccMncConfiguration(operatorNumeric,
                    prevOperatorNumeric, mPhone.getContext());
            if (operatorNumeric == null) {
            if (operatorNumeric == null) {
                if (DBG) log("operatorNumeric is null");
                if (DBG) log("operatorNumeric is null");
                mPhone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
                mPhone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
Loading