• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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 package com.android.tv.util;
17 
18 import android.os.SystemClock;
19 
20 /**
21  * An interface through which system clocks can be read. The {@link #SYSTEM} implementation
22  * must be used for all non-test cases.
23  */
24 public interface Clock {
25     /**
26      * Returns the current time in milliseconds since January 1, 1970 00:00:00.0 UTC.
27      * See {@link System#currentTimeMillis()}.
28      */
currentTimeMillis()29     long currentTimeMillis();
30 
31     /**
32      * Returns milliseconds since boot, including time spent in sleep.
33      *
34      * @see SystemClock#elapsedRealtime()
35      */
elapsedRealtime()36     long elapsedRealtime();
37 
38     /**
39      * Waits a given number of milliseconds (of uptimeMillis) before returning.
40      *
41      * @param ms to sleep before returning, in milliseconds of uptime.
42      * @see SystemClock#sleep(long)
43      */
sleep(long ms)44     void sleep(long ms);
45 
46     /**
47      * The default implementation of Clock.
48      */
49     Clock SYSTEM = new Clock() {
50         @Override
51         public long currentTimeMillis() {
52             return System.currentTimeMillis();
53         }
54 
55         @Override
56         public long elapsedRealtime() {
57             return SystemClock.elapsedRealtime();
58         }
59 
60         @Override
61         public void sleep(long ms) {
62             SystemClock.sleep(ms);
63         }
64     };
65 }
66