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