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

Commit 1c1ffa0c authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

Promote MccTable to telephony and use it for both gsm/cdma

This adds timezone/locale/wifi-regulator-channels initialization to cdma (gsm already had it).

bug: 2071211
parent e1da8be5
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -54,8 +54,7 @@ public abstract class IccRecords extends Handler implements IccConstants {
    protected boolean isVoiceMailFixed = false;
    protected int countVoiceMessages = 0;

    protected int mncLength = 0;   // 0 is used to indicate that the value
                         // is not initialized
    protected int mncLength = UNINITIALIZED;
    protected int mailboxIndex = 0; // 0 is no mailbox dailing number associated

    protected String spn;
@@ -63,6 +62,10 @@ public abstract class IccRecords extends Handler implements IccConstants {

    // ***** Constants

    // Markers for mncLength
    protected static final int UNINITIALIZED = -1;
    protected static final int UNKNOWN = 0;

    // Bitmasks for SPN display rules.
    protected static final int SPN_RULE_SHOW_SPN  = 0x01;
    protected static final int SPN_RULE_SHOW_PLMN = 0x02;
@@ -234,4 +237,3 @@ public abstract class IccRecords extends Handler implements IccConstants {

    protected abstract void log(String s);
}
+106 −3
Original line number Diff line number Diff line
@@ -14,7 +14,17 @@
 * limitations under the License.
 */

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

import android.app.ActivityManagerNative;
import android.app.AlarmManager;
import android.content.Context;
import android.content.res.Configuration;
import android.net.wifi.WifiManager;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Log;

import java.util.Arrays;

@@ -475,8 +485,10 @@ public final class MccTable
        0x65630400, 0x67660400, 0x70790400, 0x73720400, 0x75790400, 0x666b0400
    };

    static final String LOG_TAG = "MccTable";

    /**
     * Given a GSM Mobile Country Code, returns a default time zone ID
     * Given a Mobile Country Code, returns a default time zone ID
     * if available.  Returns null if unavailable.
     */
    public static String defaultTimeZoneForMcc(int mcc) {
@@ -494,7 +506,7 @@ public final class MccTable
    }

    /**
     * Given a GSM Mobile Country Code, returns an ISO two-character
     * Given a Mobile Country Code, returns an ISO two-character
     * country code if available.  Returns "" if unavailable.
     */
    public static String countryCodeForMcc(int mcc) {
@@ -553,4 +565,95 @@ public final class MccTable
        return wifi;
    }

    /**
     * Updates MCC and MNC device configuration information for application retrieving
     * correct version of resources.  If either MCC or MNC is 0, they will be ignored (not set).
     * @param phone PhoneBae to act on.
     * @param mccmnc truncated imsi with just the MCC and MNC - MNC assumed to be from 4th to end
     */
    public static void updateMccMncConfiguration(PhoneBase phone, String mccmnc) {
        Configuration config = new Configuration();
        int mcc, mnc;

        try {
            mcc = Integer.parseInt(mccmnc.substring(0,3));
            mnc = Integer.parseInt(mccmnc.substring(3));
        } catch (NumberFormatException e) {
            Log.e(LOG_TAG, "Error parsing IMSI");
            return;
        }

        Log.d(LOG_TAG, "updateMccMncConfiguration: mcc=" + mcc + ", mnc=" + mnc);

        if (mcc != 0) {
            config.mcc = mcc;
            setTimezoneFromMccIfNeeded(phone, mcc);
            setLocaleFromMccIfNeeded(phone, mcc);
            setWifiChannelsFromMccIfNeeded(phone, mcc);
        }
        if (mnc != 0) {
            config.mnc = mnc;
        }
        try {
            ActivityManagerNative.getDefault().updateConfiguration(config);
        } catch (RemoteException e) {
            Log.e(LOG_TAG, "Can't update configuration", e);
        }
    }

    /**
     * If the timezone is not already set, set it based on the MCC of the SIM.
     * @param phone PhoneBase to act on (get context from).
     * @param mcc Mobile Country Code of the SIM or SIM-like entity (build prop on CDMA)
     */
    private static void setTimezoneFromMccIfNeeded(PhoneBase phone, int mcc) {
        String timezone = SystemProperties.get(ServiceStateTracker.TIMEZONE_PROPERTY);
        if (timezone == null || timezone.length() == 0) {
            String zoneId = defaultTimeZoneForMcc(mcc);
            if (zoneId != null && zoneId.length() > 0) {
                Context context = phone.getContext();
                // Set time zone based on MCC
                AlarmManager alarm =
                        (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                alarm.setTimeZone(zoneId);
                Log.d(LOG_TAG, "timezone set to "+zoneId);
            }
        }
    }

    /**
     * If the locale is not already set, set it based on the MCC of the SIM.
     * @param phone PhoneBase to act on.
     * @param mcc Mobile Country Code of the SIM or SIM-like entity (build prop on CDMA)
     */
    private static void setLocaleFromMccIfNeeded(PhoneBase phone, int mcc) {
        String language = MccTable.defaultLanguageForMcc(mcc);
        String country = MccTable.countryCodeForMcc(mcc);

        Log.d(LOG_TAG, "locale set to "+language+"_"+country);
        phone.setSystemLocale(language, country);
    }

    /**
     * If the number of allowed wifi channels has not been set, set it based on
     * the MCC of the SIM.
     * @param phone PhoneBase to act on (get context from).
     * @param mcc Mobile Country Code of the SIM or SIM-like entity (build prop on CDMA)
     */
    private static void setWifiChannelsFromMccIfNeeded(PhoneBase phone, int mcc) {
        int wifiChannels = MccTable.wifiChannelsForMcc(mcc);
        if (wifiChannels != 0) {
            Context context = phone.getContext();
            // only set to this default if the user hasn't manually set it
            try {
                Settings.Secure.getInt(context.getContentResolver(),
                        Settings.Secure.WIFI_NUM_ALLOWED_CHANNELS);
            } catch (Settings.SettingNotFoundException e) {
                Log.d(LOG_TAG, "WIFI_NUM_ALLOWED_CHANNESL set to " + wifiChannels);
                WifiManager wM = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                // don't persist
                wM.setNumAllowedChannels(wifiChannels, false);
            }
        }
    }
}
+2 −22
Original line number Diff line number Diff line
@@ -48,10 +48,7 @@ import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.DataConnection;
// TODO(Moto): need to move MccTable from telephony.gsm to telephony
// since there is no difference between CDMA and GSM for MccTable and
// CDMA uses gsm's MccTable is not good.
import com.android.internal.telephony.gsm.MccTable;
import com.android.internal.telephony.MccTable;
import com.android.internal.telephony.IccCard;
import com.android.internal.telephony.IccException;
import com.android.internal.telephony.IccFileHandler;
@@ -203,7 +200,7 @@ public class CDMAPhone extends PhoneBase {
        updateCurrentCarrierInProvider(operatorNumeric);

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


        // Notify voicemails.
@@ -1406,21 +1403,4 @@ public class CDMAPhone extends PhoneBase {
        return false;
    }

    /**
     * Updates MCC and MNC device configuration information for application retrieving
     * correct version of resources
     *
     */
    private void updateMccMncConfiguration(String operatorNumeric) {
        if (operatorNumeric.length() >= 5) {
            Configuration config = new Configuration();
            config.mcc = Integer.parseInt(operatorNumeric.substring(0,3));
            config.mnc = Integer.parseInt(operatorNumeric.substring(3));
            try {
                ActivityManagerNative.getDefault().updateConfiguration(config);
            } catch (RemoteException e) {
                Log.e(LOG_TAG, "Can't update configuration", e);
            }
        }
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -45,9 +45,8 @@ import android.util.TimeUtils;
import com.android.internal.telephony.CommandException;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.DataConnectionTracker;
import com.android.internal.telephony.gsm.MccTable;
import com.android.internal.telephony.IccCard;
import com.android.internal.telephony.PhoneProxy;
import com.android.internal.telephony.MccTable;
import com.android.internal.telephony.ServiceStateTracker;
import com.android.internal.telephony.TelephonyEventLog;
import com.android.internal.telephony.TelephonyIntents;
+5 −5
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import com.android.internal.telephony.AdnRecordLoader;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.TelephonyProperties;
import com.android.internal.telephony.cdma.RuimCard;
import com.android.internal.telephony.gsm.MccTable;
import com.android.internal.telephony.MccTable;

// can't be used since VoiceMailConstants is not public
//import com.android.internal.telephony.gsm.VoiceMailConstants;
@@ -109,7 +109,7 @@ public final class RuimRecords extends IccRecords {
    @Override
    protected void onRadioOffOrNotAvailable() {
        countVoiceMessages = 0;
        mncLength = 0;
        mncLength = UNINITIALIZED;
        iccid = null;

        adnCache.reset();
@@ -167,7 +167,7 @@ public final class RuimRecords extends IccRecords {
        }

        // TODO(Moto): mncLength is not set anywhere.
        if (mncLength != 0) {
        if (mncLength != UNINITIALIZED && mncLength != UNKNOWN) {
            // Length = length of MCC + length of MNC
            // TODO: change spec name
            // length of mcc = 3 (3GPP2 C.S0005 - Section 2.3)
Loading