Search in sources :

Example 1 with OffsetResult

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

the class TimeZoneLookupHelper method lookupByInstantOffsetDst.

private static OffsetResult lookupByInstantOffsetDst(long timeMillis, int utcOffsetMillis, @Nullable Boolean isDst) {
    String[] zones = TimeZone.getAvailableIDs();
    TimeZone match = null;
    boolean isOnlyMatch = true;
    for (String zone : zones) {
        TimeZone tz = TimeZone.getFrozenTimeZone(zone);
        if (offsetMatchesAtTime(tz, utcOffsetMillis, isDst, timeMillis)) {
            if (match == null) {
                match = tz;
            } else {
                isOnlyMatch = false;
                break;
            }
        }
    }
    if (match == null) {
        return null;
    }
    return new OffsetResult(match, isOnlyMatch);
}
Also used : TimeZone(android.icu.util.TimeZone) OffsetResult(android.timezone.CountryTimeZones.OffsetResult)

Example 2 with OffsetResult

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

the class TimeZoneSuggesterImpl method findTimeZoneFromCountryAndNitz.

/**
 * Creates a {@link TelephonyTimeZoneSuggestion} using network country code and NITZ.
 */
@NonNull
private TelephonyTimeZoneSuggestion findTimeZoneFromCountryAndNitz(int slotIndex, @NonNull String countryIsoCode, @NonNull TimestampedValue<NitzData> nitzSignal) {
    Objects.requireNonNull(countryIsoCode);
    Objects.requireNonNull(nitzSignal);
    TelephonyTimeZoneSuggestion.Builder suggestionBuilder = new TelephonyTimeZoneSuggestion.Builder(slotIndex);
    suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz:" + " countryIsoCode=" + countryIsoCode + ", nitzSignal=" + nitzSignal);
    NitzData nitzData = Objects.requireNonNull(nitzSignal.getValue());
    if (isNitzSignalOffsetInfoBogus(countryIsoCode, nitzData)) {
        suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz: NITZ signal looks bogus");
        return suggestionBuilder.build();
    }
    // Try to find a match using both country + NITZ signal.
    OffsetResult lookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(nitzData, countryIsoCode);
    if (lookupResult != null) {
        suggestionBuilder.setZoneId(lookupResult.getTimeZone().getID());
        suggestionBuilder.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET);
        int quality = lookupResult.isOnlyMatch() ? TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE : TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET;
        suggestionBuilder.setQuality(quality);
        suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz:" + " lookupResult=" + lookupResult);
        return suggestionBuilder.build();
    }
    // The country + offset provided no match, so see if the country by itself would be enough.
    CountryResult countryResult = mTimeZoneLookupHelper.lookupByCountry(countryIsoCode, nitzData.getCurrentTimeInMillis());
    if (countryResult == null) {
        // Country not recognized.
        suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz: lookupByCountry() country not recognized");
        return suggestionBuilder.build();
    }
    // use it.
    if (countryResult.quality == CountryResult.QUALITY_SINGLE_ZONE || countryResult.quality == CountryResult.QUALITY_DEFAULT_BOOSTED) {
        suggestionBuilder.setZoneId(countryResult.zoneId);
        suggestionBuilder.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
        suggestionBuilder.setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
        suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz: high quality country-only suggestion:" + " countryResult=" + countryResult);
        return suggestionBuilder.build();
    }
    // Quality is not high enough to set the zone using country only.
    suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz: country-only suggestion" + " quality not high enough. countryResult=" + countryResult);
    return suggestionBuilder.build();
}
Also used : TelephonyTimeZoneSuggestion(android.app.timezonedetector.TelephonyTimeZoneSuggestion) CountryResult(com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult) NitzData(com.android.internal.telephony.NitzData) OffsetResult(android.timezone.CountryTimeZones.OffsetResult) NonNull(android.annotation.NonNull)

Example 3 with OffsetResult

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

the class NitzStateMachineTestSupportTest method test_czechia_assumptions.

@Test
public void test_czechia_assumptions() {
    assertEquals(CZECHIA_SCENARIO.getTimeZone().getID(), CZECHIA_COUNTRY_DEFAULT_ZONE_ID);
    // quality == QUALITY_SINGLE_ZONE, so the default zone is a good match.
    CountryResult expectedCountryLookupResult = new CountryResult(CZECHIA_COUNTRY_DEFAULT_ZONE_ID, QUALITY_SINGLE_ZONE, ARBITRARY_DEBUG_INFO);
    CountryResult actualCountryLookupResult = mTimeZoneLookupHelper.lookupByCountry(CZECHIA_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(CZECHIA_SCENARIO.getTimeZone(), true);
    OffsetResult actualLookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(CZECHIA_SCENARIO.createNitzData(), CZECHIA_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 4 with OffsetResult

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

the class NitzStateMachineTestSupportTest method test_newZealand_assumptions.

@Test
public void test_newZealand_assumptions() {
    assertEquals(NEW_ZEALAND_DEFAULT_SCENARIO.getTimeZone().getID(), NEW_ZEALAND_COUNTRY_DEFAULT_ZONE_ID);
    // Check we'll get the expected behavior from TimeZoneLookupHelper.
    // quality == QUALITY_DEFAULT_BOOSTED, so the default zone is a good match.
    CountryResult expectedCountryLookupResult = new CountryResult(NEW_ZEALAND_COUNTRY_DEFAULT_ZONE_ID, QUALITY_DEFAULT_BOOSTED, ARBITRARY_DEBUG_INFO);
    CountryResult actualCountryLookupResult = mTimeZoneLookupHelper.lookupByCountry(NEW_ZEALAND_DEFAULT_SCENARIO.getNetworkCountryIsoCode(), ARBITRARY_SYSTEM_CLOCK_TIME);
    assertEquals(expectedCountryLookupResult, actualCountryLookupResult);
    // Check NEW_ZEALAND_DEFAULT_SCENARIO.
    {
        // isOnlyMatch == true, so the combination of country + NITZ should be enough for a
        // match.
        OffsetResult expectedLookupResult = new OffsetResult(NEW_ZEALAND_DEFAULT_SCENARIO.getTimeZone(), true);
        OffsetResult actualLookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(NEW_ZEALAND_DEFAULT_SCENARIO.createNitzData(), NEW_ZEALAND_DEFAULT_SCENARIO.getNetworkCountryIsoCode());
        assertEquals(expectedLookupResult, actualLookupResult);
    }
    // Check NEW_ZEALAND_OTHER_SCENARIO.
    {
        // isOnlyMatch == true, so the combination of country + NITZ should be enough for a
        // match.
        OffsetResult expectedLookupResult = new OffsetResult(NEW_ZEALAND_OTHER_SCENARIO.getTimeZone(), true);
        OffsetResult actualLookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(NEW_ZEALAND_OTHER_SCENARIO.createNitzData(), NEW_ZEALAND_OTHER_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 5 with OffsetResult

use of android.timezone.CountryTimeZones.OffsetResult 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)

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