# Clock

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/Clock.java+class:androidx.media3.common.util.Clock)

*** ** * ** ***


```
@UnstableApi
public interface Clock
```

<br />

Known direct subclasses [FakeClock](https://developer.android.com/reference/androidx/media3/test/utils/FakeClock), [SystemClock](https://developer.android.com/reference/androidx/media3/common/util/SystemClock)

|---|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeClock` | Fake `https://developer.android.com/reference/androidx/media3/common/util/Clock` implementation that allows to `https://developer.android.com/reference/androidx/media3/test/utils/FakeClock#advanceTime(long)` manually to trigger pending timed messages. |
| `https://developer.android.com/reference/androidx/media3/common/util/SystemClock` | The standard implementation of `https://developer.android.com/reference/androidx/media3/common/util/Clock`, an instance of which is available via `https://developer.android.com/reference/androidx/media3/common/util/Clock#DEFAULT()`. |

*** ** * ** ***

An interface through which system clocks can be read and `https://developer.android.com/reference/androidx/media3/common/util/HandlerWrapper`s created. The `https://developer.android.com/reference/androidx/media3/common/util/Clock#DEFAULT()` implementation must be used for all non-test cases.

## Summary

| ### Constants |
|---|---|
| `default static final https://developer.android.com/reference/androidx/media3/common/util/Clock` | `https://developer.android.com/reference/androidx/media3/common/util/Clock#DEFAULT()` Default `https://developer.android.com/reference/androidx/media3/common/util/Clock` to use for all non-test cases. |

| ### Public methods |
|---|---|
| `abstract https://developer.android.com/reference/androidx/media3/common/util/HandlerWrapper` | `https://developer.android.com/reference/androidx/media3/common/util/Clock#createHandler(android.os.Looper,android.os.Handler.Callback)( https://developer.android.com/reference/android/os/Looper.html looper, @https://developer.android.com/reference/androidx/annotation/Nullable @https://checkerframework.org/api/org/checkerframework/checker/initialization/qual/UnknownInitialization.html https://developer.android.com/reference/android/os/Handler.Callback.html callback )` Creates a `https://developer.android.com/reference/androidx/media3/common/util/HandlerWrapper` using a specified looper and a specified callback for handling messages. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/common/util/Clock#currentTimeMillis()()` Returns the current time in milliseconds since the Unix Epoch. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/common/util/Clock#elapsedRealtime()()` |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/common/util/Clock#nanoTime()()` See `https://developer.android.com/reference/java/lang/System.html#nanoTime()` |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/common/util/Clock#onThreadBlocked()()` Notifies the clock that the current thread is about to be blocked and won't return until a condition on another thread becomes true. |
| `abstract long` | `https://developer.android.com/reference/androidx/media3/common/util/Clock#uptimeMillis()()` |

## Constants

### DEFAULT

```
default static final Clock DEFAULT
```

Default `https://developer.android.com/reference/androidx/media3/common/util/Clock` to use for all non-test cases.

## Public methods

### createHandler

```
abstract HandlerWrapper createHandler(
    Looper looper,
    @Nullable @UnknownInitialization Handler.Callback callback
)
```

Creates a `https://developer.android.com/reference/androidx/media3/common/util/HandlerWrapper` using a specified looper and a specified callback for handling messages.

| See also |
|---|---|
| `https://developer.android.com/reference/android/os/Handler.html#Handler(android.os.Looper, android.os.Handler.Callback)` |   |

### currentTimeMillis

```
abstract long currentTimeMillis()
```

Returns the current time in milliseconds since the Unix Epoch.

| See also |
|---|---|
| `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` |   |

### elapsedRealtime

```
abstract long elapsedRealtime()
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()` |   |

### nanoTime

```
abstract long nanoTime()
```

See `https://developer.android.com/reference/java/lang/System.html#nanoTime()`

### onThreadBlocked

```
abstract void onThreadBlocked()
```

Notifies the clock that the current thread is about to be blocked and won't return until a condition on another thread becomes true.

Should be a no-op for all non-test cases.

### uptimeMillis

```
abstract long uptimeMillis()
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/os/SystemClock.html#uptimeMillis()` |   |