Switch "UTC time" to "Unix epoch time"

This is more correct.

Bug: 218802673
Test: Compile only
Change-Id: Ic477c021529a94b4a3665426b7daaf6567fa311a
This commit is contained in:
Neil Fuller
2022-02-10 11:29:34 +00:00
parent fce6976257
commit 115132dbaa
9 changed files with 227 additions and 208 deletions

View File

@@ -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 * <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 * 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()}, * 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 * when the Unix epoch time is first obtained (usually under a wakelock). This enables Android to
* for latency introduced between suggestion creation and eventual use. Adjustments for other * 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 * sources of latency, i.e. those before the external time suggestion is created, must be handled by
* the creator. * the creator.
* *
* <p>{@code elapsedRealtimeMillis} and {@code suggestionMillis} represent the suggested time. * <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 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 * according to the Unix time scale. {@code elapsedRealtimeMillis} is the value of the elapsed
* suggestionMillis} was established. Note that the elapsed realtime clock is considered accurate * realtime clock when {@code suggestionMillis} was established. Note that the elapsed realtime
* but it is volatile, so time suggestions cannot be persisted across device resets. * 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 * <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 * 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 @NonNull
private final TimestampedValue<Long> mUtcTime; private final TimestampedValue<Long> mUnixEpochTime;
@Nullable @Nullable
private ArrayList<String> mDebugInfo; private ArrayList<String> mDebugInfo;
@@ -92,12 +93,12 @@ public final class ExternalTimeSuggestion implements Parcelable {
* ExternalTimeSuggestion} for more details. * ExternalTimeSuggestion} for more details.
* *
* @param elapsedRealtimeMillis the elapsed realtime clock reference for the suggestion * @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 * Unix epoch
*/ */
public ExternalTimeSuggestion(@ElapsedRealtimeLong long elapsedRealtimeMillis, public ExternalTimeSuggestion(@ElapsedRealtimeLong long elapsedRealtimeMillis,
@CurrentTimeMillisLong long suggestionMillis) { @CurrentTimeMillisLong long suggestionMillis) {
mUtcTime = new TimestampedValue(elapsedRealtimeMillis, suggestionMillis); mUnixEpochTime = new TimestampedValue(elapsedRealtimeMillis, suggestionMillis);
} }
private static ExternalTimeSuggestion createFromParcel(Parcel in) { private static ExternalTimeSuggestion createFromParcel(Parcel in) {
@@ -117,7 +118,7 @@ public final class ExternalTimeSuggestion implements Parcelable {
@Override @Override
public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeParcelable(mUtcTime, 0); dest.writeParcelable(mUnixEpochTime, 0);
dest.writeList(mDebugInfo); dest.writeList(mDebugInfo);
} }
@@ -125,8 +126,8 @@ public final class ExternalTimeSuggestion implements Parcelable {
* {@hide} * {@hide}
*/ */
@NonNull @NonNull
public TimestampedValue<Long> getUtcTime() { public TimestampedValue<Long> getUnixEpochTime() {
return mUtcTime; return mUnixEpochTime;
} }
/** /**
@@ -160,17 +161,18 @@ public final class ExternalTimeSuggestion implements Parcelable {
return false; return false;
} }
ExternalTimeSuggestion that = (ExternalTimeSuggestion) o; ExternalTimeSuggestion that = (ExternalTimeSuggestion) o;
return Objects.equals(mUtcTime, that.mUtcTime); return Objects.equals(mUnixEpochTime, that.mUnixEpochTime);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mUtcTime); return Objects.hash(mUnixEpochTime);
} }
@Override @Override
public String toString() { public String toString() {
return "ExternalTimeSuggestion{" + "mUtcTime=" + mUtcTime + ", mDebugInfo=" + mDebugInfo return "ExternalTimeSuggestion{" + "mUnixEpochTime=" + mUnixEpochTime
+ ", mDebugInfo=" + mDebugInfo
+ '}'; + '}';
} }
} }

View File

@@ -31,11 +31,11 @@ import java.util.Objects;
/** /**
* A time signal from a GNSS source. * A time signal from a GNSS source.
* *
* <p>{@code utcTime} is the suggested time. The {@code utcTime.value} is the number of milliseconds * <p>{@code unixEpochTime} is the suggested time. The {@code unixEpochTime.value} is the number of
* elapsed since 1/1/1970 00:00:00 UTC. The {@code utcTime.referenceTimeMillis} is the value of the * milliseconds elapsed since 1/1/1970 00:00:00 UTC according to the Unix time system. The {@code
* elapsed realtime clock when the {@code utcTime.value} was established. * unixEpochTime.referenceTimeMillis} is the value of the elapsed realtime clock when the {@code
* Note that the elapsed realtime clock is considered accurate but it is volatile, so time * unixEpochTime.value} was established. Note that the elapsed realtime clock is considered accurate
* suggestions cannot be persisted across device resets. * 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 * <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 * record why the suggestion exists and how it was entered. This information exists only to aid in
@@ -57,19 +57,21 @@ public final class GnssTimeSuggestion implements Parcelable {
} }
}; };
@NonNull private final TimestampedValue<Long> mUtcTime; @NonNull private final TimestampedValue<Long> mUnixEpochTime;
@Nullable private ArrayList<String> mDebugInfo; @Nullable private ArrayList<String> mDebugInfo;
public GnssTimeSuggestion(@NonNull TimestampedValue<Long> utcTime) { public GnssTimeSuggestion(@NonNull TimestampedValue<Long> unixEpochTime) {
mUtcTime = Objects.requireNonNull(utcTime); mUnixEpochTime = Objects.requireNonNull(unixEpochTime);
Objects.requireNonNull(utcTime.getValue()); Objects.requireNonNull(unixEpochTime.getValue());
} }
private static GnssTimeSuggestion createFromParcel(Parcel in) { private static GnssTimeSuggestion createFromParcel(Parcel in) {
TimestampedValue<Long> utcTime = in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class); TimestampedValue<Long> unixEpochTime =
GnssTimeSuggestion suggestion = new GnssTimeSuggestion(utcTime); in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class);
GnssTimeSuggestion suggestion = new GnssTimeSuggestion(unixEpochTime);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(null /* classLoader */, java.lang.String.class); ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(
null /* classLoader */, java.lang.String.class);
suggestion.mDebugInfo = debugInfo; suggestion.mDebugInfo = debugInfo;
return suggestion; return suggestion;
} }
@@ -81,13 +83,13 @@ public final class GnssTimeSuggestion implements Parcelable {
@Override @Override
public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeParcelable(mUtcTime, 0); dest.writeParcelable(mUnixEpochTime, 0);
dest.writeList(mDebugInfo); dest.writeList(mDebugInfo);
} }
@NonNull @NonNull
public TimestampedValue<Long> getUtcTime() { public TimestampedValue<Long> getUnixEpochTime() {
return mUtcTime; return mUnixEpochTime;
} }
@NonNull @NonNull
@@ -117,18 +119,18 @@ public final class GnssTimeSuggestion implements Parcelable {
return false; return false;
} }
GnssTimeSuggestion that = (GnssTimeSuggestion) o; GnssTimeSuggestion that = (GnssTimeSuggestion) o;
return Objects.equals(mUtcTime, that.mUtcTime); return Objects.equals(mUnixEpochTime, that.mUnixEpochTime);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mUtcTime); return Objects.hash(mUnixEpochTime);
} }
@Override @Override
public String toString() { public String toString() {
return "GnssTimeSuggestion{" return "GnssTimeSuggestion{"
+ "mUtcTime=" + mUtcTime + "mUnixEpochTime=" + mUnixEpochTime
+ ", mDebugInfo=" + mDebugInfo + ", mDebugInfo=" + mDebugInfo
+ '}'; + '}';
} }

View File

