Search in sources :

Example 16 with NitzData

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

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

the class NitzSignalInputFilterPredicateFactoryTest method testTrivalentPredicate_rateLimitCheck_elapsedRealtime.

@Test
public void testTrivalentPredicate_rateLimitCheck_elapsedRealtime() {
    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);
    // Two identical signals: no spacing so the new signal should not be processed.
    {
        assertFalse(triPredicate.mustProcessNitzSignal(baseSignal, baseSignal));
    }
    // Two signals not spaced apart enough: the new signal should not processed.
    {
        int elapsedTimeIncrement = nitzSpacingThreshold - 1;
        TimestampedValue<NitzData> newSignal = createIncrementedNitzSignal(baseSignal, elapsedTimeIncrement);
        assertFalse(triPredicate.mustProcessNitzSignal(baseSignal, newSignal));
    }
    // Two signals spaced apart: the new signal should be processed.
    {
        int elapsedTimeIncrement = nitzSpacingThreshold + 1;
        TimestampedValue<NitzData> newSignal = createIncrementedNitzSignal(baseSignal, elapsedTimeIncrement);
        assertTrue(triPredicate.mustProcessNitzSignal(baseSignal, newSignal));
    }
}
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 18 with NitzData

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

the class NitzSignalInputFilterPredicateFactoryTest method testTrivalentPredicate_bogusElapsedRealtimeCheck.

@Test
public void testTrivalentPredicate_bogusElapsedRealtimeCheck() {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    long elapsedRealtimeClock = mFakeDeviceState.elapsedRealtime();
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(elapsedRealtimeClock);
    TrivalentPredicate triPredicate = createBogusElapsedRealtimeCheck(mContext, mFakeDeviceState);
    assertNull(triPredicate.mustProcessNitzSignal(null, nitzSignal));
    // Any signal that claims to be from the future must be rejected.
    TimestampedValue<NitzData> bogusNitzSignal = new TimestampedValue<>(elapsedRealtimeClock + 1, nitzSignal.getValue());
    assertFalse(triPredicate.mustProcessNitzSignal(null, bogusNitzSignal));
}
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 19 with NitzData

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

the class NitzSignalInputFilterPredicateFactoryTest method testNitzSignalInputFilterPredicateImpl_nullIsIgnored.

@Test
public void testNitzSignalInputFilterPredicateImpl_nullIsIgnored() {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    TrivalentPredicate nullPredicate = (x, y) -> null;
    TrivalentPredicate[] triPredicates = { nullPredicate };
    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 20 with NitzData

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

the class NitzSignalInputFilterPredicateFactoryTest method testTrivalentPredicate_noOldSignalCheck.

@Test
public void testTrivalentPredicate_noOldSignalCheck() {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    TrivalentPredicate triPredicate = NitzSignalInputFilterPredicateFactory.createNoOldSignalCheck();
    assertTrue(triPredicate.mustProcessNitzSignal(null, nitzSignal));
    assertNull(triPredicate.mustProcessNitzSignal(nitzSignal, nitzSignal));
}
Also used : 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