Search in sources :

Example 1 with DeviceState

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

the class NitzSignalInputFilterPredicateFactory method createBogusElapsedRealtimeCheck.

/**
 * Returns a {@link TrivalentPredicate} function that implements a check for a bad reference
 * time associated with {@code newSignal}. The function can return {@code false} or
 * {@code null}.
 */
@VisibleForTesting
@NonNull
public static TrivalentPredicate createBogusElapsedRealtimeCheck(@NonNull Context context, @NonNull DeviceState deviceState) {
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    final WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG);
    return (oldSignal, newSignal) -> {
        Objects.requireNonNull(newSignal);
        // Validate the newSignal to reject obviously bogus elapsedRealtime values.
        try {
            // Acquire the wake lock as we are reading the elapsed realtime clock below.
            wakeLock.acquire();
            long elapsedRealtime = deviceState.elapsedRealtime();
            long millisSinceNitzReceived = elapsedRealtime - newSignal.getReferenceTimeMillis();
            if (millisSinceNitzReceived < 0 || millisSinceNitzReceived > Integer.MAX_VALUE) {
                if (DBG) {
                    Rlog.d(LOG_TAG, "mustProcessNitzSignal: Not processing NITZ signal" + " because unexpected elapsedRealtime=" + elapsedRealtime + " nitzSignal=" + newSignal);
                }
                return false;
            }
            return null;
        } finally {
            wakeLock.release();
        }
    };
}
Also used : PowerManager(android.os.PowerManager) Context(android.content.Context) Arrays(java.util.Arrays) Nullable(android.annotation.Nullable) TimestampedValue(android.os.TimestampedValue) NonNull(android.annotation.NonNull) NitzData(com.android.internal.telephony.NitzData) Objects(java.util.Objects) WakeLock(android.os.PowerManager.WakeLock) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) PowerManager(android.os.PowerManager) Rlog(com.android.telephony.Rlog) DeviceState(com.android.internal.telephony.NitzStateMachine.DeviceState) NitzSignalInputFilterPredicate(com.android.internal.telephony.nitz.NitzStateMachineImpl.NitzSignalInputFilterPredicate) WakeLock(android.os.PowerManager.WakeLock) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) NonNull(android.annotation.NonNull)

Aggregations

NonNull (android.annotation.NonNull)1 Nullable (android.annotation.Nullable)1 Context (android.content.Context)1 PowerManager (android.os.PowerManager)1 WakeLock (android.os.PowerManager.WakeLock)1 TimestampedValue (android.os.TimestampedValue)1 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)1 NitzData (com.android.internal.telephony.NitzData)1 DeviceState (com.android.internal.telephony.NitzStateMachine.DeviceState)1 NitzSignalInputFilterPredicate (com.android.internal.telephony.nitz.NitzStateMachineImpl.NitzSignalInputFilterPredicate)1 Rlog (com.android.telephony.Rlog)1 Arrays (java.util.Arrays)1 Objects (java.util.Objects)1