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

Commit c8ce0435 authored by Neil Fuller's avatar Neil Fuller
Browse files

Correct a misunderstanding of the NITZ spec

The NITZ spec doesn't give units for the DST offset
component of the full offset. It turns out the value
can only be for one or two hours which apparently
is taken literally as "number of hours", not specified
in quarter hours like the full offset.

The actual value is not used anywhere currently: we
just check for "was the value provided" and "is value
!= 0". This means that the logic won't change, just
the absolute value / scaling value is being corrected
and logcat will show correct information.

Bug: 112043518
Test: atest com.android.internal.telephony.NitzDataTest
Test: atest com.android.internal.telephony.TimeZoneLookupHelperTest
Change-Id: I1d40225641aa8406090d19cba7d679294067c206
parent c5b8de5c
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import java.util.TimeZone;
public final class NitzData {
    private static final String LOG_TAG = ServiceStateTracker.LOG_TAG;
    private static final int MS_PER_QUARTER_HOUR = 15 * 60 * 1000;
    private static final int MS_PER_HOUR = 60 * 60 * 1000;

    /* Time stamp after 19 January 2038 is not supported under 32 bit */
    private static final int MAX_NITZ_YEAR = 2037;
@@ -111,11 +112,11 @@ public final class NitzData {

            // DST correction is already applied to the UTC offset. We could subtract it if we
            // wanted the raw offset.
            Integer dstAdjustmentQuarterHours =
            Integer dstAdjustmentHours =
                    (nitzSubs.length >= 8) ? Integer.parseInt(nitzSubs[7]) : null;
            Integer dstAdjustmentMillis = null;
            if (dstAdjustmentQuarterHours != null) {
                dstAdjustmentMillis = dstAdjustmentQuarterHours * MS_PER_QUARTER_HOUR;
            if (dstAdjustmentHours != null) {
                dstAdjustmentMillis = dstAdjustmentHours * MS_PER_HOUR;
            }

            // As a special extension, the Android emulator appends the name of
+6 −9
Original line number Diff line number Diff line
@@ -53,19 +53,17 @@ public class NitzDataTest {
            assertNull(nitz.getEmulatorHostTimeZone());
        }
        {
            NitzData nitz = NitzData.parse("15/06/20,01:02:03+8,4");
            NitzData nitz = NitzData.parse("15/06/20,01:02:03+8,1");
            assertEquals(createUtcTime(2015, 6, 20, 1, 2, 3), nitz.getCurrentTimeInMillis());
            assertEquals(TimeUnit.MINUTES.toMillis(8 * 15), nitz.getLocalOffsetMillis());
            assertEquals(TimeUnit.MINUTES.toMillis(4 * 15),
                    nitz.getDstAdjustmentMillis().longValue());
            assertEquals(TimeUnit.HOURS.toMillis(1), nitz.getDstAdjustmentMillis().longValue());
            assertNull(nitz.getEmulatorHostTimeZone());
        }
        {
            NitzData nitz = NitzData.parse("15/06/20,01:02:03-8,4");
            NitzData nitz = NitzData.parse("15/06/20,01:02:03-8,1");
            assertEquals(createUtcTime(2015, 6, 20, 1, 2, 3), nitz.getCurrentTimeInMillis());
            assertEquals(TimeUnit.MINUTES.toMillis(-8 * 15), nitz.getLocalOffsetMillis());
            assertEquals(TimeUnit.MINUTES.toMillis(4 * 15),
                    nitz.getDstAdjustmentMillis().longValue());
            assertEquals(TimeUnit.HOURS.toMillis(1), nitz.getDstAdjustmentMillis().longValue());
            assertNull(nitz.getEmulatorHostTimeZone());
        }
    }
@@ -90,11 +88,10 @@ public class NitzDataTest {

    @Test
    public void testParse_androidEmulatorTimeZoneExtension() {
        NitzData nitz = NitzData.parse("15/06/20,01:02:03-32,4,America!Los_Angeles");
        NitzData nitz = NitzData.parse("15/06/20,01:02:03-32,1,America!Los_Angeles");
        assertEquals(createUtcTime(2015, 6, 20, 1, 2, 3), nitz.getCurrentTimeInMillis());
        assertEquals(TimeUnit.MINUTES.toMillis(-32 * 15), nitz.getLocalOffsetMillis());
        assertEquals(TimeUnit.MINUTES.toMillis(4 * 15),
                nitz.getDstAdjustmentMillis().longValue());
        assertEquals(TimeUnit.HOURS.toMillis(1), nitz.getDstAdjustmentMillis().longValue());
        assertEquals("America/Los_Angeles", nitz.getEmulatorHostTimeZone().getID());
    }

+1 −1
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ public class TimeZoneLookupHelperTest {

        // Summer, known DST state (DST == true).
        {
            String summerTimeNitzStringWithDst = summerTimeNitzString + ",4";
            String summerTimeNitzStringWithDst = summerTimeNitzString + ",1";
            NitzData nitzData = NitzData.parse(summerTimeNitzStringWithDst);
            int expectedUtcOffset = (int) TimeUnit.HOURS.toMillis(2);
            Integer expectedDstOffset = (int) TimeUnit.HOURS.toMillis(1);