diff options
9 files changed, 215 insertions, 204 deletions
diff --git a/core/java/android/app/time/ExternalTimeSuggestion.java b/core/java/android/app/time/ExternalTimeSuggestion.java index 8e281c07c45d..a7c0e5c79607 100644 --- a/core/java/android/app/time/ExternalTimeSuggestion.java +++ b/core/java/android/app/time/ExternalTimeSuggestion.java @@ -50,16 +50,17 @@ import java.util.Objects; * <p>The creator of an external suggestion is expected to be separate Android process, e.g. a * process integrating with the external time source via a HAL or local network. The creator must * capture the elapsed realtime reference clock, e.g. via {@link SystemClock#elapsedRealtime()}, - * when the UTC time is first obtained (usually under a wakelock). This enables Android to adjust - * for latency introduced between suggestion creation and eventual use. Adjustments for other + * when the Unix epoch time is first obtained (usually under a wakelock). This enables Android to + * adjust for latency introduced between suggestion creation and eventual use. Adjustments for other * sources of latency, i.e. those before the external time suggestion is created, must be handled by * the creator. * * <p>{@code elapsedRealtimeMillis} and {@code suggestionMillis} represent the suggested time. - * {@code suggestionMillis} is the number of milliseconds elapsed since 1/1/1970 00:00:00 UTC. - * {@code elapsedRealtimeMillis} is the value of the elapsed realtime clock when {@code - * suggestionMillis} was established. Note that the elapsed realtime clock is considered accurate - * but it is volatile, so time suggestions cannot be persisted across device resets. + * {@code suggestionMillis} is the number of milliseconds elapsed since 1/1/1970 00:00:00 UTC + * according to the Unix time scale. {@code elapsedRealtimeMillis} is the value of the elapsed + * realtime clock when {@code suggestionMillis} was established. Note that the elapsed realtime + * clock is considered accurate but it is volatile, so time suggestions cannot be persisted across + * device resets. * * <p>{@code debugInfo} contains debugging metadata associated with the suggestion. This is used to * record why the suggestion exists and how it was entered. This information exists only to aid in @@ -83,7 +84,7 @@ public final class ExternalTimeSuggestion implements Parcelable { }; @NonNull - private final TimestampedValue<Long> mUtcTime; + private final TimestampedValue<Long> mUnixEpochTime; @Nullable private ArrayList<String> mDebugInfo; @@ -92,12 +93,12 @@ public final class ExternalTimeSuggestion implements Parcelable { * ExternalTimeSuggestion} for more details. * * @param elapsedRealtimeMillis the elapsed realtime clock reference for the suggestion - * @param suggestionMillis the suggested UTC time in milliseconds since the start of the + * @param suggestionMillis the suggested time in milliseconds since the start of the * Unix epoch */ public ExternalTimeSuggestion(@ElapsedRealtimeLong long elapsedRealtimeMillis, @CurrentTimeMillisLong long suggestionMillis) { - mUtcTime = new TimestampedValue(elapsedRealtimeMillis, suggestionMillis); + mUnixEpochTime = new TimestampedValue(elapsedRealtimeMillis, suggestionMillis); } private static ExternalTimeSuggestion createFromParcel(Parcel in) { @@ -117,7 +118,7 @@ public final class ExternalTimeSuggestion implements Parcelable { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeParcelable(mUtcTime, 0); + dest.writeParcelable(mUnixEpochTime, 0); dest.writeList(mDebugInfo); } @@ -125,8 +126,8 @@ public final class ExternalTimeSuggestion implements Parcelable { * {@hide} */ @NonNull - public TimestampedValue<Long> getUtcTime() { - return mUtcTime; + public TimestampedValue<Long> getUnixEpochTime() { + return mUnixEpochTime; } /** @@ -160,17 +161,18 @@ public final class ExternalTimeSuggestion implements Parcelable { return false; } ExternalTimeSuggestion that = (ExternalTimeSuggestion) o; - return Objects.equals(mUtcTime, that.mUtcTime); + return Objects.equals(mUnixEpochTime, that.mUnixEpochTime); } @Override public int hashCode() { - return Objects.hash(mUtcTime); + return Objects.hash(mUnixEpochTime); } @Override public String toString() { - return "ExternalTimeSuggestion{" + "mUtcTime=" + mUtcTime + ", mDebugInfo=" + mDebugInfo + return "ExternalTimeSuggestion{" + "mUnixEpochTime=" + mUnixEpochTime + + ", mDebugInfo=" + mDebugInfo + '}'; } } diff --git a/core/java/android/app/timedetector/GnssTimeSuggestion.java b/core/java/android/app/timedetector/GnssTimeSuggestion.java index 6478a2dd2aa9..34f4565fb410 100644 --- a/core/java/android/app/timedetector/GnssTimeSuggestion.java +++ b/core/java/android/app/timedetector/GnssTimeSuggestion.java @@ -31,11 +31,11 @@ import java.util.Objects; /** * A time signal from a GNSS source. * - * <p>{@code utcTime} is the suggested time. The {@code utcTime.value} is the number of milliseconds - * elapsed since 1/1/1970 00:00:00 UTC. The {@code utcTime.referenceTimeMillis} is the value of the - * elapsed realtime clock when the {@code utcTime.value} was established. - * Note that the elapsed realtime clock is considered accurate but it is volatile, so time - * suggestions cannot be persisted across device resets. + * <p>{@code unixEpochTime} is the suggested time. The {@code unixEpochTime.value} is the number of + * milliseconds elapsed since 1/1/1970 00:00:00 UTC according to the Unix time system. The {@code + * unixEpochTime.referenceTimeMillis} is the value of the elapsed realtime clock when the {@code + * unixEpochTime.value} was established. Note that the elapsed realtime clock is considered accurate + * but it is volatile, so time suggestions cannot be persisted across device resets. * * <p>{@code debugInfo} contains debugging metadata associated with the suggestion. This is used to * record why the suggestion exists and how it was entered. This information exists only to aid in @@ -57,17 +57,17 @@ public final class GnssTimeSuggestion implements Parcelable { } }; - @NonNull private final TimestampedValue<Long> mUtcTime; + @NonNull private final TimestampedValue<Long> mUnixEpochTime; @Nullable private ArrayList<String> mDebugInfo; - public GnssTimeSuggestion(@NonNull TimestampedValue<Long> utcTime) { - mUtcTime = Objects.requireNonNull(utcTime); - Objects.requireNonNull(utcTime.getValue()); + public GnssTimeSuggestion(@NonNull TimestampedValue<Long> unixEpochTime) { + mUnixEpochTime = Objects.requireNonNull(unixEpochTime); + Objects.requireNonNull(unixEpochTime.getValue()); } private static GnssTimeSuggestion createFromParcel(Parcel in) { - TimestampedValue<Long> utcTime = in.readParcelable(null /* classLoader */); - GnssTimeSuggestion suggestion = new GnssTimeSuggestion(utcTime); + TimestampedValue<Long> unixEpochTime = in.readParcelable(null /* classLoader */); + GnssTimeSuggestion suggestion = new GnssTimeSuggestion(unixEpochTime); @SuppressWarnings("unchecked") ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(null /* classLoader */); suggestion.mDebugInfo = debugInfo; @@ -81,13 +81,13 @@ public final class GnssTimeSuggestion implements Parcelable { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeParcelable(mUtcTime, 0); + dest.writeParcelable(mUnixEpochTime, 0); dest.writeList(mDebugInfo); } @NonNull - public TimestampedValue<Long> getUtcTime() { - return mUtcTime; + public TimestampedValue<Long> getUnixEpochTime() { + return mUnixEpochTime; } @NonNull @@ -117,18 +117,18 @@ public final class GnssTimeSuggestion implements Parcelable { return false; } GnssTimeSuggestion that = (GnssTimeSuggestion) o; - return Objects.equals(mUtcTime, that.mUtcTime); + return Objects.equals(mUnixEpochTime, that.mUnixEpochTime); } @Override public int hashCode() { - return Objects.hash(mUtcTime); + return Objects.hash(mUnixEpochTime); } @Override public String toString() { return "GnssTimeSuggestion{" - + "mUtcTime=" + mUtcTime + + "mUnixEpochTime=" + mUnixEpochTime + ", mDebugInfo=" + mDebugInfo + '}'; } diff --git a/core/java/android/app/timedetector/ManualTimeSuggestion.java b/core/java/android/app/timedetector/ManualTimeSuggestion.java index 299e9518e329..76db33b1c32b 100644 --- a/core/java/android/app/timedetector/ManualTimeSuggestion.java +++ b/core/java/android/app/timedetector/ManualTimeSuggestion.java @@ -31,9 +31,9 @@ import java.util.Objects; /** * A time signal from a manual (user provided) source. * - * <p>{@code utcTime} is the suggested time. The {@code utcTime.value} is the number of milliseconds - * elapsed since 1/1/1970 00:00:00 UTC. The {@code utcTime.referenceTimeMillis} is the value of the - * elapsed realtime clock when the {@code utcTime.value} was established. + * <p>{@code unixEpochTime} is the suggested time. The {@code unixEpochTime.value} is the number of + * milliseconds elapsed since 1/1/1970 00:00:00 UTC. The {@code unixEpochTime.referenceTimeMillis} + * is the value of the elapsed realtime clock when the {@code unixEpochTime.value} was established. * Note that the elapsed realtime clock is considered accurate but it is volatile, so time * suggestions cannot be persisted across device resets. * @@ -57,17 +57,17 @@ public final class ManualTimeSuggestion implements Parcelable { } }; - @NonNull private final TimestampedValue<Long> mUtcTime; + @NonNull private final TimestampedValue<Long> mUnixEpochTime; @Nullable private ArrayList<String> mDebugInfo; - public ManualTimeSuggestion(@NonNull TimestampedValue<Long> utcTime) { - mUtcTime = Objects.requireNonNull(utcTime); - Objects.requireNonNull(utcTime.getValue()); + public ManualTimeSuggestion(@NonNull TimestampedValue<Long> unixEpochTime) { + mUnixEpochTime = Objects.requireNonNull(unixEpochTime); + Objects.requireNonNull(unixEpochTime.getValue()); } private static ManualTimeSuggestion createFromParcel(Parcel in) { - TimestampedValue<Long> utcTime = in.readParcelable(null /* classLoader */); - ManualTimeSuggestion suggestion = new ManualTimeSuggestion(utcTime); + TimestampedValue<Long> unixEpochTime = in.readParcelable(null /* classLoader */); + ManualTimeSuggestion suggestion = new ManualTimeSuggestion(unixEpochTime); @SuppressWarnings("unchecked") ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(null /* classLoader */); suggestion.mDebugInfo = debugInfo; @@ -81,13 +81,13 @@ public final class ManualTimeSuggestion implements Parcelable { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeParcelable(mUtcTime, 0); + dest.writeParcelable(mUnixEpochTime, 0); dest.writeList(mDebugInfo); } @NonNull - public TimestampedValue<Long> getUtcTime() { - return mUtcTime; + public TimestampedValue<Long> getUnixEpochTime() { + return mUnixEpochTime; } @NonNull @@ -117,18 +117,18 @@ public final class ManualTimeSuggestion implements Parcelable { return false; } ManualTimeSuggestion that = (ManualTimeSuggestion) o; - return Objects.equals(mUtcTime, that.mUtcTime); + return Objects.equals(mUnixEpochTime, that.mUnixEpochTime); } @Override public int hashCode() { - return Objects.hash(mUtcTime); + return Objects.hash(mUnixEpochTime); } @Override public String toString() { return "ManualTimeSuggestion{" - + "mUtcTime=" + mUtcTime + + "mUnixEpochTime=" + mUnixEpochTime + ", mDebugInfo=" + mDebugInfo + '}'; } diff --git a/core/java/android/app/timedetector/NetworkTimeSuggestion.java b/core/java/android/app/timedetector/NetworkTimeSuggestion.java index a5259c27ec42..e22f1d6ea8be 100644 --- a/core/java/android/app/timedetector/NetworkTimeSuggestion.java +++ b/core/java/android/app/timedetector/NetworkTimeSuggestion.java @@ -31,11 +31,12 @@ import java.util.Objects; /** * A time signal from a network time source like NTP. * - * <p>{@code utcTime} contains the suggested time. The {@code utcTime.value} is the number of - * milliseconds elapsed since 1/1/1970 00:00:00 UTC. The {@code utcTime.referenceTimeMillis} is the - * value of the elapsed realtime clock when the {@code utcTime.value} was established. - * Note that the elapsed realtime clock is considered accurate but it is volatile, so time - * suggestions cannot be persisted across device resets. + * <p>{@code unixEpochTime} contains the suggested time. The {@code unixEpochTime.value} is the + * number of milliseconds elapsed since 1/1/1970 00:00:00 UTC according to the Unix time system. + * The {@code unixEpochTime.referenceTimeMillis} is the value of the elapsed realtime clock when + * the {@code unixEpochTime.value} was established. Note that the elapsed realtime clock is + * considered accurate but it is volatile, so time suggestions cannot be persisted across device + * resets. * * <p>{@code debugInfo} contains debugging metadata associated with the suggestion. This is used to * record why the suggestion exists and how it was determined. This information exists only to aid @@ -57,17 +58,17 @@ public final class NetworkTimeSuggestion implements Parcelable { } }; - @NonNull private final TimestampedValue<Long> mUtcTime; + @NonNull private final TimestampedValue<Long> mUnixEpochTime; @Nullable private ArrayList<String> mDebugInfo; - public NetworkTimeSuggestion(@NonNull TimestampedValue<Long> utcTime) { - mUtcTime = Objects.requireNonNull(utcTime); - Objects.requireNonNull(utcTime.getValue()); + public NetworkTimeSuggestion(@NonNull TimestampedValue<Long> unixEpochTime) { + mUnixEpochTime = Objects.requireNonNull(unixEpochTime); + Objects.requireNonNull(unixEpochTime.getValue()); } private static NetworkTimeSuggestion createFromParcel(Parcel in) { - TimestampedValue<Long> utcTime = in.readParcelable(null /* classLoader */); - NetworkTimeSuggestion suggestion = new NetworkTimeSuggestion(utcTime); + TimestampedValue<Long> unixEpochTime = in.readParcelable(null /* classLoader */); + NetworkTimeSuggestion suggestion = new NetworkTimeSuggestion(unixEpochTime); @SuppressWarnings("unchecked") ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(null /* classLoader */); suggestion.mDebugInfo = debugInfo; @@ -81,13 +82,13 @@ public final class NetworkTimeSuggestion implements Parcelable { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeParcelable(mUtcTime, 0); + dest.writeParcelable(mUnixEpochTime, 0); dest.writeList(mDebugInfo); } @NonNull - public TimestampedValue<Long> getUtcTime() { - return mUtcTime; + public TimestampedValue<Long> getUnixEpochTime() { + return mUnixEpochTime; } @NonNull @@ -117,18 +118,18 @@ public final class NetworkTimeSuggestion implements Parcelable { return false; } NetworkTimeSuggestion that = (NetworkTimeSuggestion) o; - return Objects.equals(mUtcTime, that.mUtcTime); + return Objects.equals(mUnixEpochTime, that.mUnixEpochTime); } @Override public int hashCode() { - return Objects.hash(mUtcTime); + return Objects.hash(mUnixEpochTime); } @Override public String toString() { return "NetworkTimeSuggestion{" - + "mUtcTime=" + mUtcTime + + "mUnixEpochTime=" + mUnixEpochTime + ", mDebugInfo=" + mDebugInfo + '}'; } diff --git a/core/java/android/app/timedetector/TelephonyTimeSuggestion.java b/core/java/android/app/timedetector/TelephonyTimeSuggestion.java index 6c3a304ed3a7..4ff75174ab57 100644 --- a/core/java/android/app/timedetector/TelephonyTimeSuggestion.java +++ b/core/java/android/app/timedetector/TelephonyTimeSuggestion.java @@ -34,12 +34,12 @@ import java.util.Objects; * <p>{@code slotIndex} identifies the suggestion source. This enables detection logic to identify * suggestions from the same source when there are several in use. * - * <p>{@code utcTime}. When not {@code null}, the {@code utcTime.value} is the number of - * milliseconds elapsed since 1/1/1970 00:00:00 UTC. The {@code utcTime.referenceTimeMillis} is the - * value of the elapsed realtime clock when the {@code utcTime.value} was established. + * <p>{@code unixEpochTime}. When not {@code null}, the {@code unixEpochTime.value} is the number of + * milliseconds elapsed since 1/1/1970 00:00:00 UTC. The {@code unixEpochTime.referenceTimeMillis} + * is the value of the elapsed realtime clock when the {@code unixEpochTime.value} was established. * Note that the elapsed realtime clock is considered accurate but it is volatile, so time - * suggestions cannot be persisted across device resets. {@code utcTime} can be {@code null} to - * indicate that the telephony source has entered an "un-opinionated" state and any previous + * suggestions cannot be persisted across device resets. {@code unixEpochTime} can be {@code null} + * to indicate that the telephony source has entered an "un-opinionated" state and any previous * suggestion from the source is being withdrawn. * * <p>{@code debugInfo} contains debugging metadata associated with the suggestion. This is used to @@ -65,19 +65,20 @@ public final class TelephonyTimeSuggestion implements Parcelable { }; private final int mSlotIndex; - @Nullable private final TimestampedValue<Long> mUtcTime; + @Nullable private final TimestampedValue<Long> mUnixEpochTime; @Nullable private ArrayList<String> mDebugInfo; private TelephonyTimeSuggestion(Builder builder) { mSlotIndex = builder.mSlotIndex; - mUtcTime = builder.mUtcTime; + mUnixEpochTime = builder.mUnixEpochTime; mDebugInfo = builder.mDebugInfo != null ? new ArrayList<>(builder.mDebugInfo) : null; } private static TelephonyTimeSuggestion createFromParcel(Parcel in) { int slotIndex = in.readInt(); + TimestampedValue<Long> unixEpochTime = in.readParcelable(null /* classLoader */); TelephonyTimeSuggestion suggestion = new TelephonyTimeSuggestion.Builder(slotIndex) - .setUtcTime(in.readParcelable(null /* classLoader */)) + .setUnixEpochTime(unixEpochTime) .build(); @SuppressWarnings("unchecked") ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(null /* classLoader */); @@ -95,7 +96,7 @@ public final class TelephonyTimeSuggestion implements Parcelable { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeInt(mSlotIndex); - dest.writeParcelable(mUtcTime, 0); + dest.writeParcelable(mUnixEpochTime, 0); dest.writeList(mDebugInfo); } @@ -111,11 +112,11 @@ public final class TelephonyTimeSuggestion implements Parcelable { /** * Returns the suggested time or {@code null} if there isn't one. * - * <p>See {@link TelephonyTimeSuggestion} for more information about {@code utcTime}. + * <p>See {@link TelephonyTimeSuggestion} for more information about {@code unixEpochTime}. */ @Nullable - public TimestampedValue<Long> getUtcTime() { - return mUtcTime; + public TimestampedValue<Long> getUnixEpochTime() { + return mUnixEpochTime; } /** @@ -163,19 +164,19 @@ public final class TelephonyTimeSuggestion implements Parcelable { } TelephonyTimeSuggestion that = (TelephonyTimeSuggestion) o; return mSlotIndex == that.mSlotIndex - && Objects.equals(mUtcTime, that.mUtcTime); + && Objects.equals(mUnixEpochTime, that.mUnixEpochTime); } @Override public int hashCode() { - return Objects.hash(mSlotIndex, mUtcTime); + return Objects.hash(mSlotIndex, mUnixEpochTime); } @Override public String toString() { return "TelephonyTimeSuggestion{" + "mSlotIndex='" + mSlotIndex + '\'' - + ", mUtcTime=" + mUtcTime + + ", mUnixEpochTime=" + mUnixEpochTime + ", mDebugInfo=" + mDebugInfo + '}'; } @@ -187,7 +188,7 @@ public final class TelephonyTimeSuggestion implements Parcelable { */ public static final class Builder { private final int mSlotIndex; - @Nullable private TimestampedValue<Long> mUtcTime; + @Nullable private TimestampedValue<Long> mUnixEpochTime; @Nullable private List<String> mDebugInfo; /** @@ -202,16 +203,16 @@ public final class TelephonyTimeSuggestion implements Parcelable { /** * Returns the builder for call chaining. * - * <p>See {@link TelephonyTimeSuggestion} for more information about {@code utcTime}. + * <p>See {@link TelephonyTimeSuggestion} for more information about {@code unixEpochTime}. */ @NonNull - public Builder setUtcTime(@Nullable TimestampedValue<Long> utcTime) { - if (utcTime != null) { - // utcTime can be null, but the value it holds cannot. - Objects.requireNonNull(utcTime.getValue()); + public Builder setUnixEpochTime(@Nullable TimestampedValue<Long> unixEpochTime) { + if (unixEpochTime != null) { + // unixEpochTime can be null, but the value it holds cannot. + Objects.requireNonNull(unixEpochTime.getValue()); } - mUtcTime = utcTime; + mUnixEpochTime = unixEpochTime; return this; } diff --git a/core/tests/coretests/src/android/app/timedetector/TelephonyTimeSuggestionTest.java b/core/tests/coretests/src/android/app/timedetector/TelephonyTimeSuggestionTest.java index 4b64dfc84fb7..cc7557977e80 100644 --- a/core/tests/coretests/src/android/app/timedetector/TelephonyTimeSuggestionTest.java +++ b/core/tests/coretests/src/android/app/timedetector/TelephonyTimeSuggestionTest.java @@ -45,13 +45,13 @@ public class TelephonyTimeSuggestionTest { assertEquals(two, one); } - builder1.setUtcTime(new TimestampedValue<>(1111L, 2222L)); + builder1.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L)); { TelephonyTimeSuggestion one = builder1.build(); assertEquals(one, one); } - builder2.setUtcTime(new TimestampedValue<>(1111L, 2222L)); + builder2.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L)); { TelephonyTimeSuggestion one = builder1.build(); TelephonyTimeSuggestion two = builder2.build(); @@ -61,7 +61,7 @@ public class TelephonyTimeSuggestionTest { TelephonyTimeSuggestion.Builder builder3 = new TelephonyTimeSuggestion.Builder(SLOT_INDEX + 1); - builder3.setUtcTime(new TimestampedValue<>(1111L, 2222L)); + builder3.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L)); { TelephonyTimeSuggestion one = builder1.build(); TelephonyTimeSuggestion three = builder3.build(); @@ -84,7 +84,7 @@ public class TelephonyTimeSuggestionTest { TelephonyTimeSuggestion.Builder builder = new TelephonyTimeSuggestion.Builder(SLOT_INDEX); assertRoundTripParcelable(builder.build()); - builder.setUtcTime(new TimestampedValue<>(1111L, 2222L)); + builder.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L)); assertRoundTripParcelable(builder.build()); // DebugInfo should also be stored (but is not checked by equals() diff --git a/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java b/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java index 357c23222658..ae4d46c387b9 100644 --- a/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java +++ b/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java @@ -69,7 +69,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { * Telephony and network suggestions older than this value are considered too old to be used. */ @VisibleForTesting - static final long MAX_UTC_TIME_AGE_MILLIS = + static final long MAX_SUGGESTION_TIME_AGE_MILLIS = TELEPHONY_BUCKET_COUNT * TELEPHONY_BUCKET_SIZE_MILLIS; /** @@ -204,9 +204,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { @Override public synchronized void suggestExternalTime(@NonNull ExternalTimeSuggestion timeSuggestion) { - final TimestampedValue<Long> newUtcTime = timeSuggestion.getUtcTime(); + final TimestampedValue<Long> newUnixEpochTime = timeSuggestion.getUnixEpochTime(); - if (!validateAutoSuggestionTime(newUtcTime, timeSuggestion)) { + if (!validateAutoSuggestionTime(newUnixEpochTime, timeSuggestion)) { return; } @@ -218,9 +218,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { @Override public synchronized void suggestGnssTime(@NonNull GnssTimeSuggestion timeSuggestion) { - final TimestampedValue<Long> newUtcTime = timeSuggestion.getUtcTime(); + final TimestampedValue<Long> newUnixEpochTime = timeSuggestion.getUnixEpochTime(); - if (!validateAutoSuggestionTime(newUtcTime, timeSuggestion)) { + if (!validateAutoSuggestionTime(newUnixEpochTime, timeSuggestion)) { return; } @@ -232,19 +232,19 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { @Override public synchronized boolean suggestManualTime(@NonNull ManualTimeSuggestion suggestion) { - final TimestampedValue<Long> newUtcTime = suggestion.getUtcTime(); + final TimestampedValue<Long> newUnixEpochTime = suggestion.getUnixEpochTime(); - if (!validateSuggestionTime(newUtcTime, suggestion)) { + if (!validateSuggestionTime(newUnixEpochTime, suggestion)) { return false; } String cause = "Manual time suggestion received: suggestion=" + suggestion; - return setSystemClockIfRequired(ORIGIN_MANUAL, newUtcTime, cause); + return setSystemClockIfRequired(ORIGIN_MANUAL, newUnixEpochTime, cause); } @Override public synchronized void suggestNetworkTime(@NonNull NetworkTimeSuggestion timeSuggestion) { - if (!validateAutoSuggestionTime(timeSuggestion.getUtcTime(), timeSuggestion)) { + if (!validateAutoSuggestionTime(timeSuggestion.getUnixEpochTime(), timeSuggestion)) { return; } @@ -274,11 +274,11 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { // unlike time zone, where a user may lose connectivity when boarding a flight and where we // do want to "forget" old signals. Suggestions that are too old are discarded later in the // detection algorithm. - if (timeSuggestion.getUtcTime() == null) { + if (timeSuggestion.getUnixEpochTime() == null) { return; } - if (!validateAutoSuggestionTime(timeSuggestion.getUtcTime(), timeSuggestion)) { + if (!validateAutoSuggestionTime(timeSuggestion.getUnixEpochTime(), timeSuggestion)) { return; } @@ -365,14 +365,14 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { @GuardedBy("this") private boolean storeTelephonySuggestion( @NonNull TelephonyTimeSuggestion suggestion) { - TimestampedValue<Long> newUtcTime = suggestion.getUtcTime(); + TimestampedValue<Long> newUnixEpochTime = suggestion.getUnixEpochTime(); int slotIndex = suggestion.getSlotIndex(); TelephonyTimeSuggestion previousSuggestion = mSuggestionBySlotIndex.get(slotIndex); if (previousSuggestion != null) { // We can log / discard suggestions with obvious issues with the reference time clock. - if (previousSuggestion.getUtcTime() == null - || previousSuggestion.getUtcTime().getValue() == null) { + if (previousSuggestion.getUnixEpochTime() == null + || previousSuggestion.getUnixEpochTime().getValue() == null) { // This should be impossible given we only store validated suggestions. Slog.w(LOG_TAG, "Previous suggestion is null or has a null time." + " previousSuggestion=" + previousSuggestion @@ -381,7 +381,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { } long referenceTimeDifference = TimestampedValue.referenceTimeDifference( - newUtcTime, previousSuggestion.getUtcTime()); + newUnixEpochTime, previousSuggestion.getUnixEpochTime()); if (referenceTimeDifference < 0) { // The reference time is before the previously received suggestion. Ignore it. Slog.w(LOG_TAG, "Out of order telephony suggestion received." @@ -398,15 +398,15 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { } private boolean validateSuggestionTime( - @NonNull TimestampedValue<Long> newUtcTime, @NonNull Object suggestion) { - if (newUtcTime.getValue() == null) { + @NonNull TimestampedValue<Long> newUnixEpochTime, @NonNull Object suggestion) { + if (newUnixEpochTime.getValue() == null) { Slog.w(LOG_TAG, "Suggested time value is null. suggestion=" + suggestion); return false; } // We can validate the suggestion against the reference time clock. long elapsedRealtimeMillis = mEnvironment.elapsedRealtimeMillis(); - if (elapsedRealtimeMillis < newUtcTime.getReferenceTimeMillis()) { + if (elapsedRealtimeMillis < newUnixEpochTime.getReferenceTimeMillis()) { // elapsedRealtime clock went backwards? Slog.w(LOG_TAG, "New reference time is in the future? Ignoring." + " elapsedRealtimeMillis=" + elapsedRealtimeMillis @@ -417,17 +417,17 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { } private boolean validateAutoSuggestionTime( - @NonNull TimestampedValue<Long> newUtcTime, @NonNull Object suggestion) { - return validateSuggestionTime(newUtcTime, suggestion) - && validateSuggestionAgainstLowerBound(newUtcTime, suggestion); + @NonNull TimestampedValue<Long> newUnixEpochTime, @NonNull Object suggestion) { + return validateSuggestionTime(newUnixEpochTime, suggestion) + && validateSuggestionAgainstLowerBound(newUnixEpochTime, suggestion); } private boolean validateSuggestionAgainstLowerBound( - @NonNull TimestampedValue<Long> newUtcTime, @NonNull Object suggestion) { + @NonNull TimestampedValue<Long> newUnixEpochTime, @NonNull Object suggestion) { Instant lowerBound = mEnvironment.autoTimeLowerBound(); // Suggestion is definitely wrong if it comes before lower time bound. - if (lowerBound.isAfter(Instant.ofEpochMilli(newUtcTime.getValue()))) { + if (lowerBound.isAfter(Instant.ofEpochMilli(newUnixEpochTime.getValue()))) { Slog.w(LOG_TAG, "Suggestion points to time before lower bound, skipping it. " + "suggestion=" + suggestion + ", lower bound=" + lowerBound); return false; @@ -446,12 +446,12 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { // Try the different origins one at a time. int[] originPriorities = mEnvironment.autoOriginPriorities(); for (int origin : originPriorities) { - TimestampedValue<Long> newUtcTime = null; + TimestampedValue<Long> newUnixEpochTime = null; String cause = null; if (origin == ORIGIN_TELEPHONY) { TelephonyTimeSuggestion bestTelephonySuggestion = findBestTelephonySuggestion(); if (bestTelephonySuggestion != null) { - newUtcTime = bestTelephonySuggestion.getUtcTime(); + newUnixEpochTime = bestTelephonySuggestion.getUnixEpochTime(); cause = "Found good telephony suggestion." + ", bestTelephonySuggestion=" + bestTelephonySuggestion + ", detectionReason=" + detectionReason; @@ -459,7 +459,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { } else if (origin == ORIGIN_NETWORK) { NetworkTimeSuggestion networkSuggestion = findLatestValidNetworkSuggestion(); if (networkSuggestion != null) { - newUtcTime = networkSuggestion.getUtcTime(); + newUnixEpochTime = networkSuggestion.getUnixEpochTime(); cause = "Found good network suggestion." + ", networkSuggestion=" + networkSuggestion + ", detectionReason=" + detectionReason; @@ -467,7 +467,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { } else if (origin == ORIGIN_GNSS) { GnssTimeSuggestion gnssTimeSuggestion = findLatestValidGnssSuggestion(); if (gnssTimeSuggestion != null) { - newUtcTime = gnssTimeSuggestion.getUtcTime(); + newUnixEpochTime = gnssTimeSuggestion.getUnixEpochTime(); cause = "Found good gnss suggestion." + ", gnssTimeSuggestion=" + gnssTimeSuggestion + ", detectionReason=" + detectionReason; @@ -475,7 +475,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { } else if (origin == ORIGIN_EXTERNAL) { ExternalTimeSuggestion externalTimeSuggestion = findLatestValidExternalSuggestion(); if (externalTimeSuggestion != null) { - newUtcTime = externalTimeSuggestion.getUtcTime(); + newUnixEpochTime = externalTimeSuggestion.getUnixEpochTime(); cause = "Found good external suggestion." + ", externalTimeSuggestion=" + externalTimeSuggestion + ", detectionReason=" + detectionReason; @@ -487,8 +487,8 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { } // Update the system clock if a good suggestion has been found. - if (newUtcTime != null) { - setSystemClockIfRequired(origin, newUtcTime, cause); + if (newUnixEpochTime != null) { + setSystemClockIfRequired(origin, newUnixEpochTime, cause); return; } } @@ -545,7 +545,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { Slog.w(LOG_TAG, "Latest suggestion unexpectedly null for slotIndex." + " slotIndex=" + slotIndex); continue; - } else if (candidateSuggestion.getUtcTime() == null) { + } else if (candidateSuggestion.getUnixEpochTime() == null) { // Unexpected - we do not store empty suggestions. Slog.w(LOG_TAG, "Latest suggestion unexpectedly empty. " + " candidateSuggestion=" + candidateSuggestion); @@ -579,8 +579,8 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { long elapsedRealtimeMillis, @NonNull TelephonyTimeSuggestion timeSuggestion) { // Validate first. - TimestampedValue<Long> utcTime = timeSuggestion.getUtcTime(); - if (!validateSuggestionUtcTime(elapsedRealtimeMillis, utcTime)) { + TimestampedValue<Long> unixEpochTime = timeSuggestion.getUnixEpochTime(); + if (!validateSuggestionUnixEpochTime(elapsedRealtimeMillis, unixEpochTime)) { Slog.w(LOG_TAG, "Existing suggestion found to be invalid" + " elapsedRealtimeMillis=" + elapsedRealtimeMillis + ", timeSuggestion=" + timeSuggestion); @@ -589,7 +589,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { // The score is based on the age since receipt. Suggestions are bucketed so two // suggestions in the same bucket from different slotIndexs are scored the same. - long ageMillis = elapsedRealtimeMillis - utcTime.getReferenceTimeMillis(); + long ageMillis = elapsedRealtimeMillis - unixEpochTime.getReferenceTimeMillis(); // Turn the age into a discrete value: 0 <= bucketIndex < TELEPHONY_BUCKET_COUNT. int bucketIndex = (int) (ageMillis / TELEPHONY_BUCKET_SIZE_MILLIS); @@ -611,9 +611,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { return null; } - TimestampedValue<Long> utcTime = networkSuggestion.getUtcTime(); + TimestampedValue<Long> unixEpochTime = networkSuggestion.getUnixEpochTime(); long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis(); - if (!validateSuggestionUtcTime(elapsedRealTimeMillis, utcTime)) { + if (!validateSuggestionUnixEpochTime(elapsedRealTimeMillis, unixEpochTime)) { // The latest suggestion is not valid, usually due to its age. return null; } @@ -631,9 +631,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { return null; } - TimestampedValue<Long> utcTime = gnssTimeSuggestion.getUtcTime(); + TimestampedValue<Long> unixEpochTime = gnssTimeSuggestion.getUnixEpochTime(); long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis(); - if (!validateSuggestionUtcTime(elapsedRealTimeMillis, utcTime)) { + if (!validateSuggestionUnixEpochTime(elapsedRealTimeMillis, unixEpochTime)) { // The latest suggestion is not valid, usually due to its age. return null; } @@ -651,9 +651,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { return null; } - TimestampedValue<Long> utcTime = externalTimeSuggestion.getUtcTime(); + TimestampedValue<Long> unixEpochTime = externalTimeSuggestion.getUnixEpochTime(); long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis(); - if (!validateSuggestionUtcTime(elapsedRealTimeMillis, utcTime)) { + if (!validateSuggestionUnixEpochTime(elapsedRealTimeMillis, unixEpochTime)) { // The latest suggestion is not valid, usually due to its age. return null; } @@ -844,9 +844,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { return mLastExternalSuggestion.get(); } - private static boolean validateSuggestionUtcTime( - long elapsedRealtimeMillis, TimestampedValue<Long> utcTime) { - long referenceTimeMillis = utcTime.getReferenceTimeMillis(); + private static boolean validateSuggestionUnixEpochTime( + long elapsedRealtimeMillis, TimestampedValue<Long> unixEpochTime) { + long referenceTimeMillis = unixEpochTime.getReferenceTimeMillis(); if (referenceTimeMillis > elapsedRealtimeMillis) { // Future reference times are ignored. They imply the reference time was wrong, or the // elapsed realtime clock used to derive it has gone backwards, neither of which are @@ -860,6 +860,6 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy { // made and never replaced, it could also mean that the time detection code remains // opinionated using a bad invalid suggestion. This caps that edge case at MAX_AGE_MILLIS. long ageMillis = elapsedRealtimeMillis - referenceTimeMillis; - return ageMillis <= MAX_UTC_TIME_AGE_MILLIS; + return ageMillis <= MAX_SUGGESTION_TIME_AGE_MILLIS; } } diff --git a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java index 32fed3bc3dc1..4519890e72a1 100644 --- a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java @@ -252,7 +252,7 @@ public class TimeDetectorServiceTest { int slotIndex = 1234; TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L); return new TelephonyTimeSuggestion.Builder(slotIndex) - .setUtcTime(timeValue) + .setUnixEpochTime(timeValue) .build(); } diff --git a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyImplTest.java b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyImplTest.java index 0d5b5a565d5a..2d9903f9cf60 100644 --- a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyImplTest.java +++ b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyImplTest.java @@ -52,12 +52,12 @@ import java.util.Objects; @RunWith(AndroidJUnit4.class) public class TimeDetectorStrategyImplTest { - private static final Instant TIME_LOWER_BOUND = createUtcTime(2009, 1, 1, 12, 0, 0); + private static final Instant TIME_LOWER_BOUND = createUnixEpochTime(2009, 1, 1, 12, 0, 0); private static final TimestampedValue<Instant> ARBITRARY_CLOCK_INITIALIZATION_INFO = new TimestampedValue<>( 123456789L /* realtimeClockMillis */, - createUtcTime(2010, 5, 23, 12, 0, 0)); + createUnixEpochTime(2010, 5, 23, 12, 0, 0)); // This is the traditional ordering for time detection on Android. private static final @Origin int [] PROVIDERS_PRIORITY = { ORIGIN_TELEPHONY, ORIGIN_NETWORK }; @@ -66,7 +66,7 @@ public class TimeDetectorStrategyImplTest { * An arbitrary time, very different from the {@link #ARBITRARY_CLOCK_INITIALIZATION_INFO} * time. Can be used as the basis for time suggestions. */ - private static final Instant ARBITRARY_TEST_TIME = createUtcTime(2018, 1, 1, 12, 0, 0); + private static final Instant ARBITRARY_TEST_TIME = createUnixEpochTime(2018, 1, 1, 12, 0, 0); private static final int ARBITRARY_SLOT_INDEX = 123456; @@ -91,7 +91,7 @@ public class TimeDetectorStrategyImplTest { .simulateTelephonyTimeSuggestion(timeSuggestion); long expectedSystemClockMillis = - mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime()); + mScript.calculateTimeInMillisForNow(timeSuggestion.getUnixEpochTime()); mScript.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis) .assertLatestTelephonySuggestion(slotIndex, timeSuggestion); } @@ -128,7 +128,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(clockIncrementMillis); long expectedSystemClockMillis1 = - mScript.calculateTimeInMillisForNow(timeSuggestion1.getUtcTime()); + mScript.calculateTimeInMillisForNow(timeSuggestion1.getUnixEpochTime()); mScript.simulateTelephonyTimeSuggestion(timeSuggestion1) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1) @@ -155,7 +155,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(clockIncrementMillis); long expectedSystemClockMillis3 = - mScript.calculateTimeInMillisForNow(timeSuggestion3.getUtcTime()); + mScript.calculateTimeInMillisForNow(timeSuggestion3.getUnixEpochTime()); mScript.simulateTelephonyTimeSuggestion(timeSuggestion3) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis3) @@ -182,8 +182,8 @@ public class TimeDetectorStrategyImplTest { mScript.generateTelephonyTimeSuggestion(slotIndex2, slotIndex2Time); mScript.simulateTimePassing(); - long expectedSystemClockMillis = - mScript.calculateTimeInMillisForNow(slotIndex2TimeSuggestion.getUtcTime()); + long expectedSystemClockMillis = mScript.calculateTimeInMillisForNow( + slotIndex2TimeSuggestion.getUnixEpochTime()); mScript.simulateTelephonyTimeSuggestion(slotIndex2TimeSuggestion) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis) @@ -199,8 +199,8 @@ public class TimeDetectorStrategyImplTest { mScript.generateTelephonyTimeSuggestion(slotIndex1, slotIndex1Time); mScript.simulateTimePassing(); - long expectedSystemClockMillis = - mScript.calculateTimeInMillisForNow(slotIndex1TimeSuggestion.getUtcTime()); + long expectedSystemClockMillis = mScript.calculateTimeInMillisForNow( + slotIndex1TimeSuggestion.getUnixEpochTime()); mScript.simulateTelephonyTimeSuggestion(slotIndex1TimeSuggestion) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis) @@ -232,8 +232,8 @@ public class TimeDetectorStrategyImplTest { mScript.generateTelephonyTimeSuggestion(slotIndex2, slotIndex2Time); mScript.simulateTimePassing(); - long expectedSystemClockMillis = - mScript.calculateTimeInMillisForNow(slotIndex2TimeSuggestion.getUtcTime()); + long expectedSystemClockMillis = mScript.calculateTimeInMillisForNow( + slotIndex2TimeSuggestion.getUnixEpochTime()); mScript.simulateTelephonyTimeSuggestion(slotIndex2TimeSuggestion) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis) @@ -267,26 +267,27 @@ public class TimeDetectorStrategyImplTest { TelephonyTimeSuggestion timeSuggestion1 = mScript.generateTelephonyTimeSuggestion(slotIndex, testTime); - TimestampedValue<Long> utcTime1 = timeSuggestion1.getUtcTime(); + TimestampedValue<Long> unixEpochTime1 = timeSuggestion1.getUnixEpochTime(); // Initialize the strategy / device with a time set from a telephony suggestion. mScript.simulateTimePassing(); - long expectedSystemClockMillis1 = mScript.calculateTimeInMillisForNow(utcTime1); + long expectedSystemClockMillis1 = mScript.calculateTimeInMillisForNow(unixEpochTime1); mScript.simulateTelephonyTimeSuggestion(timeSuggestion1) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1) .assertLatestTelephonySuggestion(slotIndex, timeSuggestion1); - // The UTC time increment should be larger than the system clock update threshold so we - // know it shouldn't be ignored for other reasons. - long validUtcTimeMillis = utcTime1.getValue() + (2 * systemClockUpdateThreshold); + // The Unix epoch time increment should be larger than the system clock update threshold so + // we know it shouldn't be ignored for other reasons. + long validUnixEpochTimeMillis = unixEpochTime1.getValue() + + (2 * systemClockUpdateThreshold); // Now supply a new signal that has an obviously bogus reference time : older than the last // one. - long referenceTimeBeforeLastSignalMillis = utcTime1.getReferenceTimeMillis() - 1; - TimestampedValue<Long> utcTime2 = new TimestampedValue<>( - referenceTimeBeforeLastSignalMillis, validUtcTimeMillis); + long referenceTimeBeforeLastSignalMillis = unixEpochTime1.getReferenceTimeMillis() - 1; + TimestampedValue<Long> unixEpochTime2 = new TimestampedValue<>( + referenceTimeBeforeLastSignalMillis, validUnixEpochTimeMillis); TelephonyTimeSuggestion timeSuggestion2 = - createTelephonyTimeSuggestion(slotIndex, utcTime2); + createTelephonyTimeSuggestion(slotIndex, unixEpochTime2); mScript.simulateTelephonyTimeSuggestion(timeSuggestion2) .verifySystemClockWasNotSetAndResetCallTracking() .assertLatestTelephonySuggestion(slotIndex, timeSuggestion1); @@ -294,22 +295,22 @@ public class TimeDetectorStrategyImplTest { // Now supply a new signal that has an obviously bogus reference time : substantially in the // future. long referenceTimeInFutureMillis = - utcTime1.getReferenceTimeMillis() + Integer.MAX_VALUE + 1; - TimestampedValue<Long> utcTime3 = new TimestampedValue<>( - referenceTimeInFutureMillis, validUtcTimeMillis); + unixEpochTime1.getReferenceTimeMillis() + Integer.MAX_VALUE + 1; + TimestampedValue<Long> unixEpochTime3 = new TimestampedValue<>( + referenceTimeInFutureMillis, validUnixEpochTimeMillis); TelephonyTimeSuggestion timeSuggestion3 = - createTelephonyTimeSuggestion(slotIndex, utcTime3); + createTelephonyTimeSuggestion(slotIndex, unixEpochTime3); mScript.simulateTelephonyTimeSuggestion(timeSuggestion3) .verifySystemClockWasNotSetAndResetCallTracking() .assertLatestTelephonySuggestion(slotIndex, timeSuggestion1); - // Just to prove validUtcTimeMillis is valid. - long validReferenceTimeMillis = utcTime1.getReferenceTimeMillis() + 100; - TimestampedValue<Long> utcTime4 = new TimestampedValue<>( - validReferenceTimeMillis, validUtcTimeMillis); - long expectedSystemClockMillis4 = mScript.calculateTimeInMillisForNow(utcTime4); + // Just to prove validUnixEpochTimeMillis is valid. + long validReferenceTimeMillis = unixEpochTime1.getReferenceTimeMillis() + 100; + TimestampedValue<Long> unixEpochTime4 = new TimestampedValue<>( + validReferenceTimeMillis, validUnixEpochTimeMillis); + long expectedSystemClockMillis4 = mScript.calculateTimeInMillisForNow(unixEpochTime4); TelephonyTimeSuggestion timeSuggestion4 = - createTelephonyTimeSuggestion(slotIndex, utcTime4); + createTelephonyTimeSuggestion(slotIndex, unixEpochTime4); mScript.simulateTelephonyTimeSuggestion(timeSuggestion4) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis4) .assertLatestTelephonySuggestion(slotIndex, timeSuggestion4); @@ -344,7 +345,7 @@ public class TimeDetectorStrategyImplTest { Instant testTime = ARBITRARY_TEST_TIME; TelephonyTimeSuggestion timeSuggestion1 = mScript.generateTelephonyTimeSuggestion(slotIndex, testTime); - TimestampedValue<Long> utcTime1 = timeSuggestion1.getUtcTime(); + TimestampedValue<Long> unixEpochTime1 = timeSuggestion1.getUnixEpochTime(); // Simulate time passing. mScript.simulateTimePassing(clockIncrementMillis); @@ -358,7 +359,7 @@ public class TimeDetectorStrategyImplTest { // Simulate more time passing. mScript.simulateTimePassing(clockIncrementMillis); - long expectedSystemClockMillis1 = mScript.calculateTimeInMillisForNow(utcTime1); + long expectedSystemClockMillis1 = mScript.calculateTimeInMillisForNow(unixEpochTime1); // Turn on auto time detection. mScript.simulateAutoTimeDetectionToggle() @@ -379,7 +380,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(clockIncrementMillis); long expectedSystemClockMillis2 = - mScript.calculateTimeInMillisForNow(timeSuggestion2.getUtcTime()); + mScript.calculateTimeInMillisForNow(timeSuggestion2.getUnixEpochTime()); // The new time, though valid, should not be set in the system clock because auto time is // disabled. @@ -406,7 +407,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(); long expectedSystemClockMillis = - mScript.calculateTimeInMillisForNow(telephonySuggestion.getUtcTime()); + mScript.calculateTimeInMillisForNow(telephonySuggestion.getUnixEpochTime()); mScript.simulateTelephonyTimeSuggestion(telephonySuggestion) .verifySystemClockWasSetAndResetCallTracking( expectedSystemClockMillis /* expectedNetworkBroadcast */) @@ -416,7 +417,7 @@ public class TimeDetectorStrategyImplTest { assertEquals(telephonySuggestion, mScript.peekBestTelephonySuggestion()); // Simulate time passing, long enough that telephonySuggestion is now too old. - mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS); + mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_SUGGESTION_TIME_AGE_MILLIS); // Look inside and check what the strategy considers the current best telephony suggestion. // It should still be the, it's just no longer used. @@ -435,7 +436,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(); long expectedSystemClockMillis = - mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime()); + mScript.calculateTimeInMillisForNow(timeSuggestion.getUnixEpochTime()); mScript.simulateManualTimeSuggestion(timeSuggestion, true /* expectedResult */) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis); } @@ -457,7 +458,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(); long expectedAutoClockMillis = - mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUtcTime()); + mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUnixEpochTime()); mScript.simulateTelephonyTimeSuggestion(telephonyTimeSuggestion) .verifySystemClockWasSetAndResetCallTracking(expectedAutoClockMillis) .assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion); @@ -480,7 +481,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(); long expectedManualClockMillis = - mScript.calculateTimeInMillisForNow(manualTimeSuggestion.getUtcTime()); + mScript.calculateTimeInMillisForNow(manualTimeSuggestion.getUnixEpochTime()); mScript.simulateManualTimeSuggestion(manualTimeSuggestion, true /* expectedResult */) .verifySystemClockWasSetAndResetCallTracking(expectedManualClockMillis) .assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion); @@ -492,7 +493,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateAutoTimeDetectionToggle(); expectedAutoClockMillis = - mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUtcTime()); + mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUnixEpochTime()); mScript.verifySystemClockWasSetAndResetCallTracking(expectedAutoClockMillis) .assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion); @@ -540,7 +541,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(); long expectedSystemClockMillis = - mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime()); + mScript.calculateTimeInMillisForNow(timeSuggestion.getUnixEpochTime()); mScript.simulateNetworkTimeSuggestion(timeSuggestion) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis); } @@ -586,7 +587,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(); long expectedSystemClockMillis = - mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime()); + mScript.calculateTimeInMillisForNow(timeSuggestion.getUnixEpochTime()); mScript.simulateGnssTimeSuggestion(timeSuggestion) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis); } @@ -617,7 +618,7 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(); long expectedSystemClockMillis = - mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime()); + mScript.calculateTimeInMillisForNow(timeSuggestion.getUnixEpochTime()); mScript.simulateExternalTimeSuggestion(timeSuggestion) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis); } @@ -671,7 +672,8 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(smallTimeIncrementMillis) .simulateNetworkTimeSuggestion(networkTimeSuggestion1) .verifySystemClockWasSetAndResetCallTracking( - mScript.calculateTimeInMillisForNow(networkTimeSuggestion1.getUtcTime())); + mScript.calculateTimeInMillisForNow( + networkTimeSuggestion1.getUnixEpochTime())); // Check internal state. mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, null) @@ -690,7 +692,8 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(smallTimeIncrementMillis) .simulateTelephonyTimeSuggestion(telephonyTimeSuggestion) .verifySystemClockWasSetAndResetCallTracking( - mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUtcTime())); + mScript.calculateTimeInMillisForNow( + telephonyTimeSuggestion.getUnixEpochTime())); // Check internal state. mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, telephonyTimeSuggestion) @@ -700,7 +703,7 @@ public class TimeDetectorStrategyImplTest { // Simulate some significant time passing: half the time allowed before a time signal // becomes "too old to use". - mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2) + mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_SUGGESTION_TIME_AGE_MILLIS / 2) .verifySystemClockWasNotSetAndResetCallTracking(); // Now another network suggestion is made. Telephony suggestions are prioritized over @@ -720,7 +723,7 @@ public class TimeDetectorStrategyImplTest { // Simulate some significant time passing: half the time allowed before a time signal // becomes "too old to use". This should mean that telephonyTimeSuggestion is now too old to // be used but networkTimeSuggestion2 is not. - mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2); + mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_SUGGESTION_TIME_AGE_MILLIS / 2); // NOTE: The TimeDetectorStrategyImpl doesn't set an alarm for the point when the last // suggestion it used becomes too old: it requires a new suggestion or an auto-time toggle @@ -743,7 +746,7 @@ public class TimeDetectorStrategyImplTest { // Verify the latest network time now wins. mScript.verifySystemClockWasSetAndResetCallTracking( - mScript.calculateTimeInMillisForNow(networkTimeSuggestion2.getUtcTime())); + mScript.calculateTimeInMillisForNow(networkTimeSuggestion2.getUnixEpochTime())); // Check internal state. mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, telephonyTimeSuggestion) @@ -774,7 +777,8 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(smallTimeIncrementMillis) .simulateGnssTimeSuggestion(gnssTimeSuggestion1) .verifySystemClockWasSetAndResetCallTracking( - mScript.calculateTimeInMillisForNow(gnssTimeSuggestion1.getUtcTime())); + mScript.calculateTimeInMillisForNow( + gnssTimeSuggestion1.getUnixEpochTime())); // Check internal state. mScript.assertLatestNetworkSuggestion(null) @@ -793,7 +797,8 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(smallTimeIncrementMillis) .simulateNetworkTimeSuggestion(networkTimeSuggestion) .verifySystemClockWasSetAndResetCallTracking( - mScript.calculateTimeInMillisForNow(networkTimeSuggestion.getUtcTime())); + mScript.calculateTimeInMillisForNow( + networkTimeSuggestion.getUnixEpochTime())); // Check internal state. mScript.assertLatestNetworkSuggestion(networkTimeSuggestion) @@ -803,7 +808,7 @@ public class TimeDetectorStrategyImplTest { // Simulate some significant time passing: half the time allowed before a time signal // becomes "too old to use". - mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2) + mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_SUGGESTION_TIME_AGE_MILLIS / 2) .verifySystemClockWasNotSetAndResetCallTracking(); // Now another gnss suggestion is made. Network suggestions are prioritized over @@ -823,7 +828,7 @@ public class TimeDetectorStrategyImplTest { // Simulate some significant time passing: half the time allowed before a time signal // becomes "too old to use". This should mean that telephonyTimeSuggestion is now too old to // be used but networkTimeSuggestion2 is not. - mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2); + mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_SUGGESTION_TIME_AGE_MILLIS / 2); // NOTE: The TimeDetectorStrategyImpl doesn't set an alarm for the point when the last // suggestion it used becomes too old: it requires a new suggestion or an auto-time toggle @@ -846,7 +851,7 @@ public class TimeDetectorStrategyImplTest { // Verify the latest gnss time now wins. mScript.verifySystemClockWasSetAndResetCallTracking( - mScript.calculateTimeInMillisForNow(gnssTimeSuggestion2.getUtcTime())); + mScript.calculateTimeInMillisForNow(gnssTimeSuggestion2.getUnixEpochTime())); // Check internal state. mScript.assertLatestNetworkSuggestion(networkTimeSuggestion) @@ -877,7 +882,8 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(smallTimeIncrementMillis) .simulateExternalTimeSuggestion(externalTimeSuggestion1) .verifySystemClockWasSetAndResetCallTracking( - mScript.calculateTimeInMillisForNow(externalTimeSuggestion1.getUtcTime())); + mScript.calculateTimeInMillisForNow( + externalTimeSuggestion1.getUnixEpochTime())); // Check internal state. mScript.assertLatestNetworkSuggestion(null) @@ -896,7 +902,8 @@ public class TimeDetectorStrategyImplTest { mScript.simulateTimePassing(smallTimeIncrementMillis) .simulateNetworkTimeSuggestion(networkTimeSuggestion) .verifySystemClockWasSetAndResetCallTracking( - mScript.calculateTimeInMillisForNow(networkTimeSuggestion.getUtcTime())); + mScript.calculateTimeInMillisForNow( + networkTimeSuggestion.getUnixEpochTime())); // Check internal state. mScript.assertLatestNetworkSuggestion(networkTimeSuggestion) @@ -906,7 +913,7 @@ public class TimeDetectorStrategyImplTest { // Simulate some significant time passing: half the time allowed before a time signal // becomes "too old to use". - mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2) + mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_SUGGESTION_TIME_AGE_MILLIS / 2) .verifySystemClockWasNotSetAndResetCallTracking(); // Now another external suggestion is made. Network suggestions are prioritized over @@ -926,7 +933,7 @@ public class TimeDetectorStrategyImplTest { // Simulate some significant time passing: half the time allowed before a time signal // becomes "too old to use". This should mean that networkTimeSuggestion is now too old to // be used but externalTimeSuggestion2 is not. - mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2); + mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_SUGGESTION_TIME_AGE_MILLIS / 2); // NOTE: The TimeDetectorStrategyImpl doesn't set an alarm for the point when the last // suggestion it used becomes too old: it requires a new suggestion or an auto-time toggle @@ -949,7 +956,7 @@ public class TimeDetectorStrategyImplTest { // Verify the latest external time now wins. mScript.verifySystemClockWasSetAndResetCallTracking( - mScript.calculateTimeInMillisForNow(externalTimeSuggestion2.getUtcTime())); + mScript.calculateTimeInMillisForNow(externalTimeSuggestion2.getUnixEpochTime())); // Check internal state. mScript.assertLatestNetworkSuggestion(networkTimeSuggestion) @@ -1438,11 +1445,11 @@ public class TimeDetectorStrategyImplTest { * reference time. */ ManualTimeSuggestion generateManualTimeSuggestion(Instant suggestedTime) { - TimestampedValue<Long> utcTime = + TimestampedValue<Long> unixEpochTime = new TimestampedValue<>( mFakeEnvironment.peekElapsedRealtimeMillis(), suggestedTime.toEpochMilli()); - return new ManualTimeSuggestion(utcTime); + return new ManualTimeSuggestion(unixEpochTime); } /** @@ -1472,11 +1479,11 @@ public class TimeDetectorStrategyImplTest { * reference time. */ NetworkTimeSuggestion generateNetworkTimeSuggestion(Instant suggestedTime) { - TimestampedValue<Long> utcTime = + TimestampedValue<Long> unixEpochTime = new TimestampedValue<>( mFakeEnvironment.peekElapsedRealtimeMillis(), suggestedTime.toEpochMilli()); - return new NetworkTimeSuggestion(utcTime); + return new NetworkTimeSuggestion(unixEpochTime); } /** @@ -1484,11 +1491,11 @@ public class TimeDetectorStrategyImplTest { * reference time. */ GnssTimeSuggestion generateGnssTimeSuggestion(Instant suggestedTime) { - TimestampedValue<Long> utcTime = + TimestampedValue<Long> unixEpochTime = new TimestampedValue<>( mFakeEnvironment.peekElapsedRealtimeMillis(), suggestedTime.toEpochMilli()); - return new GnssTimeSuggestion(utcTime); + return new GnssTimeSuggestion(unixEpochTime); } /** @@ -1504,19 +1511,19 @@ public class TimeDetectorStrategyImplTest { * Calculates what the supplied time would be when adjusted for the movement of the fake * elapsed realtime clock. */ - long calculateTimeInMillisForNow(TimestampedValue<Long> utcTime) { - return TimeDetectorStrategy.getTimeAt(utcTime, peekElapsedRealtimeMillis()); + long calculateTimeInMillisForNow(TimestampedValue<Long> unixEpochTime) { + return TimeDetectorStrategy.getTimeAt(unixEpochTime, peekElapsedRealtimeMillis()); } } private static TelephonyTimeSuggestion createTelephonyTimeSuggestion(int slotIndex, - TimestampedValue<Long> utcTime) { + TimestampedValue<Long> unixEpochTime) { return new TelephonyTimeSuggestion.Builder(slotIndex) - .setUtcTime(utcTime) + .setUnixEpochTime(unixEpochTime) .build(); } - private static Instant createUtcTime(int year, int monthInYear, int day, int hourOfDay, + private static Instant createUnixEpochTime(int year, int monthInYear, int day, int hourOfDay, int minute, int second) { return LocalDateTime.of(year, monthInYear, day, hourOfDay, minute, second) .toInstant(ZoneOffset.UTC); |