Search in sources :

Example 11 with OffsetResult

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;
}
Also used : OffsetResult(android.timezone.CountryTimeZones.OffsetResult) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) Nullable(android.annotation.Nullable)

Example 12 with OffsetResult

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();
}
Also used : TelephonyTimeZoneSuggestion(android.app.timezonedetector.TelephonyTimeZoneSuggestion) NitzData(com.android.internal.telephony.NitzData) OffsetResult(android.timezone.CountryTimeZones.OffsetResult) NonNull(android.annotation.NonNull)

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