Search in sources :

Example 11 with TelephonyTimeZoneSuggestion

use of android.app.timezonedetector.TelephonyTimeZoneSuggestion in project android_frameworks_opt_telephony by LineageOS.

the class NitzStateMachineImplTest method test_emptyCountryStringUsTime_nitzReceivedFirst.

@Test
public void test_emptyCountryStringUsTime_nitzReceivedFirst() throws Exception {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    Script script = new Script().initializeSystemClock(ARBITRARY_SYSTEM_CLOCK_TIME).networkAvailable();
    // Simulate receiving the NITZ signal.
    script.nitzReceived(nitzSignal);
    // Verify the state machine did the right thing.
    // No time zone should be set. A NITZ signal by itself is not enough.
    TelephonyTimeSuggestion expectedTimeSuggestion = createTimeSuggestionFromNitzSignal(SLOT_INDEX, nitzSignal);
    script.verifyTimeAndTimeZoneSuggestedAndReset(expectedTimeSuggestion, EMPTY_TIME_ZONE_SUGGESTION);
    // Check NitzStateMachine exposed state.
    assertEquals(nitzSignal.getValue(), mNitzStateMachineImpl.getCachedNitzData());
    // Simulate an empty country being set.
    script.countryReceived("");
    // Capture output from the real suggester and confirm it meets the test's needs /
    // expectations.
    TelephonyTimeZoneSuggestion expectedTimeZoneSuggestion = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, "", /* countryIsoCode */
    nitzSignal);
    assertEquals(MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY, expectedTimeZoneSuggestion.getMatchType());
    assertEquals(QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET, expectedTimeZoneSuggestion.getQuality());
    // Verify the state machine did the right thing.
    script.verifyOnlyTimeZoneWasSuggestedAndReset(expectedTimeZoneSuggestion);
    // Check NitzStateMachine exposed state.
    assertEquals(nitzSignal.getValue(), mNitzStateMachineImpl.getCachedNitzData());
}
Also used : TelephonyTimeSuggestion(android.app.timedetector.TelephonyTimeSuggestion) TelephonyTimeZoneSuggestion(android.app.timezonedetector.TelephonyTimeZoneSuggestion) NitzData(com.android.internal.telephony.NitzData) Scenario(com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test)

Example 12 with TelephonyTimeZoneSuggestion

use of android.app.timezonedetector.TelephonyTimeZoneSuggestion in project android_frameworks_opt_telephony by LineageOS.

the class TimeServiceHelperImpl method maybeSuggestDeviceTimeZone.

@Override
public void maybeSuggestDeviceTimeZone(@NonNull TelephonyTimeZoneSuggestion newSuggestion) {
    Objects.requireNonNull(newSuggestion);
    TelephonyTimeZoneSuggestion oldSuggestion = mLastSuggestedTimeZone;
    if (shouldSendNewTimeZoneSuggestion(oldSuggestion, newSuggestion)) {
        mTimeZoneLog.log("Suggesting time zone update: " + newSuggestion);
        mTimeZoneDetector.suggestTelephonyTimeZone(newSuggestion);
        mLastSuggestedTimeZone = newSuggestion;
    }
}
Also used : TelephonyTimeZoneSuggestion(android.app.timezonedetector.TelephonyTimeZoneSuggestion)

Example 13 with TelephonyTimeZoneSuggestion

use of android.app.timezonedetector.TelephonyTimeZoneSuggestion 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)

Example 14 with TelephonyTimeZoneSuggestion

use of android.app.timezonedetector.TelephonyTimeZoneSuggestion 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

TelephonyTimeZoneSuggestion (android.app.timezonedetector.TelephonyTimeZoneSuggestion)14 NitzData (com.android.internal.telephony.NitzData)11 TelephonyTest (com.android.internal.telephony.TelephonyTest)8 Scenario (com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario)8 Test (org.junit.Test)8 TelephonyTimeSuggestion (android.app.timedetector.TelephonyTimeSuggestion)7 NonNull (android.annotation.NonNull)4 OffsetResult (android.timezone.CountryTimeZones.OffsetResult)2 CountryResult (com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult)2 TimestampedValue (android.os.TimestampedValue)1