@@ -31,9 +31,9 @@ import java.util.Objects;
/** /**
* A time signal from a manual (user provided) source. * 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 * <p>{@code unixEpochTime} is the suggested time. The {@code unixEpochTime.value} is the number of
* elapsed since 1/1/1970 00:00:00 UTC. The {@code utcTime.referenceTimeMillis} is the value of the * milliseconds elapsed since 1/1/1970 00:00:00 UTC. The {@code unixEpochTime.referenceTimeMillis}
* elapsed realtime clock when the {@code utcTime.value} was established. * 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 * Note that the elapsed realtime clock is considered accurate but it is volatile, so time
* suggestions cannot be persisted across device resets. * suggestions cannot be persisted across device resets.
* *
@@ -57,19 +57,21 @@ public final class ManualTimeSuggestion implements Parcelable {
} }
}; };
@NonNull private final TimestampedValue<Long> mUtcTime; @NonNull private final TimestampedValue<Long> mUnixEpochTime;
@Nullable private ArrayList<String> mDebugInfo; @Nullable private ArrayList<String> mDebugInfo;
public ManualTimeSuggestion(@NonNull TimestampedValue<Long> utcTime) { public ManualTimeSuggestion(@NonNull TimestampedValue<Long> unixEpochTime) {
mUtcTime = Objects.requireNonNull(utcTime); mUnixEpochTime = Objects.requireNonNull(unixEpochTime);
Objects.requireNonNull(utcTime.getValue()); Objects.requireNonNull(unixEpochTime.getValue());
} }
private static ManualTimeSuggestion createFromParcel(Parcel in) { private static ManualTimeSuggestion createFromParcel(Parcel in) {
TimestampedValue<Long> utcTime = in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class); TimestampedValue<Long> unixEpochTime =
ManualTimeSuggestion suggestion = new ManualTimeSuggestion(utcTime); in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class);
ManualTimeSuggestion suggestion = new ManualTimeSuggestion(unixEpochTime);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(null /* classLoader */, java.lang.String.class); ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(
null /* classLoader */, java.lang.String.class);
suggestion.mDebugInfo = debugInfo; suggestion.mDebugInfo = debugInfo;
return suggestion; return suggestion;
} }
@@ -81,13 +83,13 @@ public final class ManualTimeSuggestion implements Parcelable {
@Override @Override
public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeParcelable(mUtcTime, 0); dest.writeParcelable(mUnixEpochTime, 0);
dest.writeList(mDebugInfo); dest.writeList(mDebugInfo);
} }
@NonNull @NonNull
public TimestampedValue<Long> getUtcTime() { public TimestampedValue<Long> getUnixEpochTime() {
return mUtcTime; return mUnixEpochTime;
} }
@NonNull @NonNull
@@ -117,18 +119,18 @@ public final class ManualTimeSuggestion implements Parcelable {
return false; return false;
} }
ManualTimeSuggestion that = (ManualTimeSuggestion) o; ManualTimeSuggestion that = (ManualTimeSuggestion) o;
return Objects.equals(mUtcTime, that.mUtcTime); return Objects.equals(mUnixEpochTime, that.mUnixEpochTime);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mUtcTime); return Objects.hash(mUnixEpochTime);
} }
@Override @Override
public String toString() { public String toString() {
return "ManualTimeSuggestion{" return "ManualTimeSuggestion{"
+ "mUtcTime=" + mUtcTime + "mUnixEpochTime=" + mUnixEpochTime
+ ", mDebugInfo=" + mDebugInfo + ", mDebugInfo=" + mDebugInfo
+ '}'; + '}';
} }

View File

@@ -31,11 +31,12 @@ import java.util.Objects;
/** /**
* A time signal from a network time source like NTP. * 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 * <p>{@code unixEpochTime} contains the suggested time. The {@code unixEpochTime.value} is the
* milliseconds elapsed since 1/1/1970 00:00:00 UTC. The {@code utcTime.referenceTimeMillis} is the * number of milliseconds elapsed since 1/1/1970 00:00:00 UTC according to the Unix time system.
* value of the elapsed realtime clock when the {@code utcTime.value} was established. * The {@code unixEpochTime.referenceTimeMillis} is the value of the elapsed realtime clock when
* Note that the elapsed realtime clock is considered accurate but it is volatile, so time * the {@code unixEpochTime.value} was established. Note that the elapsed realtime clock is
* suggestions cannot be persisted across device resets. * 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 * <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 * record why the suggestion exists and how it was determined. This information exists only to aid
@@ -57,19 +58,21 @@ public final class NetworkTimeSuggestion implements Parcelable {
} }
}; };
@NonNull private final TimestampedValue<Long> mUtcTime; @NonNull private final TimestampedValue<Long> mUnixEpochTime;
@Nullable private ArrayList<String> mDebugInfo; @Nullable private ArrayList<String> mDebugInfo;
public NetworkTimeSuggestion(@NonNull TimestampedValue<Long> utcTime) { public NetworkTimeSuggestion(@NonNull TimestampedValue<Long> unixEpochTime) {
mUtcTime = Objects.requireNonNull(utcTime); mUnixEpochTime = Objects.requireNonNull(unixEpochTime);
Objects.requireNonNull(utcTime.getValue()); Objects.requireNonNull(unixEpochTime.getValue());
} }
private static NetworkTimeSuggestion createFromParcel(Parcel in) { private static NetworkTimeSuggestion createFromParcel(Parcel in) {
TimestampedValue<Long> utcTime = in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class); TimestampedValue<Long> unixEpochTime =
NetworkTimeSuggestion suggestion = new NetworkTimeSuggestion(utcTime); in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class);
NetworkTimeSuggestion suggestion = new NetworkTimeSuggestion(unixEpochTime);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(null /* classLoader */, java.lang.String.class); ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(
null /* classLoader */, java.lang.String.class);
suggestion.mDebugInfo = debugInfo; suggestion.mDebugInfo = debugInfo;
return suggestion; return suggestion;
} }
@@ -81,13 +84,13 @@ public final class NetworkTimeSuggestion implements Parcelable {
@Override @Override
public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeParcelable(mUtcTime, 0); dest.writeParcelable(mUnixEpochTime, 0);
dest.writeList(mDebugInfo); dest.writeList(mDebugInfo);
} }
@NonNull @NonNull
public TimestampedValue<Long> getUtcTime() { public TimestampedValue<Long> getUnixEpochTime() {
return mUtcTime; return mUnixEpochTime;
} }
@NonNull @NonNull
@@ -117,18 +120,18 @@ public final class NetworkTimeSuggestion implements Parcelable {
return false; return false;
} }
NetworkTimeSuggestion that = (NetworkTimeSuggestion) o; NetworkTimeSuggestion that = (NetworkTimeSuggestion) o;
return Objects.equals(mUtcTime, that.mUtcTime); return Objects.equals(mUnixEpochTime, that.mUnixEpochTime);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mUtcTime); return Objects.hash(mUnixEpochTime);
} }
@Override @Override
public String toString() { public String toString() {
return "NetworkTimeSuggestion{" return "NetworkTimeSuggestion{"
+ "mUtcTime=" + mUtcTime + "mUnixEpochTime=" + mUnixEpochTime
+ ", mDebugInfo=" + mDebugInfo + ", mDebugInfo=" + mDebugInfo
+ '}'; + '}';
} }

View File

