docs/doc/reference/com/google/android/exoplayer2/testutil/FakeClock.html
Package com.google.android.exoplayer2.testutil
All Implemented Interfaces:Clock
public classFakeClockextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")implements[Clock](../util/Clock.html "interface in com.google.android.exoplayer2.util")
Fake Clock implementation that allows to advance the time manually to trigger pending timed messages.
All timed messages sent by a Handler created from this clock are governed by the clock's time. Messages sent through these handlers are not triggered until previous messages on any thread have been handled to ensure deterministic execution. Note that this includes messages sent from the main Robolectric test thread, meaning that these messages are only triggered if the main test thread is idle, which can be explicitly requested by calling ShadowLooper.idleMainLooper().
The clock also sets the time of the SystemClock to match the clock's time.
Nested Classes | Modifier and Type | Class | Description |
| --- | --- | --- |
| protected class | FakeClock.HandlerMessage |
Message data saved to send messages or execute runnables at a later time on a Handler.
|
-
DEFAULT
Constructors | Constructor | Description |
| --- | --- |
| FakeClock(boolean isAutoAdvancing) |
Creates a fake clock that assumes that the system was booted exactly at time 0 (the Unix Epoch) and an initialTimeMs of 0.
|
| FakeClock(long initialTimeMs) |
Creates a fake clock that doesn't auto-advance and assumes that the system was booted exactly at time 0 (the Unix Epoch) and initialTimeMs milliseconds have passed since system boot.
|
| FakeClock(long initialTimeMs, boolean isAutoAdvancing) |
Creates a fake clock that assumes that the system was booted exactly at time 0 (the Unix Epoch) and initialTimeMs milliseconds have passed since system boot.
|
| FakeClock(long bootTimeMs, long initialTimeMs, boolean isAutoAdvancing) |
Creates a fake clock specifying when the system was booted and how much time has passed since then.
|
All Methods Instance Methods Concrete Methods | Modifier and Type | Method | Description |
| --- | --- | --- |
| protected void | addPendingHandlerMessage(FakeClock.HandlerMessage message) |
Adds a message to the list of pending messages.
|
| void | advanceTime(long timeDiffMs) |
Advance timestamp of FakeClock by the specified duration.
|
| HandlerWrapper | createHandler(Looper looper, Handler.Callback callback) |
Creates a HandlerWrapper using a specified looper and a specified callback for handling messages.
|
| long | currentTimeMillis() |
Returns the current time in milliseconds since the Unix Epoch.
|
| long | elapsedRealtime() | |
| long | nanoTime() |
See System.nanoTime()
|
| 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.
|
| long | uptimeMillis() | |
-
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
public FakeClock(long initialTimeMs)
Creates a fake clock that doesn't auto-advance and assumes that the system was booted exactly at time 0 (the Unix Epoch) and initialTimeMs milliseconds have passed since system boot.
Parameters:initialTimeMs - The initial elapsed time since the boot time, in milliseconds.
-
public FakeClock(boolean isAutoAdvancing)
Creates a fake clock that assumes that the system was booted exactly at time 0 (the Unix Epoch) and an initialTimeMs of 0.
Parameters:isAutoAdvancing - Whether the clock should automatically advance the time to the time of next message that is due to be sent.
-
public FakeClock(long initialTimeMs,
boolean isAutoAdvancing)
Creates a fake clock that assumes that the system was booted exactly at time 0 (the Unix Epoch) and initialTimeMs milliseconds have passed since system boot.
Parameters:initialTimeMs - The initial elapsed time since the boot time, in milliseconds.isAutoAdvancing - Whether the clock should automatically advance the time to the time of next message that is due to be sent.
-
public FakeClock(long bootTimeMs,
long initialTimeMs,
boolean isAutoAdvancing)
Creates a fake clock specifying when the system was booted and how much time has passed since then.
Parameters:bootTimeMs - The time the system was booted since the Unix Epoch, in milliseconds.initialTimeMs - The initial elapsed time since the boot time, in milliseconds.isAutoAdvancing - Whether the clock should automatically advance the time to the time of next message that is due to be sent.
-
public void advanceTime(long timeDiffMs)
Advance timestamp of FakeClock by the specified duration.
Parameters:timeDiffMs - The amount of time to add to the timestamp in milliseconds.
-
public long currentTimeMillis()
Description copied from interface: Clock
Returns the current time in milliseconds since the Unix Epoch.
Specified by:currentTimeMillis in interface ClockSee Also:System.currentTimeMillis()
-
public long elapsedRealtime()
Specified by:elapsedRealtime in interface ClockSee Also:SystemClock.elapsedRealtime()
-
public long nanoTime()
Description copied from interface: Clock
See System.nanoTime()
Specified by:nanoTime in interface Clock
-
public long uptimeMillis()
Specified by:uptimeMillis in interface ClockSee Also:SystemClock.uptimeMillis()
-
public[HandlerWrapper](../util/HandlerWrapper.html "interface in com.google.android.exoplayer2.util")createHandler([Looper](https://developer.android.com/reference/android/os/Looper.html "class or interface in android.os")looper,
@Nullable[Handler.Callback](https://developer.android.com/reference/android/os/Handler.Callback.html "class or interface in android.os")callback)
Description copied from interface: Clock
Creates a HandlerWrapper using a specified looper and a specified callback for handling messages.
Specified by:createHandler in interface ClockSee Also:Handler(Looper, Handler.Callback)
-
public void onThreadBlocked()
Description copied from interface: Clock
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.
Specified by:onThreadBlocked in interface Clock
-
protected void addPendingHandlerMessage([FakeClock.HandlerMessage](FakeClock.HandlerMessage.html "class in com.google.android.exoplayer2.testutil")message)
Adds a message to the list of pending messages.