Search in sources :

Example 11 with Scenario

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

Example 12 with Scenario

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

the class NitzStateMachineImplTest method test_nitzThenCountry.

@Test
public void test_nitzThenCountry() throws Exception {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    String networkCountryIsoCode = scenario.getNetworkCountryIsoCode();
    // Capture test expectations from the real suggester and confirm we can tell the difference
    // between them.
    TelephonyTimeZoneSuggestion expectedTimeZoneSuggestion1 = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, null, /* countryIsoCode */
    nitzSignal);
    TelephonyTimeZoneSuggestion expectedTimeZoneSuggestion2 = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, networkCountryIsoCode, nitzSignal);
    assertNotEquals(expectedTimeZoneSuggestion1, expectedTimeZoneSuggestion2);
    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.
    TelephonyTimeSuggestion expectedTimeSuggestion = createTimeSuggestionFromNitzSignal(SLOT_INDEX, nitzSignal);
    script.verifyTimeAndTimeZoneSuggestedAndReset(expectedTimeSuggestion, expectedTimeZoneSuggestion1);
    // Check NitzStateMachine exposed state.
    assertEquals(nitzSignal.getValue(), mNitzStateMachineImpl.getCachedNitzData());
    // Simulate country being known and verify the behavior.
    script.countryReceived(networkCountryIsoCode).verifyOnlyTimeZoneWasSuggestedAndReset(expectedTimeZoneSuggestion2);
    // Check NitzStateMachine exposed state.
    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 13 with Scenario

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

the class NitzStateMachineImplTest method test_handleNetworkUnavailableClearsNetworkState.

/**
 * Confirm losing the network / NITZ doesn't clear country state.
 */
@Test
public void test_handleNetworkUnavailableClearsNetworkState() throws Exception {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1.mutableCopy();
    int timeStepMillis = (int) TimeUnit.HOURS.toMillis(3);
    String countryIsoCode = scenario.getNetworkCountryIsoCode();
    Script script = new Script().initializeSystemClock(ARBITRARY_SYSTEM_CLOCK_TIME).networkAvailable();
    // Simulate a device receiving signals that allow it to detect time and time zone.
    TimestampedValue<NitzData> initialNitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    TelephonyTimeSuggestion expectedInitialTimeSuggestion = createTimeSuggestionFromNitzSignal(SLOT_INDEX, initialNitzSignal);
    // Simulate receiving the NITZ signal and country.
    script.nitzReceived(initialNitzSignal).countryReceived(countryIsoCode);
    // Verify the state machine did the right thing.
    TelephonyTimeZoneSuggestion expectedInitialTimeZoneSuggestion = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, countryIsoCode, initialNitzSignal);
    script.verifyTimeAndTimeZoneSuggestedAndReset(expectedInitialTimeSuggestion, expectedInitialTimeZoneSuggestion);
    // Check state that NitzStateMachine must expose.
    assertEquals(initialNitzSignal.getValue(), mNitzStateMachineImpl.getCachedNitzData());
    // Simulate the passage of time and update the device realtime clock.
    scenario.incrementTime(timeStepMillis);
    script.incrementTime(timeStepMillis);
    // Simulate network being lost.
    script.networkUnavailable();
    // Check the "no NITZ" time and time zone suggestions are made.
    TelephonyTimeZoneSuggestion expectedMiddleTimeZoneSuggestion = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, countryIsoCode, null);
    script.verifyTimeAndTimeZoneSuggestedAndReset(EMPTY_TIME_SUGGESTION, expectedMiddleTimeZoneSuggestion);
    // Check state that NitzStateMachine must expose.
    assertNull(mNitzStateMachineImpl.getCachedNitzData());
    // Simulate the passage of time and update the device realtime clock.
    scenario.incrementTime(timeStepMillis);
    script.incrementTime(timeStepMillis);
    // Simulate the network being found.
    script.networkAvailable().verifyNothingWasSuggested();
    // Check the state that NitzStateMachine must expose.
    assertNull(mNitzStateMachineImpl.getCachedNitzData());
    // Simulate the passage of time and update the device realtime clock.
    scenario.incrementTime(timeStepMillis);
    script.incrementTime(timeStepMillis);
    // Simulate the device receiving NITZ signal again. Now the NitzStateMachine should be
    // opinionated again.
    TimestampedValue<NitzData> finalNitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    script.nitzReceived(finalNitzSignal);
    // Verify the state machine did the right thing.
    TelephonyTimeSuggestion expectedFinalTimeSuggestion = createTimeSuggestionFromNitzSignal(SLOT_INDEX, finalNitzSignal);
    TelephonyTimeZoneSuggestion expectedFinalTimeZoneSuggestion = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, countryIsoCode, finalNitzSignal);
    script.verifyTimeAndTimeZoneSuggestedAndReset(expectedFinalTimeSuggestion, expectedFinalTimeZoneSuggestion);
    // Check state that NitzStateMachine must expose.
    assertEquals(finalNitzSignal.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 14 with Scenario

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

the class NitzStateMachineImplTest method test_countryThenNitz.

@Test
public void test_countryThenNitz() throws Exception {
    Scenario scenario = UNIQUE_US_ZONE_SCENARIO1;
    String networkCountryIsoCode = scenario.getNetworkCountryIsoCode();
    TimestampedValue<NitzData> nitzSignal = scenario.createNitzSignal(mFakeDeviceState.elapsedRealtime());
    // Capture expected results from the real suggester and confirm we can tell the difference
    // between them.
    TelephonyTimeZoneSuggestion expectedTimeZoneSuggestion1 = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, networkCountryIsoCode, null);
    TelephonyTimeZoneSuggestion expectedTimeZoneSuggestion2 = mRealTimeZoneSuggester.getTimeZoneSuggestion(SLOT_INDEX, networkCountryIsoCode, nitzSignal);
    assertNotNull(expectedTimeZoneSuggestion2);
    assertNotEquals(expectedTimeZoneSuggestion1, expectedTimeZoneSuggestion2);
    Script script = new Script().initializeSystemClock(ARBITRARY_SYSTEM_CLOCK_TIME).networkAvailable();
    // Simulate country being known.
    script.countryReceived(networkCountryIsoCode);
    script.verifyOnlyTimeZoneWasSuggestedAndReset(expectedTimeZoneSuggestion1);
    // Check NitzStateMachine exposed state.
    assertNull(mNitzStateMachineImpl.getCachedNitzData());
    // Simulate NITZ being received and verify the behavior.
    script.nitzReceived(nitzSignal);
    TelephonyTimeSuggestion expectedTimeSuggestion = createTimeSuggestionFromNitzSignal(SLOT_INDEX, nitzSignal);
    script.verifyTimeAndTimeZoneSuggestedAndReset(expectedTimeSuggestion, expectedTimeZoneSuggestion2);
    // Check NitzStateMachine exposed state.
    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 15 with Scenario

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

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