1 /* 2 * Copyright (C) 2016 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.Wifi 15 */ 16 17 package com.android.server.wifi; 18 19 import android.os.SystemClock; 20 21 import javax.annotation.concurrent.ThreadSafe; 22 23 /** 24 * Wrapper class for time operations. Allows replacement of clock operations for testing. 25 */ 26 @ThreadSafe 27 public class Clock { 28 29 /** 30 * Get the current time of the clock in milliseconds. 31 * 32 * @return Current time in milliseconds. 33 */ getWallClockMillis()34 public long getWallClockMillis() { 35 return System.currentTimeMillis(); 36 } 37 38 /** 39 * Returns milliseconds since boot, including time spent in sleep. 40 * 41 * @return Current time since boot in milliseconds. 42 */ getElapsedSinceBootMillis()43 public long getElapsedSinceBootMillis() { 44 return SystemClock.elapsedRealtime(); 45 } 46 47 /** 48 * Returns nanoseconds since boot, including time spent in sleep. 49 * 50 * @return Current time since boot in nanoseconds. 51 */ getElapsedSinceBootNanos()52 public long getElapsedSinceBootNanos() { 53 return SystemClock.elapsedRealtimeNanos(); 54 } 55 56 /** 57 * Returns milliseconds since boot, not counting time spent in deep sleep. 58 * 59 * @return Milliseconds of non-sleep uptime since boot. 60 */ getUptimeSinceBootMillis()61 public long getUptimeSinceBootMillis() { 62 return SystemClock.uptimeMillis(); 63 } 64 65 /** 66 * Waits a given number of milliseconds (of uptimeMillis) before returning. 67 */ sleep(long ms)68 public void sleep(long ms) { 69 SystemClock.sleep(ms); 70 } 71 } 72