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();
}
};
}
Aggregations