Skip to content

Commit

Permalink
Add nanoTime method to Clock to support overriding System.nanoTime()
Browse files Browse the repository at this point in the history
#minor-release

PiperOrigin-RevId: 545237925
  • Loading branch information
microkatz committed Jul 5, 2023
1 parent a783d70 commit de4575d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public long uptimeMillis() {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ public synchronized long elapsedRealtime() {
return timeSinceBootMs;
}

@Override
public synchronized long nanoTime() {
// Milliseconds to nanoseconds
return timeSinceBootMs * 1000000L;
}

@Override
public long uptimeMillis() {
return elapsedRealtime();
Expand Down

0 comments on commit de4575d

Please sign in to comment.