Switch "UTC time" to "Unix epoch time"
This is more correct. Bug: 218802673 Test: Compile only Change-Id: Ic477c021529a94b4a3665426b7daaf6567fa311a
This commit is contained in:
@@ -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
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
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 */, android.os.TimestampedValue.class);
|
||||
GnssTimeSuggestion suggestion = new GnssTimeSuggestion(utcTime);
|
||||
TimestampedValue<Long> unixEpochTime =
|
||||
in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class);
|
||||
GnssTimeSuggestion suggestion = new GnssTimeSuggestion(unixEpochTime);
|
||||
@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;
|
||||
return suggestion;
|
||||
}
|
||||
@@ -81,13 +83,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 +119,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
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
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 */, android.os.TimestampedValue.class);
|
||||
ManualTimeSuggestion suggestion = new ManualTimeSuggestion(utcTime);
|
||||
TimestampedValue<Long> unixEpochTime =
|
||||
in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class);
|
||||
ManualTimeSuggestion suggestion = new ManualTimeSuggestion(unixEpochTime);
|
||||
@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;
|
||||
return suggestion;
|
||||
}
|
||||
@@ -81,13 +83,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 +119,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
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
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 */, android.os.TimestampedValue.class);
|
||||
NetworkTimeSuggestion suggestion = new NetworkTimeSuggestion(utcTime);
|
||||
TimestampedValue<Long> unixEpochTime =
|
||||
in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class);
|
||||
NetworkTimeSuggestion suggestion = new NetworkTimeSuggestion(unixEpochTime);
|
||||
@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;
|
||||
return suggestion;
|
||||
}
|
||||
@@ -81,13 +84,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 +120,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
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@@ -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,22 +65,25 @@ 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 */, android.os.TimestampedValue.class);
|
||||
TelephonyTimeSuggestion suggestion = new TelephonyTimeSuggestion.Builder(slotIndex)
|
||||
.setUtcTime(in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class))
|
||||
.setUnixEpochTime(unixEpochTime)
|
||||
.build();
|
||||
@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) {
|
||||
suggestion.addDebugInfo(debugInfo);
|
||||
}
|
||||
@@ -95,7 +98,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 +114,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 +166,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 +190,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 +205,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static final long MAX_UTC_TIME_AGE_MILLIS =
|
||||
static final long MAX_SUGGESTION_TIME_AGE_MILLIS =
|
||||
TELEPHONY_BUCKET_COUNT * TELEPHONY_BUCKET_SIZE_MILLIS;
|
||||
|
||||
/**
|
||||
@@ -205,9 +205,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;
|
||||
}
|
||||
|
||||
@@ -219,9 +219,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;
|
||||
}
|
||||
|
||||
@@ -233,19 +233,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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -370,14 +370,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
|
||||
@@ -386,7 +386,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."
|
||||
@@ -403,15 +403,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
|
||||
@@ -422,17 +422,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;
|
||||
@@ -451,12 +451,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;
|
||||
@@ -464,7 +464,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;
|
||||
@@ -472,7 +472,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;
|
||||
@@ -480,7 +480,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;
|
||||
@@ -492,8 +492,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;
|
||||
}
|
||||
}
|
||||
@@ -550,7 +550,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);
|
||||
@@ -584,8 +584,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);
|
||||
@@ -594,7 +594,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);
|
||||
@@ -616,9 +616,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;
|
||||
}
|
||||
@@ -636,9 +636,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;
|
||||
}
|
||||
@@ -656,9 +656,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;
|
||||
}
|
||||
@@ -849,9 +849,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
|
||||
@@ -865,6 +865,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user