Search in sources :

Example 6 with OffsetResult

use of android.timezone.CountryTimeZones.OffsetResult in project android_frameworks_opt_telephony by LineageOS.

the class NitzStateMachineTestSupportTest method test_nonUniqueUs_assumptions.

@Test
public void test_nonUniqueUs_assumptions() {
    // Check we'll get the expected behavior from TimeZoneLookupHelper.
    // quality == QUALITY_MULTIPLE_ZONES_DIFFERENT_OFFSETS, therefore the country's default zone
    // shouldn't be considered a good match.
    CountryResult expectedCountryLookupResult = new CountryResult(US_COUNTRY_DEFAULT_ZONE_ID, QUALITY_MULTIPLE_ZONES_DIFFERENT_OFFSETS, ARBITRARY_DEBUG_INFO);
    CountryResult actualCountryLookupResult = mTimeZoneLookupHelper.lookupByCountry(NON_UNIQUE_US_ZONE_SCENARIO.getNetworkCountryIsoCode(), ARBITRARY_SYSTEM_CLOCK_TIME);
    assertEquals(expectedCountryLookupResult, actualCountryLookupResult);
    // By definition, there are multiple matching zones for the NON_UNIQUE_US_ZONE_SCENARIO.
    {
        OffsetResult actualLookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(NON_UNIQUE_US_ZONE_SCENARIO.createNitzData(), NON_UNIQUE_US_ZONE_SCENARIO.getNetworkCountryIsoCode());
        List<String> possibleZones = Arrays.asList(NON_UNIQUE_US_ZONE_SCENARIO_ZONES);
        assertTrue(possibleZones.contains(actualLookupResult.getTimeZone().getID()));
        assertFalse(actualLookupResult.isOnlyMatch());
    }
}
Also used : CountryResult(com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult) List(java.util.List) OffsetResult(android.timezone.CountryTimeZones.OffsetResult) Test(org.junit.Test)

Example 7 with OffsetResult

use of android.timezone.CountryTimeZones.OffsetResult in project android_frameworks_opt_telephony by LineageOS.

the class NitzStateMachineTestSupportTest method test_unitedKingdom_assumptions.

@Test
public void test_unitedKingdom_assumptions() {
    assertEquals(UNITED_KINGDOM_SCENARIO.getTimeZone().getID(), UNITED_KINGDOM_COUNTRY_DEFAULT_ZONE_ID);
    // Check we'll get the expected behavior from TimeZoneLookupHelper.
    // quality == QUALITY_SINGLE_ZONE, so the default zone is a good match.
    CountryResult expectedCountryLookupResult = new CountryResult(UNITED_KINGDOM_COUNTRY_DEFAULT_ZONE_ID, QUALITY_SINGLE_ZONE, ARBITRARY_DEBUG_INFO);
    CountryResult actualCountryLookupResult = mTimeZoneLookupHelper.lookupByCountry(UNITED_KINGDOM_SCENARIO.getNetworkCountryIsoCode(), ARBITRARY_SYSTEM_CLOCK_TIME);
    assertEquals(expectedCountryLookupResult, actualCountryLookupResult);
    // isOnlyMatch == true, so the combination of country + NITZ should be enough for a match.
    OffsetResult expectedLookupResult = new OffsetResult(UNITED_KINGDOM_SCENARIO.getTimeZone(), true);
    OffsetResult actualLookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(UNITED_KINGDOM_SCENARIO.createNitzData(), UNITED_KINGDOM_SCENARIO.getNetworkCountryIsoCode());
    assertEquals(expectedLookupResult, actualLookupResult);
}
Also used : CountryResult(com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult) OffsetResult(android.timezone.CountryTimeZones.OffsetResult) Test(org.junit.Test)

Example 8 with OffsetResult

use of android.timezone.CountryTimeZones.OffsetResult in project android_frameworks_opt_telephony by LineageOS.

the class TimeZoneLookupHelperTest method testLookupByNitzCountry_dstKnownAndUnknown.

