• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 android.os;
18 
19 import com.android.layoutlib.bridge.impl.DelegateManager;
20 import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
21 import com.android.tools.layoutlib.java.System_Delegate;
22 
23 /**
24  * Delegate implementing the native methods of android.os.SystemClock
25  *
26  * Through the layoutlib_create tool, the original native methods of SystemClock have been replaced
27  * by calls to methods of the same name in this delegate class.
28  *
29  * Because it's a stateless class to start with, there's no need to keep a {@link DelegateManager}
30  * around to map int to instance of the delegate.
31  *
32  */
33 public class SystemClock_Delegate {
34     /**
35      * Returns milliseconds since boot, not counting time spent in deep sleep.
36      * <b>Note:</b> This value may get reset occasionally (before it would
37      * otherwise wrap around).
38      *
39      * @return milliseconds of non-sleep uptime since boot.
40      */
41     @LayoutlibDelegate
uptimeMillis()42     /*package*/ static long uptimeMillis() {
43         return System_Delegate.currentTimeMillis() - System_Delegate.bootTimeMillis();
44     }
45 
46     /**
47      * Returns milliseconds since boot, including time spent in sleep.
48      *
49      * @return elapsed milliseconds since boot.
50      */
51     @LayoutlibDelegate
elapsedRealtime()52     /*package*/ static long elapsedRealtime() {
53         return System_Delegate.currentTimeMillis() - System_Delegate.bootTimeMillis();
54     }
55 
56     /**
57      * Returns nanoseconds since boot, including time spent in sleep.
58      *
59      * @return elapsed nanoseconds since boot.
60      */
61     @LayoutlibDelegate
elapsedRealtimeNanos()62     /*package*/ static long elapsedRealtimeNanos() {
63         return System_Delegate.nanoTime() - System_Delegate.bootTime();
64     }
65 
66     /**
67      * Returns milliseconds running in the current thread.
68      *
69      * @return elapsed milliseconds in the thread
70      */
71     @LayoutlibDelegate
currentThreadTimeMillis()72     /*package*/ static long currentThreadTimeMillis() {
73         return System_Delegate.currentTimeMillis();
74     }
75 
76     /**
77      * Returns microseconds running in the current thread.
78      *
79      * @return elapsed microseconds in the thread
80      *
81      * @hide
82      */
83     @LayoutlibDelegate
currentThreadTimeMicro()84     /*package*/ static long currentThreadTimeMicro() {
85         return System_Delegate.currentTimeMillis() * 1000;
86     }
87 
88     /**
89      * Returns current wall time in  microseconds.
90      *
91      * @return elapsed microseconds in wall time
92      *
93      * @hide
94      */
95     @LayoutlibDelegate
currentTimeMicro()96     /*package*/ static long currentTimeMicro() {
97         return elapsedRealtime() * 1000;
98     }
99 }
100