• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 java.time.Instant;
22 
23 import javax.annotation.concurrent.ThreadSafe;
24 
25 /**
26  * Wrapper class for time operations. Allows replacement of clock operations for testing.
27  */
28 @ThreadSafe
29 public class Clock {
30 
31     /**
32      * Get the current time of the clock in milliseconds.
33      *
34      * @return Current time in milliseconds.
35      */
getWallClockMillis()36     public long getWallClockMillis() {
37         return System.currentTimeMillis();
38     }
39 
40     /**
41      * Returns milliseconds since boot, including time spent in sleep.
42      *
43      * @return Current time since boot in milliseconds.
44      */
getElapsedSinceBootMillis()45     public long getElapsedSinceBootMillis() {
46         return SystemClock.elapsedRealtime();
47     }
48 
49    /**
50      * Returns nanoseconds since boot, including time spent in sleep.
51      *
52      * @return Current time since boot in nanoseconds.
53      */
getElapsedSinceBootNanos()54     public long getElapsedSinceBootNanos() {
55         return SystemClock.elapsedRealtimeNanos();
56     }
57 
58     /**
59      * Returns milliseconds since boot, not counting time spent in deep sleep.
60      *
61      * @return Milliseconds of non-sleep uptime since boot.
62      */
getUptimeSinceBootMillis()63     public long getUptimeSinceBootMillis() {
64         return SystemClock.uptimeMillis();
65     }
66 
67     /**
68      * Waits a given number of milliseconds (of uptimeMillis) before returning.
69      */
sleep(long ms)70     public void sleep(long ms) {
71         SystemClock.sleep(ms);
72     }
73 
getCurrentInstant()74     public Instant getCurrentInstant() {
75         return Instant.now();
76     }
77 }
78