@Test
public void testLookupByNitzCountry_dstKnownAndUnknown() {
    // Historical dates are used to avoid the test breaking due to data changes.
    // However, algorithm updates may change the exact time zone returned, though it shouldn't
    // ever be a less exact match.
    long nhSummerTimeMillis = createUtcTime(2015, 6, 20, 1, 2, 3);
    long nhWinterTimeMillis = createUtcTime(2015, 1, 20, 1, 2, 3);
    // A country in the northern hemisphere with one time zone.
    // Andora
    String adIso = "AD";
    // 2015-06-20 01:02:03 UTC, UTC+2
    String summerTimeNitzString = "15/06/20,01:02:03+8";
    // 2015-01-20 01:02:03 UTC, UTC+1
    String winterTimeNitzString = "15/01/20,01:02:03+4";
    // Summer, known & correct DST state (DST == true).
    {
        String summerTimeNitzStringWithDst = summerTimeNitzString + ",1";
        NitzData nitzData = NitzData.parse(summerTimeNitzStringWithDst);
        int expectedUtcOffset = (int) TimeUnit.HOURS.toMillis(2);
        Integer expectedDstOffset = (int) TimeUnit.HOURS.toMillis(1);
        assertEquals(expectedUtcOffset, nitzData.getLocalOffsetMillis());
        assertEquals(expectedDstOffset, nitzData.getDstAdjustmentMillis());
        OffsetResult adSummerWithDstResult = mTimeZoneLookupHelper.lookupByNitzCountry(nitzData, adIso);
        OffsetResult expectedResult = new OffsetResult(zone("Europe/Andorra"), true);
        assertEquals(expectedResult, adSummerWithDstResult);
        assertOffsetResultZoneOffsets(nhSummerTimeMillis, expectedUtcOffset, expectedDstOffset, adSummerWithDstResult);
    }
    // Summer, known & incorrect DST state (DST == false)
    {
        String summerTimeNitzStringWithNoDst = summerTimeNitzString + ",0";
        NitzData nitzData = NitzData.parse(summerTimeNitzStringWithNoDst);
        OffsetResult adSummerWithNoDstResult = mTimeZoneLookupHelper.lookupByNitzCountry(nitzData, adIso);
        assertNull(adSummerWithNoDstResult);
    }
    // Winter, known & correct DST state (DST == false)
    {
        String winterTimeNitzStringWithNoDst = winterTimeNitzString + ",0";
        NitzData nitzData = NitzData.parse(winterTimeNitzStringWithNoDst);
        int expectedUtcOffset = (int) TimeUnit.HOURS.toMillis(1);
        Integer expectedDstOffset = 0;
        assertEquals(expectedUtcOffset, nitzData.getLocalOffsetMillis());
        assertEquals(expectedDstOffset, nitzData.getDstAdjustmentMillis());
        OffsetResult adWinterWithDstResult = mTimeZoneLookupHelper.lookupByNitzCountry(nitzData, adIso);
        OffsetResult expectedResult = new OffsetResult(zone("Europe/Andorra"), true);
        assertEquals(expectedResult, adWinterWithDstResult);
        assertOffsetResultZoneOffsets(nhWinterTimeMillis, expectedUtcOffset, expectedDstOffset, adWinterWithDstResult);
    }
    // Winter, known & incorrect DST state (DST == true)
    {
        String winterTimeNitzStringWithDst = winterTimeNitzString + ",1";
        NitzData nitzData = NitzData.parse(winterTimeNitzStringWithDst);
        OffsetResult adWinterWithDstResult = mTimeZoneLookupHelper.lookupByNitzCountry(nitzData, adIso);
        assertNull(adWinterWithDstResult);
    }
    // Summer, unknown DST state (will match any DST state with the correct offset).
    {
        NitzData nitzData = NitzData.parse(summerTimeNitzString);
        int expectedUtcOffset = (int) TimeUnit.HOURS.toMillis(2);
        // Unknown
        Integer expectedDstOffset = null;
        assertEquals(expectedUtcOffset, nitzData.getLocalOffsetMillis());
        assertEquals(expectedDstOffset, nitzData.getDstAdjustmentMillis());
        OffsetResult adSummerUnknownDstResult = mTimeZoneLookupHelper.lookupByNitzCountry(nitzData, adIso);
        OffsetResult expectedResult = new OffsetResult(zone("Europe/Andorra"), true);
        assertEquals(expectedResult, adSummerUnknownDstResult);
        assertOffsetResultZoneOffsets(nhSummerTimeMillis, expectedUtcOffset, expectedDstOffset, adSummerUnknownDstResult);
    }
    // Winter, unknown DST state (will match any DST state with the correct offset)
    {
        NitzData nitzData = NitzData.parse(winterTimeNitzString);
        int expectedUtcOffset = (int) TimeUnit.HOURS.toMillis(1);
        // Unknown
        Integer expectedDstOffset = null;
        assertEquals(expectedUtcOffset, nitzData.getLocalOffsetMillis());
        assertEquals(expectedDstOffset, nitzData.getDstAdjustmentMillis());
        OffsetResult adWinterUnknownDstResult = mTimeZoneLookupHelper.lookupByNitzCountry(nitzData, adIso);
        OffsetResult expectedResult = new OffsetResult(zone("Europe/Andorra"), true);
        assertEquals(expectedResult, adWinterUnknownDstResult);
        assertOffsetResultZoneOffsets(nhWinterTimeMillis, expectedUtcOffset, expectedDstOffset, adWinterUnknownDstResult);
    }
}
Also used : NitzData(com.android.internal.telephony.NitzData) OffsetResult(android.timezone.CountryTimeZones.OffsetResult) Test(org.junit.Test)

Example 9 with OffsetResult

use of android.timezone.CountryTimeZones.OffsetResult in project android_frameworks_opt_telephony by LineageOS.

the class TimeZoneLookupHelperTest method testDefaultBoostBehavior.

