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, not counting time spent in deep sleep. 58 * 59 * @return nanoseconds of non-sleep uptime since boot. 60 */ 61 @LayoutlibDelegate uptimeNanos()62 /*package*/ static long uptimeNanos() { 63 return System_Delegate.nanoTime() - System_Delegate.bootTime(); 64 } 65 66 /** 67 * Returns nanoseconds since boot, including time spent in sleep. 68 * 69 * @return elapsed nanoseconds since boot. 70 */ 71 @LayoutlibDelegate elapsedRealtimeNanos()72 /*package*/ static long elapsedRealtimeNanos() { 73 return System_Delegate.nanoTime() - System_Delegate.bootTime(); 74 } 75 76 /** 77 * Returns milliseconds running in the current thread. 78 * 79 * @return elapsed milliseconds in the thread 80 */ 81 @LayoutlibDelegate currentThreadTimeMillis()82 /*package*/ static long currentThreadTimeMillis() { 83 return System_Delegate.currentTimeMillis(); 84 } 85 86 /** 87 * Returns microseconds running in the current thread. 88 * 89 * @return elapsed microseconds in the thread 90 * 91 * @hide 92 */ 93 @LayoutlibDelegate currentThreadTimeMicro()94 /*package*/ static long currentThreadTimeMicro() { 95 return System_Delegate.currentTimeMillis() * 1000; 96 } 97 98 /** 99 * Returns current wall time in microseconds. 100 * 101 * @return elapsed microseconds in wall time 102 * 103 * @hide 104 */ 105 @LayoutlibDelegate currentTimeMicro()106 /*package*/ static long currentTimeMicro() { 107 return elapsedRealtime() * 1000; 108 } 109 } 110