use of com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult in project android_frameworks_opt_telephony by LineageOS.
the class TimeZoneLookupHelperTest method testLookupByCountry_oneEffectiveZone.
@Test
public void testLookupByCountry_oneEffectiveZone() {
// Historical dates are used to avoid the test breaking due to data changes.
// DE has two time zones according to IANA data: Europe/Berlin and Europe/Busingen, but they
// become effectively identical after 338950800000 millis (Sun, 28 Sep 1980 01:00:00 GMT).
// Android data tells us that Europe/Berlin the one that was "kept".
long nhSummerTimeMillis = createUtcTime(1975, 6, 20, 1, 2, 3);
long nhWinterTimeMillis = createUtcTime(1975, 1, 20, 1, 2, 3);
// Before 1980, quality == QUALITY_MULTIPLE_ZONES_SAME_OFFSET because Europe/Busingen was
// relevant.
CountryResult expectedResult = new CountryResult("Europe/Berlin", QUALITY_MULTIPLE_ZONES_SAME_OFFSET, ARBITRARY_DEBUG_INFO);
assertEquals(expectedResult, mTimeZoneLookupHelper.lookupByCountry("de", nhSummerTimeMillis));
assertEquals(expectedResult, mTimeZoneLookupHelper.lookupByCountry("de", nhWinterTimeMillis));
// And in 2015, quality == QUALITY_SINGLE_ZONE because Europe/Busingen became irrelevant
// after 1980.
nhSummerTimeMillis = createUtcTime(2015, 6, 20, 1, 2, 3);
nhWinterTimeMillis = createUtcTime(2015, 1, 20, 1, 2, 3);
expectedResult = new CountryResult("Europe/Berlin", QUALITY_SINGLE_ZONE, ARBITRARY_DEBUG_INFO);
assertEquals(expectedResult, mTimeZoneLookupHelper.lookupByCountry("de", nhSummerTimeMillis));
assertEquals(expectedResult, mTimeZoneLookupHelper.lookupByCountry("de", nhWinterTimeMillis));
}
use of com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult 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();
}
use of com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult in project android_frameworks_opt_telephony by LineageOS.
the class TimeZoneSuggesterImpl method findTimeZoneFromNetworkCountryCode.
/**
* Creates a {@link TelephonyTimeZoneSuggestion} using only network country code; works well on
* countries which only have one time zone or multiple zones with the same offset.
*
* @param countryIsoCode country code from network MCC
* @param whenMillis the time to use when looking at time zone rules data
*/
@NonNull
private TelephonyTimeZoneSuggestion findTimeZoneFromNetworkCountryCode(int slotIndex, @NonNull String countryIsoCode, long whenMillis) {
Objects.requireNonNull(countryIsoCode);
if (TextUtils.isEmpty(countryIsoCode)) {
throw new IllegalArgumentException("countryIsoCode must not be empty");
}
TelephonyTimeZoneSuggestion.Builder suggestionBuilder = new TelephonyTimeZoneSuggestion.Builder(slotIndex);
suggestionBuilder.addDebugInfo("findTimeZoneFromNetworkCountryCode:" + " whenMillis=" + whenMillis + ", countryIsoCode=" + countryIsoCode);
CountryResult lookupResult = mTimeZoneLookupHelper.lookupByCountry(countryIsoCode, whenMillis);
if (lookupResult != null) {
suggestionBuilder.setZoneId(lookupResult.zoneId);
suggestionBuilder.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
int quality;
if (lookupResult.quality == CountryResult.QUALITY_SINGLE_ZONE || lookupResult.quality == CountryResult.QUALITY_DEFAULT_BOOSTED) {
quality = TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE;
} else if (lookupResult.quality == CountryResult.QUALITY_MULTIPLE_ZONES_SAME_OFFSET) {
quality = TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET;
} else if (lookupResult.quality == CountryResult.QUALITY_MULTIPLE_ZONES_DIFFERENT_OFFSETS) {
quality = TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS;
} else {
// This should never happen.
throw new IllegalArgumentException("lookupResult.quality not recognized: countryIsoCode=" + countryIsoCode + ", whenMillis=" + whenMillis + ", lookupResult=" + lookupResult);
}
suggestionBuilder.setQuality(quality);
suggestionBuilder.addDebugInfo("findTimeZoneFromNetworkCountryCode: lookupResult=" + lookupResult);
} else {
suggestionBuilder.addDebugInfo("findTimeZoneFromNetworkCountryCode: Country not recognized?");
}
return suggestionBuilder.build();
}
use of com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult 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);
}
use of com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult 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);
}
}
Aggregations