Search in sources :

Example 1 with TelephonyTimeZoneSuggestion

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

the class NitzStateMachineImpl method doTimeZoneDetection.

/**
 * Perform a round of time zone detection and notify the time zone detection service as needed.
 */
private void doTimeZoneDetection(@Nullable String countryIsoCode, @Nullable TimestampedValue<NitzData> nitzSignal, @NonNull String reason) {
    try {
        Objects.requireNonNull(reason);
        TelephonyTimeZoneSuggestion suggestion = mTimeZoneSuggester.getTimeZoneSuggestion(mSlotIndex, countryIsoCode, nitzSignal);
        suggestion.addDebugInfo("Detection reason=" + reason);
        if (DBG) {
            Rlog.d(LOG_TAG, "doTimeZoneDetection: countryIsoCode=" + countryIsoCode + ", nitzSignal=" + nitzSignal + ", suggestion=" + suggestion + ", reason=" + reason);
        }
        mTimeServiceHelper.maybeSuggestDeviceTimeZone(suggestion);
    } catch (RuntimeException ex) {
        Rlog.e(LOG_TAG, "doTimeZoneDetection: Exception thrown" + " mSlotIndex=" + mSlotIndex + ", countryIsoCode=" + countryIsoCode + ", nitzSignal=" + nitzSignal + ", reason=" + reason + ", ex=" + ex, ex);
    }
}
Also used : TelephonyTimeZoneSuggestion(android.app.timezonedetector.TelephonyTimeZoneSuggestion)

Example 2 with TelephonyTimeZoneSuggestion

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

the class TimeZoneSuggesterImpl method findTimeZoneFromCountryAndNitz.

/**
 * Creates a {@link TelephonyTimeZoneSuggestion} using network country code and NITZ.
 */
@NonNull
private TelephonyTimeZoneSuggestion findTimeZoneFromCountryAndNitz(int slotIndex, @NonNull String countryIsoCode, @NonNull TimestampedValue<NitzData> nitzSignal) {
    Objects.requireNonNull(countryIsoCode);
    Objects.requireNonNull(nitzSignal);
    TelephonyTimeZoneSuggestion.Builder suggestionBuilder = new TelephonyTimeZoneSuggestion.Builder(slotIndex);
    suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz:" + " countryIsoCode=" + countryIsoCode + ", nitzSignal=" + nitzSignal);
    NitzData nitzData = Objects.requireNonNull(nitzSignal.getValue());
    if (isNitzSignalOffsetInfoBogus(countryIsoCode, nitzData)) {
        suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz: NITZ signal looks bogus");
        return suggestionBuilder.build();
    }
    // Try to find a match using both country + NITZ signal.
    OffsetResult lookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(nitzData, countryIsoCode);
    if (lookupResult != null) {
        suggestionBuilder.setZoneId(lookupResult.getTimeZone().getID());
        suggestionBuilder.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET);
        int quality = lookupResult.isOnlyMatch() ? TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE : TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET;
        suggestionBuilder.setQuality(quality);
        suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz:" + " lookupResult=" + lookupResult);
        return suggestionBuilder.build();
    }
    // The country + offset provided no match, so see if the country by itself would be enough.
    CountryResult countryResult = mTimeZoneLookupHelper.lookupByCountry(countryIsoCode, nitzData.getCurrentTimeInMillis());
    if (countryResult == null) {
        // Country not recognized.
        suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz: lookupByCountry() country not recognized");
        return suggestionBuilder.build();
    }
    // use it.
    if (countryResult.quality == CountryResult.QUALITY_SINGLE_ZONE || countryResult.quality == CountryResult.QUALITY_DEFAULT_BOOSTED) {
        suggestionBuilder.setZoneId(countryResult.zoneId);
        suggestionBuilder.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
        suggestionBuilder.setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
        suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz: high quality country-only suggestion:" + " countryResult=" + countryResult);
        return suggestionBuilder.build();
    }
    // Quality is not high enough to set the zone using country only.
    suggestionBuilder.addDebugInfo("findTimeZoneFromCountryAndNitz: country-only suggestion" + " quality not high enough. countryResult=" + countryResult);
    return suggestionBuilder.build();
}
Also used : TelephonyTimeZoneSuggestion(android.app.timezonedetector.TelephonyTimeZoneSuggestion) CountryResult(com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult) NitzData(com.android.internal.telephony.NitzData) OffsetResult(android.timezone.CountryTimeZones.OffsetResult) NonNull(android.annotation.NonNull)

Example 3 with TelephonyTimeZoneSuggestion

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

the class TimeZoneSuggesterImpl method findTimeZoneFromNetworkCountryCode.

/**
 * Creates a {@link TelephonyTimeZoneSuggestion} using only network country code; works well on
 * countries which only have one time zone or multiple zones with the same offset.
 *
 * @param countryIsoCode country code from network MCC
 * @param whenMillis the time to use when looking at time zone rules data
 */
@NonNull
private TelephonyTimeZoneSuggestion findTimeZoneFromNetworkCountryCode(int slotIndex, @NonNull String countryIsoCode, long whenMillis) {
    Objects.requireNonNull(countryIsoCode);
    if (TextUtils.isEmpty(countryIsoCode)) {
        throw new IllegalArgumentException("countryIsoCode must not be empty");
    }
    TelephonyTimeZoneSuggestion.Builder suggestionBuilder = new TelephonyTimeZoneSuggestion.Builder(slotIndex);
    suggestionBuilder.addDebugInfo("findTimeZoneFromNetworkCountryCode:" + " whenMillis=" + whenMillis + ", countryIsoCode=" + countryIsoCode);
    CountryResult lookupResult = mTimeZoneLookupHelper.lookupByCountry(countryIsoCode, whenMillis);
    if (lookupResult != null) {
        suggestionBuilder.setZoneId(lookupResult.zoneId);
        suggestionBuilder.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
        int quality;
        if (lookupResult.quality == CountryResult.QUALITY_SINGLE_ZONE || lookupResult.quality == CountryResult.QUALITY_DEFAULT_BOOSTED) {
            quality = TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE;
        } else if (lookupResult.quality == CountryResult.QUALITY_MULTIPLE_ZONES_SAME_OFFSET) {
            quality = TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET;
        } else if (lookupResult.quality == CountryResult.QUALITY_MULTIPLE_ZONES_DIFFERENT_OFFSETS) {
            quality = TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS;
        } else {
            // This should never happen.
            throw new IllegalArgumentException("lookupResult.quality not recognized: countryIsoCode=" + countryIsoCode + ", whenMillis=" + whenMillis + ", lookupResult=" + lookupResult);
        }
        suggestionBuilder.setQuality(quality);
        suggestionBuilder.addDebugInfo("findTimeZoneFromNetworkCountryCode: lookupResult=" + lookupResult);
    } else {
        suggestionBuilder.addDebugInfo("findTimeZoneFromNetworkCountryCode: Country not recognized?");
    }
    return suggestionBuilder.build();
}
Also used : TelephonyTimeZoneSuggestion(android.app.timezonedetector.TelephonyTimeZoneSuggestion) CountryResult(com.android.internal.telephony.nitz.TimeZoneLookupHelper.CountryResult) NonNull(android.annotation.NonNull)

Example 4 with TelephonyTimeZoneSuggestion

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

the class NitzStateMachineImplTest method test_emptyCountryString_countryReceivedFirst.

@Test
public void test_emptyCountryString_countryReceivedFirst() 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 an empty country being set.
    script.countryReceived("");
    // Nothing should be set. The country is not valid.
    script.verifyOnlyTimeZoneWasSuggestedAndReset(EMPTY_TIME_ZONE_SUGGESTION);
    // Check NitzStateMachine exposed state.
    assertNull(mNitzStateMachineImpl.getCachedNitzData());
    // Simulate receiving the NITZ signal.
    script.nitzReceived(nitzSignal);
    TelephonyTimeSuggestion expectedTimeSuggestion = createTimeSuggestionFromNitzSignal(SLOT_INDEX, nitzSignal);
    // 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.verifyTimeAndTimeZoneSuggestedAndReset(expectedTimeSuggestion, 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 5 with TelephonyTimeZoneSuggestion

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

the class NitzStateMachineImplTest method test_countryUnavailableClearsTimeZoneSuggestion.

@Test
public void test_countryUnavailableClearsTimeZoneSuggestion() 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 country and verify the state machine does the right thing.
    script.countryReceived(scenario.getNetworkCountryIsoCode());
    TelephonyTimeZoneSuggestion expectedTimeZoneSuggestion1 = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, scenario.getNetworkCountryIsoCode(), null);
    script.verifyOnlyTimeZoneWasSuggestedAndReset(expectedTimeZoneSuggestion1);
    // Simulate receiving an NITZ signal and verify the state machine does the right thing.
    script.nitzReceived(nitzSignal);
    TelephonyTimeSuggestion expectedTimeSuggestion = createTimeSuggestionFromNitzSignal(SLOT_INDEX, nitzSignal);
    TelephonyTimeZoneSuggestion expectedTimeZoneSuggestion2 = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, scenario.getNetworkCountryIsoCode(), nitzSignal);
    script.verifyTimeAndTimeZoneSuggestedAndReset(expectedTimeSuggestion, expectedTimeZoneSuggestion2);
    // Check state that NitzStateMachine must expose.
    assertEquals(nitzSignal.getValue(), mNitzStateMachineImpl.getCachedNitzData());
    // Simulate the country becoming unavailable and verify the state machine does the right
    // thing.
    script.countryUnavailable();
    TelephonyTimeZoneSuggestion expectedTimeZoneSuggestion3 = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, null, /* countryIsoCode */
    nitzSignal);
    script.verifyOnlyTimeZoneWasSuggestedAndReset(expectedTimeZoneSuggestion3);
    // Check state that NitzStateMachine must expose.
    assertEquals(nitzSignal.getValue(), mNitzStateMachineImpl.getCachedNitzData());
}
Also used : TelephonyTimeZoneSuggestion(android.app.timezonedetector.TelephonyTimeZoneSuggestion) TelephonyTimeSuggestion(android.app.timedetector.TelephonyTimeSuggestion) NitzData(com.android.internal.telephony.NitzData) Scenario(com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test)

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