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

PiperOrigin-RevId: 545237925
(cherry picked from commit de4575da28ee98a46e284cc8c7f11d34da1df29e)
This commit is contained in:
michaelkatz 2023-07-03 16:29:13 +00:00 committed by Tianyi Feng
parent 26ee4c35f3
commit cb7b3862c4
4 changed files with 17 additions and 0 deletions

View File

@ -10,6 +10,9 @@
Previously indent and tab offset were included when limiting the cue
length to 32 characters (which was technically correct by the spec)
([#11019](https://github.com/google/ExoPlayer/issues/11019)).
* Test Utilities:
* Add a `nanoTime()` method to `Clock` to provide override support of
`System.nanoTime()`
## 1.1
### 1.1.0 (2023-07-05)

View File

@ -46,6 +46,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.

View File

@ -44,6 +44,11 @@ public class SystemClock implements Clock {
return android.os.SystemClock.uptimeMillis();
}
@Override
public long nanoTime() {
return System.nanoTime();
}
@Override
public HandlerWrapper createHandler(Looper looper, @Nullable Callback callback) {
return new SystemHandlerWrapper(new Handler(looper, callback));

View File

@ -147,6 +147,12 @@ public class FakeClock implements Clock {
return timeSinceBootMs;
}
@Override
public synchronized long nanoTime() {
// Milliseconds to nanoseconds
return timeSinceBootMs * 1000000L;
}
@Override
public long uptimeMillis() {
return elapsedRealtime();