Search in sources :

Example 6 with Scenario

use of com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario 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 7 with Scenario

use of com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario 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 8 with Scenario

use of com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario 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)

Example 9 with Scenario

use of com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario in project android_frameworks_opt_telephony by LineageOS.

the class NitzStateMachineImplTest method test_airplaneModeClearsState.

@Test
public void test_airplaneModeClearsState() throws Exception {
    Scenario scenario = UNITED_KINGDOM_SCENARIO.mutableCopy();
    int timeStepMillis = (int) TimeUnit.HOURS.toMillis(3);
    Script script = new Script().initializeSystemClock(ARBITRARY_SYSTEM_CLOCK_TIME).networkAvailable();
    // Pre-flight: Simulate a device receiving signals that allow it to detect time and time
    // zone.
    TimestampedValue<NitzData> preFlightNitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    TelephonyTimeSuggestion expectedPreFlightTimeSuggestion = createTimeSuggestionFromNitzSignal(SLOT_INDEX, preFlightNitzSignal);
    String preFlightCountryIsoCode = scenario.getNetworkCountryIsoCode();
    // Simulate receiving the NITZ signal and country.
    script.nitzReceived(preFlightNitzSignal).countryReceived(preFlightCountryIsoCode);
    // Verify the state machine did the right thing.
    TelephonyTimeZoneSuggestion expectedPreFlightTimeZoneSuggestion = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, preFlightCountryIsoCode, preFlightNitzSignal);
    script.verifyTimeAndTimeZoneSuggestedAndReset(expectedPreFlightTimeSuggestion, expectedPreFlightTimeZoneSuggestion);
    // Check state that NitzStateMachine must expose.
    assertEquals(preFlightNitzSignal.getValue(), mNitzStateMachineImpl.getCachedNitzData());
    // Boarded flight: Airplane mode turned on / time zone detection still enabled.
    // The NitzStateMachine must lose all state and stop having an opinion about time zone.
    // Simulate the passage of time and update the device realtime clock.
    scenario.incrementTime(timeStepMillis);
    script.incrementTime(timeStepMillis);
    // Simulate airplane mode being turned on.
    script.toggleAirplaneMode(true);
    // Verify the state machine did the right thing.
    // Check the time zone suggestion was withdrawn (time is not currently withdrawn).
    script.verifyTimeAndTimeZoneSuggestedAndReset(EMPTY_TIME_SUGGESTION, EMPTY_TIME_ZONE_SUGGESTION);
    // Check state that NitzStateMachine must expose.
    assertNull(mNitzStateMachineImpl.getCachedNitzData());
    // During flight: Airplane mode turned off / time zone detection still enabled.
    // The NitzStateMachine still must not have an opinion about time zone / hold any state.
    // Simulate the passage of time and update the device realtime clock.
    scenario.incrementTime(timeStepMillis);
    script.incrementTime(timeStepMillis);
    // Simulate airplane mode being turned off.
    script.toggleAirplaneMode(false);
    // Verify nothing was suggested: The last suggestion was empty so nothing has changed.
    script.verifyNothingWasSuggested();
    // Check the state that NitzStateMachine must expose.
    assertNull(mNitzStateMachineImpl.getCachedNitzData());
    // Post flight: Device has moved and receives new signals.
    // Simulate the passage of time and update the device realtime clock.
    scenario.incrementTime(timeStepMillis);
    script.incrementTime(timeStepMillis);
    // Simulate the movement to the destination.
    scenario.changeCountry(UNIQUE_US_ZONE_SCENARIO1.getTimeZoneId(), UNIQUE_US_ZONE_SCENARIO1.getNetworkCountryIsoCode());
    // Simulate the device receiving NITZ signal and country again after the flight. Now the
    // NitzStateMachine should be opinionated again.
    TimestampedValue<NitzData> postFlightNitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    String postFlightCountryCode = scenario.getNetworkCountryIsoCode();
    script.countryReceived(postFlightCountryCode).nitzReceived(postFlightNitzSignal);
    // Verify the state machine did the right thing.
    TelephonyTimeSuggestion expectedPostFlightTimeSuggestion = createTimeSuggestionFromNitzSignal(SLOT_INDEX, postFlightNitzSignal);
    TelephonyTimeZoneSuggestion expectedPostFlightTimeZoneSuggestion = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, postFlightCountryCode, postFlightNitzSignal);
    script.verifyTimeAndTimeZoneSuggestedAndReset(expectedPostFlightTimeSuggestion, expectedPostFlightTimeZoneSuggestion);
    // Check state that NitzStateMachine must expose.
    assertEquals(postFlightNitzSignal.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 10 with Scenario

use of com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario in project android_frameworks_opt_telephony by LineageOS.

the class TimeZoneSuggesterImplTest method test_emptySuggestionForNullCountryWithNitz.

@Test
public void test_emptySuggestionForNullCountryWithNitz() throws Exception {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(ARBITRARY_REALTIME_MILLIS);
    assertEquals(EMPTY_TIME_ZONE_SUGGESTION, mTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, null, /* countryIsoCode */
    nitzSignal));
}
Also used : 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)19 TelephonyTest (com.android.internal.telephony.TelephonyTest)19 Scenario (com.android.internal.telephony.nitz.NitzStateMachineTestSupport.Scenario)19 Test (org.junit.Test)19 TrivalentPredicate (com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.TrivalentPredicate)9 TelephonyTimeZoneSuggestion (android.app.timezonedetector.TelephonyTimeZoneSuggestion)8 TimestampedValue (android.os.TimestampedValue)8 TelephonyTimeSuggestion (android.app.timedetector.TelephonyTimeSuggestion)7 NitzSignalInputFilterPredicateImpl (com.android.internal.telephony.nitz.NitzSignalInputFilterPredicateFactory.NitzSignalInputFilterPredicateImpl)5 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