Search in sources :

Example 1 with TimestampedValue

use of android.os.TimestampedValue 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 2 with TimestampedValue

use of android.os.TimestampedValue 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)

Example 3 with TimestampedValue

use of android.os.TimestampedValue in project android_frameworks_opt_telephony by LineageOS.

the class NitzSignalInputFilterPredicateFactoryTest method testNitzSignalInputFilterPredicateImpl_falseIsHonored.

@Test
public void testNitzSignalInputFilterPredicateImpl_falseIsHonored() {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    TrivalentPredicate nullPredicate = (x, y) -> null;
    TrivalentPredicate falsePredicate = (x, y) -> false;
    TrivalentPredicate exceptionPredicate = (x, y) -> {
        throw new RuntimeException();
    };
    TrivalentPredicate[] triPredicates = { nullPredicate, falsePredicate, exceptionPredicate };
    NitzSignalInputFilterPredicateImpl impl = new NitzSignalInputFilterPredicateImpl(triPredicates);
    assertFalse(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 TimestampedValue

use of android.os.TimestampedValue in project android_frameworks_opt_telephony by LineageOS.

the class NitzSignalInputFilterPredicateFactoryTest method testTrivalentPredicate_rateLimitCheck_offsetDifference.

@Test
public void testTrivalentPredicate_rateLimitCheck_offsetDifference() {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    int nitzSpacingThreshold = mFakeDeviceState.getNitzUpdateSpacingMillis();
    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> intermediateNitzSignal = createIncrementedNitzSignal(baseSignal, elapsedTimeIncrement);
    NitzData intermediateNitzData = intermediateNitzSignal.getValue();
    assertFalse(triPredicate.mustProcessNitzSignal(baseSignal, intermediateNitzSignal));
    // Two signals spaced apart so that the second would be filtered, but they contain different
    // offset information so should be detected as "different" and processed.
    {
        // Modifying the local offset should be enough to recognize the NitzData as different.
        NitzData differentOffsetNitzData = NitzData.createForTests(intermediateNitzData.getLocalOffsetMillis() + 1, intermediateNitzData.getDstAdjustmentMillis(), intermediateNitzData.getCurrentTimeInMillis(), intermediateNitzData.getEmulatorHostTimeZone());
        TimestampedValue<NitzData> differentOffsetSignal = new TimestampedValue<>(baseSignal.getReferenceTimeMillis() + elapsedTimeIncrement, differentOffsetNitzData);
        assertTrue(triPredicate.mustProcessNitzSignal(baseSignal, differentOffsetSignal));
    }
}
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)

Example 5 with TimestampedValue

use of android.os.TimestampedValue in project android_frameworks_opt_telephony by LineageOS.

the class TimeZoneSuggesterImplTest method test_emulatorNitzExtensionUsedForTimeZone.

@Test
public void test_emulatorNitzExtensionUsedForTimeZone() throws Exception {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    TimestampedValue<NitzData> originalNitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    // Create an NITZ signal with an explicit time zone (as can happen on emulators).
    NitzData originalNitzData = originalNitzSignal.getValue();
    // A time zone that is obviously not in the US, but because the explicit value is present it
    // should not be questioned.
    String emulatorTimeZoneId = "Europe/London";
    NitzData emulatorNitzData = NitzData.createForTests(originalNitzData.getLocalOffsetMillis(), originalNitzData.getDstAdjustmentMillis(), originalNitzData.getCurrentTimeInMillis(), java.util.TimeZone.getTimeZone(emulatorTimeZoneId));
    TimestampedValue<NitzData> emulatorNitzSignal = new TimestampedValue<>(originalNitzSignal.getReferenceTimeMillis(), emulatorNitzData);
    TelephonyTimeZoneSuggestion expectedTimeZoneSuggestion = new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX).setZoneId(emulatorTimeZoneId).setMatchType(MATCH_TYPE_EMULATOR_ZONE_ID).setQuality(QUALITY_SINGLE_ZONE).build();
    TelephonyTimeZoneSuggestion actualSuggestion = mTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, scenario.getNetworkCountryIsoCode(), emulatorNitzSignal);
    assertEquals(expectedTimeZoneSuggestion, actualSuggestion);
}
Also used : TelephonyTimeZoneSuggestion(android.app.timezonedetector.TelephonyTimeZoneSuggestion) TimestampedValue(android.os.TimestampedValue) 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

TimestampedValue (android.os.TimestampedValue)9 NitzData (com.android.internal.telephony.NitzData)9 TelephonyTest (com.android.internal.telephony.TelephonyTest)8 Scenario (com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario)8 Test (org.junit.Test)8 TrivalentPredicate (com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.TrivalentPredicate)7 NitzSignalInputFilterPredicateImpl (com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.NitzSignalInputFilterPredicateImpl)3 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 After (org.junit.After)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertNull (org.junit.Assert.assertNull)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Assert.fail (org.junit.Assert.fail)3 Before (org.junit.Before)3 NonNull (android.annotation.NonNull)1 TelephonyTimeZoneSuggestion (android.app.timezonedetector.TelephonyTimeZoneSuggestion)1