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 * Wrapper class for time operations. Allows replacement of clock operations for testing. 22 */ 23 public class Clock { 24 25 /** 26 * Get the current time of the clock in milliseconds. 27 * 28 * @return Current time in milliseconds. 29 */ getWallClockMillis()30 public long getWallClockMillis() { 31 return System.currentTimeMillis(); 32 } 33 34 /** 35 * Returns milliseconds since boot, including time spent in sleep. 36 * 37 * @return Current time since boot in milliseconds. 38 */ getElapsedSinceBootMillis()39 public long getElapsedSinceBootMillis() { 40 return SystemClock.elapsedRealtime(); 41 } 42 43 /** 44 * Returns nanoseconds since boot, including time spent in sleep. 45 * 46 * @return Current time since boot in nanoseconds. 47 */ getElapsedSinceBootNanos()48 public long getElapsedSinceBootNanos() { 49 return SystemClock.elapsedRealtimeNanos(); 50 } 51 52 /** 53 * Returns milliseconds since boot, not counting time spent in deep sleep. 54 * 55 * @return Milliseconds of non-sleep uptime since boot. 56 */ getUptimeSinceBootMillis()57 public long getUptimeSinceBootMillis() { 58 return SystemClock.uptimeMillis(); 59 } 60 61 } 62