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

Commit 41372b06 authored by yifan.bai's avatar yifan.bai Committed by Yifan Bai
Browse files

Fix timezone cannot be updated automatically when no NITZ received

When no NITZ received, timezone can be updated by mobile country code.
This procedure is in pollStateDone method and only happens when network 
changed. So if user manually changed timezone then turn on AutoTimezone 
Setting and network is stable, timezone cannot be automatically updated.

To fix, when turn on auto timezone setting, if there is no NITZ timezone
, immediately update timezone by country code.

Test: Build pass
parent 7c121bee
Loading
Loading
Loading
Loading
+38 −25
Original line number Original line Diff line number Diff line
@@ -2866,31 +2866,7 @@ public class ServiceStateTracker extends Handler {


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

                    updateTimeZoneByNetworkCountryCode(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("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");
                        }
                    }
                }
                }


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


@@ -4995,4 +4977,35 @@ public class ServiceStateTracker extends Handler {
        }
        }
        return regState;
        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");
            }
        }
    }
}
}