Search in sources :

Example 6 with CountryResult

use of com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult in project android_frameworks_opt_telephony by LineageOS.

the class NitzStateMachineTestSupportTest method test_uniqueUs_assumptions.

@Test
public void test_uniqueUs_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(UNIQUE_US_ZONE_SCENARIO1.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(UNIQUE_US_ZONE_SCENARIO1.getTimeZone(), true);
        OffsetResult actualLookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(UNIQUE_US_ZONE_SCENARIO1.createNitzData(), UNIQUE_US_ZONE_SCENARIO1.getNetworkCountryIsoCode());
        assertEquals(expectedLookupResult, actualLookupResult);
    }
    // isOnlyMatch == true, so the combination of country + NITZ should be enough for a match.
    {
        OffsetResult expectedLookupResult = new OffsetResult(UNIQUE_US_ZONE_SCENARIO2.getTimeZone(), true);
        OffsetResult actualLookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(UNIQUE_US_ZONE_SCENARIO2.createNitzData(), UNIQUE_US_ZONE_SCENARIO2.getNetworkCountryIsoCode());
        assertEquals(expectedLookupResult, actualLookupResult);
    }
}
Also used : CountryResult(com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult) OffsetResult(android.timezone.CountryTimeZones.OffsetResult) Test(org.junit.Test)

Example 7 with CountryResult

use of com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult 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 8 with CountryResult

use of com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult 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 9 with CountryResult

use of com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult 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 CountryResult

use of com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult in project android_frameworks_opt_telephony by LineageOS.

the class TimeZoneLookupHelperTest method testLookupByCountry_oneZone.

@Test
public void testLookupByCountry_oneZone() {
    // GB has one time zone.
    CountryResult expectedResult = new CountryResult("Europe/London", QUALITY_SINGLE_ZONE, ARBITRARY_DEBUG_INFO);
    assertEquals(expectedResult, mTimeZoneLookupHelper.lookupByCountry("gb", NH_SUMMER_TIME_MILLIS));
    assertEquals(expectedResult, mTimeZoneLookupHelper.lookupByCountry("gb", NH_WINTER_TIME_MILLIS));
}
Also used : CountryResult(com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult) Test(org.junit.Test)

Aggregations

CountryResult (com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult)12 Test (org.junit.Test)10 OffsetResult (android.timezone.CountryTimeZones.OffsetResult)8 NitzData (com.android.internal.telephony.NitzData)3 NonNull (android.annotation.NonNull)2 TelephonyTimeZoneSuggestion (android.app.timezonedetector.TelephonyTimeZoneSuggestion)2 List (java.util.List)1