use of android.timezone.CountryTimeZones.TimeZoneMapping in project android_frameworks_opt_telephony by LineageOS.
the class TimeZoneLookupHelper method lookupByCountry.
/**
* Returns information about the time zones used in a country at a given time.
*
* {@code null} can be returned if a problem occurs during lookup, e.g. if the country code is
* unrecognized, if the country is uninhabited, or if there is a problem with the data.
*/
@VisibleForTesting
@Nullable
public CountryResult lookupByCountry(@NonNull String isoCountryCode, long whenMillis) {
CountryTimeZones countryTimeZones = getCountryTimeZones(isoCountryCode);
if (countryTimeZones == null) {
// Unknown country code.
return null;
}
TimeZone countryDefaultZone = countryTimeZones.getDefaultTimeZone();
if (countryDefaultZone == null) {
// This is not expected: the country default should have been validated before.
return null;
}
String debugInfo;
int matchQuality;
if (countryTimeZones.isDefaultTimeZoneBoosted()) {
matchQuality = CountryResult.QUALITY_DEFAULT_BOOSTED;
debugInfo = "Country default is boosted";
} else {
List<TimeZoneMapping> effectiveTimeZoneMappings = countryTimeZones.getEffectiveTimeZoneMappingsAt(whenMillis);
if (effectiveTimeZoneMappings.isEmpty()) {
// This should never happen unless there's been an error loading the data.
// Treat it the same as a low quality answer.
matchQuality = QUALITY_MULTIPLE_ZONES_DIFFERENT_OFFSETS;
debugInfo = "No effective time zones found at whenMillis=" + whenMillis;
} else if (effectiveTimeZoneMappings.size() == 1) {
// The default is the only zone so it's a good candidate.
matchQuality = CountryResult.QUALITY_SINGLE_ZONE;
debugInfo = "One effective time zone found at whenMillis=" + whenMillis;
} else {
boolean countryUsesDifferentOffsets = countryUsesDifferentOffsets(whenMillis, effectiveTimeZoneMappings, countryDefaultZone);
matchQuality = countryUsesDifferentOffsets ? QUALITY_MULTIPLE_ZONES_DIFFERENT_OFFSETS : QUALITY_MULTIPLE_ZONES_SAME_OFFSET;
debugInfo = "countryUsesDifferentOffsets=" + countryUsesDifferentOffsets + " at" + " whenMillis=" + whenMillis;
}
}
return new CountryResult(countryDefaultZone.getID(), matchQuality, debugInfo);
}
use of android.timezone.CountryTimeZones.TimeZoneMapping in project android_frameworks_opt_telephony by LineageOS.
the class TimeZoneLookupHelper method countryUsesDifferentOffsets.
private static boolean countryUsesDifferentOffsets(long whenMillis, @NonNull List<TimeZoneMapping> effectiveTimeZoneMappings, @NonNull TimeZone countryDefaultZone) {
String countryDefaultId = countryDefaultZone.getID();
int countryDefaultOffset = countryDefaultZone.getOffset(whenMillis);
for (TimeZoneMapping timeZoneMapping : effectiveTimeZoneMappings) {
if (timeZoneMapping.getTimeZoneId().equals(countryDefaultId)) {
continue;
}
TimeZone timeZone = timeZoneMapping.getTimeZone();
int candidateOffset = timeZone.getOffset(whenMillis);
if (countryDefaultOffset != candidateOffset) {
return true;
}
}
return false;
}
Aggregations