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

Commit dd7bdb0a authored by Wink Saville's avatar Wink Saville Committed by Android (Google) Code Review
Browse files

Merge "Fix phone is sometimes in America/Dawson canadian time zone"

parents 84d5e219 335ef479
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.telephony.ServiceState;
import android.telephony.cdma.CdmaCellLocation;
import android.os.AsyncResult;
import android.os.Message;
import android.os.SystemProperties;
import android.provider.Telephony.Intents;

import android.text.TextUtils;
@@ -370,14 +371,23 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
            phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA,
                    ss.getOperatorAlphaLong());

            String prevOperatorNumeric =
                    SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
            operatorNumeric = ss.getOperatorNumeric();
            phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);

            if (operatorNumeric == null) {
                if (DBG) {
                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
                            " prevOperatorNumeric=" + prevOperatorNumeric +
                            " mNeedFixZone=" + mNeedFixZone +
                            " clear PROPERTY_OPERATOR_ISO_COUNTRY");
                }
                phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
                mGotCountryCode = false;
            } else {
                String isoCountryCode = "";
                String mcc = operatorNumeric.substring(0, 3);
                try {
                    isoCountryCode = MccTable.countryCodeForMcc(Integer.parseInt(operatorNumeric
                            .substring(0, 3)));
@@ -386,11 +396,20 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
                } catch (StringIndexOutOfBoundsException ex) {
                    loge("countryCodeForMcc error" + ex);
                }
                if (DBG) {
                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
                            " prevOperatorNumeric=" + prevOperatorNumeric +
                            " mNeedFixZone=" + mNeedFixZone +
                            " mcc=" + mcc + " iso-cc=" + isoCountryCode);
                }

                phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY,
                        isoCountryCode);
                mGotCountryCode = true;
                if (mNeedFixZone) {

                // Fix the time zone If the operator changed or we need to fix it because
                // when the NITZ time came in we didn't know the country code.
                if ( ! operatorNumeric.equals(prevOperatorNumeric) || mNeedFixZone) {
                    fixTimeZone(isoCountryCode);
                }
            }
+42 −6
Original line number Diff line number Diff line
@@ -866,6 +866,12 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
        // If the offset is (0, false) and the time zone property
        // is set, use the time zone property rather than GMT.
        String zoneName = SystemProperties.get(TIMEZONE_PROPERTY);
        if (DBG) {
            log("fixTimeZone zoneName='" + zoneName +
                "' mZoneOffset=" + mZoneOffset + " mZoneDst=" + mZoneDst +
                " iso-cc='" + isoCountryCode +
                "' iso-cc-idx=" + Arrays.binarySearch(GMT_COUNTRY_CODES, isoCountryCode));
        }
        if ((mZoneOffset == 0) && (mZoneDst == false) && (zoneName != null)
                && (zoneName.length() > 0)
                && (Arrays.binarySearch(GMT_COUNTRY_CODES, isoCountryCode) < 0)) {
@@ -880,19 +886,25 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
                // Adjust the saved NITZ time to account for tzOffset.
                mSavedTime = mSavedTime - tzOffset;
            }
            if (DBG) log("fixTimeZone: using default TimeZone");
        } else if (isoCountryCode.equals("")) {
            // Country code not found. This is likely a test network.
            // Get a TimeZone based only on the NITZ parameters (best guess).
            zone = getNitzTimeZone(mZoneOffset, mZoneDst, mZoneTime);
            if (DBG) log("fixTimeZone: using NITZ TimeZone");
        } else {
            zone = TimeUtils.getTimeZone(mZoneOffset, mZoneDst, mZoneTime, isoCountryCode);
            if (DBG) log("fixTimeZone: using getTimeZone(off, dst, time, iso)");
        }

        mNeedFixZone = false;

        if (zone != null) {
            log("fixTimeZone: zone != null zone.getID=" + zone.getID());
            if (getAutoTimeZone()) {
                setAndBroadcastNetworkSetTimeZone(zone.getID());
            } else {
                log("fixTimeZone: zone == null");
            }
            saveNitzTimeZone(zone.getID());
        }
