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

Commit a15a4f0d authored by Amit Mahajan's avatar Amit Mahajan Committed by Gerrit Code Review
Browse files

Merge "Fix timezone cannot be updated automatically when no NITZ received"

parents e9f33e6f 41372b06
Loading
Loading
Loading
Loading
+38 −25
Original line number Diff line number Diff line
@@ -2860,31 +2860,7 @@ public class ServiceStateTracker extends Handler {

                if (!mNitzUpdatedTime && !mcc.equals("000") && !TextUtils.isEmpty(iso)
                        && getAutoTimeZone()) {

                    // Test both paths if ignore nitz is true
                    boolean testOneUniqueOffsetPath = SystemProperties.getBoolean(
                            TelephonyProperties.PROPERTY_IGNORE_NITZ, false)
                            && ((SystemClock.uptimeMillis() & 1) == 0);

                    List<String> uniqueZoneIds = TimeUtils.getTimeZoneIdsWithUniqueOffsets(iso);
                    if ((uniqueZoneIds.size() == 1) || testOneUniqueOffsetPath) {
                        String zoneId = uniqueZoneIds.get(0);
                        if (DBG) {
                            log("pollStateDone: no nitz but one TZ for iso-cc=" + iso
                                    + " with zone.getID=" + zoneId
                                    + " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath);
                        }
                        mTimeZoneLog.log("pollStateDone: set time zone=" + zoneId
                                + " mcc=" + mcc + " iso=" + iso);
                        setAndBroadcastNetworkSetTimeZone(zoneId);
                    } else {
                        if (DBG) {
                            log("pollStateDone: there are " + uniqueZoneIds.size()
                                    + " unique offsets for iso-cc='" + iso
                                    + " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath
                                    + "', do nothing");
                        }
                    }
                    updateTimeZoneByNetworkCountryCode(iso);
                }

                if (!mPhone.isPhoneTypeGsm()) {
@@ -3834,6 +3810,12 @@ public class ServiceStateTracker extends Handler {
        mTimeZoneLog.log(tmpLog);
        if (mSavedTimeZone != null) {
            setAndBroadcastNetworkSetTimeZone(mSavedTimeZone);
        } else {
            String iso = ((TelephonyManager) mPhone.getContext().getSystemService(
                    Context.TELEPHONY_SERVICE)).getNetworkCountryIsoForPhone(mPhone.getPhoneId());
            if (!TextUtils.isEmpty(iso)) {
                updateTimeZoneByNetworkCountryCode(iso);
            }
        }
    }

@@ -4990,4 +4972,35 @@ public class ServiceStateTracker extends Handler {
        }
        return regState;
    }

    /**
     * Update time zone by network country code, works on countries which only have one time zone.
     * @param iso Country code from network MCC
     */
    private void updateTimeZoneByNetworkCountryCode(String iso) {
        // Test both paths if ignore nitz is true
        boolean testOneUniqueOffsetPath = SystemProperties.getBoolean(
                TelephonyProperties.PROPERTY_IGNORE_NITZ, false)
                && ((SystemClock.uptimeMillis() & 1) == 0);

        List<String> uniqueZoneIds = TimeUtils.getTimeZoneIdsWithUniqueOffsets(iso);
        if ((uniqueZoneIds.size() == 1) || testOneUniqueOffsetPath) {
            String zoneId = uniqueZoneIds.get(0);
            if (DBG) {
                log("updateTimeZoneByNetworkCountryCode: no nitz but one TZ for iso-cc=" + iso
                        + " with zone.getID=" + zoneId
                        + " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath);
            }
            mTimeZoneLog.log("updateTimeZoneByNetworkCountryCode: set time zone=" + zoneId
                    + " iso=" + iso);
            setAndBroadcastNetworkSetTimeZone(zoneId);
        } else {
            if (DBG) {
                log("updateTimeZoneByNetworkCountryCode: there are " + uniqueZoneIds.size()
                        + " unique offsets for iso-cc='" + iso
                        + " testOneUniqueOffsetPath=" + testOneUniqueOffsetPath
                        + "', do nothing");
            }
        }
    }
}