@Test
public void testDefaultBoostBehavior() {
    long timeMillis = createUtcTime(2015, 6, 20, 1, 2, 3);
    // An example known to be explicitly boosted. New Zealand has two zones but the vast
    // majority of the population use one of them so Android's data file explicitly boosts the
    // country default. If that changes in future this test will need to be changed to use
    // another example.
    String countryIsoCode = "nz";
    CountryResult expectedResult = new CountryResult("Pacific/Auckland", QUALITY_DEFAULT_BOOSTED, ARBITRARY_DEBUG_INFO);
    assertEquals(expectedResult, mTimeZoneLookupHelper.lookupByCountry(countryIsoCode, timeMillis));
    // Data correct for the North and South Island.
    int majorityWinterOffset = (int) TimeUnit.HOURS.toMillis(12);
    NitzData majorityNitzData = NitzData.createForTests(majorityWinterOffset, 0, timeMillis, null);
    // Boost doesn't directly affect lookupByNitzCountry()
    OffsetResult majorityOffsetResult = mTimeZoneLookupHelper.lookupByNitzCountry(majorityNitzData, countryIsoCode);
    assertEquals(zone("Pacific/Auckland"), majorityOffsetResult.getTimeZone());
    assertTrue(majorityOffsetResult.isOnlyMatch());
    // Data correct for the Chatham Islands.
    int chathamWinterOffset = majorityWinterOffset + ((int) TimeUnit.MINUTES.toMillis(45));
    NitzData chathamNitzData = NitzData.createForTests(chathamWinterOffset, 0, timeMillis, null);
    OffsetResult chathamOffsetResult = mTimeZoneLookupHelper.lookupByNitzCountry(chathamNitzData, countryIsoCode);
    assertEquals(zone("Pacific/Chatham"), chathamOffsetResult.getTimeZone());
    assertTrue(chathamOffsetResult.isOnlyMatch());
    // NITZ data that makes no sense for NZ results in no match.
    int nonsenseOffset = (int) TimeUnit.HOURS.toMillis(5);
    NitzData nonsenseNitzData = NitzData.createForTests(nonsenseOffset, 0, timeMillis, null);
    OffsetResult nonsenseOffsetResult = mTimeZoneLookupHelper.lookupByNitzCountry(nonsenseNitzData, countryIsoCode);
    assertNull(nonsenseOffsetResult);
}
Also used : CountryResult(com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult) NitzData(com.android.internal.telephony.NitzData) OffsetResult(android.timezone.CountryTimeZones.OffsetResult) Test(org.junit.Test)

Example 10 with OffsetResult

use of android.timezone.CountryTimeZones.OffsetResult in project android_frameworks_opt_telephony by LineageOS.

the class TimeZoneLookupHelperTest method testNoDefaultBoostBehavior.

@Test
public void testNoDefaultBoostBehavior() {
    long timeMillis = createUtcTime(2015, 6, 20, 1, 2, 3);
    // An example known to not be explicitly boosted. Micronesia is spread out and there's no
    // suitable default.
    String countryIsoCode = "fm";
    CountryResult expectedResult = new CountryResult("Pacific/Pohnpei", QUALITY_MULTIPLE_ZONES_DIFFERENT_OFFSETS, ARBITRARY_DEBUG_INFO);
    assertEquals(expectedResult, mTimeZoneLookupHelper.lookupByCountry(countryIsoCode, timeMillis));
    // Prove an OffsetResult can be found with the correct offset.
    int chuukWinterOffset = (int) TimeUnit.HOURS.toMillis(10);
    NitzData chuukNitzData = NitzData.createForTests(chuukWinterOffset, 0, timeMillis, null);
    OffsetResult chuukOffsetResult = mTimeZoneLookupHelper.lookupByNitzCountry(chuukNitzData, countryIsoCode);
    assertEquals(zone("Pacific/Chuuk"), chuukOffsetResult.getTimeZone());
    assertTrue(chuukOffsetResult.isOnlyMatch());
    // NITZ data that makes no sense for FM: no boost means we should get nothing.
    int nonsenseOffset = (int) TimeUnit.HOURS.toMillis(5);
    NitzData nonsenseNitzData = NitzData.createForTests(nonsenseOffset, 0, timeMillis, null);
    OffsetResult nonsenseOffsetResult = mTimeZoneLookupHelper.lookupByNitzCountry(nonsenseNitzData, countryIsoCode);
    assertNull(nonsenseOffsetResult);
}
Also used : CountryResult(com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult) NitzData(com.android.internal.telephony.NitzData) OffsetResult(android.timezone.CountryTimeZones.OffsetResult) Test(org.junit.Test)

Aggregations

OffsetResult (android.timezone.CountryTimeZones.OffsetResult)12 CountryResult (com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult)8 Test (org.junit.Test)8 NitzData (com.android.internal.telephony.NitzData)5 NonNull (android.annotation.NonNull)2 TelephonyTimeZoneSuggestion (android.app.timezonedetector.TelephonyTimeZoneSuggestion)2 Nullable (android.annotation.Nullable)1 TimeZone (android.icu.util.TimeZone)1 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)1 List (java.util.List)1