@@ -985,14 +997,23 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
            phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA,
                    ss.getOperatorAlphaLong());

            String prevOperatorNumeric =
                    SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
            operatorNumeric = ss.getOperatorNumeric();
            phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);

            if (operatorNumeric == null) {
                if (DBG) {
                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
                            " prevOperatorNumeric=" + prevOperatorNumeric +
                            " mNeedFixZone=" + mNeedFixZone +
                            " clear PROPERTY_OPERATOR_ISO_COUNTRY");
                }
                phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
                mGotCountryCode = false;
            } else {
                String isoCountryCode = "";
                String mcc = operatorNumeric.substring(0, 3);
                try{
                    isoCountryCode = MccTable.countryCodeForMcc(Integer.parseInt(
                            operatorNumeric.substring(0,3)));
@@ -1001,11 +1022,20 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
                } catch ( StringIndexOutOfBoundsException ex) {
                    loge("pollStateDone: countryCodeForMcc error" + ex);
                }
                if (DBG) {
                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
                            " prevOperatorNumeric=" + prevOperatorNumeric +
                            " mNeedFixZone=" + mNeedFixZone +
                            " mcc=" + mcc + " iso-cc=" + isoCountryCode);
                }

                phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY,
                        isoCountryCode);
                mGotCountryCode = true;
                if (mNeedFixZone) {

                // Fix the time zone If the operator changed or we need to fix it because
                // when the NITZ time came in we didn't know the country code.
                if ( ! operatorNumeric.equals(prevOperatorNumeric) || mNeedFixZone) {
                    fixTimeZone(isoCountryCode);
                }
            }
