• 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 
17 package com.android.tools.layoutlib.java;
18 
19 import com.android.tools.layoutlib.create.ReplaceMethodCallsAdapter;
20 
21 import java.util.concurrent.TimeUnit;
22 import java.util.concurrent.atomic.AtomicLong;
23 
24 /**
25  * Provides dummy implementation of methods that don't exist on the host VM.
26  * This also providers a time control that allows to set a specific system time.
27  *
28  * @see ReplaceMethodCallsAdapter
29  */
30 @SuppressWarnings("unused")
31 public class System_Delegate {
32     // Current system time
33     private static AtomicLong mNanosTime = new AtomicLong(System.nanoTime());
34     // Time that the system booted up in nanos
35     private static AtomicLong mBootNanosTime = new AtomicLong(System.nanoTime());
36 
log(String message)37     public static void log(String message) {
38         // ignore.
39     }
40 
log(String message, Throwable th)41     public static void log(String message, Throwable th) {
42         // ignore.
43     }
44 
setNanosTime(long nanos)45     public static void setNanosTime(long nanos) {
46         mNanosTime.set(nanos);
47     }
48 
setBootTimeNanos(long nanos)49     public static void setBootTimeNanos(long nanos) {
50         mBootNanosTime.set(nanos);
51     }
52 
nanoTime()53     public static long nanoTime() {
54         return mNanosTime.get();
55     }
56 
currentTimeMillis()57     public static long currentTimeMillis() {
58         return TimeUnit.NANOSECONDS.toMillis(mNanosTime.get());
59     }
60 
bootTime()61     public static long bootTime() {
62         return mBootNanosTime.get();
63     }
64 
bootTimeMillis()65     public static long bootTimeMillis() {
66         return TimeUnit.NANOSECONDS.toMillis(mBootNanosTime.get());
67     }
68 }
69