Class ShadowPausedSystemClock
LooperMode.Mode.PAUSED
is active.
In this variant, System times (both elapsed realtime and uptime) are controlled by this class.
The current times are fixed in place. You can manually advance both by calling SystemClock.setCurrentTimeMillis(long)
or just advance elapsed realtime only by calling deepSleep(long)
.
SystemClock.uptimeMillis()
and SystemClock.currentThreadTimeMillis()
are
identical.
This class should not be referenced directly. Use ShadowSystemClock instead.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.robolectric.shadows.ShadowSystemClock
ShadowSystemClock.Picker
-
Field Summary
Fields inherited from class org.robolectric.shadows.ShadowSystemClock
networkTimeAvailable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static long
protected static long
protected static long
protected static long
protected static void
deepSleep
(long millis) Advances the current time (elapsed realtime only) by given millis, without sleeping the current thread.protected static long
protected static long
static void
reset()
protected static boolean
setCurrentTimeMillis
(long millis) Sets the current wall time (both elapsed realtime and uptime).protected static void
sleep
(long millis) Advances the current time (both elapsed realtime and uptime) by given millis, without sleeping the current thread.protected static long
protected static long
Methods inherited from class org.robolectric.shadows.ShadowSystemClock
advanceBy, advanceBy, currentGnssTimeClock, currentTimeMillis, nanoTime, setGnssTimeAvailable, setNanoTime, setNetworkTimeAvailable, simulateDeepSleep
-
Constructor Details
-
ShadowPausedSystemClock
public ShadowPausedSystemClock()
-
-
Method Details
-
sleep
Advances the current time (both elapsed realtime and uptime) by given millis, without sleeping the current thread. -
deepSleep
protected static void deepSleep(long millis) Advances the current time (elapsed realtime only) by given millis, without sleeping the current thread.This is to simulate scenarios like suspend-to-RAM, where only elapsed realtime is incremented when the device is in deep sleep.
-
setCurrentTimeMillis
Sets the current wall time (both elapsed realtime and uptime).This API sets both of the elapsed realtime and uptime to the specified value.
Use of this method is discouraged. It currently has the following inconsistent behavior:
- >It doesn't check permissions. In real android this method is protected by the signature/privileged SET_TIME permission, thus it is uncallable by most apps
- It doesn't actually change the value of System.currentTimeMillis for non-instrumented code aka nearly all user tests and apps It only allows advancing the current time, not moving it backwards
- It incorrectly changes the value of SystemClock.uptime, elapsedRealtime, and for instrumented code System.nanoTime. In real android these are all independent clocks
It is recommended to use ShadowSystemClock.advanceBy instead to advance SystemClock.uptimeMillis and SystemClock.elapsedRealTime
- Returns:
- false if specified time is less than current uptime.
-
uptimeMillis
-
uptimeNanos
-
elapsedRealtime
-
elapsedRealtimeNanos
-
currentThreadTimeMillis
-
currentThreadTimeMicro
-
currentTimeMicro
-
currentNetworkTimeMillis
-
reset
-