@@ -1316,7 +1346,6 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
            String iso = SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY);

            if (zone == null) {

                if (mGotCountryCode) {
                    if (iso != null && iso.length() > 0) {
                        zone = TimeUtils.getTimeZone(tzOffset, dst != 0,
@@ -1332,16 +1361,21 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
                }
            }

            if (zone == null) {
                // We got the time before the country, so we don't know
                // how to identify the DST rules yet.  Save the information
                // and hope to fix it up later.
            if ((zone == null) || (mZoneOffset != tzOffset) || (mZoneDst != (dst != 0))){
                // We got the time before the country or the zone has changed
                // so we don't know how to identify the DST rules yet.  Save
                // the information and hope to fix it up later.

                mNeedFixZone = true;
                mZoneOffset  = tzOffset;
                mZoneDst     = dst != 0;
                mZoneTime    = c.getTimeInMillis();
            }
            if (DBG) {
                log("NITZ: tzOffset=" + tzOffset + " dst=" + dst + " zone=" + zone.getID() +
                        " iso=" + iso + " mGotCountryCode=" + mGotCountryCode +
                        " mNeedFixZone=" + mNeedFixZone);
            }

            if (zone != null) {
                if (getAutoTimeZone()) {
@@ -1461,6 +1495,7 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
     * @param zoneId timezone set by carrier
     */
    private void setAndBroadcastNetworkSetTimeZone(String zoneId) {
        if (DBG) log("setAndBroadcastNetworkSetTimeZone: setTimeZone=" + zoneId);
        AlarmManager alarm =
            (AlarmManager) phone.getContext().getSystemService(Context.ALARM_SERVICE);
        alarm.setTimeZone(zoneId);
@@ -1477,6 +1512,7 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
     * @param time time set by network
     */
    private void setAndBroadcastNetworkSetTime(long time) {
        if (DBG) log("setAndBroadcastNetworkSetTime: time=" + time + "ms");
        SystemClock.setCurrentTimeMillis(time);
        Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIME);
        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
+21 −20
Original line number Diff line number Diff line
@@ -852,12 +852,16 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
            phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA,
                ss.getOperatorAlphaLong());

            String prevOperatorNumeric =
                    SystemProperties.get(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, "");
            operatorNumeric = ss.getOperatorNumeric();
            phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, operatorNumeric);

            if (operatorNumeric == null) {
                if (DBG) {
                    log("pollStateDone: operatorNumeric is null:" +
                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
                            " prevOperatorNumeric=" + prevOperatorNumeric +
                            " mNeedFixZone=" + mNeedFixZone +
                            " clear PROPERTY_OPERATOR_ISO_COUNTRY");
                }
                phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
@@ -875,7 +879,9 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                }
                if (DBG) {
                    log("pollStateDone: operatorNumeric=" + operatorNumeric +
                            " mcc=" + mcc + " iso=" + iso);
                            " prevOperatorNumeric=" + prevOperatorNumeric +
                            " mNeedFixZone=" + mNeedFixZone +
                            " mcc=" + mcc + " iso-cc=" + iso);
                }

                phone.setSystemProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso);
@@ -895,7 +901,7 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                    if ((uniqueZones.size() == 1) || testOneUniqueOffsetPath) {
                        zone = uniqueZones.get(0);
                        if (DBG) {
                           log("pollStateDone: no nitz but one TZ for iso=" + iso +
                           log("pollStateDone: no nitz but one TZ for iso-cc=" + iso +
                                   " with zone.getID=" + zone.getID() +
                                   " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath);
                        }
@@ -903,22 +909,24 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                    } else {
                        if (DBG) {
                            log("pollStateDone: there are " + uniqueZones.size() +
                                " unique offsets for iso='" + iso +
                                " unique offsets for iso-cc='" + iso +
                                " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath +
                                "', do nothing");
                        }
                    }
                }

                if (mNeedFixZone) {
                // Fix the time zone If the operator changed or we need to fix it because
                // when the NITZ time came in we didn't know the country code.
                if ( ! operatorNumeric.equals(prevOperatorNumeric) || mNeedFixZone) {
                    // If the offset is (0, false) and the timezone property
                    // is set, use the timezone property rather than
                    // GMT.
                    String zoneName = SystemProperties.get(TIMEZONE_PROPERTY);
                    if (DBG) {
                        log("pollStateDone: mNeedFixZone==true zoneName='" + zoneName +
                        log("pollStateDone: fix time zone zoneName='" + zoneName +
                            "' mZoneOffset=" + mZoneOffset + " mZoneDst=" + mZoneDst +
                            " iso='" + iso +
                            " iso-cc='" + iso +
                            "' iso-cc-idx=" + Arrays.binarySearch(GMT_COUNTRY_CODES, iso));
                    }
                    if ((mZoneOffset == 0) && (mZoneDst == false) &&
@@ -957,15 +965,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                    } else {
                        log("pollStateDone: zone == null");
                    }
                } else {
                    if (DBG) {
                        String zoneName = SystemProperties.get(TIMEZONE_PROPERTY);
                        zone = TimeZone.getDefault();
                        log("pollStateDone: mNeedFixZone==false zoneName='" + zoneName +
                                "' mZoneOffset=" + mZoneOffset + " mZoneDst=" + mZoneDst +
                                " iso='" + iso +
                                "' iso-cc-idx=" + Arrays.binarySearch(GMT_COUNTRY_CODES, iso));
                    }
                }
            }

@@ -1442,10 +1441,10 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                }
            }

            if (zone == null) {
                // We got the time before the country, so we don't know
                // how to identify the DST rules yet.  Save the information
                // and hope to fix it up later.
            if ((zone == null) || (mZoneOffset != tzOffset) || (mZoneDst != (dst != 0))){
                // We got the time before the country or the zone has changed
                // so we don't know how to identify the DST rules yet.  Save
                // the information and hope to fix it up later.

                mNeedFixZone = true;
                mZoneOffset  = tzOffset;
@@ -1556,6 +1555,7 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
     * @param zoneId timezone set by carrier
     */
    private void setAndBroadcastNetworkSetTimeZone(String zoneId) {
        if (DBG) log("setAndBroadcastNetworkSetTimeZone: setTimeZone=" + zoneId);
        AlarmManager alarm =
            (AlarmManager) phone.getContext().getSystemService(Context.ALARM_SERVICE);
        alarm.setTimeZone(zoneId);
@@ -1576,6 +1576,7 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
     * @param time time set by network
     */
    private void setAndBroadcastNetworkSetTime(long time) {
        if (DBG) log("setAndBroadcastNetworkSetTime: time=" + time + "ms");
        SystemClock.setCurrentTimeMillis(time);
        Intent intent = new Intent(TelephonyIntents.ACTION_NETWORK_SET_TIME);
        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);