Search in sources :

Example 6 with TimestampedValue

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

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

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

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

the class NitzSignalInputFilterPredicateFactory method createRateLimitCheck.

/**
 * Returns a {@link TrivalentPredicate} function that implements filtering using
 * {@code oldSignal} and {@code newSignal}. The function can return {@code true} or
 * {@code false} and so is intended as the final function in a chain.
 *
 * Function detail: if an NITZ signal received that is too similar to a previous one
 * it should be disregarded if it's received within a configured time period.
 * The general contract for {@link TrivalentPredicate} allows {@code previousSignal} to be
 * {@code null}, but previous functions are expected to prevent it in this case.
 */
@VisibleForTesting
@NonNull
public static TrivalentPredicate createRateLimitCheck(@NonNull DeviceState deviceState) {
    return new TrivalentPredicate() {

        @Override
        @NonNull
        public Boolean mustProcessNitzSignal(@NonNull TimestampedValue<NitzData> previousSignal, @NonNull TimestampedValue<NitzData> newSignal) {
            Objects.requireNonNull(newSignal);
            Objects.requireNonNull(newSignal.getValue());
            Objects.requireNonNull(previousSignal);
            Objects.requireNonNull(previousSignal.getValue());
            NitzData newNitzData = newSignal.getValue();
            NitzData previousNitzData = previousSignal.getValue();
            // was.
            if (!offsetInfoIsTheSame(previousNitzData, newNitzData)) {
                return true;
            }
            // Now check the continuous NitzData field (time) to see if it is sufficiently
            // different.
            int nitzUpdateSpacing = deviceState.getNitzUpdateSpacingMillis();
            int nitzUpdateDiff = deviceState.getNitzUpdateDiffMillis();
            // Calculate the elapsed time between the new signal and the last signal.
            long elapsedRealtimeSinceLastSaved = newSignal.getReferenceTimeMillis() - previousSignal.getReferenceTimeMillis();
            // Calculate the UTC difference between the time the two signals hold.
            long utcTimeDifferenceMillis = newNitzData.getCurrentTimeInMillis() - previousNitzData.getCurrentTimeInMillis();
            // Ideally the difference between elapsedRealtimeSinceLastSaved and
            // utcTimeDifferenceMillis would be zero.
            long millisGainedOrLost = Math.abs(utcTimeDifferenceMillis - elapsedRealtimeSinceLastSaved);
            if (elapsedRealtimeSinceLastSaved > nitzUpdateSpacing || millisGainedOrLost > nitzUpdateDiff) {
                return true;
            }
            if (DBG) {
                Rlog.d(LOG_TAG, "mustProcessNitzSignal: NITZ signal filtered" + " previousSignal=" + previousSignal + ", newSignal=" + newSignal + ", nitzUpdateSpacing=" + nitzUpdateSpacing + ", nitzUpdateDiff=" + nitzUpdateDiff);
            }
            return false;
        }

        private boolean offsetInfoIsTheSame(NitzData one, NitzData two) {
            return Objects.equals(two.getDstAdjustmentMillis(), one.getDstAdjustmentMillis()) && Objects.equals(two.getEmulatorHostTimeZone(), one.getEmulatorHostTimeZone()) && two.getLocalOffsetMillis() == one.getLocalOffsetMillis();
        }
    };
}
Also used : TimestampedValue(android.os.TimestampedValue) NonNull(android.annotation.NonNull) NitzData(com.android.internal.telephony.NitzData) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) NonNull(android.annotation.NonNull)

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