@@ -34,12 +34,12 @@ import java.util.Objects;
* <p>{@code slotIndex} identifies the suggestion source. This enables detection logic to identify * <p>{@code slotIndex} identifies the suggestion source. This enables detection logic to identify
* suggestions from the same source when there are several in use. * 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 * <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 utcTime.referenceTimeMillis} is the * milliseconds elapsed since 1/1/1970 00:00:00 UTC. The {@code unixEpochTime.referenceTimeMillis}
* value of the elapsed realtime clock when the {@code utcTime.value} was established. * 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 * 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 * suggestions cannot be persisted across device resets. {@code unixEpochTime} can be {@code null}
* indicate that the telephony source has entered an "un-opinionated" state and any previous * to indicate that the telephony source has entered an "un-opinionated" state and any previous
* suggestion from the source is being withdrawn. * suggestion from the source is being withdrawn.
* *
* <p>{@code debugInfo} contains debugging metadata associated with the suggestion. This is used to * <p>{@code debugInfo} contains debugging metadata associated with the suggestion. This is used to
@@ -65,22 +65,25 @@ public final class TelephonyTimeSuggestion implements Parcelable {
}; };
private final int mSlotIndex; private final int mSlotIndex;
@Nullable private final TimestampedValue<Long> mUtcTime; @Nullable private final TimestampedValue<Long> mUnixEpochTime;
@Nullable private ArrayList<String> mDebugInfo; @Nullable private ArrayList<String> mDebugInfo;
private TelephonyTimeSuggestion(Builder builder) { private TelephonyTimeSuggestion(Builder builder) {
mSlotIndex = builder.mSlotIndex; mSlotIndex = builder.mSlotIndex;
mUtcTime = builder.mUtcTime; mUnixEpochTime = builder.mUnixEpochTime;
mDebugInfo = builder.mDebugInfo != null ? new ArrayList<>(builder.mDebugInfo) : null; mDebugInfo = builder.mDebugInfo != null ? new ArrayList<>(builder.mDebugInfo) : null;
} }
private static TelephonyTimeSuggestion createFromParcel(Parcel in) { private static TelephonyTimeSuggestion createFromParcel(Parcel in) {
int slotIndex = in.readInt(); int slotIndex = in.readInt();
TimestampedValue<Long> unixEpochTime =
in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class);
TelephonyTimeSuggestion suggestion = new TelephonyTimeSuggestion.Builder(slotIndex) TelephonyTimeSuggestion suggestion = new TelephonyTimeSuggestion.Builder(slotIndex)
.setUtcTime(in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class)) .setUnixEpochTime(unixEpochTime)
.build(); .build();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(null /* classLoader */, java.lang.String.class); ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(
null /* classLoader */, java.lang.String.class);
if (debugInfo != null) { if (debugInfo != null) {
suggestion.addDebugInfo(debugInfo); suggestion.addDebugInfo(debugInfo);
} }
@@ -95,7 +98,7 @@ public final class TelephonyTimeSuggestion implements Parcelable {
@Override @Override
public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mSlotIndex); dest.writeInt(mSlotIndex);
dest.writeParcelable(mUtcTime, 0); dest.writeParcelable(mUnixEpochTime, 0);
dest.writeList(mDebugInfo); dest.writeList(mDebugInfo);
} }
@@ -111,11 +114,11 @@ public final class TelephonyTimeSuggestion implements Parcelable {
/** /**
* Returns the suggested time or {@code null} if there isn't one. * 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 @Nullable
public TimestampedValue<Long> getUtcTime() { public TimestampedValue<Long> getUnixEpochTime() {
return mUtcTime; return mUnixEpochTime;
} }
/** /**
@@ -163,19 +166,19 @@ public final class TelephonyTimeSuggestion implements Parcelable {
} }
TelephonyTimeSuggestion that = (TelephonyTimeSuggestion) o; TelephonyTimeSuggestion that = (TelephonyTimeSuggestion) o;
return mSlotIndex == that.mSlotIndex return mSlotIndex == that.mSlotIndex
&& Objects.equals(mUtcTime, that.mUtcTime); && Objects.equals(mUnixEpochTime, that.mUnixEpochTime);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mSlotIndex, mUtcTime); return Objects.hash(mSlotIndex, mUnixEpochTime);
} }
@Override @Override
public String toString() { public String toString() {
return "TelephonyTimeSuggestion{" return "TelephonyTimeSuggestion{"
+ "mSlotIndex='" + mSlotIndex + '\'' + "mSlotIndex='" + mSlotIndex + '\''
+ ", mUtcTime=" + mUtcTime + ", mUnixEpochTime=" + mUnixEpochTime
+ ", mDebugInfo=" + mDebugInfo + ", mDebugInfo=" + mDebugInfo
+ '}'; + '}';
} }
@@ -187,7 +190,7 @@ public final class TelephonyTimeSuggestion implements Parcelable {
*/ */
public static final class Builder { public static final class Builder {
private final int mSlotIndex; private final int mSlotIndex;
@Nullable private TimestampedValue<Long> mUtcTime; @Nullable private TimestampedValue<Long> mUnixEpochTime;
@Nullable private List<String> mDebugInfo; @Nullable private List<String> mDebugInfo;
/** /**
@@ -202,16 +205,16 @@ public final class TelephonyTimeSuggestion implements Parcelable {
/** /**
* Returns the builder for call chaining. * 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 @NonNull
public Builder setUtcTime(@Nullable TimestampedValue<Long> utcTime) { public Builder setUnixEpochTime(@Nullable TimestampedValue<Long> unixEpochTime) {
if (utcTime != null) { if (unixEpochTime != null) {
// utcTime can be null, but the value it holds cannot. // unixEpochTime can be null, but the value it holds cannot.
Objects.requireNonNull(utcTime.getValue()); Objects.requireNonNull(unixEpochTime.getValue());
} }
mUtcTime = utcTime; mUnixEpochTime = unixEpochTime;
return this; return this;
} }

View File

@@ -45,13 +45,13 @@ public class TelephonyTimeSuggestionTest {
assertEquals(two, one); assertEquals(two, one);
} }
builder1.setUtcTime(new TimestampedValue<>(1111L, 2222L)); builder1.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L));
{ {
TelephonyTimeSuggestion one = builder1.build(); TelephonyTimeSuggestion one = builder1.build();
assertEquals(one, one); assertEquals(one, one);
} }
builder2.setUtcTime(new TimestampedValue<>(1111L, 2222L)); builder2.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L));
{ {
TelephonyTimeSuggestion one = builder1.build(); TelephonyTimeSuggestion one = builder1.build();
TelephonyTimeSuggestion two = builder2.build(); TelephonyTimeSuggestion two = builder2.build();
@@ -61,7 +61,7 @@ public class TelephonyTimeSuggestionTest {
TelephonyTimeSuggestion.Builder builder3 = TelephonyTimeSuggestion.Builder builder3 =
new TelephonyTimeSuggestion.Builder(SLOT_INDEX + 1); new TelephonyTimeSuggestion.Builder(SLOT_INDEX + 1);
builder3.setUtcTime(new TimestampedValue<>(1111L, 2222L)); builder3.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L));
{ {
TelephonyTimeSuggestion one = builder1.build(); TelephonyTimeSuggestion one = builder1.build();
TelephonyTimeSuggestion three = builder3.build(); TelephonyTimeSuggestion three = builder3.build();
@@ -84,7 +84,7 @@ public class TelephonyTimeSuggestionTest {
TelephonyTimeSuggestion.Builder builder = new TelephonyTimeSuggestion.Builder(SLOT_INDEX); TelephonyTimeSuggestion.Builder builder = new TelephonyTimeSuggestion.Builder(SLOT_INDEX);
assertRoundTripParcelable(builder.build()); assertRoundTripParcelable(builder.build());
builder.setUtcTime(new TimestampedValue<>(1111L, 2222L)); builder.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L));
assertRoundTripParcelable(builder.build()); assertRoundTripParcelable(builder.build());
// DebugInfo should also be stored (but is not checked by equals() // DebugInfo should also be stored (but is not checked by equals()

View File

@@ -70,7 +70,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
* Telephony and network suggestions older than this value are considered too old to be used. * Telephony and network suggestions older than this value are considered too old to be used.
*/ */
@VisibleForTesting @VisibleForTesting
static final long MAX_UTC_TIME_AGE_MILLIS = static final long MAX_SUGGESTION_TIME_AGE_MILLIS =
TELEPHONY_BUCKET_COUNT * TELEPHONY_BUCKET_SIZE_MILLIS; TELEPHONY_BUCKET_COUNT * TELEPHONY_BUCKET_SIZE_MILLIS;
/** /**
@@ -205,9 +205,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
@Override @Override
public synchronized void suggestExternalTime(@NonNull ExternalTimeSuggestion timeSuggestion) { 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; return;
} }
@@ -219,9 +219,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
@Override @Override
public synchronized void suggestGnssTime(@NonNull GnssTimeSuggestion timeSuggestion) { 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; return;
} }
@@ -233,19 +233,19 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
@Override @Override
public synchronized boolean suggestManualTime(@NonNull ManualTimeSuggestion suggestion) { 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; return false;
} }
String cause = "Manual time suggestion received: suggestion=" + suggestion; String cause = "Manual time suggestion received: suggestion=" + suggestion;
return setSystemClockIfRequired(ORIGIN_MANUAL, newUtcTime, cause); return setSystemClockIfRequired(ORIGIN_MANUAL, newUnixEpochTime, cause);
} }
@Override @Override
public synchronized void suggestNetworkTime(@NonNull NetworkTimeSuggestion timeSuggestion) { public synchronized void suggestNetworkTime(@NonNull NetworkTimeSuggestion timeSuggestion) {
if (!validateAutoSuggestionTime(timeSuggestion.getUtcTime(), timeSuggestion)) { if (!validateAutoSuggestionTime(timeSuggestion.getUnixEpochTime(), timeSuggestion)) {
return; return;
} }
@@ -275,11 +275,11 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
// unlike time zone, where a user may lose connectivity when boarding a flight and where we // 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 // do want to "forget" old signals. Suggestions that are too old are discarded later in the
// detection algorithm. // detection algorithm.
if (timeSuggestion.getUtcTime() == null) { if (timeSuggestion.getUnixEpochTime() == null) {
return; return;
} }
if (!validateAutoSuggestionTime(timeSuggestion.getUtcTime(), timeSuggestion)) { if (!validateAutoSuggestionTime(timeSuggestion.getUnixEpochTime(), timeSuggestion)) {
return; return;
} }
@@ -370,14 +370,14 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
@GuardedBy("this") @GuardedBy("this")
private boolean storeTelephonySuggestion( private boolean storeTelephonySuggestion(
@NonNull TelephonyTimeSuggestion suggestion) { @NonNull TelephonyTimeSuggestion suggestion) {
TimestampedValue<Long> newUtcTime = suggestion.getUtcTime(); TimestampedValue<Long> newUnixEpochTime = suggestion.getUnixEpochTime();
int slotIndex = suggestion.getSlotIndex(); int slotIndex = suggestion.getSlotIndex();
TelephonyTimeSuggestion previousSuggestion = mSuggestionBySlotIndex.get(slotIndex); TelephonyTimeSuggestion previousSuggestion = mSuggestionBySlotIndex.get(slotIndex);
if (previousSuggestion != null) { if (previousSuggestion != null) {
// We can log / discard suggestions with obvious issues with the reference time clock. // We can log / discard suggestions with obvious issues with the reference time clock.
if (previousSuggestion.getUtcTime() == null if (previousSuggestion.getUnixEpochTime() == null
|| previousSuggestion.getUtcTime().getValue() == null) { || previousSuggestion.getUnixEpochTime().getValue() == null) {
// This should be impossible given we only store validated suggestions. // This should be impossible given we only store validated suggestions.
Slog.w(LOG_TAG, "Previous suggestion is null or has a null time." Slog.w(LOG_TAG, "Previous suggestion is null or has a null time."
+ " previousSuggestion=" + previousSuggestion + " previousSuggestion=" + previousSuggestion
@@ -386,7 +386,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
} }
long referenceTimeDifference = TimestampedValue.referenceTimeDifference( long referenceTimeDifference = TimestampedValue.referenceTimeDifference(
newUtcTime, previousSuggestion.getUtcTime()); newUnixEpochTime, previousSuggestion.getUnixEpochTime());
if (referenceTimeDifference < 0) { if (referenceTimeDifference < 0) {
// The reference time is before the previously received suggestion. Ignore it. // The reference time is before the previously received suggestion. Ignore it.
Slog.w(LOG_TAG, "Out of order telephony suggestion received." Slog.w(LOG_TAG, "Out of order telephony suggestion received."
@@ -403,15 +403,15 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
} }
private boolean validateSuggestionTime( private boolean validateSuggestionTime(
@NonNull TimestampedValue<Long> newUtcTime, @NonNull Object suggestion) { @NonNull TimestampedValue<Long> newUnixEpochTime, @NonNull Object suggestion) {
if (newUtcTime.getValue() == null) { if (newUnixEpochTime.getValue() == null) {
Slog.w(LOG_TAG, "Suggested time value is null. suggestion=" + suggestion); Slog.w(LOG_TAG, "Suggested time value is null. suggestion=" + suggestion);
return false; return false;
} }
// We can validate the suggestion against the reference time clock. // We can validate the suggestion against the reference time clock.
long elapsedRealtimeMillis = mEnvironment.elapsedRealtimeMillis(); long elapsedRealtimeMillis = mEnvironment.elapsedRealtimeMillis();
if (elapsedRealtimeMillis < newUtcTime.getReferenceTimeMillis()) { if (elapsedRealtimeMillis < newUnixEpochTime.getReferenceTimeMillis()) {
// elapsedRealtime clock went backwards? // elapsedRealtime clock went backwards?
Slog.w(LOG_TAG, "New reference time is in the future? Ignoring." Slog.w(LOG_TAG, "New reference time is in the future? Ignoring."
+ " elapsedRealtimeMillis=" + elapsedRealtimeMillis + " elapsedRealtimeMillis=" + elapsedRealtimeMillis
@@ -422,17 +422,17 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
} }
private boolean validateAutoSuggestionTime( private boolean validateAutoSuggestionTime(
@NonNull TimestampedValue<Long> newUtcTime, @NonNull Object suggestion) { @NonNull TimestampedValue<Long> newUnixEpochTime, @NonNull Object suggestion) {
return validateSuggestionTime(newUtcTime, suggestion) return validateSuggestionTime(newUnixEpochTime, suggestion)
&& validateSuggestionAgainstLowerBound(newUtcTime, suggestion); && validateSuggestionAgainstLowerBound(newUnixEpochTime, suggestion);
} }
private boolean validateSuggestionAgainstLowerBound( private boolean validateSuggestionAgainstLowerBound(
@NonNull TimestampedValue<Long> newUtcTime, @NonNull Object suggestion) { @NonNull TimestampedValue<Long> newUnixEpochTime, @NonNull Object suggestion) {
Instant lowerBound = mEnvironment.autoTimeLowerBound(); Instant lowerBound = mEnvironment.autoTimeLowerBound();
// Suggestion is definitely wrong if it comes before lower time bound. // 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. " Slog.w(LOG_TAG, "Suggestion points to time before lower bound, skipping it. "
+ "suggestion=" + suggestion + ", lower bound=" + lowerBound); + "suggestion=" + suggestion + ", lower bound=" + lowerBound);
return false; return false;
@@ -451,12 +451,12 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
// Try the different origins one at a time. // Try the different origins one at a time.
int[] originPriorities = mEnvironment.autoOriginPriorities(); int[] originPriorities = mEnvironment.autoOriginPriorities();
for (int origin : originPriorities) { for (int origin : originPriorities) {
TimestampedValue<Long> newUtcTime = null; TimestampedValue<Long> newUnixEpochTime = null;
String cause = null; String cause = null;
if (origin == ORIGIN_TELEPHONY) { if (origin == ORIGIN_TELEPHONY) {
TelephonyTimeSuggestion bestTelephonySuggestion = findBestTelephonySuggestion(); TelephonyTimeSuggestion bestTelephonySuggestion = findBestTelephonySuggestion();
if (bestTelephonySuggestion != null) { if (bestTelephonySuggestion != null) {
newUtcTime = bestTelephonySuggestion.getUtcTime(); newUnixEpochTime = bestTelephonySuggestion.getUnixEpochTime();
cause = "Found good telephony suggestion." cause = "Found good telephony suggestion."
+ ", bestTelephonySuggestion=" + bestTelephonySuggestion + ", bestTelephonySuggestion=" + bestTelephonySuggestion
+ ", detectionReason=" + detectionReason; + ", detectionReason=" + detectionReason;
@@ -464,7 +464,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
} else if (origin == ORIGIN_NETWORK) { } else if (origin == ORIGIN_NETWORK) {
NetworkTimeSuggestion networkSuggestion = findLatestValidNetworkSuggestion(); NetworkTimeSuggestion networkSuggestion = findLatestValidNetworkSuggestion();
if (networkSuggestion != null) { if (networkSuggestion != null) {
newUtcTime = networkSuggestion.getUtcTime(); newUnixEpochTime = networkSuggestion.getUnixEpochTime();
cause = "Found good network suggestion." cause = "Found good network suggestion."
+ ", networkSuggestion=" + networkSuggestion + ", networkSuggestion=" + networkSuggestion
+ ", detectionReason=" + detectionReason; + ", detectionReason=" + detectionReason;
@@ -472,7 +472,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
} else if (origin == ORIGIN_GNSS) { } else if (origin == ORIGIN_GNSS) {
GnssTimeSuggestion gnssTimeSuggestion = findLatestValidGnssSuggestion(); GnssTimeSuggestion gnssTimeSuggestion = findLatestValidGnssSuggestion();
if (gnssTimeSuggestion != null) { if (gnssTimeSuggestion != null) {
newUtcTime = gnssTimeSuggestion.getUtcTime(); newUnixEpochTime = gnssTimeSuggestion.getUnixEpochTime();
cause = "Found good gnss suggestion." cause = "Found good gnss suggestion."
+ ", gnssTimeSuggestion=" + gnssTimeSuggestion + ", gnssTimeSuggestion=" + gnssTimeSuggestion
+ ", detectionReason=" + detectionReason; + ", detectionReason=" + detectionReason;
@@ -480,7 +480,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
} else if (origin == ORIGIN_EXTERNAL) { } else if (origin == ORIGIN_EXTERNAL) {
ExternalTimeSuggestion externalTimeSuggestion = findLatestValidExternalSuggestion(); ExternalTimeSuggestion externalTimeSuggestion = findLatestValidExternalSuggestion();
if (externalTimeSuggestion != null) { if (externalTimeSuggestion != null) {
newUtcTime = externalTimeSuggestion.getUtcTime(); newUnixEpochTime = externalTimeSuggestion.getUnixEpochTime();
cause = "Found good external suggestion." cause = "Found good external suggestion."
+ ", externalTimeSuggestion=" + externalTimeSuggestion + ", externalTimeSuggestion=" + externalTimeSuggestion
+ ", detectionReason=" + detectionReason; + ", detectionReason=" + detectionReason;
@@ -492,8 +492,8 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
} }
// Update the system clock if a good suggestion has been found. // Update the system clock if a good suggestion has been found.
if (newUtcTime != null) { if (newUnixEpochTime != null) {
setSystemClockIfRequired(origin, newUtcTime, cause); setSystemClockIfRequired(origin, newUnixEpochTime, cause);
return; return;
} }
} }
@@ -550,7 +550,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
Slog.w(LOG_TAG, "Latest suggestion unexpectedly null for slotIndex." Slog.w(LOG_TAG, "Latest suggestion unexpectedly null for slotIndex."
+ " slotIndex=" + slotIndex); + " slotIndex=" + slotIndex);
continue; continue;
} else if (candidateSuggestion.getUtcTime() == null) { } else if (candidateSuggestion.getUnixEpochTime() == null) {
// Unexpected - we do not store empty suggestions. // Unexpected - we do not store empty suggestions.
Slog.w(LOG_TAG, "Latest suggestion unexpectedly empty. " Slog.w(LOG_TAG, "Latest suggestion unexpectedly empty. "
+ " candidateSuggestion=" + candidateSuggestion); + " candidateSuggestion=" + candidateSuggestion);
@@ -584,8 +584,8 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
long elapsedRealtimeMillis, @NonNull TelephonyTimeSuggestion timeSuggestion) { long elapsedRealtimeMillis, @NonNull TelephonyTimeSuggestion timeSuggestion) {
// Validate first. // Validate first.
TimestampedValue<Long> utcTime = timeSuggestion.getUtcTime(); TimestampedValue<Long> unixEpochTime = timeSuggestion.getUnixEpochTime();
if (!validateSuggestionUtcTime(elapsedRealtimeMillis, utcTime)) { if (!validateSuggestionUnixEpochTime(elapsedRealtimeMillis, unixEpochTime)) {
Slog.w(LOG_TAG, "Existing suggestion found to be invalid" Slog.w(LOG_TAG, "Existing suggestion found to be invalid"
+ " elapsedRealtimeMillis=" + elapsedRealtimeMillis + " elapsedRealtimeMillis=" + elapsedRealtimeMillis
+ ", timeSuggestion=" + timeSuggestion); + ", timeSuggestion=" + timeSuggestion);
@@ -594,7 +594,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
// The score is based on the age since receipt. Suggestions are bucketed so two // 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. // 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. // Turn the age into a discrete value: 0 <= bucketIndex < TELEPHONY_BUCKET_COUNT.
int bucketIndex = (int) (ageMillis / TELEPHONY_BUCKET_SIZE_MILLIS); int bucketIndex = (int) (ageMillis / TELEPHONY_BUCKET_SIZE_MILLIS);
@@ -616,9 +616,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
return null; return null;
} }
TimestampedValue<Long> utcTime = networkSuggestion.getUtcTime(); TimestampedValue<Long> unixEpochTime = networkSuggestion.getUnixEpochTime();
long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis(); long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis();
if (!validateSuggestionUtcTime(elapsedRealTimeMillis, utcTime)) { if (!validateSuggestionUnixEpochTime(elapsedRealTimeMillis, unixEpochTime)) {
// The latest suggestion is not valid, usually due to its age. // The latest suggestion is not valid, usually due to its age.
return null; return null;
} }
@@ -636,9 +636,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
return null; return null;
} }
TimestampedValue<Long> utcTime = gnssTimeSuggestion.getUtcTime(); TimestampedValue<Long> unixEpochTime = gnssTimeSuggestion.getUnixEpochTime();
long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis(); long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis();
if (!validateSuggestionUtcTime(elapsedRealTimeMillis, utcTime)) { if (!validateSuggestionUnixEpochTime(elapsedRealTimeMillis, unixEpochTime)) {
// The latest suggestion is not valid, usually due to its age. // The latest suggestion is not valid, usually due to its age.
return null; return null;
} }
@@ -656,9 +656,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
return null; return null;
} }
TimestampedValue<Long> utcTime = externalTimeSuggestion.getUtcTime(); TimestampedValue<Long> unixEpochTime = externalTimeSuggestion.getUnixEpochTime();
long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis(); long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis();
if (!validateSuggestionUtcTime(elapsedRealTimeMillis, utcTime)) { if (!validateSuggestionUnixEpochTime(elapsedRealTimeMillis, unixEpochTime)) {
// The latest suggestion is not valid, usually due to its age. // The latest suggestion is not valid, usually due to its age.
return null; return null;
} }
@@ -849,9 +849,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
return mLastExternalSuggestion.get(); return mLastExternalSuggestion.get();
} }
private static boolean validateSuggestionUtcTime( private static boolean validateSuggestionUnixEpochTime(
long elapsedRealtimeMillis, TimestampedValue<Long> utcTime) { long elapsedRealtimeMillis, TimestampedValue<Long> unixEpochTime) {
long referenceTimeMillis = utcTime.getReferenceTimeMillis(); long referenceTimeMillis = unixEpochTime.getReferenceTimeMillis();
if (referenceTimeMillis > elapsedRealtimeMillis) { if (referenceTimeMillis > elapsedRealtimeMillis) {
// Future reference times are ignored. They imply the reference time was wrong, or the // 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 // elapsed realtime clock used to derive it has gone backwards, neither of which are
@@ -865,6 +865,6 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
// made and never replaced, it could also mean that the time detection code remains // 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. // opinionated using a bad invalid suggestion. This caps that edge case at MAX_AGE_MILLIS.
long ageMillis = elapsedRealtimeMillis - referenceTimeMillis; long ageMillis = elapsedRealtimeMillis - referenceTimeMillis;
return ageMillis <= MAX_UTC_TIME_AGE_MILLIS; return ageMillis <= MAX_SUGGESTION_TIME_AGE_MILLIS;
} }
} }

View File

@@ -252,7 +252,7 @@ public class TimeDetectorServiceTest {
int slotIndex = 1234; int slotIndex = 1234;
TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L); TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L);
return new TelephonyTimeSuggestion.Builder(slotIndex) return new TelephonyTimeSuggestion.Builder(slotIndex)
.setUtcTime(timeValue) .setUnixEpochTime(timeValue)
.build(); .build();
} }

View File

@@ -52,12 +52,12 @@ import java.util.Objects;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class TimeDetectorStrategyImplTest { 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 = private static final TimestampedValue<Instant> ARBITRARY_CLOCK_INITIALIZATION_INFO =
new TimestampedValue<>( new TimestampedValue<>(
123456789L /* realtimeClockMillis */, 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. // This is the traditional ordering for time detection on Android.
private static final @Origin int [] PROVIDERS_PRIORITY = { ORIGIN_TELEPHONY, ORIGIN_NETWORK }; 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} * An arbitrary time, very different from the {@link #ARBITRARY_CLOCK_INITIALIZATION_INFO}
* time. Can be used as the basis for time suggestions. * 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; private static final int ARBITRARY_SLOT_INDEX = 123456;
@@ -91,7 +91,7 @@ public class TimeDetectorStrategyImplTest {
.simulateTelephonyTimeSuggestion(timeSuggestion); .simulateTelephonyTimeSuggestion(timeSuggestion);
long expectedSystemClockMillis = long expectedSystemClockMillis =
mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime()); mScript.calculateTimeInMillisForNow(timeSuggestion.getUnixEpochTime());
mScript.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis) mScript.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion); .assertLatestTelephonySuggestion(slotIndex, timeSuggestion);
} }
@@ -128,7 +128,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(clockIncrementMillis); mScript.simulateTimePassing(clockIncrementMillis);
long expectedSystemClockMillis1 = long expectedSystemClockMillis1 =
mScript.calculateTimeInMillisForNow(timeSuggestion1.getUtcTime()); mScript.calculateTimeInMillisForNow(timeSuggestion1.getUnixEpochTime());
mScript.simulateTelephonyTimeSuggestion(timeSuggestion1) mScript.simulateTelephonyTimeSuggestion(timeSuggestion1)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1)
@@ -155,7 +155,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(clockIncrementMillis); mScript.simulateTimePassing(clockIncrementMillis);
long expectedSystemClockMillis3 = long expectedSystemClockMillis3 =
mScript.calculateTimeInMillisForNow(timeSuggestion3.getUtcTime()); mScript.calculateTimeInMillisForNow(timeSuggestion3.getUnixEpochTime());
mScript.simulateTelephonyTimeSuggestion(timeSuggestion3) mScript.simulateTelephonyTimeSuggestion(timeSuggestion3)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis3) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis3)
@@ -182,8 +182,8 @@ public class TimeDetectorStrategyImplTest {
mScript.generateTelephonyTimeSuggestion(slotIndex2, slotIndex2Time); mScript.generateTelephonyTimeSuggestion(slotIndex2, slotIndex2Time);
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedSystemClockMillis = long expectedSystemClockMillis = mScript.calculateTimeInMillisForNow(
mScript.calculateTimeInMillisForNow(slotIndex2TimeSuggestion.getUtcTime()); slotIndex2TimeSuggestion.getUnixEpochTime());
mScript.simulateTelephonyTimeSuggestion(slotIndex2TimeSuggestion) mScript.simulateTelephonyTimeSuggestion(slotIndex2TimeSuggestion)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
@@ -199,8 +199,8 @@ public class TimeDetectorStrategyImplTest {
mScript.generateTelephonyTimeSuggestion(slotIndex1, slotIndex1Time); mScript.generateTelephonyTimeSuggestion(slotIndex1, slotIndex1Time);
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedSystemClockMillis = long expectedSystemClockMillis = mScript.calculateTimeInMillisForNow(
mScript.calculateTimeInMillisForNow(slotIndex1TimeSuggestion.getUtcTime()); slotIndex1TimeSuggestion.getUnixEpochTime());
mScript.simulateTelephonyTimeSuggestion(slotIndex1TimeSuggestion) mScript.simulateTelephonyTimeSuggestion(slotIndex1TimeSuggestion)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
@@ -232,8 +232,8 @@ public class TimeDetectorStrategyImplTest {
mScript.generateTelephonyTimeSuggestion(slotIndex2, slotIndex2Time); mScript.generateTelephonyTimeSuggestion(slotIndex2, slotIndex2Time);
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedSystemClockMillis = long expectedSystemClockMillis = mScript.calculateTimeInMillisForNow(
mScript.calculateTimeInMillisForNow(slotIndex2TimeSuggestion.getUtcTime()); slotIndex2TimeSuggestion.getUnixEpochTime());
mScript.simulateTelephonyTimeSuggestion(slotIndex2TimeSuggestion) mScript.simulateTelephonyTimeSuggestion(slotIndex2TimeSuggestion)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
@@ -267,26 +267,27 @@ public class TimeDetectorStrategyImplTest {
TelephonyTimeSuggestion timeSuggestion1 = TelephonyTimeSuggestion timeSuggestion1 =
mScript.generateTelephonyTimeSuggestion(slotIndex, testTime); 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. // Initialize the strategy / device with a time set from a telephony suggestion.
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedSystemClockMillis1 = mScript.calculateTimeInMillisForNow(utcTime1); long expectedSystemClockMillis1 = mScript.calculateTimeInMillisForNow(unixEpochTime1);
mScript.simulateTelephonyTimeSuggestion(timeSuggestion1) mScript.simulateTelephonyTimeSuggestion(timeSuggestion1)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1)
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1); .assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
// The UTC time increment should be larger than the system clock update threshold so we // The Unix epoch time increment should be larger than the system clock update threshold so
// know it shouldn't be ignored for other reasons. // we know it shouldn't be ignored for other reasons.
long validUtcTimeMillis = utcTime1.getValue() + (2 * systemClockUpdateThreshold); long validUnixEpochTimeMillis = unixEpochTime1.getValue()
+ (2 * systemClockUpdateThreshold);
// Now supply a new signal that has an obviously bogus reference time : older than the last // Now supply a new signal that has an obviously bogus reference time : older than the last
// one. // one.
long referenceTimeBeforeLastSignalMillis = utcTime1.getReferenceTimeMillis() - 1; long referenceTimeBeforeLastSignalMillis = unixEpochTime1.getReferenceTimeMillis() - 1;
TimestampedValue<Long> utcTime2 = new TimestampedValue<>( TimestampedValue<Long> unixEpochTime2 = new TimestampedValue<>(
referenceTimeBeforeLastSignalMillis, validUtcTimeMillis); referenceTimeBeforeLastSignalMillis, validUnixEpochTimeMillis);
TelephonyTimeSuggestion timeSuggestion2 = TelephonyTimeSuggestion timeSuggestion2 =
createTelephonyTimeSuggestion(slotIndex, utcTime2); createTelephonyTimeSuggestion(slotIndex, unixEpochTime2);
mScript.simulateTelephonyTimeSuggestion(timeSuggestion2) mScript.simulateTelephonyTimeSuggestion(timeSuggestion2)
.verifySystemClockWasNotSetAndResetCallTracking() .verifySystemClockWasNotSetAndResetCallTracking()
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1); .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 // Now supply a new signal that has an obviously bogus reference time : substantially in the
// future. // future.
long referenceTimeInFutureMillis = long referenceTimeInFutureMillis =
utcTime1.getReferenceTimeMillis() + Integer.MAX_VALUE + 1; unixEpochTime1.getReferenceTimeMillis() + Integer.MAX_VALUE + 1;
TimestampedValue<Long> utcTime3 = new TimestampedValue<>( TimestampedValue<Long> unixEpochTime3 = new TimestampedValue<>(
referenceTimeInFutureMillis, validUtcTimeMillis); referenceTimeInFutureMillis, validUnixEpochTimeMillis);
TelephonyTimeSuggestion timeSuggestion3 = TelephonyTimeSuggestion timeSuggestion3 =
createTelephonyTimeSuggestion(slotIndex, utcTime3); createTelephonyTimeSuggestion(slotIndex, unixEpochTime3);
mScript.simulateTelephonyTimeSuggestion(timeSuggestion3) mScript.simulateTelephonyTimeSuggestion(timeSuggestion3)
.verifySystemClockWasNotSetAndResetCallTracking() .verifySystemClockWasNotSetAndResetCallTracking()
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1); .assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
// Just to prove validUtcTimeMillis is valid. // Just to prove validUnixEpochTimeMillis is valid.
long validReferenceTimeMillis = utcTime1.getReferenceTimeMillis() + 100; long validReferenceTimeMillis = unixEpochTime1.getReferenceTimeMillis() + 100;
TimestampedValue<Long> utcTime4 = new TimestampedValue<>( TimestampedValue<Long> unixEpochTime4 = new TimestampedValue<>(
validReferenceTimeMillis, validUtcTimeMillis); validReferenceTimeMillis, validUnixEpochTimeMillis);
long expectedSystemClockMillis4 = mScript.calculateTimeInMillisForNow(utcTime4); long expectedSystemClockMillis4 = mScript.calculateTimeInMillisForNow(unixEpochTime4);
TelephonyTimeSuggestion timeSuggestion4 = TelephonyTimeSuggestion timeSuggestion4 =
createTelephonyTimeSuggestion(slotIndex, utcTime4); createTelephonyTimeSuggestion(slotIndex, unixEpochTime4);
mScript.simulateTelephonyTimeSuggestion(timeSuggestion4) mScript.simulateTelephonyTimeSuggestion(timeSuggestion4)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis4) .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis4)
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion4); .assertLatestTelephonySuggestion(slotIndex, timeSuggestion4);
@@ -344,7 +345,7 @@ public class TimeDetectorStrategyImplTest {
Instant testTime = ARBITRARY_TEST_TIME; Instant testTime = ARBITRARY_TEST_TIME;
TelephonyTimeSuggestion timeSuggestion1 = TelephonyTimeSuggestion timeSuggestion1 =
mScript.generateTelephonyTimeSuggestion(slotIndex, testTime); mScript.generateTelephonyTimeSuggestion(slotIndex, testTime);
TimestampedValue<Long> utcTime1 = timeSuggestion1.getUtcTime(); TimestampedValue<Long> unixEpochTime1 = timeSuggestion1.getUnixEpochTime();
// Simulate time passing. // Simulate time passing.
mScript.simulateTimePassing(clockIncrementMillis); mScript.simulateTimePassing(clockIncrementMillis);
@@ -358,7 +359,7 @@ public class TimeDetectorStrategyImplTest {
// Simulate more time passing. // Simulate more time passing.
mScript.simulateTimePassing(clockIncrementMillis); mScript.simulateTimePassing(clockIncrementMillis);
long expectedSystemClockMillis1 = mScript.calculateTimeInMillisForNow(utcTime1); long expectedSystemClockMillis1 = mScript.calculateTimeInMillisForNow(unixEpochTime1);
// Turn on auto time detection. // Turn on auto time detection.
mScript.simulateAutoTimeDetectionToggle() mScript.simulateAutoTimeDetectionToggle()
@@ -379,7 +380,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(clockIncrementMillis); mScript.simulateTimePassing(clockIncrementMillis);
long expectedSystemClockMillis2 = 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 // The new time, though valid, should not be set in the system clock because auto time is
// disabled. // disabled.
@@ -406,7 +407,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedSystemClockMillis = long expectedSystemClockMillis =
mScript.calculateTimeInMillisForNow(telephonySuggestion.getUtcTime()); mScript.calculateTimeInMillisForNow(telephonySuggestion.getUnixEpochTime());
mScript.simulateTelephonyTimeSuggestion(telephonySuggestion) mScript.simulateTelephonyTimeSuggestion(telephonySuggestion)
.verifySystemClockWasSetAndResetCallTracking( .verifySystemClockWasSetAndResetCallTracking(
expectedSystemClockMillis /* expectedNetworkBroadcast */) expectedSystemClockMillis /* expectedNetworkBroadcast */)
@@ -416,7 +417,7 @@ public class TimeDetectorStrategyImplTest {
assertEquals(telephonySuggestion, mScript.peekBestTelephonySuggestion()); assertEquals(telephonySuggestion, mScript.peekBestTelephonySuggestion());
// Simulate time passing, long enough that telephonySuggestion is now too old. // 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. // Look inside and check what the strategy considers the current best telephony suggestion.
// It should still be the, it's just no longer used. // It should still be the, it's just no longer used.
@@ -435,7 +436,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedSystemClockMillis = long expectedSystemClockMillis =
mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime()); mScript.calculateTimeInMillisForNow(timeSuggestion.getUnixEpochTime());
mScript.simulateManualTimeSuggestion(timeSuggestion, true /* expectedResult */) mScript.simulateManualTimeSuggestion(timeSuggestion, true /* expectedResult */)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis); .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis);
} }
@@ -457,7 +458,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedAutoClockMillis = long expectedAutoClockMillis =
mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUtcTime()); mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUnixEpochTime());
mScript.simulateTelephonyTimeSuggestion(telephonyTimeSuggestion) mScript.simulateTelephonyTimeSuggestion(telephonyTimeSuggestion)
.verifySystemClockWasSetAndResetCallTracking(expectedAutoClockMillis) .verifySystemClockWasSetAndResetCallTracking(expectedAutoClockMillis)
.assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion); .assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion);
@@ -480,7 +481,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedManualClockMillis = long expectedManualClockMillis =
mScript.calculateTimeInMillisForNow(manualTimeSuggestion.getUtcTime()); mScript.calculateTimeInMillisForNow(manualTimeSuggestion.getUnixEpochTime());
mScript.simulateManualTimeSuggestion(manualTimeSuggestion, true /* expectedResult */) mScript.simulateManualTimeSuggestion(manualTimeSuggestion, true /* expectedResult */)
.verifySystemClockWasSetAndResetCallTracking(expectedManualClockMillis) .verifySystemClockWasSetAndResetCallTracking(expectedManualClockMillis)
.assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion); .assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion);
@@ -492,7 +493,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateAutoTimeDetectionToggle(); mScript.simulateAutoTimeDetectionToggle();
expectedAutoClockMillis = expectedAutoClockMillis =
mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUtcTime()); mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUnixEpochTime());
mScript.verifySystemClockWasSetAndResetCallTracking(expectedAutoClockMillis) mScript.verifySystemClockWasSetAndResetCallTracking(expectedAutoClockMillis)
.assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion); .assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion);
@@ -540,7 +541,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedSystemClockMillis = long expectedSystemClockMillis =
mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime()); mScript.calculateTimeInMillisForNow(timeSuggestion.getUnixEpochTime());
mScript.simulateNetworkTimeSuggestion(timeSuggestion) mScript.simulateNetworkTimeSuggestion(timeSuggestion)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis); .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis);
} }
@@ -586,7 +587,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedSystemClockMillis = long expectedSystemClockMillis =
mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime()); mScript.calculateTimeInMillisForNow(timeSuggestion.getUnixEpochTime());
mScript.simulateGnssTimeSuggestion(timeSuggestion) mScript.simulateGnssTimeSuggestion(timeSuggestion)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis); .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis);
} }
@@ -617,7 +618,7 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(); mScript.simulateTimePassing();
long expectedSystemClockMillis = long expectedSystemClockMillis =
mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime()); mScript.calculateTimeInMillisForNow(timeSuggestion.getUnixEpochTime());
mScript.simulateExternalTimeSuggestion(timeSuggestion) mScript.simulateExternalTimeSuggestion(timeSuggestion)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis); .verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis);
} }
@@ -671,7 +672,8 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(smallTimeIncrementMillis) mScript.simulateTimePassing(smallTimeIncrementMillis)
.simulateNetworkTimeSuggestion(networkTimeSuggestion1) .simulateNetworkTimeSuggestion(networkTimeSuggestion1)
.verifySystemClockWasSetAndResetCallTracking( .verifySystemClockWasSetAndResetCallTracking(
mScript.calculateTimeInMillisForNow(networkTimeSuggestion1.getUtcTime())); mScript.calculateTimeInMillisForNow(
networkTimeSuggestion1.getUnixEpochTime()));
// Check internal state. // Check internal state.
mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, null) mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, null)
@@ -690,7 +692,8 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(smallTimeIncrementMillis) mScript.simulateTimePassing(smallTimeIncrementMillis)
.simulateTelephonyTimeSuggestion(telephonyTimeSuggestion) .simulateTelephonyTimeSuggestion(telephonyTimeSuggestion)
.verifySystemClockWasSetAndResetCallTracking( .verifySystemClockWasSetAndResetCallTracking(
mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUtcTime())); mScript.calculateTimeInMillisForNow(
telephonyTimeSuggestion.getUnixEpochTime()));
// Check internal state. // Check internal state.
mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, telephonyTimeSuggestion) 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 // Simulate some significant time passing: half the time allowed before a time signal
// becomes "too old to use". // becomes "too old to use".
mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2) mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_SUGGESTION_TIME_AGE_MILLIS / 2)
.verifySystemClockWasNotSetAndResetCallTracking(); .verifySystemClockWasNotSetAndResetCallTracking();
// Now another network suggestion is made. Telephony suggestions are prioritized over // 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 // 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 // becomes "too old to use". This should mean that telephonyTimeSuggestion is now too old to
// be used but networkTimeSuggestion2 is not. // 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 // 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 // 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. // Verify the latest network time now wins.
mScript.verifySystemClockWasSetAndResetCallTracking( mScript.verifySystemClockWasSetAndResetCallTracking(
mScript.calculateTimeInMillisForNow(networkTimeSuggestion2.getUtcTime())); mScript.calculateTimeInMillisForNow(networkTimeSuggestion2.getUnixEpochTime()));
// Check internal state. // Check internal state.
mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, telephonyTimeSuggestion) mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, telephonyTimeSuggestion)
@@ -774,7 +777,8 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(smallTimeIncrementMillis) mScript.simulateTimePassing(smallTimeIncrementMillis)
.simulateGnssTimeSuggestion(gnssTimeSuggestion1) .simulateGnssTimeSuggestion(gnssTimeSuggestion1)
.verifySystemClockWasSetAndResetCallTracking( .verifySystemClockWasSetAndResetCallTracking(
mScript.calculateTimeInMillisForNow(gnssTimeSuggestion1.getUtcTime())); mScript.calculateTimeInMillisForNow(
gnssTimeSuggestion1.getUnixEpochTime()));
// Check internal state. // Check internal state.
mScript.assertLatestNetworkSuggestion(null) mScript.assertLatestNetworkSuggestion(null)
@@ -793,7 +797,8 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(smallTimeIncrementMillis) mScript.simulateTimePassing(smallTimeIncrementMillis)
.simulateNetworkTimeSuggestion(networkTimeSuggestion) .simulateNetworkTimeSuggestion(networkTimeSuggestion)
.verifySystemClockWasSetAndResetCallTracking( .verifySystemClockWasSetAndResetCallTracking(
mScript.calculateTimeInMillisForNow(networkTimeSuggestion.getUtcTime())); mScript.calculateTimeInMillisForNow(
networkTimeSuggestion.getUnixEpochTime()));
// Check internal state. // Check internal state.
mScript.assertLatestNetworkSuggestion(networkTimeSuggestion) mScript.assertLatestNetworkSuggestion(networkTimeSuggestion)
@@ -803,7 +808,7 @@ public class TimeDetectorStrategyImplTest {
// Simulate some significant time passing: half the time allowed before a time signal // Simulate some significant time passing: half the time allowed before a time signal
// becomes "too old to use". // becomes "too old to use".
mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2) mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_SUGGESTION_TIME_AGE_MILLIS / 2)
.verifySystemClockWasNotSetAndResetCallTracking(); .verifySystemClockWasNotSetAndResetCallTracking();
// Now another gnss suggestion is made. Network suggestions are prioritized over // 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 // 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 // becomes "too old to use". This should mean that telephonyTimeSuggestion is now too old to
// be used but networkTimeSuggestion2 is not. // 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 // 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 // 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. // Verify the latest gnss time now wins.
mScript.verifySystemClockWasSetAndResetCallTracking( mScript.verifySystemClockWasSetAndResetCallTracking(
mScript.calculateTimeInMillisForNow(gnssTimeSuggestion2.getUtcTime())); mScript.calculateTimeInMillisForNow(gnssTimeSuggestion2.getUnixEpochTime()));
// Check internal state. // Check internal state.
mScript.assertLatestNetworkSuggestion(networkTimeSuggestion) mScript.assertLatestNetworkSuggestion(networkTimeSuggestion)
@@ -877,7 +882,8 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(smallTimeIncrementMillis) mScript.simulateTimePassing(smallTimeIncrementMillis)
.simulateExternalTimeSuggestion(externalTimeSuggestion1) .simulateExternalTimeSuggestion(externalTimeSuggestion1)
.verifySystemClockWasSetAndResetCallTracking( .verifySystemClockWasSetAndResetCallTracking(
mScript.calculateTimeInMillisForNow(externalTimeSuggestion1.getUtcTime())); mScript.calculateTimeInMillisForNow(
externalTimeSuggestion1.getUnixEpochTime()));
// Check internal state. // Check internal state.
mScript.assertLatestNetworkSuggestion(null) mScript.assertLatestNetworkSuggestion(null)
@@ -896,7 +902,8 @@ public class TimeDetectorStrategyImplTest {
mScript.simulateTimePassing(smallTimeIncrementMillis) mScript.simulateTimePassing(smallTimeIncrementMillis)
.simulateNetworkTimeSuggestion(networkTimeSuggestion) .simulateNetworkTimeSuggestion(networkTimeSuggestion)
.verifySystemClockWasSetAndResetCallTracking( .verifySystemClockWasSetAndResetCallTracking(
mScript.calculateTimeInMillisForNow(networkTimeSuggestion.getUtcTime())); mScript.calculateTimeInMillisForNow(
networkTimeSuggestion.getUnixEpochTime()));
// Check internal state. // Check internal state.
mScript.assertLatestNetworkSuggestion(networkTimeSuggestion) mScript.assertLatestNetworkSuggestion(networkTimeSuggestion)
@@ -906,7 +913,7 @@ public class TimeDetectorStrategyImplTest {
// Simulate some significant time passing: half the time allowed before a time signal // Simulate some significant time passing: half the time allowed before a time signal
// becomes "too old to use". // becomes "too old to use".
mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2) mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_SUGGESTION_TIME_AGE_MILLIS / 2)
.verifySystemClockWasNotSetAndResetCallTracking(); .verifySystemClockWasNotSetAndResetCallTracking();
// Now another external suggestion is made. Network suggestions are prioritized over // 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 // 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 // becomes "too old to use". This should mean that networkTimeSuggestion is now too old to
// be used but externalTimeSuggestion2 is not. // 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 // 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 // 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. // Verify the latest external time now wins.
mScript.verifySystemClockWasSetAndResetCallTracking( mScript.verifySystemClockWasSetAndResetCallTracking(
mScript.calculateTimeInMillisForNow(externalTimeSuggestion2.getUtcTime())); mScript.calculateTimeInMillisForNow(externalTimeSuggestion2.getUnixEpochTime()));
// Check internal state. // Check internal state.
mScript.assertLatestNetworkSuggestion(networkTimeSuggestion) mScript.assertLatestNetworkSuggestion(networkTimeSuggestion)
@@ -1438,11 +1445,11 @@ public class TimeDetectorStrategyImplTest {
* reference time. * reference time.
*/ */
ManualTimeSuggestion generateManualTimeSuggestion(Instant suggestedTime) { ManualTimeSuggestion generateManualTimeSuggestion(Instant suggestedTime) {
TimestampedValue<Long> utcTime = TimestampedValue<Long> unixEpochTime =
new TimestampedValue<>( new TimestampedValue<>(
mFakeEnvironment.peekElapsedRealtimeMillis(), mFakeEnvironment.peekElapsedRealtimeMillis(),
suggestedTime.toEpochMilli()); suggestedTime.toEpochMilli());
return new ManualTimeSuggestion(utcTime); return new ManualTimeSuggestion(unixEpochTime);
} }
/** /**
@@ -1472,11 +1479,11 @@ public class TimeDetectorStrategyImplTest {
* reference time. * reference time.
*/ */
NetworkTimeSuggestion generateNetworkTimeSuggestion(Instant suggestedTime) { NetworkTimeSuggestion generateNetworkTimeSuggestion(Instant suggestedTime) {
TimestampedValue<Long> utcTime = TimestampedValue<Long> unixEpochTime =
new TimestampedValue<>( new TimestampedValue<>(
mFakeEnvironment.peekElapsedRealtimeMillis(), mFakeEnvironment.peekElapsedRealtimeMillis(),
suggestedTime.toEpochMilli()); suggestedTime.toEpochMilli());
return new NetworkTimeSuggestion(utcTime); return new NetworkTimeSuggestion(unixEpochTime);
} }
/** /**
@@ -1484,11 +1491,11 @@ public class TimeDetectorStrategyImplTest {
* reference time. * reference time.
*/ */
GnssTimeSuggestion generateGnssTimeSuggestion(Instant suggestedTime) { GnssTimeSuggestion generateGnssTimeSuggestion(Instant suggestedTime) {
TimestampedValue<Long> utcTime = TimestampedValue<Long> unixEpochTime =
new TimestampedValue<>( new TimestampedValue<>(
mFakeEnvironment.peekElapsedRealtimeMillis(), mFakeEnvironment.peekElapsedRealtimeMillis(),
suggestedTime.toEpochMilli()); 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 * Calculates what the supplied time would be when adjusted for the movement of the fake
* elapsed realtime clock. * elapsed realtime clock.
*/ */
long calculateTimeInMillisForNow(TimestampedValue<Long> utcTime) { long calculateTimeInMillisForNow(TimestampedValue<Long> unixEpochTime) {
return TimeDetectorStrategy.getTimeAt(utcTime, peekElapsedRealtimeMillis()); return TimeDetectorStrategy.getTimeAt(unixEpochTime, peekElapsedRealtimeMillis());
} }
} }
private static TelephonyTimeSuggestion createTelephonyTimeSuggestion(int slotIndex, private static TelephonyTimeSuggestion createTelephonyTimeSuggestion(int slotIndex,
TimestampedValue<Long> utcTime) { TimestampedValue<Long> unixEpochTime) {
return new TelephonyTimeSuggestion.Builder(slotIndex) return new TelephonyTimeSuggestion.Builder(slotIndex)
.setUtcTime(utcTime) .setUnixEpochTime(unixEpochTime)
.build(); .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) { int minute, int second) {
return LocalDateTime.of(year, monthInYear, day, hourOfDay, minute, second) return LocalDateTime.of(year, monthInYear, day, hourOfDay, minute, second)
.toInstant(ZoneOffset.UTC); .toInstant(ZoneOffset.UTC);