use of android.timezone.CountryTimeZones.OffsetResult in project android_frameworks_opt_telephony by LineageOS.
the class TimeZoneLookupHelper method lookupByNitz.
/**
* Looks for a time zone using only information present in the supplied {@link NitzData} object.
*
* <p><em>Note:</em> Because multiple time zones can have the same offset / DST state at a given
* time this process is error prone; an arbitrary match is returned when there are multiple
* candidates. The algorithm can also return a non-exact match by assuming that the DST
* information provided by NITZ is incorrect. This method can return {@code null} if no matching
* time zones are found.
*/
@VisibleForTesting
@Nullable
public OffsetResult lookupByNitz(@NonNull NitzData nitzData) {
int utcOffsetMillis = nitzData.getLocalOffsetMillis();
long timeMillis = nitzData.getCurrentTimeInMillis();
// Android NITZ time zone matching doesn't try to do a precise match using the DST offset
// supplied by the carrier. It only considers whether or not the carrier suggests local time
// is DST (if known). NITZ is limited in only being able to express DST offsets in whole
// hours and the DST info is optional.
Integer dstAdjustmentMillis = nitzData.getDstAdjustmentMillis();
Boolean isDst = dstAdjustmentMillis == null ? null : dstAdjustmentMillis != 0;
OffsetResult match = lookupByInstantOffsetDst(timeMillis, utcOffsetMillis, isDst);
if (match == null && isDst != null) {
// This branch is extremely unlikely and could probably be removed. The match above will
// have searched the entire tzdb for a zone with the same total offset and isDst state.
// Here we try another match but use "null" for isDst to indicate that only the total
// offset should be considered. If, by the end of this, there isn't a match then the
// current offset suggested by the carrier must be highly unusual.
match = lookupByInstantOffsetDst(timeMillis, utcOffsetMillis, null);
}
return match;
}
use of android.timezone.CountryTimeZones.OffsetResult in project android_frameworks_opt_telephony by LineageOS.
the class TimeZoneSuggesterImpl method findTimeZoneForTestNetwork.
/**
* Creates a {@link TelephonyTimeZoneSuggestion} using only NITZ. This happens when the device
* is attached to a test cell with an unrecognized MCC. In these cases we try to return a
* suggestion for an arbitrary time zone that matches the NITZ offset information.
*/
@NonNull
private TelephonyTimeZoneSuggestion findTimeZoneForTestNetwork(int slotIndex, @NonNull TimestampedValue<NitzData> nitzSignal) {
Objects.requireNonNull(nitzSignal);
NitzData nitzData = Objects.requireNonNull(nitzSignal.getValue());
TelephonyTimeZoneSuggestion.Builder suggestionBuilder = new TelephonyTimeZoneSuggestion.Builder(slotIndex);
suggestionBuilder.addDebugInfo("findTimeZoneForTestNetwork: nitzSignal=" + nitzSignal);
OffsetResult lookupResult = mTimeZoneLookupHelper.lookupByNitz(nitzData);
if (lookupResult == null) {
suggestionBuilder.addDebugInfo("findTimeZoneForTestNetwork: No zone found");
} else {
suggestionBuilder.setZoneId(lookupResult.getTimeZone().getID());
suggestionBuilder.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY);
int quality = lookupResult.isOnlyMatch() ? TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE : TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET;
suggestionBuilder.setQuality(quality);
suggestionBuilder.addDebugInfo("findTimeZoneForTestNetwork: lookupResult=" + lookupResult);
}
return suggestionBuilder.build();
}
Aggregations