Class ShadowSystemClock

java.lang.Object
org.robolectric.shadows.ShadowSystemClock
Direct Known Subclasses:
ShadowLegacySystemClock, ShadowPausedSystemClock

@Implements(value=android.os.SystemClock.class, shadowPicker=Picker.class) 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.

  • Field Details

    • networkTimeAvailable

      protected static boolean networkTimeAvailable
  • Constructor Details

    • ShadowSystemClock

      public ShadowSystemClock()
  • Method Details

    • currentTimeMillis

      public static long currentTimeMillis()
      Implements System.currentTimeMillis() through ShadowWrangler.
      Returns:
      Current time in millis.
    • nanoTime

      @Deprecated public static long nanoTime()
      Deprecated.
      Don't call this method directly; instead, use System.nanoTime().
      Implements System.nanoTime().
      Returns:
      Current time with nanos.
    • setNanoTime

      public static void setNanoTime(long nanoTime)
      Sets the value for System.nanoTime().

      May only be used for LooperMode.Mode.LEGACY. For LooperMode.Mode.PAUSED, is calculated based on SystemClock.uptimeMillis() and can't be set explicitly.

    • setNetworkTimeAvailable

      public static void setNetworkTimeAvailable(boolean available)
      Sets whether network time is available.
    • advanceBy

      public static void advanceBy(long time, TimeUnit unit)
      An alternate to advanceBy(Duration) for older Android code bases where Duration is not available.
    • advanceBy

      public static void advanceBy(Duration duration)
      A convenience method for advancing the clock via SystemClock.setCurrentTimeMillis(long)
      Parameters:
      duration - The interval by which to advance.
    • simulateDeepSleep

      public static void simulateDeepSleep(Duration duration)
      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. For LooperMode.Mode.LEGACY, is equal to .

    • currentGnssTimeClock

      @Implementation(minSdk=29) protected static Object currentGnssTimeClock()
    • setGnssTimeAvailable

      public static void setGnssTimeAvailable(boolean available)
      Sets whether gnss location based time is available.
    • reset

      public static void reset()