Remove usages of TimestampedValue<Long>
Remove usages of TimestampedValue<Long> now we have UnixEpochTime, which
is the same thing but intended to be public and without the use of
generic Long (so no null checks needed).
Bug: 236612872
Test: Build only
Change-Id: I340754389536c09613d8c092ce5005a7eec605ef
diff --git a/core/java/android/app/time/ExternalTimeSuggestion.java b/core/java/android/app/time/ExternalTimeSuggestion.java
index a7828ab..f4826ec 100644
--- a/core/java/android/app/time/ExternalTimeSuggestion.java
+++ b/core/java/android/app/time/ExternalTimeSuggestion.java
@@ -24,7 +24,6 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ShellCommand;
-import android.os.TimestampedValue;
import java.io.PrintWriter;
import java.util.List;
@@ -48,9 +47,9 @@
*
* <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 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
+ * capture the elapsed realtime clock value, e.g. via {@link SystemClock#elapsedRealtime()}, 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.
*
@@ -97,7 +96,7 @@
public ExternalTimeSuggestion(@ElapsedRealtimeLong long elapsedRealtimeMillis,
@CurrentTimeMillisLong long suggestionMillis) {
mTimeSuggestionHelper = new TimeSuggestionHelper(ExternalTimeSuggestion.class,
- new TimestampedValue<>(elapsedRealtimeMillis, suggestionMillis));
+ new UnixEpochTime(elapsedRealtimeMillis, suggestionMillis));
}
private ExternalTimeSuggestion(@NonNull TimeSuggestionHelper helper) {
@@ -118,7 +117,7 @@
* {@hide}
*/
@NonNull
- public TimestampedValue<Long> getUnixEpochTime() {
+ public UnixEpochTime getUnixEpochTime() {
return mTimeSuggestionHelper.getUnixEpochTime();
}
diff --git a/core/java/android/app/time/TimeManager.java b/core/java/android/app/time/TimeManager.java
index 6a833fd..9f66f09 100644
--- a/core/java/android/app/time/TimeManager.java
+++ b/core/java/android/app/time/TimeManager.java
@@ -28,7 +28,6 @@
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
-import android.os.TimestampedValue;
import android.util.ArrayMap;
import android.util.Log;
@@ -339,10 +338,7 @@
Log.d(TAG, "setTime called: " + unixEpochTime);
}
try {
- TimestampedValue<Long> manualTime = new TimestampedValue<>(
- unixEpochTime.getElapsedRealtimeMillis(),
- unixEpochTime.getUnixEpochTimeMillis());
- ManualTimeSuggestion manualTimeSuggestion = new ManualTimeSuggestion(manualTime);
+ ManualTimeSuggestion manualTimeSuggestion = new ManualTimeSuggestion(unixEpochTime);
manualTimeSuggestion.addDebugInfo("TimeManager.setTime()");
manualTimeSuggestion.addDebugInfo("UID: " + android.os.Process.myUid());
manualTimeSuggestion.addDebugInfo("UserHandle: " + android.os.Process.myUserHandle());
diff --git a/core/java/android/app/time/TimeZoneCapabilities.java b/core/java/android/app/time/TimeZoneCapabilities.java
index 5d4629f..2f147ce 100644
--- a/core/java/android/app/time/TimeZoneCapabilities.java
+++ b/core/java/android/app/time/TimeZoneCapabilities.java
@@ -41,16 +41,15 @@
@SystemApi
public final class TimeZoneCapabilities implements Parcelable {
- public static final @NonNull Creator<TimeZoneCapabilities> CREATOR =
- new Creator<TimeZoneCapabilities>() {
- public TimeZoneCapabilities createFromParcel(Parcel in) {
- return TimeZoneCapabilities.createFromParcel(in);
- }
+ public static final @NonNull Creator<TimeZoneCapabilities> CREATOR = new Creator<>() {
+ public TimeZoneCapabilities createFromParcel(Parcel in) {
+ return TimeZoneCapabilities.createFromParcel(in);
+ }
- public TimeZoneCapabilities[] newArray(int size) {
- return new TimeZoneCapabilities[size];
- }
- };
+ public TimeZoneCapabilities[] newArray(int size) {
+ return new TimeZoneCapabilities[size];
+ }
+ };
/**
* The user the capabilities are for. This is used for object equality and debugging but there
diff --git a/core/java/android/app/time/UnixEpochTime.java b/core/java/android/app/time/UnixEpochTime.java
index 2683547..f1a176e 100644
--- a/core/java/android/app/time/UnixEpochTime.java
+++ b/core/java/android/app/time/UnixEpochTime.java
@@ -23,7 +23,6 @@
import android.os.Parcelable;
import android.os.ShellCommand;
import android.os.SystemClock;
-import android.os.TimestampedValue;
import java.io.PrintWriter;
import java.util.Objects;
@@ -181,10 +180,4 @@
@NonNull UnixEpochTime one, @NonNull UnixEpochTime two) {
return one.mElapsedRealtimeMillis - two.mElapsedRealtimeMillis;
}
-
- // TODO(b/246256335) Switch to using UnixEpochTime where possible and remove this method.
- /** @hide */
- public TimestampedValue<Long> toTimestampedValue() {
- return new TimestampedValue<>(mElapsedRealtimeMillis, mUnixEpochTimeMillis);
- }
}
diff --git a/core/java/android/app/timedetector/ManualTimeSuggestion.java b/core/java/android/app/timedetector/ManualTimeSuggestion.java
index b447799..0be4267 100644
--- a/core/java/android/app/timedetector/ManualTimeSuggestion.java
+++ b/core/java/android/app/timedetector/ManualTimeSuggestion.java
@@ -18,10 +18,10 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.app.time.UnixEpochTime;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ShellCommand;
-import android.os.TimestampedValue;
import java.io.PrintWriter;
import java.util.List;
@@ -51,7 +51,7 @@
@NonNull private final TimeSuggestionHelper mTimeSuggestionHelper;
- public ManualTimeSuggestion(@NonNull TimestampedValue<Long> unixEpochTime) {
+ public ManualTimeSuggestion(@NonNull UnixEpochTime unixEpochTime) {
mTimeSuggestionHelper = new TimeSuggestionHelper(ManualTimeSuggestion.class, unixEpochTime);
}
@@ -70,7 +70,7 @@
}
@NonNull
- public TimestampedValue<Long> getUnixEpochTime() {
+ public UnixEpochTime getUnixEpochTime() {
return mTimeSuggestionHelper.getUnixEpochTime();
}
diff --git a/core/java/android/app/timedetector/TelephonyTimeSuggestion.java b/core/java/android/app/timedetector/TelephonyTimeSuggestion.java
index e0347c0..f149a26 100644
--- a/core/java/android/app/timedetector/TelephonyTimeSuggestion.java
+++ b/core/java/android/app/timedetector/TelephonyTimeSuggestion.java
@@ -18,10 +18,10 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.app.time.UnixEpochTime;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ShellCommand;
-import android.os.TimestampedValue;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -67,7 +67,7 @@
};
private final int mSlotIndex;
- @Nullable private final TimestampedValue<Long> mUnixEpochTime;
+ @Nullable private final UnixEpochTime mUnixEpochTime;
@Nullable private ArrayList<String> mDebugInfo;
private TelephonyTimeSuggestion(Builder builder) {
@@ -78,13 +78,13 @@
private static TelephonyTimeSuggestion createFromParcel(Parcel in) {
int slotIndex = in.readInt();
- TimestampedValue<Long> unixEpochTime =
- in.readParcelable(null /* classLoader */, android.os.TimestampedValue.class);
+ UnixEpochTime unixEpochTime =
+ in.readParcelable(null /* classLoader */, UnixEpochTime.class);
TelephonyTimeSuggestion suggestion = new TelephonyTimeSuggestion.Builder(slotIndex)
.setUnixEpochTime(unixEpochTime)
.build();
@SuppressWarnings("unchecked")
- ArrayList<String> debugInfo = (ArrayList<String>) in.readArrayList(
+ ArrayList<String> debugInfo = in.readArrayList(
null /* classLoader */, java.lang.String.class);
if (debugInfo != null) {
suggestion.addDebugInfo(debugInfo);
@@ -96,7 +96,7 @@
public static TelephonyTimeSuggestion parseCommandLineArg(@NonNull ShellCommand cmd)
throws IllegalArgumentException {
Integer slotIndex = null;
- Long referenceTimeMillis = null;
+ Long elapsedRealtimeMillis = null;
Long unixEpochTimeMillis = null;
String opt;
while ((opt = cmd.getNextArg()) != null) {
@@ -105,8 +105,9 @@
slotIndex = Integer.parseInt(cmd.getNextArgRequired());
break;
}
- case "--reference_time": {
- referenceTimeMillis = Long.parseLong(cmd.getNextArgRequired());
+ case "--reference_time":
+ case "--elapsed_realtime": {
+ elapsedRealtimeMillis = Long.parseLong(cmd.getNextArgRequired());
break;
}
case "--unix_epoch_time": {
@@ -122,15 +123,14 @@
if (slotIndex == null) {
throw new IllegalArgumentException("No slotIndex specified.");
}
- if (referenceTimeMillis == null) {
- throw new IllegalArgumentException("No referenceTimeMillis specified.");
+ if (elapsedRealtimeMillis == null) {
+ throw new IllegalArgumentException("No elapsedRealtimeMillis specified.");
}
if (unixEpochTimeMillis == null) {
throw new IllegalArgumentException("No unixEpochTimeMillis specified.");
}
- TimestampedValue<Long> timeSignal =
- new TimestampedValue<>(referenceTimeMillis, unixEpochTimeMillis);
+ UnixEpochTime timeSignal = new UnixEpochTime(elapsedRealtimeMillis, unixEpochTimeMillis);
Builder builder = new Builder(slotIndex)
.setUnixEpochTime(timeSignal)
.addDebugInfo("Command line injection");
@@ -141,7 +141,7 @@
public static void printCommandLineOpts(PrintWriter pw) {
pw.println("Telephony suggestion options:");
pw.println(" --slot_index <number>");
- pw.println(" --reference_time <elapsed realtime millis>");
+ pw.println(" --elapsed_realtime <elapsed realtime millis>");
pw.println(" --unix_epoch_time <Unix epoch time millis>");
pw.println();
pw.println("See " + TelephonyTimeSuggestion.class.getName() + " for more information");
@@ -174,7 +174,7 @@
* <p>See {@link TelephonyTimeSuggestion} for more information about {@code unixEpochTime}.
*/
@Nullable
- public TimestampedValue<Long> getUnixEpochTime() {
+ public UnixEpochTime getUnixEpochTime() {
return mUnixEpochTime;
}
@@ -247,7 +247,7 @@
*/
public static final class Builder {
private final int mSlotIndex;
- @Nullable private TimestampedValue<Long> mUnixEpochTime;
+ @Nullable private UnixEpochTime mUnixEpochTime;
@Nullable private List<String> mDebugInfo;
/**
@@ -265,12 +265,7 @@
* <p>See {@link TelephonyTimeSuggestion} for more information about {@code unixEpochTime}.
*/
@NonNull
- public Builder setUnixEpochTime(@Nullable TimestampedValue<Long> unixEpochTime) {
- if (unixEpochTime != null) {
- // unixEpochTime can be null, but the value it holds cannot.
- Objects.requireNonNull(unixEpochTime.getValue());
- }
-
+ public Builder setUnixEpochTime(@Nullable UnixEpochTime unixEpochTime) {
mUnixEpochTime = unixEpochTime;
return this;
}
diff --git a/core/java/android/app/timedetector/TimeDetector.java b/core/java/android/app/timedetector/TimeDetector.java
index 9d996ad..f95d6d3 100644
--- a/core/java/android/app/timedetector/TimeDetector.java
+++ b/core/java/android/app/timedetector/TimeDetector.java
@@ -19,9 +19,9 @@
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
+import android.app.time.UnixEpochTime;
import android.content.Context;
import android.os.SystemClock;
-import android.os.TimestampedValue;
/**
* The interface through which system components can query and send signals to the
@@ -108,9 +108,8 @@
* @hide
*/
static ManualTimeSuggestion createManualTimeSuggestion(long when, String why) {
- TimestampedValue<Long> utcTime =
- new TimestampedValue<>(SystemClock.elapsedRealtime(), when);
- ManualTimeSuggestion manualTimeSuggestion = new ManualTimeSuggestion(utcTime);
+ UnixEpochTime unixEpochTime = new UnixEpochTime(SystemClock.elapsedRealtime(), when);
+ ManualTimeSuggestion manualTimeSuggestion = new ManualTimeSuggestion(unixEpochTime);
manualTimeSuggestion.addDebugInfo(why);
return manualTimeSuggestion;
}
diff --git a/core/java/android/app/timedetector/TimeSuggestionHelper.java b/core/java/android/app/timedetector/TimeSuggestionHelper.java
index e89839c..67dc6b8 100644
--- a/core/java/android/app/timedetector/TimeSuggestionHelper.java
+++ b/core/java/android/app/timedetector/TimeSuggestionHelper.java
@@ -18,9 +18,9 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.app.time.UnixEpochTime;
import android.os.Parcel;
import android.os.ShellCommand;
-import android.os.TimestampedValue;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -51,20 +51,19 @@
public final class TimeSuggestionHelper {
@NonNull private final Class<?> mHelpedClass;
- @NonNull private final TimestampedValue<Long> mUnixEpochTime;
+ @NonNull private final UnixEpochTime mUnixEpochTime;
@Nullable private ArrayList<String> mDebugInfo;
/** Creates a helper for the specified class, containing the supplied properties. */
public TimeSuggestionHelper(@NonNull Class<?> helpedClass,
- @NonNull TimestampedValue<Long> unixEpochTime) {
+ @NonNull UnixEpochTime unixEpochTime) {
mHelpedClass = Objects.requireNonNull(helpedClass);
mUnixEpochTime = Objects.requireNonNull(unixEpochTime);
- Objects.requireNonNull(unixEpochTime.getValue());
}
/** See {@link TimeSuggestionHelper} for property details. */
@NonNull
- public TimestampedValue<Long> getUnixEpochTime() {
+ public UnixEpochTime getUnixEpochTime() {
return mUnixEpochTime;
}
@@ -146,8 +145,8 @@
public static TimeSuggestionHelper handleCreateFromParcel(@NonNull Class<?> helpedClass,
@NonNull Parcel in) {
@SuppressWarnings("unchecked")
- TimestampedValue<Long> unixEpochTime = in.readParcelable(
- null /* classLoader */, TimestampedValue.class);
+ UnixEpochTime unixEpochTime =
+ in.readParcelable(null /* classLoader */, UnixEpochTime.class);
TimeSuggestionHelper suggestionHelper =
new TimeSuggestionHelper(helpedClass, unixEpochTime);
suggestionHelper.mDebugInfo = in.readArrayList(null /* classLoader */, String.class);
@@ -164,13 +163,14 @@
public static TimeSuggestionHelper handleParseCommandLineArg(
@NonNull Class<?> helpedClass, @NonNull ShellCommand cmd)
throws IllegalArgumentException {
- Long referenceTimeMillis = null;
+ Long elapsedRealtimeMillis = null;
Long unixEpochTimeMillis = null;
String opt;
while ((opt = cmd.getNextArg()) != null) {
switch (opt) {
- case "--reference_time": {
- referenceTimeMillis = Long.parseLong(cmd.getNextArgRequired());
+ case "--reference_time":
+ case "--elapsed_realtime": {
+ elapsedRealtimeMillis = Long.parseLong(cmd.getNextArgRequired());
break;
}
case "--unix_epoch_time": {
@@ -183,15 +183,14 @@
}
}
- if (referenceTimeMillis == null) {
+ if (elapsedRealtimeMillis == null) {
throw new IllegalArgumentException("No referenceTimeMillis specified.");
}
if (unixEpochTimeMillis == null) {
throw new IllegalArgumentException("No unixEpochTimeMillis specified.");
}
- TimestampedValue<Long> timeSignal =
- new TimestampedValue<>(referenceTimeMillis, unixEpochTimeMillis);
+ UnixEpochTime timeSignal = new UnixEpochTime(elapsedRealtimeMillis, unixEpochTimeMillis);
TimeSuggestionHelper suggestionHelper = new TimeSuggestionHelper(helpedClass, timeSignal);
suggestionHelper.addDebugInfo("Command line injection");
return suggestionHelper;
@@ -201,8 +200,8 @@
public static void handlePrintCommandLineOpts(
@NonNull PrintWriter pw, @NonNull String typeName, @NonNull Class<?> clazz) {
pw.printf("%s suggestion options:\n", typeName);
- pw.println(" --reference_time <elapsed realtime millis> - the elapsed realtime millis when"
- + " unix epoch time was read");
+ pw.println(" --elapsed_realtime <elapsed realtime millis> - the elapsed realtime millis"
+ + " when unix epoch time was read");
pw.println(" --unix_epoch_time <Unix epoch time millis>");
pw.println();
pw.println("See " + clazz.getName() + " for more information");
diff --git a/core/tests/coretests/src/android/app/time/ExternalTimeSuggestionTest.java b/core/tests/coretests/src/android/app/time/ExternalTimeSuggestionTest.java
index 90b3305..92149eb 100644
--- a/core/tests/coretests/src/android/app/time/ExternalTimeSuggestionTest.java
+++ b/core/tests/coretests/src/android/app/time/ExternalTimeSuggestionTest.java
@@ -40,14 +40,14 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_noUnixEpochTime() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321");
+ "--elapsed_realtime 54321");
ExternalTimeSuggestion.parseCommandLineArg(testShellCommand);
}
@Test
public void testParseCommandLineArg_validSuggestion() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --unix_epoch_time 12345");
+ "--elapsed_realtime 54321 --unix_epoch_time 12345");
ExternalTimeSuggestion expectedSuggestion = new ExternalTimeSuggestion(54321L, 12345L);
ExternalTimeSuggestion actualSuggestion =
ExternalTimeSuggestion.parseCommandLineArg(testShellCommand);
@@ -57,7 +57,7 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_unknownArgument() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --unix_epoch_time 12345 --bad_arg 0");
+ "--elapsed_realtime 54321 --unix_epoch_time 12345 --bad_arg 0");
ExternalTimeSuggestion.parseCommandLineArg(testShellCommand);
}
}
diff --git a/core/tests/coretests/src/android/app/timedetector/ManualTimeSuggestionTest.java b/core/tests/coretests/src/android/app/timedetector/ManualTimeSuggestionTest.java
index 94218cd..0c7c8c1 100644
--- a/core/tests/coretests/src/android/app/timedetector/ManualTimeSuggestionTest.java
+++ b/core/tests/coretests/src/android/app/timedetector/ManualTimeSuggestionTest.java
@@ -23,15 +23,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import android.app.time.UnixEpochTime;
import android.os.ShellCommand;
-import android.os.TimestampedValue;
import org.junit.Test;
public class ManualTimeSuggestionTest {
- private static final TimestampedValue<Long> ARBITRARY_TIME =
- new TimestampedValue<>(1111L, 2222L);
+ private static final UnixEpochTime ARBITRARY_TIME = new UnixEpochTime(1111L, 2222L);
@Test
public void testEquals() {
@@ -42,9 +41,9 @@
assertEquals(one, two);
assertEquals(two, one);
- TimestampedValue<Long> differentTime = new TimestampedValue<>(
- ARBITRARY_TIME.getReferenceTimeMillis() + 1,
- ARBITRARY_TIME.getValue());
+ UnixEpochTime differentTime = new UnixEpochTime(
+ ARBITRARY_TIME.getElapsedRealtimeMillis() + 1,
+ ARBITRARY_TIME.getUnixEpochTimeMillis());
ManualTimeSuggestion three = new ManualTimeSuggestion(differentTime);
assertNotEquals(one, three);
assertNotEquals(three, one);
@@ -76,15 +75,15 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_noUnixEpochTime() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321");
+ "--elapsed_realtime 54321");
ManualTimeSuggestion.parseCommandLineArg(testShellCommand);
}
@Test
public void testParseCommandLineArg_validSuggestion() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --unix_epoch_time 12345");
- TimestampedValue<Long> timeSignal = new TimestampedValue<>(54321L, 12345L);
+ "--elapsed_realtime 54321 --unix_epoch_time 12345");
+ UnixEpochTime timeSignal = new UnixEpochTime(54321L, 12345L);
ManualTimeSuggestion expectedSuggestion = new ManualTimeSuggestion(timeSignal);
ManualTimeSuggestion actualSuggestion =
ManualTimeSuggestion.parseCommandLineArg(testShellCommand);
@@ -94,7 +93,7 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_unknownArgument() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --unix_epoch_time 12345 --bad_arg 0");
+ "--elapsed_realtime 54321 --unix_epoch_time 12345 --bad_arg 0");
ManualTimeSuggestion.parseCommandLineArg(testShellCommand);
}
}
diff --git a/core/tests/coretests/src/android/app/timedetector/TelephonyTimeSuggestionTest.java b/core/tests/coretests/src/android/app/timedetector/TelephonyTimeSuggestionTest.java
index bb995a8..26cb902 100644
--- a/core/tests/coretests/src/android/app/timedetector/TelephonyTimeSuggestionTest.java
+++ b/core/tests/coretests/src/android/app/timedetector/TelephonyTimeSuggestionTest.java
@@ -23,8 +23,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import android.app.time.UnixEpochTime;
import android.os.ShellCommand;
-import android.os.TimestampedValue;
import org.junit.Test;
@@ -47,13 +47,13 @@
assertEquals(two, one);
}
- builder1.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L));
+ builder1.setUnixEpochTime(new UnixEpochTime(1111L, 2222L));
{
TelephonyTimeSuggestion one = builder1.build();
assertEquals(one, one);
}
- builder2.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L));
+ builder2.setUnixEpochTime(new UnixEpochTime(1111L, 2222L));
{
TelephonyTimeSuggestion one = builder1.build();
TelephonyTimeSuggestion two = builder2.build();
@@ -63,7 +63,7 @@
TelephonyTimeSuggestion.Builder builder3 =
new TelephonyTimeSuggestion.Builder(SLOT_INDEX + 1);
- builder3.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L));
+ builder3.setUnixEpochTime(new UnixEpochTime(1111L, 2222L));
{
TelephonyTimeSuggestion one = builder1.build();
TelephonyTimeSuggestion three = builder3.build();
@@ -86,7 +86,7 @@
TelephonyTimeSuggestion.Builder builder = new TelephonyTimeSuggestion.Builder(SLOT_INDEX);
assertRoundTripParcelable(builder.build());
- builder.setUnixEpochTime(new TimestampedValue<>(1111L, 2222L));
+ builder.setUnixEpochTime(new UnixEpochTime(1111L, 2222L));
assertRoundTripParcelable(builder.build());
// DebugInfo should also be stored (but is not checked by equals()
@@ -101,7 +101,7 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_noSlotIndex() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --unix_epoch_time 12345");
+ "--elapsed_realtime 54321 --unix_epoch_time 12345");
TelephonyTimeSuggestion.parseCommandLineArg(testShellCommand);
}
@@ -115,17 +115,17 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_noUnixEpochTime() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--slot_index 0 --reference_time 54321");
+ "--slot_index 0 --elapsed_realtime 54321");
TelephonyTimeSuggestion.parseCommandLineArg(testShellCommand);
}
@Test
public void testParseCommandLineArg_validSuggestion() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--slot_index 0 --reference_time 54321 --unix_epoch_time 12345");
+ "--slot_index 0 --elapsed_realtime 54321 --unix_epoch_time 12345");
TelephonyTimeSuggestion expectedSuggestion =
new TelephonyTimeSuggestion.Builder(0)
- .setUnixEpochTime(new TimestampedValue<>(54321L, 12345L))
+ .setUnixEpochTime(new UnixEpochTime(54321L, 12345L))
.build();
TelephonyTimeSuggestion actualSuggestion =
TelephonyTimeSuggestion.parseCommandLineArg(testShellCommand);
@@ -135,7 +135,7 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_unknownArgument() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--slot_index 0 --reference_time 54321 --unix_epoch_time 12345 --bad_arg 0");
+ "--slot_index 0 --elapsed_realtime 54321 --unix_epoch_time 12345 --bad_arg 0");
TelephonyTimeSuggestion.parseCommandLineArg(testShellCommand);
}
}
diff --git a/services/core/java/com/android/server/timedetector/GnssTimeSuggestion.java b/services/core/java/com/android/server/timedetector/GnssTimeSuggestion.java
index 3349975..a7b1e23 100644
--- a/services/core/java/com/android/server/timedetector/GnssTimeSuggestion.java
+++ b/services/core/java/com/android/server/timedetector/GnssTimeSuggestion.java
@@ -17,9 +17,9 @@
package com.android.server.timedetector;
import android.annotation.NonNull;
+import android.app.time.UnixEpochTime;
import android.app.timedetector.TimeSuggestionHelper;
import android.os.ShellCommand;
-import android.os.TimestampedValue;
import java.io.PrintWriter;
import java.util.List;
@@ -34,7 +34,7 @@
@NonNull private final TimeSuggestionHelper mTimeSuggestionHelper;
- public GnssTimeSuggestion(@NonNull TimestampedValue<Long> unixEpochTime) {
+ public GnssTimeSuggestion(@NonNull UnixEpochTime unixEpochTime) {
mTimeSuggestionHelper = new TimeSuggestionHelper(GnssTimeSuggestion.class, unixEpochTime);
}
@@ -43,7 +43,7 @@
}
@NonNull
- public TimestampedValue<Long> getUnixEpochTime() {
+ public UnixEpochTime getUnixEpochTime() {
return mTimeSuggestionHelper.getUnixEpochTime();
}
diff --git a/services/core/java/com/android/server/timedetector/GnssTimeUpdateService.java b/services/core/java/com/android/server/timedetector/GnssTimeUpdateService.java
index 421f7ce..fef7148 100644
--- a/services/core/java/com/android/server/timedetector/GnssTimeUpdateService.java
+++ b/services/core/java/com/android/server/timedetector/GnssTimeUpdateService.java
@@ -20,6 +20,7 @@
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.app.AlarmManager;
+import android.app.time.UnixEpochTime;
import android.content.Context;
import android.location.LocationListener;
import android.location.LocationManager;
@@ -31,7 +32,6 @@
import android.os.ResultReceiver;
import android.os.ShellCallback;
import android.os.SystemClock;
-import android.os.TimestampedValue;
import android.util.LocalLog;
import android.util.Log;
@@ -122,7 +122,7 @@
@GuardedBy("mLock") @Nullable private AlarmManager.OnAlarmListener mAlarmListener;
@GuardedBy("mLock") @Nullable private LocationListener mLocationListener;
- @Nullable private volatile TimestampedValue<Long> mLastSuggestedGnssTime;
+ @Nullable private volatile UnixEpochTime mLastSuggestedGnssTime;
@VisibleForTesting
GnssTimeUpdateService(@NonNull Context context, @NonNull AlarmManager alarmManager,
@@ -263,8 +263,7 @@
long gnssUnixEpochTimeMillis = locationTime.getUnixEpochTimeMillis();
long elapsedRealtimeMs = locationTime.getElapsedRealtimeNanos() / 1_000_000L;
- TimestampedValue<Long> timeSignal =
- new TimestampedValue<>(elapsedRealtimeMs, gnssUnixEpochTimeMillis);
+ UnixEpochTime timeSignal = new UnixEpochTime(elapsedRealtimeMs, gnssUnixEpochTimeMillis);
mLastSuggestedGnssTime = timeSignal;
GnssTimeSuggestion timeSuggestion = new GnssTimeSuggestion(timeSignal);
diff --git a/services/core/java/com/android/server/timedetector/NetworkTimeSuggestion.java b/services/core/java/com/android/server/timedetector/NetworkTimeSuggestion.java
index f62c7ed..71c5d428 100644
--- a/services/core/java/com/android/server/timedetector/NetworkTimeSuggestion.java
+++ b/services/core/java/com/android/server/timedetector/NetworkTimeSuggestion.java
@@ -18,8 +18,8 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.app.time.UnixEpochTime;
import android.os.ShellCommand;
-import android.os.TimestampedValue;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -48,7 +48,7 @@
*/
public final class NetworkTimeSuggestion {
- @NonNull private final TimestampedValue<Long> mUnixEpochTime;
+ @NonNull private final UnixEpochTime mUnixEpochTime;
private final int mUncertaintyMillis;
@Nullable private ArrayList<String> mDebugInfo;
@@ -57,8 +57,7 @@
*
* <p>See {@link NetworkTimeSuggestion} for property details.
*/
- public NetworkTimeSuggestion(
- @NonNull TimestampedValue<Long> unixEpochTime, int uncertaintyMillis) {
+ public NetworkTimeSuggestion(@NonNull UnixEpochTime unixEpochTime, int uncertaintyMillis) {
mUnixEpochTime = Objects.requireNonNull(unixEpochTime);
if (uncertaintyMillis < 0) {
throw new IllegalArgumentException("uncertaintyMillis < 0");
@@ -68,7 +67,7 @@
/** See {@link NetworkTimeSuggestion} for property details. */
@NonNull
- public TimestampedValue<Long> getUnixEpochTime() {
+ public UnixEpochTime getUnixEpochTime() {
return mUnixEpochTime;
}
@@ -126,14 +125,15 @@
/** Parses command line args to create a {@link NetworkTimeSuggestion}. */
public static NetworkTimeSuggestion parseCommandLineArg(@NonNull ShellCommand cmd)
throws IllegalArgumentException {
- Long referenceTimeMillis = null;
+ Long elapsedRealtimeMillis = null;
Long unixEpochTimeMillis = null;
Integer uncertaintyMillis = null;
String opt;
while ((opt = cmd.getNextArg()) != null) {
switch (opt) {
- case "--reference_time": {
- referenceTimeMillis = Long.parseLong(cmd.getNextArgRequired());
+ case "--reference_time":
+ case "--elapsed_realtime": {
+ elapsedRealtimeMillis = Long.parseLong(cmd.getNextArgRequired());
break;
}
case "--unix_epoch_time": {
@@ -150,8 +150,8 @@
}
}
- if (referenceTimeMillis == null) {
- throw new IllegalArgumentException("No referenceTimeMillis specified.");
+ if (elapsedRealtimeMillis == null) {
+ throw new IllegalArgumentException("No elapsedRealtimeMillis specified.");
}
if (unixEpochTimeMillis == null) {
throw new IllegalArgumentException("No unixEpochTimeMillis specified.");
@@ -160,8 +160,7 @@
throw new IllegalArgumentException("No uncertaintyMillis specified.");
}
- TimestampedValue<Long> timeSignal =
- new TimestampedValue<>(referenceTimeMillis, unixEpochTimeMillis);
+ UnixEpochTime timeSignal = new UnixEpochTime(elapsedRealtimeMillis, unixEpochTimeMillis);
NetworkTimeSuggestion networkTimeSuggestion =
new NetworkTimeSuggestion(timeSignal, uncertaintyMillis);
networkTimeSuggestion.addDebugInfo("Command line injection");
@@ -171,8 +170,8 @@
/** Prints the command line args needed to create a {@link NetworkTimeSuggestion}. */
public static void printCommandLineOpts(PrintWriter pw) {
pw.printf("%s suggestion options:\n", "Network");
- pw.println(" --reference_time <elapsed realtime millis> - the elapsed realtime millis when"
- + " unix epoch time was read");
+ pw.println(" --elapsed_realtime <elapsed realtime millis> - the elapsed realtime millis"
+ + " when unix epoch time was read");
pw.println(" --unix_epoch_time <Unix epoch time millis>");
pw.println(" --uncertainty_millis <Uncertainty millis> - a positive error bound (+/-)"
+ " estimate for unix epoch time");
diff --git a/services/core/java/com/android/server/timedetector/NetworkTimeUpdateService.java b/services/core/java/com/android/server/timedetector/NetworkTimeUpdateService.java
index 59c118d..4803011 100644
--- a/services/core/java/com/android/server/timedetector/NetworkTimeUpdateService.java
+++ b/services/core/java/com/android/server/timedetector/NetworkTimeUpdateService.java
@@ -20,6 +20,7 @@
import android.annotation.Nullable;
import android.app.AlarmManager;
import android.app.PendingIntent;
+import android.app.time.UnixEpochTime;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
@@ -38,7 +39,6 @@
import android.os.ResultReceiver;
import android.os.ShellCallback;
import android.os.SystemClock;
-import android.os.TimestampedValue;
import android.provider.Settings;
import android.util.LocalLog;
import android.util.Log;
@@ -278,7 +278,7 @@
/** Suggests the time to the time detector. It may choose use it to set the system clock. */
private void makeNetworkTimeSuggestion(
@NonNull TimeResult ntpResult, @NonNull String debugInfo) {
- TimestampedValue<Long> timeSignal = new TimestampedValue<>(
+ UnixEpochTime timeSignal = new UnixEpochTime(
ntpResult.getElapsedRealtimeMillis(), ntpResult.getTimeMillis());
NetworkTimeSuggestion timeSuggestion =
new NetworkTimeSuggestion(timeSignal, ntpResult.getUncertaintyMillis());
diff --git a/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java b/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java
index ac2a391..bc86ed0 100644
--- a/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java
+++ b/services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java
@@ -24,7 +24,6 @@
import android.app.time.UnixEpochTime;
import android.app.timedetector.ManualTimeSuggestion;
import android.app.timedetector.TelephonyTimeSuggestion;
-import android.os.TimestampedValue;
import android.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
@@ -109,15 +108,6 @@
// Utility methods below are to be moved to a better home when one becomes more obvious.
/**
- * Adjusts the supplied time value by applying the difference between the reference time
- * supplied and the reference time associated with the time.
- */
- static long getTimeAt(@NonNull TimestampedValue<Long> timeValue, long referenceClockMillisNow) {
- return (referenceClockMillisNow - timeValue.getReferenceTimeMillis())
- + timeValue.getValue();
- }
-
- /**
* Converts one of the {@code ORIGIN_} constants to a human readable string suitable for config
* and debug usage. Throws an {@link IllegalArgumentException} if the value is unrecognized.
*/
diff --git a/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java b/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java
index 3235bf0..510896d 100644
--- a/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java
+++ b/services/core/java/com/android/server/timedetector/TimeDetectorStrategyImpl.java
@@ -32,7 +32,6 @@
import android.app.timedetector.TelephonyTimeSuggestion;
import android.content.Context;
import android.os.Handler;
-import android.os.TimestampedValue;
import android.util.IndentingPrintWriter;
import android.util.Slog;
@@ -99,7 +98,7 @@
// going through this strategy code.
@GuardedBy("this")
@Nullable
- private TimestampedValue<Long> mLastAutoSystemClockTimeSet;
+ private UnixEpochTime mLastAutoSystemClockTimeSet;
/**
* A mapping from slotIndex to a time suggestion. We typically expect one or two mappings:
@@ -209,7 +208,7 @@
}
Objects.requireNonNull(suggestion);
- final TimestampedValue<Long> newUnixEpochTime = suggestion.getUnixEpochTime();
+ final UnixEpochTime newUnixEpochTime = suggestion.getUnixEpochTime();
if (!validateAutoSuggestionTime(newUnixEpochTime, suggestion)) {
return;
@@ -231,7 +230,7 @@
}
Objects.requireNonNull(suggestion);
- final TimestampedValue<Long> newUnixEpochTime = suggestion.getUnixEpochTime();
+ final UnixEpochTime newUnixEpochTime = suggestion.getUnixEpochTime();
if (!validateAutoSuggestionTime(newUnixEpochTime, suggestion)) {
return;
@@ -258,7 +257,7 @@
Objects.requireNonNull(suggestion);
- final TimestampedValue<Long> newUnixEpochTime = suggestion.getUnixEpochTime();
+ final UnixEpochTime newUnixEpochTime = suggestion.getUnixEpochTime();
if (!validateManualSuggestionTime(newUnixEpochTime, suggestion)) {
return false;
@@ -321,7 +320,7 @@
@Origin int origin = ORIGIN_MANUAL;
UnixEpochTime unixEpochTime = timeState.getUnixEpochTime();
setSystemClockAndConfidenceUnderWakeLock(
- origin, unixEpochTime.toTimestampedValue(), confidence, "setTimeZoneState()");
+ origin, unixEpochTime, confidence, "setTimeZoneState()");
} finally {
mEnvironment.releaseWakeLock();
}
@@ -473,14 +472,13 @@
@GuardedBy("this")
private boolean storeTelephonySuggestion(
@NonNull TelephonyTimeSuggestion suggestion) {
- TimestampedValue<Long> newUnixEpochTime = suggestion.getUnixEpochTime();
+ UnixEpochTime 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.getUnixEpochTime() == null
- || previousSuggestion.getUnixEpochTime().getValue() == null) {
+ // We can log / discard suggestions with obvious issues with the elapsed realtime clock.
+ if (previousSuggestion.getUnixEpochTime() == 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
@@ -488,10 +486,10 @@
return false;
}
- long referenceTimeDifference = TimestampedValue.referenceTimeDifference(
+ long referenceTimeDifference = UnixEpochTime.elapsedRealtimeDifference(
newUnixEpochTime, previousSuggestion.getUnixEpochTime());
if (referenceTimeDifference < 0) {
- // The reference time is before the previously received suggestion. Ignore it.
+ // The elapsed realtime is before the previously received suggestion. Ignore it.
Slog.w(LOG_TAG, "Out of order telephony suggestion received."
+ " referenceTimeDifference=" + referenceTimeDifference
+ " previousSuggestion=" + previousSuggestion
@@ -507,23 +505,18 @@
@GuardedBy("this")
private boolean validateSuggestionCommon(
- @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.
+ @NonNull UnixEpochTime newUnixEpochTime, @NonNull Object suggestion) {
+ // We can validate the suggestion against the elapsed realtime clock.
long elapsedRealtimeMillis = mEnvironment.elapsedRealtimeMillis();
- if (elapsedRealtimeMillis < newUnixEpochTime.getReferenceTimeMillis()) {
+ if (elapsedRealtimeMillis < newUnixEpochTime.getElapsedRealtimeMillis()) {
// elapsedRealtime clock went backwards?
- Slog.w(LOG_TAG, "New reference time is in the future? Ignoring."
+ Slog.w(LOG_TAG, "New elapsed realtime is in the future? Ignoring."
+ " elapsedRealtimeMillis=" + elapsedRealtimeMillis
+ ", suggestion=" + suggestion);
return false;
}
- if (newUnixEpochTime.getValue()
+ if (newUnixEpochTime.getUnixEpochTimeMillis()
> mCurrentConfigurationInternal.getSuggestionUpperBound().toEpochMilli()) {
// This check won't prevent a device's system clock exceeding Integer.MAX_VALUE Unix
// seconds through the normal passage of time, but it will stop it jumping above 2038
@@ -537,11 +530,11 @@
/**
* Returns {@code true} if an automatic time suggestion time is valid.
- * See also {@link #validateManualSuggestionTime(TimestampedValue, Object)}.
+ * See also {@link #validateManualSuggestionTime(UnixEpochTime, Object)}.
*/
@GuardedBy("this")
private boolean validateAutoSuggestionTime(
- @NonNull TimestampedValue<Long> newUnixEpochTime, @NonNull Object suggestion) {
+ @NonNull UnixEpochTime newUnixEpochTime, @NonNull Object suggestion) {
Instant lowerBound = mCurrentConfigurationInternal.getAutoSuggestionLowerBound();
return validateSuggestionCommon(newUnixEpochTime, suggestion)
&& validateSuggestionAgainstLowerBound(newUnixEpochTime, suggestion,
@@ -550,11 +543,11 @@
/**
* Returns {@code true} if a manual time suggestion time is valid.
- * See also {@link #validateAutoSuggestionTime(TimestampedValue, Object)}.
+ * See also {@link #validateAutoSuggestionTime(UnixEpochTime, Object)}.
*/
@GuardedBy("this")
private boolean validateManualSuggestionTime(
- @NonNull TimestampedValue<Long> newUnixEpochTime, @NonNull Object suggestion) {
+ @NonNull UnixEpochTime newUnixEpochTime, @NonNull Object suggestion) {
Instant lowerBound = mCurrentConfigurationInternal.getManualSuggestionLowerBound();
// Suggestion is definitely wrong if it comes before lower time bound.
@@ -564,11 +557,11 @@
@GuardedBy("this")
private boolean validateSuggestionAgainstLowerBound(
- @NonNull TimestampedValue<Long> newUnixEpochTime, @NonNull Object suggestion,
+ @NonNull UnixEpochTime newUnixEpochTime, @NonNull Object suggestion,
@NonNull Instant lowerBound) {
// Suggestion is definitely wrong if it comes before lower time bound.
- if (lowerBound.toEpochMilli() > newUnixEpochTime.getValue()) {
+ if (lowerBound.toEpochMilli() > newUnixEpochTime.getUnixEpochTimeMillis()) {
Slog.w(LOG_TAG, "Suggestion points to time before lower bound, skipping it. "
+ "suggestion=" + suggestion + ", lower bound=" + lowerBound);
return false;
@@ -582,7 +575,7 @@
// Try the different origins one at a time.
int[] originPriorities = mCurrentConfigurationInternal.getAutoOriginPriorities();
for (int origin : originPriorities) {
- TimestampedValue<Long> newUnixEpochTime = null;
+ UnixEpochTime newUnixEpochTime = null;
String cause = null;
if (origin == ORIGIN_TELEPHONY) {
TelephonyTimeSuggestion bestTelephonySuggestion = findBestTelephonySuggestion();
@@ -670,7 +663,7 @@
// The heuristic works as follows:
// Recency: The most recent suggestion from each slotIndex is scored. The score is based on
// a discrete age bucket, i.e. so signals received around the same time will be in the same
- // bucket, thus applying a loose reference time ordering. The suggestion with the highest
+ // bucket, thus applying a loose elapsed realtime ordering. The suggestion with the highest
// score is used.
// Consistency: If there a multiple suggestions with the same score, the suggestion with the
// lowest slotIndex is always taken.
@@ -722,7 +715,7 @@
long elapsedRealtimeMillis, @NonNull TelephonyTimeSuggestion timeSuggestion) {
// Validate first.
- TimestampedValue<Long> unixEpochTime = timeSuggestion.getUnixEpochTime();
+ UnixEpochTime unixEpochTime = timeSuggestion.getUnixEpochTime();
if (!validateSuggestionUnixEpochTime(elapsedRealtimeMillis, unixEpochTime)) {
Slog.w(LOG_TAG, "Existing suggestion found to be invalid"
+ " elapsedRealtimeMillis=" + elapsedRealtimeMillis
@@ -732,7 +725,7 @@
// 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 - unixEpochTime.getReferenceTimeMillis();
+ long ageMillis = elapsedRealtimeMillis - unixEpochTime.getElapsedRealtimeMillis();
// Turn the age into a discrete value: 0 <= bucketIndex < TELEPHONY_BUCKET_COUNT.
int bucketIndex = (int) (ageMillis / TELEPHONY_BUCKET_SIZE_MILLIS);
@@ -754,7 +747,7 @@
return null;
}
- TimestampedValue<Long> unixEpochTime = networkSuggestion.getUnixEpochTime();
+ UnixEpochTime unixEpochTime = networkSuggestion.getUnixEpochTime();
long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis();
if (!validateSuggestionUnixEpochTime(elapsedRealTimeMillis, unixEpochTime)) {
// The latest suggestion is not valid, usually due to its age.
@@ -774,7 +767,7 @@
return null;
}
- TimestampedValue<Long> unixEpochTime = gnssTimeSuggestion.getUnixEpochTime();
+ UnixEpochTime unixEpochTime = gnssTimeSuggestion.getUnixEpochTime();
long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis();
if (!validateSuggestionUnixEpochTime(elapsedRealTimeMillis, unixEpochTime)) {
// The latest suggestion is not valid, usually due to its age.
@@ -794,7 +787,7 @@
return null;
}
- TimestampedValue<Long> unixEpochTime = externalTimeSuggestion.getUnixEpochTime();
+ UnixEpochTime unixEpochTime = externalTimeSuggestion.getUnixEpochTime();
long elapsedRealTimeMillis = mEnvironment.elapsedRealtimeMillis();
if (!validateSuggestionUnixEpochTime(elapsedRealTimeMillis, unixEpochTime)) {
// The latest suggestion is not valid, usually due to its age.
@@ -806,7 +799,7 @@
@GuardedBy("this")
private boolean setSystemClockAndConfidenceIfRequired(
- @Origin int origin, @NonNull TimestampedValue<Long> time, @NonNull String cause) {
+ @Origin int origin, @NonNull UnixEpochTime time, @NonNull String cause) {
// Any time set through this class is inherently high confidence. Either it came directly
// from a user, or it was detected automatically.
@@ -851,7 +844,7 @@
*/
@GuardedBy("this")
private void upgradeSystemClockConfidenceIfRequired(
- @NonNull TimestampedValue<Long> autoDetectedUnixEpochTime, @NonNull String cause) {
+ @NonNull UnixEpochTime autoDetectedUnixEpochTime, @NonNull String cause) {
@TimeConfidence int newTimeConfidence = TIME_CONFIDENCE_HIGH;
@TimeConfidence int currentTimeConfidence = mEnvironment.systemClockConfidence();
boolean timeNeedsConfirmation = currentTimeConfidence < newTimeConfidence;
@@ -866,8 +859,8 @@
// enough) to raise the confidence.
long elapsedRealtimeMillis = mEnvironment.elapsedRealtimeMillis();
long actualSystemClockMillis = mEnvironment.systemClockMillis();
- long adjustedAutoDetectedUnixEpochMillis = TimeDetectorStrategy.getTimeAt(
- autoDetectedUnixEpochTime, elapsedRealtimeMillis);
+ long adjustedAutoDetectedUnixEpochMillis =
+ autoDetectedUnixEpochTime.at(elapsedRealtimeMillis).getUnixEpochTimeMillis();
long absTimeDifferenceMillis =
Math.abs(adjustedAutoDetectedUnixEpochMillis - actualSystemClockMillis);
int confidenceUpgradeThresholdMillis =
@@ -899,7 +892,7 @@
@GuardedBy("this")
private boolean setSystemClockAndConfidenceUnderWakeLock(
- @Origin int origin, @NonNull TimestampedValue<Long> newTime,
+ @Origin int origin, @NonNull UnixEpochTime newTime,
@TimeConfidence int newTimeConfidence, @NonNull String cause) {
long elapsedRealtimeMillis = mEnvironment.elapsedRealtimeMillis();
@@ -909,8 +902,8 @@
// CLOCK_PARANOIA : Check to see if this class owns the clock or if something else
// may be setting the clock.
if (mLastAutoSystemClockTimeSet != null) {
- long expectedTimeMillis = TimeDetectorStrategy.getTimeAt(
- mLastAutoSystemClockTimeSet, elapsedRealtimeMillis);
+ long expectedTimeMillis = mLastAutoSystemClockTimeSet.at(elapsedRealtimeMillis)
+ .getUnixEpochTimeMillis();
long absSystemClockDifference =
Math.abs(expectedTimeMillis - actualSystemClockMillis);
if (absSystemClockDifference > SYSTEM_CLOCK_PARANOIA_THRESHOLD_MILLIS) {
@@ -931,7 +924,7 @@
// in confidence then system state must be updated.
// Adjust for the time that has elapsed since the signal was received.
- long newSystemClockMillis = TimeDetectorStrategy.getTimeAt(newTime, elapsedRealtimeMillis);
+ long newSystemClockMillis = newTime.at(elapsedRealtimeMillis).getUnixEpochTimeMillis();
long absTimeDifference = Math.abs(newSystemClockMillis - actualSystemClockMillis);
long systemClockUpdateThreshold =
mCurrentConfigurationInternal.getSystemClockUpdateThresholdMillis();
@@ -1073,21 +1066,21 @@
}
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
+ long currentElapsedRealtimeMillis, UnixEpochTime unixEpochTime) {
+ long suggestionElapsedRealtimeMillis = unixEpochTime.getElapsedRealtimeMillis();
+ if (suggestionElapsedRealtimeMillis > currentElapsedRealtimeMillis) {
+ // Future elapsed realtimes are ignored. They imply the elapsed realtime was wrong, or
+ // the elapsed realtime clock used to derive it has gone backwards, neither of which are
// supportable situations.
return false;
}
// Any suggestion > MAX_AGE_MILLIS is treated as too old. Although time is relentless and
- // predictable, the accuracy of the reference time clock may be poor over long periods which
- // would lead to errors creeping in. Also, in edge cases where a bad suggestion has been
- // made and never replaced, it could also mean that the time detection code remains
+ // predictable, the accuracy of the elapsed realtime clock may be poor over long periods
+ // which would lead to errors creeping in. Also, in edge cases where a bad suggestion has
+ // been 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;
+ long ageMillis = currentElapsedRealtimeMillis - suggestionElapsedRealtimeMillis;
return ageMillis <= MAX_SUGGESTION_TIME_AGE_MILLIS;
}
}
diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java
index 85986dd..1e88c47 100644
--- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java
+++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java
@@ -216,8 +216,8 @@
*
* <p>This field is only actually used when telephony time zone fallback is supported, but the
* value is maintained even when it isn't supported as it can be turned on at any time via
- * server flags. The reference time is the elapsed realtime when the mode last changed to help
- * ordering between fallback mode switches and suggestions.
+ * server flags. The elapsed realtime when the mode last changed is used to help ordering
+ * between fallback mode switches and suggestions.
*
* <p>See {@link TimeZoneDetectorStrategy} for more information.
*/
diff --git a/services/tests/servicestests/src/com/android/server/timedetector/GnssTimeSuggestionTest.java b/services/tests/servicestests/src/com/android/server/timedetector/GnssTimeSuggestionTest.java
index f25d94e..57d5469 100644
--- a/services/tests/servicestests/src/com/android/server/timedetector/GnssTimeSuggestionTest.java
+++ b/services/tests/servicestests/src/com/android/server/timedetector/GnssTimeSuggestionTest.java
@@ -21,15 +21,15 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import android.app.time.UnixEpochTime;
import android.os.ShellCommand;
-import android.os.TimestampedValue;
import org.junit.Test;
public class GnssTimeSuggestionTest {
- private static final TimestampedValue<Long> ARBITRARY_TIME =
- new TimestampedValue<>(1111L, 2222L);
+ private static final UnixEpochTime ARBITRARY_TIME =
+ new UnixEpochTime(1111L, 2222L);
@Test
public void testEquals() {
@@ -40,9 +40,9 @@
assertEquals(one, two);
assertEquals(two, one);
- TimestampedValue<Long> differentTime = new TimestampedValue<>(
- ARBITRARY_TIME.getReferenceTimeMillis() + 1,
- ARBITRARY_TIME.getValue());
+ UnixEpochTime differentTime = new UnixEpochTime(
+ ARBITRARY_TIME.getElapsedRealtimeMillis() + 1,
+ ARBITRARY_TIME.getUnixEpochTimeMillis());
GnssTimeSuggestion three = new GnssTimeSuggestion(differentTime);
assertNotEquals(one, three);
assertNotEquals(three, one);
@@ -63,15 +63,15 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_noUnixEpochTime() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321");
+ "--elapsed_realtime 54321");
GnssTimeSuggestion.parseCommandLineArg(testShellCommand);
}
@Test
public void testParseCommandLineArg_validSuggestion() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --unix_epoch_time 12345");
- TimestampedValue<Long> timeSignal = new TimestampedValue<>(54321L, 12345L);
+ "--elapsed_realtime 54321 --unix_epoch_time 12345");
+ UnixEpochTime timeSignal = new UnixEpochTime(54321L, 12345L);
GnssTimeSuggestion expectedSuggestion = new GnssTimeSuggestion(timeSignal);
GnssTimeSuggestion actualSuggestion =
GnssTimeSuggestion.parseCommandLineArg(testShellCommand);
@@ -81,7 +81,7 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_unknownArgument() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --unix_epoch_time 12345 --bad_arg 0");
+ "--elapsed_realtime 54321 --unix_epoch_time 12345 --bad_arg 0");
GnssTimeSuggestion.parseCommandLineArg(testShellCommand);
}
}
diff --git a/services/tests/servicestests/src/com/android/server/timedetector/GnssTimeUpdateServiceTest.java b/services/tests/servicestests/src/com/android/server/timedetector/GnssTimeUpdateServiceTest.java
index 3f550d0..c8afb78 100644
--- a/services/tests/servicestests/src/com/android/server/timedetector/GnssTimeUpdateServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/timedetector/GnssTimeUpdateServiceTest.java
@@ -28,6 +28,7 @@
import android.app.AlarmManager;
import android.app.AlarmManager.OnAlarmListener;
+import android.app.time.UnixEpochTime;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
@@ -35,7 +36,6 @@
import android.location.LocationManagerInternal;
import android.location.LocationRequest;
import android.location.LocationTime;
-import android.os.TimestampedValue;
import androidx.test.runner.AndroidJUnit4;
@@ -73,7 +73,7 @@
@Test
public void testLocationListenerOnLocationChanged_validLocationTime_suggestsGnssTime() {
- TimestampedValue<Long> timeSignal = new TimestampedValue<>(
+ UnixEpochTime timeSignal = new UnixEpochTime(
ELAPSED_REALTIME_MS, GNSS_TIME);
GnssTimeSuggestion timeSuggestion = new GnssTimeSuggestion(timeSignal);
LocationTime locationTime = new LocationTime(GNSS_TIME, ELAPSED_REALTIME_NS);
@@ -178,7 +178,7 @@
private void advanceServiceToSleepingState(
ArgumentCaptor<LocationListener> locationListenerCaptor,
ArgumentCaptor<OnAlarmListener> alarmListenerCaptor) {
- TimestampedValue<Long> timeSignal = new TimestampedValue<>(
+ UnixEpochTime timeSignal = new UnixEpochTime(
ELAPSED_REALTIME_MS, GNSS_TIME);
GnssTimeSuggestion timeSuggestion = new GnssTimeSuggestion(timeSignal);
LocationTime locationTime = new LocationTime(GNSS_TIME, ELAPSED_REALTIME_NS);
diff --git a/services/tests/servicestests/src/com/android/server/timedetector/NetworkTimeSuggestionTest.java b/services/tests/servicestests/src/com/android/server/timedetector/NetworkTimeSuggestionTest.java
index f5a37b9..fcc76d3 100644
--- a/services/tests/servicestests/src/com/android/server/timedetector/NetworkTimeSuggestionTest.java
+++ b/services/tests/servicestests/src/com/android/server/timedetector/NetworkTimeSuggestionTest.java
@@ -21,15 +21,15 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import android.app.time.UnixEpochTime;
import android.os.ShellCommand;
-import android.os.TimestampedValue;
import org.junit.Test;
public class NetworkTimeSuggestionTest {
- private static final TimestampedValue<Long> ARBITRARY_TIME =
- new TimestampedValue<>(1111L, 2222L);
+ private static final UnixEpochTime ARBITRARY_TIME =
+ new UnixEpochTime(1111L, 2222L);
private static final int ARBITRARY_UNCERTAINTY_MILLIS = 3333;
@Test
@@ -43,9 +43,9 @@
assertEquals(one, two);
assertEquals(two, one);
- TimestampedValue<Long> differentTime = new TimestampedValue<>(
- ARBITRARY_TIME.getReferenceTimeMillis() + 1,
- ARBITRARY_TIME.getValue());
+ UnixEpochTime differentTime = new UnixEpochTime(
+ ARBITRARY_TIME.getElapsedRealtimeMillis() + 1,
+ ARBITRARY_TIME.getUnixEpochTimeMillis());
NetworkTimeSuggestion three = new NetworkTimeSuggestion(
differentTime, ARBITRARY_UNCERTAINTY_MILLIS);
assertNotEquals(one, three);
@@ -73,22 +73,22 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_noUnixEpochTime() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --uncertainty_millis 111");
+ "--elapsed_realtime 54321 --uncertainty_millis 111");
NetworkTimeSuggestion.parseCommandLineArg(testShellCommand);
}
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_noUncertaintyMillis() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --unix_epoch_time 12345");
+ "--elapsed_realtime 54321 --unix_epoch_time 12345");
NetworkTimeSuggestion.parseCommandLineArg(testShellCommand);
}
@Test
public void testParseCommandLineArg_validSuggestion() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --unix_epoch_time 12345 --uncertainty_millis 111");
- TimestampedValue<Long> timeSignal = new TimestampedValue<>(54321L, 12345L);
+ "--elapsed_realtime 54321 --unix_epoch_time 12345 --uncertainty_millis 111");
+ UnixEpochTime timeSignal = new UnixEpochTime(54321L, 12345L);
NetworkTimeSuggestion expectedSuggestion = new NetworkTimeSuggestion(timeSignal, 111);
NetworkTimeSuggestion actualSuggestion =
NetworkTimeSuggestion.parseCommandLineArg(testShellCommand);
@@ -98,7 +98,7 @@
@Test(expected = IllegalArgumentException.class)
public void testParseCommandLineArg_unknownArgument() {
ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--reference_time 54321 --unix_epoch_time 12345 --bad_arg 0");
+ "--elapsed_realtime 54321 --unix_epoch_time 12345 --bad_arg 0");
NetworkTimeSuggestion.parseCommandLineArg(testShellCommand);
}
}
diff --git a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorInternalImplTest.java b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorInternalImplTest.java
index f8092a6..5b61752 100644
--- a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorInternalImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorInternalImplTest.java
@@ -18,9 +18,9 @@
import static org.mockito.Mockito.mock;
+import android.app.time.UnixEpochTime;
import android.content.Context;
import android.os.HandlerThread;
-import android.os.TimestampedValue;
import androidx.test.runner.AndroidJUnit4;
@@ -74,7 +74,7 @@
}
private static NetworkTimeSuggestion createNetworkTimeSuggestion() {
- TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L);
+ UnixEpochTime timeValue = new UnixEpochTime(100L, 1_000_000L);
return new NetworkTimeSuggestion(timeValue, 123);
}
@@ -90,7 +90,7 @@
}
private static GnssTimeSuggestion createGnssTimeSuggestion() {
- TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L);
+ UnixEpochTime timeValue = new UnixEpochTime(100L, 1_000_000L);
return new GnssTimeSuggestion(timeValue);
}
}
diff --git a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java
index 1218489..ba5f66c 100644
--- a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorServiceTest.java
@@ -49,7 +49,6 @@
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.ParcelableException;
-import android.os.TimestampedValue;
import android.util.NtpTrustedTime;
import androidx.test.runner.AndroidJUnit4;
@@ -578,24 +577,24 @@
private static TelephonyTimeSuggestion createTelephonyTimeSuggestion() {
int slotIndex = 1234;
- TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L);
+ UnixEpochTime timeValue = new UnixEpochTime(100L, 1_000_000L);
return new TelephonyTimeSuggestion.Builder(slotIndex)
.setUnixEpochTime(timeValue)
.build();
}
private static ManualTimeSuggestion createManualTimeSuggestion() {
- TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L);
+ UnixEpochTime timeValue = new UnixEpochTime(100L, 1_000_000L);
return new ManualTimeSuggestion(timeValue);
}
private static NetworkTimeSuggestion createNetworkTimeSuggestion() {
- TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L);
+ UnixEpochTime timeValue = new UnixEpochTime(100L, 1_000_000L);
return new NetworkTimeSuggestion(timeValue, 123);
}
private static GnssTimeSuggestion createGnssTimeSuggestion() {
- TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L);
+ UnixEpochTime timeValue = new UnixEpochTime(100L, 1_000_000L);
return new GnssTimeSuggestion(timeValue);
}
diff --git a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyImplTest.java b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyImplTest.java
index 9ec70dc..0863228 100644
--- a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyImplTest.java
@@ -320,7 +320,7 @@
Instant suggestionInstant = initialClockTime.getValue()
.plusMillis(timeElapsedMillis)
.plusMillis(confidenceUpgradeThresholdMillis);
- TimestampedValue<Long> matchingClockTime = new TimestampedValue<>(
+ UnixEpochTime matchingClockTime = new UnixEpochTime(
script.peekElapsedRealtimeMillis(),
suggestionInstant.toEpochMilli());
TelephonyTimeSuggestion timeSuggestion = new TelephonyTimeSuggestion.Builder(slotIndex)
@@ -357,7 +357,7 @@
Instant suggestionInstant = initialClockTime.getValue()
.plusMillis(timeElapsedMillis)
.plusMillis(confidenceUpgradeThresholdMillis + 1);
- TimestampedValue<Long> mismatchingClockTime = new TimestampedValue<>(
+ UnixEpochTime mismatchingClockTime = new UnixEpochTime(
script.peekElapsedRealtimeMillis(),
suggestionInstant.toEpochMilli());
TelephonyTimeSuggestion timeSuggestion = new TelephonyTimeSuggestion.Builder(slotIndex)
@@ -392,7 +392,7 @@
// Create a suggestion time that doesn't closely match the current system clock.
Instant initialClockInstant = initialClockTime.getValue();
- TimestampedValue<Long> mismatchingClockTime = new TimestampedValue<>(
+ UnixEpochTime mismatchingClockTime = new UnixEpochTime(
script.peekElapsedRealtimeMillis(),
initialClockInstant.plusMillis(timeElapsedMillis + 1_000_000).toEpochMilli());
TelephonyTimeSuggestion timeSuggestion = new TelephonyTimeSuggestion.Builder(slotIndex)
@@ -418,7 +418,7 @@
TelephonyTimeSuggestion timeSuggestion1 =
script.generateTelephonyTimeSuggestion(slotIndex, testTime);
- TimestampedValue<Long> unixEpochTime1 = timeSuggestion1.getUnixEpochTime();
+ UnixEpochTime unixEpochTime1 = timeSuggestion1.getUnixEpochTime();
// Initialize the strategy / device with a time set from a telephony suggestion.
script.simulateTimePassing();
@@ -430,13 +430,13 @@
// 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()
+ long validUnixEpochTimeMillis = unixEpochTime1.getUnixEpochTimeMillis()
+ (2 * systemClockUpdateThresholdMillis);
- // Now supply a new signal that has an obviously bogus reference time : older than the last
- // one.
- long referenceTimeBeforeLastSignalMillis = unixEpochTime1.getReferenceTimeMillis() - 1;
- TimestampedValue<Long> unixEpochTime2 = new TimestampedValue<>(
+ // Now supply a new signal that has an obviously bogus elapsed realtime : older than the
+ // last one.
+ long referenceTimeBeforeLastSignalMillis = unixEpochTime1.getElapsedRealtimeMillis() - 1;
+ UnixEpochTime unixEpochTime2 = new UnixEpochTime(
referenceTimeBeforeLastSignalMillis, validUnixEpochTimeMillis);
TelephonyTimeSuggestion timeSuggestion2 =
createTelephonyTimeSuggestion(slotIndex, unixEpochTime2);
@@ -445,11 +445,11 @@
.verifySystemClockWasNotSetAndResetCallTracking()
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
- // Now supply a new signal that has an obviously bogus reference time : substantially in the
- // future.
+ // Now supply a new signal that has an obviously bogus elapsed realtime; one substantially
+ // in the future.
long referenceTimeInFutureMillis =
- unixEpochTime1.getReferenceTimeMillis() + Integer.MAX_VALUE + 1;
- TimestampedValue<Long> unixEpochTime3 = new TimestampedValue<>(
+ unixEpochTime1.getElapsedRealtimeMillis() + Integer.MAX_VALUE + 1;
+ UnixEpochTime unixEpochTime3 = new UnixEpochTime(
referenceTimeInFutureMillis, validUnixEpochTimeMillis);
TelephonyTimeSuggestion timeSuggestion3 =
createTelephonyTimeSuggestion(slotIndex, unixEpochTime3);
@@ -459,8 +459,8 @@
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
// Just to prove validUnixEpochTimeMillis is valid.
- long validReferenceTimeMillis = unixEpochTime1.getReferenceTimeMillis() + 100;
- TimestampedValue<Long> unixEpochTime4 = new TimestampedValue<>(
+ long validReferenceTimeMillis = unixEpochTime1.getElapsedRealtimeMillis() + 100;
+ UnixEpochTime unixEpochTime4 = new UnixEpochTime(
validReferenceTimeMillis, validUnixEpochTimeMillis);
long expectedSystemClockMillis4 = script.calculateTimeInMillisForNow(unixEpochTime4);
TelephonyTimeSuggestion timeSuggestion4 =
@@ -486,7 +486,7 @@
Instant testTime = ARBITRARY_TEST_TIME;
TelephonyTimeSuggestion timeSuggestion1 =
script.generateTelephonyTimeSuggestion(slotIndex, testTime);
- TimestampedValue<Long> unixEpochTime1 = timeSuggestion1.getUnixEpochTime();
+ UnixEpochTime unixEpochTime1 = timeSuggestion1.getUnixEpochTime();
// Simulate time passing.
script.simulateTimePassing(clockIncrementMillis);
@@ -2099,11 +2099,11 @@
/**
* Generates a ManualTimeSuggestion using the current elapsed realtime clock for the
- * reference time.
+ * elapsed realtime.
*/
ManualTimeSuggestion generateManualTimeSuggestion(Instant suggestedTime) {
- TimestampedValue<Long> unixEpochTime =
- new TimestampedValue<>(
+ UnixEpochTime unixEpochTime =
+ new UnixEpochTime(
mFakeEnvironment.peekElapsedRealtimeMillis(),
suggestedTime.toEpochMilli());
return new ManualTimeSuggestion(unixEpochTime);
@@ -2111,17 +2111,16 @@
/**
* Generates a {@link TelephonyTimeSuggestion} using the current elapsed realtime clock for
- * the reference time.
+ * the elapsed realtime.
*/
TelephonyTimeSuggestion generateTelephonyTimeSuggestion(int slotIndex, long timeMillis) {
- TimestampedValue<Long> time =
- new TimestampedValue<>(peekElapsedRealtimeMillis(), timeMillis);
+ UnixEpochTime time = new UnixEpochTime(peekElapsedRealtimeMillis(), timeMillis);
return createTelephonyTimeSuggestion(slotIndex, time);
}
/**
* Generates a {@link TelephonyTimeSuggestion} using the current elapsed realtime clock for
- * the reference time.
+ * the elapsed realtime.
*/
TelephonyTimeSuggestion generateTelephonyTimeSuggestion(
int slotIndex, Instant suggestedTime) {
@@ -2133,11 +2132,11 @@
/**
* Generates a NetworkTimeSuggestion using the current elapsed realtime clock for the
- * reference time.
+ * elapsed realtime.
*/
NetworkTimeSuggestion generateNetworkTimeSuggestion(Instant suggestedTime) {
- TimestampedValue<Long> unixEpochTime =
- new TimestampedValue<>(
+ UnixEpochTime unixEpochTime =
+ new UnixEpochTime(
mFakeEnvironment.peekElapsedRealtimeMillis(),
suggestedTime.toEpochMilli());
return new NetworkTimeSuggestion(unixEpochTime, 123);
@@ -2145,11 +2144,11 @@
/**
* Generates a GnssTimeSuggestion using the current elapsed realtime clock for the
- * reference time.
+ * elapsed realtime.
*/
GnssTimeSuggestion generateGnssTimeSuggestion(Instant suggestedTime) {
- TimestampedValue<Long> unixEpochTime =
- new TimestampedValue<>(
+ UnixEpochTime unixEpochTime =
+ new UnixEpochTime(
mFakeEnvironment.peekElapsedRealtimeMillis(),
suggestedTime.toEpochMilli());
return new GnssTimeSuggestion(unixEpochTime);
@@ -2157,7 +2156,7 @@
/**
* Generates a ExternalTimeSuggestion using the current elapsed realtime clock for the
- * reference time.
+ * elapsed realtime.
*/
ExternalTimeSuggestion generateExternalTimeSuggestion(Instant suggestedTime) {
return new ExternalTimeSuggestion(mFakeEnvironment.peekElapsedRealtimeMillis(),
@@ -2168,8 +2167,8 @@
* Calculates what the supplied time would be when adjusted for the movement of the fake
* elapsed realtime clock.
*/
- long calculateTimeInMillisForNow(TimestampedValue<Long> unixEpochTime) {
- return TimeDetectorStrategy.getTimeAt(unixEpochTime, peekElapsedRealtimeMillis());
+ long calculateTimeInMillisForNow(UnixEpochTime unixEpochTime) {
+ return unixEpochTime.at(peekElapsedRealtimeMillis()).getUnixEpochTimeMillis();
}
Script simulateConfirmTime(UnixEpochTime confirmationTime, boolean expectedReturnValue) {
@@ -2179,7 +2178,7 @@
}
private static TelephonyTimeSuggestion createTelephonyTimeSuggestion(int slotIndex,
- TimestampedValue<Long> unixEpochTime) {
+ UnixEpochTime unixEpochTime) {
return new TelephonyTimeSuggestion.Builder(slotIndex)
.setUnixEpochTime(unixEpochTime)
.build();
diff --git a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyTest.java b/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyTest.java
deleted file mode 100644
index f1e9191..0000000
--- a/services/tests/servicestests/src/com/android/server/timedetector/TimeDetectorStrategyTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.timedetector;
-
-import static org.junit.Assert.assertEquals;
-
-import android.os.TimestampedValue;
-
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public class TimeDetectorStrategyTest {
-
- @Test
- public void testGetTimeAt() {
- long timeMillis = 1000L;
- int referenceTimeMillis = 100;
- TimestampedValue<Long> timestampedValue =
- new TimestampedValue<>(referenceTimeMillis, timeMillis);
- // Reference time is after the timestamp.
- assertEquals(
- timeMillis + (125 - referenceTimeMillis),
- TimeDetectorStrategy.getTimeAt(timestampedValue, 125));
-
- // Reference time is before the timestamp.
- assertEquals(
- timeMillis + (75 - referenceTimeMillis),
- TimeDetectorStrategy.getTimeAt(timestampedValue, 75));
- }
-}