All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.shadows.ShadowSystem Maven / Gradle / Ivy

The newest version!
package org.robolectric.shadows;

import android.os.SystemClock;
import java.util.concurrent.TimeUnit;
import org.robolectric.annotation.LooperMode;

public class ShadowSystem {

  /**
   * Implements {@link System#nanoTime} through ShadowWrangler.
   *
   * @return Current time with nanos.
   */
  @SuppressWarnings("unused")
  public static long nanoTime() {
    if (ShadowLooper.looperMode() == LooperMode.Mode.LEGACY) {
      return ShadowLegacySystemClock.nanoTime();
    } else {
      return TimeUnit.MILLISECONDS.toNanos(SystemClock.uptimeMillis());
    }
  }

  /**
   * Implements {@link System#currentTimeMillis} through ShadowWrangler.
   *
   * @return Current time with millis.
   */
  @SuppressWarnings("unused")
  public static long currentTimeMillis() {
    if (ShadowLooper.looperMode() == LooperMode.Mode.LEGACY) {
      return ShadowLegacySystemClock.currentTimeMillis();
    } else {
      return SystemClock.uptimeMillis();
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy