• 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.internal.lang;
17 
18 import com.android.layoutlib.bridge.android.BridgeContext;
19 
20 import java.util.concurrent.TimeUnit;
21 
22 import static com.android.layoutlib.bridge.impl.RenderAction.getCurrentContext;
23 
24 /**
25  * Provides alternative implementations 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 {
log(String message)32     public static void log(String message) {
33         // ignore.
34     }
35 
log(String message, Throwable th)36     public static void log(String message, Throwable th) {
37         // ignore.
38     }
39 
setNanosTime(long nanos)40     public static void setNanosTime(long nanos) {
41         BridgeContext context = getCurrentContext();
42         if (context != null) {
43             context.getSessionInteractiveData().setNanosTime(nanos);
44         }
45     }
46 
setBootTimeNanos(long nanos)47     public static void setBootTimeNanos(long nanos) {
48         BridgeContext context = getCurrentContext();
49         if (context != null) {
50             context.getSessionInteractiveData().setBootNanosTime(nanos);
51         }
52     }
53 
nanoTime()54     public static long nanoTime() {
55         BridgeContext context = getCurrentContext();
56         if (context != null) {
57             return context.getSessionInteractiveData().getNanosTime();
58         }
59         return 0;
60     }
61 
currentTimeMillis()62     public static long currentTimeMillis() {
63         return TimeUnit.NANOSECONDS.toMillis(nanoTime());
64     }
65 
bootTime()66     public static long bootTime() {
67         BridgeContext context = getCurrentContext();
68         if (context != null) {
69             return context.getSessionInteractiveData().getBootNanosTime();
70         }
71         return 0;
72     }
73 
bootTimeMillis()74     public static long bootTimeMillis() {
75         return TimeUnit.NANOSECONDS.toMillis(bootTime());
76     }
77 
78     // This is no-op since layoutlib infrastructure loads all the native libraries.
loadLibrary(String libname)79     public static void loadLibrary(String libname) {
80         // ignore.
81     }
82 }
83