Package org.robolectric.shadows
Class ShadowSystemClock
java.lang.Object
org.robolectric.shadows.ShadowSystemClock
- Direct Known Subclasses:
ShadowLegacySystemClock,ShadowPausedSystemClock
@Implements(value=android.os.SystemClock.class,
shadowPicker=Picker.class,
looseSignatures=true)
public abstract class ShadowSystemClock
extends Object
The shadow API for
SystemClock.
The behavior of SystemClock in Robolectric will differ based on the current LooperMode. See ShadowLegacySystemClock and ShadowPausedSystemClock for more
details.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAn alternate toadvanceBy(Duration)for older Android code bases where Duration is not available.static voidA convenience method for advancing the clock viaSystemClock.setCurrentTimeMillis(long)protected static Objectstatic longImplementsSystem.currentTimeMillis()through ShadowWrangler.static longnanoTime()Deprecated.static voidreset()static voidsetGnssTimeAvailable(boolean available) Sets whether gnss location based time is available.static voidsetNanoTime(long nanoTime) Sets the value forSystem.nanoTime().static voidsetNetworkTimeAvailable(boolean available) Sets whether network time is available.static voidsimulateDeepSleep(Duration duration) In a deep sleep scenario, is advanced for this duration when in deep sleep whilst maintains its original value.
-
Field Details
-
networkTimeAvailable
protected static boolean networkTimeAvailable
-
-
Constructor Details
-
ShadowSystemClock
public ShadowSystemClock()
-
-
Method Details
-
currentTimeMillis
public static long currentTimeMillis()ImplementsSystem.currentTimeMillis()through ShadowWrangler.- Returns:
- Current time in millis.
-
nanoTime
Deprecated.Don't call this method directly; instead, useSystem.nanoTime().ImplementsSystem.nanoTime().- Returns:
- Current time with nanos.
-
setNanoTime
public static void setNanoTime(long nanoTime) Sets the value forSystem.nanoTime().May only be used for
LooperMode.Mode.LEGACY. ForLooperMode.Mode.PAUSED, is calculated based onSystemClock.uptimeMillis()and can't be set explicitly. -
setNetworkTimeAvailable
public static void setNetworkTimeAvailable(boolean available) Sets whether network time is available. -
advanceBy
An alternate toadvanceBy(Duration)for older Android code bases where Duration is not available. -
advanceBy
A convenience method for advancing the clock viaSystemClock.setCurrentTimeMillis(long)- Parameters:
duration- The interval by which to advance.
-
simulateDeepSleep
In a deep sleep scenario, is advanced for this duration when in deep sleep whilst maintains its original value.May only be used for
LooperMode.Mode.PAUSED. ForLooperMode.Mode.LEGACY, is equal to . -
currentGnssTimeClock
-
setGnssTimeAvailable
public static void setGnssTimeAvailable(boolean available) Sets whether gnss location based time is available. -
reset
public static void reset()
-
System.nanoTime().