Search in sources :

Example 1 with NitzData

use of com.android.internal.telephony.NitzData 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 2 with NitzData

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

the class NitzSignalInputFilterPredicateFactoryTest method testNitzSignalInputFilterPredicateImpl_nullSecondArgumentRejected.

@Test
public void testNitzSignalInputFilterPredicateImpl_nullSecondArgumentRejected() {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    TrivalentPredicate[] triPredicates = {};
    NitzSignalInputFilterPredicateImpl impl = new NitzSignalInputFilterPredicateImpl(triPredicates);
    try {
        impl.mustProcessNitzSignal(nitzSignal, null);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : TrivalentPredicate(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.TrivalentPredicate) NitzData(com.android.internal.telephony.NitzData) Scenario(com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario) NitzSignalInputFilterPredicateImpl(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.NitzSignalInputFilterPredicateImpl) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test)

Example 3 with NitzData

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

the class NitzSignalInputFilterPredicateFactoryTest method testNitzSignalInputFilterPredicateImpl_trueIsHonored.

@Test
public void testNitzSignalInputFilterPredicateImpl_trueIsHonored() {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    TrivalentPredicate nullPredicate = (x, y) -> null;
    TrivalentPredicate truePredicate = (x, y) -> true;
    TrivalentPredicate exceptionPredicate = (x, y) -> {
        throw new RuntimeException();
    };
    TrivalentPredicate[] triPredicates = { nullPredicate, truePredicate, exceptionPredicate };
    NitzSignalInputFilterPredicateImpl impl = new NitzSignalInputFilterPredicateImpl(triPredicates);
    assertTrue(impl.mustProcessNitzSignal(null, nitzSignal));
}
Also used : NitzSignalInputFilterPredicateFactory.createIgnoreNitzPropertyCheck(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.createIgnoreNitzPropertyCheck) TrivalentPredicate(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.TrivalentPredicate) NitzSignalInputFilterPredicateFactory.createRateLimitCheck(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.createRateLimitCheck) TimestampedValue(android.os.TimestampedValue) TelephonyTest(com.android.internal.telephony.TelephonyTest) Assert.assertTrue(org.junit.Assert.assertTrue) FakeDeviceState(com.android.internal.telephony.nitz.NitzStateMachineTestSupport.FakeDeviceState) Test(org.junit.Test) UNIQUE_US_ZONE_SCENARIO1(com.android.internal.telephony.nitz.NitzStateMachineTestSupport.UNIQUE_US_ZONE_SCENARIO1) NitzSignalInputFilterPredicateFactory.createBogusElapsedRealtimeCheck(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.createBogusElapsedRealtimeCheck) NitzData(com.android.internal.telephony.NitzData) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) NitzSignalInputFilterPredicateImpl(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.NitzSignalInputFilterPredicateImpl) After(org.junit.After) Assert.fail(org.junit.Assert.fail) Scenario(com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario) Before(org.junit.Before) TrivalentPredicate(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.TrivalentPredicate) NitzData(com.android.internal.telephony.NitzData) Scenario(com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario) NitzSignalInputFilterPredicateImpl(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.NitzSignalInputFilterPredicateImpl) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test)

Example 4 with NitzData

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

the class NitzSignalInputFilterPredicateFactoryTest method testNitzSignalInputFilterPredicateImpl_defaultIsTrue.

@Test
public void testNitzSignalInputFilterPredicateImpl_defaultIsTrue() {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    NitzSignalInputFilterPredicateImpl impl = new NitzSignalInputFilterPredicateImpl(new TrivalentPredicate[0]);
    assertTrue(impl.mustProcessNitzSignal(null, nitzSignal));
}
Also used : NitzData(com.android.internal.telephony.NitzData) Scenario(com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario) NitzSignalInputFilterPredicateImpl(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.NitzSignalInputFilterPredicateImpl) TelephonyTest(com.android.internal.telephony.TelephonyTest) Test(org.junit.Test)

Example 5 with NitzData

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

the class NitzSignalInputFilterPredicateFactoryTest method testTrivalentPredicate_rateLimitCheck_utcTimeDifferences.

