Commit 0af25ccd by michaelkatz Committed by Tianyi Feng

Add nanoTime method to Clock to support overriding System.nanoTime()

#minor-release

PiperOrigin-RevId: 545237925
(cherry picked from commit 527073acdfa4a1f1e43bc3abb3ef7a54e0bb8696)
parent d876028a
......@@ -51,6 +51,9 @@ public interface Clock {
*/
long uptimeMillis();
/** See {@link java.lang.System#nanoTime()} */
long nanoTime();
/**
* Creates a {@link HandlerWrapper} using a specified looper and a specified callback for handling
* messages.
......
......@@ -50,6 +50,11 @@ public class SystemClock implements Clock {
}
@Override
public long nanoTime() {
return System.nanoTime();
}
@Override
public HandlerWrapper createHandler(Looper looper, @Nullable Callback callback) {
return new SystemHandlerWrapper(new Handler(looper, callback));
}
......
......@@ -146,6 +146,12 @@ public class FakeClock implements Clock {
}
@Override
public synchronized long nanoTime() {
// Milliseconds to nanoseconds
return timeSinceBootMs * 1000000L;
}
@Override
public long uptimeMillis() {
return elapsedRealtime();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment