Search in sources :

Example 26 with NitzData

use of com.android.internal.telephony.NitzData in project android_frameworks_opt_telephony by LineageOS.

the class TimeZoneSuggesterImpl method getTimeZoneSuggestion.

@Override
@NonNull
public TelephonyTimeZoneSuggestion getTimeZoneSuggestion(int slotIndex, @Nullable String countryIsoCode, @Nullable TimestampedValue<NitzData> nitzSignal) {
    try {
        // Check for overriding NITZ-based signals from Android running in an emulator.
        TelephonyTimeZoneSuggestion overridingSuggestion = null;
        if (nitzSignal != null) {
            NitzData nitzData = nitzSignal.getValue();
            if (nitzData.getEmulatorHostTimeZone() != null) {
                TelephonyTimeZoneSuggestion.Builder builder = new TelephonyTimeZoneSuggestion.Builder(slotIndex).setZoneId(nitzData.getEmulatorHostTimeZone().getID()).setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID).setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE).addDebugInfo("Emulator time zone override: " + nitzData);
                overridingSuggestion = builder.build();
            }
        }
        TelephonyTimeZoneSuggestion suggestion;
        if (overridingSuggestion != null) {
            suggestion = overridingSuggestion;
        } else if (countryIsoCode == null) {
            if (nitzSignal == null) {
                suggestion = createEmptySuggestion(slotIndex, "getTimeZoneSuggestion: nitzSignal=null, countryIsoCode=null");
            } else {
                // NITZ only - wait until we have a country.
                suggestion = createEmptySuggestion(slotIndex, "getTimeZoneSuggestion:" + " nitzSignal=" + nitzSignal + ", countryIsoCode=null");
            }
        } else {
            // countryIsoCode != null
            if (nitzSignal == null) {
                if (countryIsoCode.isEmpty()) {
                    // This is assumed to be a test network with no NITZ data to go on.
                    suggestion = createEmptySuggestion(slotIndex, "getTimeZoneSuggestion: nitzSignal=null, countryIsoCode=\"\"");
                } else {
                    // Country only
                    suggestion = findTimeZoneFromNetworkCountryCode(slotIndex, countryIsoCode, mDeviceState.currentTimeMillis());
                }
            } else {
                // nitzSignal != null
                if (countryIsoCode.isEmpty()) {
                    // We have been told we have a country code but it's empty. This is most
                    // likely because we're on a test network that's using a bogus MCC
                    // (eg, "001"). Obtain a TimeZone based only on the NITZ parameters: without
                    // a country it will be arbitrary, but it should at least have the correct
                    // offset.
                    suggestion = findTimeZoneForTestNetwork(slotIndex, nitzSignal);
                } else {
                    // We have both NITZ and Country code.
                    suggestion = findTimeZoneFromCountryAndNitz(slotIndex, countryIsoCode, nitzSignal);
                }
            }
        }
        // Ensure the return value is never null.
        Objects.requireNonNull(suggestion);
        return suggestion;
    } catch (RuntimeException e) {
        // This would suggest a coding error. Log at a high level and try to avoid leaving the
        // device in a bad state by making an "empty" suggestion.
        String message = "getTimeZoneSuggestion: Error during lookup: " + " countryIsoCode=" + countryIsoCode + ", nitzSignal=" + nitzSignal + ", e=" + e.getMessage();
        TelephonyTimeZoneSuggestion errorSuggestion = createEmptySuggestion(slotIndex, message);
        Rlog.w(LOG_TAG, message, e);
        return errorSuggestion;
    }
}
Also used : TelephonyTimeZoneSuggestion(android.app.timezonedetector.TelephonyTimeZoneSuggestion) NitzData(com.android.internal.telephony.NitzData) NonNull(android.annotation.NonNull)

Aggregations

NitzData (com.android.internal.telephony.NitzData)26 Test (org.junit.Test)22 TelephonyTest (com.android.internal.telephony.TelephonyTest)19 Scenario (com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario)19 TelephonyTimeZoneSuggestion (android.app.timezonedetector.TelephonyTimeZoneSuggestion)11 TimestampedValue (android.os.TimestampedValue)9 TrivalentPredicate (com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.TrivalentPredicate)9 TelephonyTimeSuggestion (android.app.timedetector.TelephonyTimeSuggestion)7 OffsetResult (android.timezone.CountryTimeZones.OffsetResult)5 NitzSignalInputFilterPredicateImpl (com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.NitzSignalInputFilterPredicateImpl)5 NonNull (android.annotation.NonNull)4 NitzSignalInputFilterPredicateFactory.createBogusElapsedRealtimeCheck (com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.createBogusElapsedRealtimeCheck)3 NitzSignalInputFilterPredicateFactory.createIgnoreNitzPropertyCheck (com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.createIgnoreNitzPropertyCheck)3 NitzSignalInputFilterPredicateFactory.createRateLimitCheck (com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.createRateLimitCheck)3 FakeDeviceState (com.android.internal.telephony.nitz.NitzStateMachineTestSupport.FakeDeviceState)3 UNIQUE_US_ZONE_SCENARIO1 (com.android.internal.telephony.nitz.NitzStateMachineTestSupport.UNIQUE_US_ZONE_SCENARIO1)3 CountryResult (com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult)3 After (org.junit.After)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertNull (org.junit.Assert.assertNull)3