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

#minor-release

PiperOrigin-RevId: 545237925
This commit is contained in:
michaelkatz 2023-07-03 16:29:13 +00:00 committed by microkatz
parent a783d704b2
commit de4575da28
4 changed files with 16 additions and 0 deletions

View File

@ -102,6 +102,8 @@
* Make `TestExoPlayerBuilder` and `FakeClock` compatible with Espresso UI
tests and Compose UI tests. This fixes a bug where playback advances
non-deterministically during Espresso or Compose view interactions.
* Add a `nanoTime()` method to `Clock` to provide override support of
`System.nanoTime()`
* Remove deprecated symbols:
* Remove
`TransformationRequest.Builder.setEnableRequestSdrToneMapping(boolean)`

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

@ -159,6 +159,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();