1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.adservices.shared.util; 18 19 import android.os.SystemClock; 20 21 /** Class for SystemClock call. */ 22 public final class Clock { 23 private static final Clock SYSTEM_CLOCK = new Clock(); 24 25 /** Returns the static instance of the {@link Clock} using {@link SystemClock}. */ getInstance()26 public static Clock getInstance() { 27 return SYSTEM_CLOCK; 28 } 29 30 /** Wrapper for {@link SystemClock#elapsedRealtime()}. */ elapsedRealtime()31 public long elapsedRealtime() { 32 return SystemClock.elapsedRealtime(); 33 } 34 35 /** Wrapper for {@link SystemClock#uptimeMillis()}. */ uptimeMillis()36 public long uptimeMillis() { 37 return SystemClock.uptimeMillis(); 38 } 39 40 /** Wrapper for {@link System#currentTimeMillis()}. */ currentTimeMillis()41 public long currentTimeMillis() { 42 return System.currentTimeMillis(); 43 } 44 45 /** 46 * Wrapper for {@link System#nanoTime()} 47 * 48 * @return current time in nanoseconds. (1 millisecond = 1,000,000 nanoseconds) 49 */ nanoTime()50 public long nanoTime() { 51 return System.nanoTime(); 52 } 53 } 54