@Test
public void testTrivalentPredicate_rateLimitCheck_utcTimeDifferences() {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    int nitzSpacingThreshold = mFakeDeviceState.getNitzUpdateSpacingMillis();
    int nitzUtcDiffThreshold = mFakeDeviceState.getNitzUpdateDiffMillis();
    NitzData baseNitzData = scenario.createNitzData();
    TrivalentPredicate triPredicate = createRateLimitCheck(mFakeDeviceState);
    long baseElapsedRealtimeMillis = mFakeDeviceState.elapsedRealtime();
    TimestampedValue<NitzData> baseSignal = new TimestampedValue<>(baseElapsedRealtimeMillis, baseNitzData);
    // Create a new NitzSignal that should be filtered.
    int elapsedTimeIncrement = nitzSpacingThreshold - 1;
    TimestampedValue<NitzData> intermediateSignal = createIncrementedNitzSignal(baseSignal, elapsedTimeIncrement);
    NitzData intermediateNitzData = intermediateSignal.getValue();
    assertFalse(triPredicate.mustProcessNitzSignal(baseSignal, intermediateSignal));
    // Two signals spaced apart so that the second would normally be filtered and it contains
    // a UTC time that is not sufficiently different.
    {
        NitzData incrementedUtcTimeNitzData = NitzData.createForTests(intermediateNitzData.getLocalOffsetMillis(), intermediateNitzData.getDstAdjustmentMillis(), intermediateNitzData.getCurrentTimeInMillis() + nitzUtcDiffThreshold - 1, intermediateNitzData.getEmulatorHostTimeZone());
        TimestampedValue<NitzData> incrementedNitzSignal = new TimestampedValue<>(intermediateSignal.getReferenceTimeMillis(), incrementedUtcTimeNitzData);
        assertFalse(triPredicate.mustProcessNitzSignal(baseSignal, incrementedNitzSignal));
    }
    // Two signals spaced apart so that the second would normally be filtered but it contains
    // a UTC time that is sufficiently different.
    {
        NitzData incrementedUtcTimeNitzData = NitzData.createForTests(intermediateNitzData.getLocalOffsetMillis(), intermediateNitzData.getDstAdjustmentMillis(), intermediateNitzData.getCurrentTimeInMillis() + nitzUtcDiffThreshold + 1, intermediateNitzData.getEmulatorHostTimeZone());
        TimestampedValue<NitzData> incrementedNitzSignal = new TimestampedValue<>(intermediateSignal.getReferenceTimeMillis(), incrementedUtcTimeNitzData);
        assertTrue(triPredicate.mustProcessNitzSignal(baseSignal, incrementedNitzSignal));
    }
    // Two signals spaced apart so that the second would normally be filtered and it contains
    // a UTC time that is not sufficiently different.
    {
        NitzData decrementedUtcTimeNitzData = NitzData.createForTests(intermediateNitzData.getLocalOffsetMillis(), intermediateNitzData.getDstAdjustmentMillis(), intermediateNitzData.getCurrentTimeInMillis() - nitzUtcDiffThreshold + 1, intermediateNitzData.getEmulatorHostTimeZone());
        TimestampedValue<NitzData> decrementedNitzSignal = new TimestampedValue<>(intermediateSignal.getReferenceTimeMillis(), decrementedUtcTimeNitzData);
        assertFalse(triPredicate.mustProcessNitzSignal(baseSignal, decrementedNitzSignal));
    }
    // Two signals spaced apart so that the second would normally be filtered but it contains
    // a UTC time that is sufficiently different.
    {
        NitzData decrementedUtcTimeNitzData = NitzData.createForTests(intermediateNitzData.getLocalOffsetMillis(), intermediateNitzData.getDstAdjustmentMillis(), intermediateNitzData.getCurrentTimeInMillis() + nitzUtcDiffThreshold + 1, intermediateNitzData.getEmulatorHostTimeZone());
        TimestampedValue<NitzData> decrementedNitzSignal = new TimestampedValue<>(intermediateSignal.getReferenceTimeMillis(), decrementedUtcTimeNitzData);
        assertTrue(triPredicate.mustProcessNitzSignal(baseSignal, decrementedNitzSignal));
    }
}
Also used : TimestampedValue(android.os.TimestampedValue) TrivalentPredicate(com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.TrivalentPredicate) 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

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