• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.create;
18 
19 import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
20 import com.android.tools.layoutlib.java.AutoCloseable;
21 import com.android.tools.layoutlib.java.Charsets;
22 import com.android.tools.layoutlib.java.IntegralToString;
23 import com.android.tools.layoutlib.java.Objects;
24 import com.android.tools.layoutlib.java.UnsafeByteSequence;
25 
26 /**
27  * Describes the work to be done by {@link AsmGenerator}.
28  */
29 public final class CreateInfo implements ICreateInfo {
30 
31     /**
32      * Returns the list of class from layoutlib_create to inject in layoutlib.
33      * The list can be empty but must not be null.
34      */
35     @Override
getInjectedClasses()36     public Class<?>[] getInjectedClasses() {
37         return INJECTED_CLASSES;
38     }
39 
40     /**
41      * Returns the list of methods to rewrite as delegates.
42      * The list can be empty but must not be null.
43      */
44     @Override
getDelegateMethods()45     public String[] getDelegateMethods() {
46         return DELEGATE_METHODS;
47     }
48 
49     /**
50      * Returns the list of classes on which to delegate all native methods.
51      * The list can be empty but must not be null.
52      */
53     @Override
getDelegateClassNatives()54     public String[] getDelegateClassNatives() {
55         return DELEGATE_CLASS_NATIVES;
56     }
57 
58     /**
59      * Returns The list of methods to stub out. Each entry must be in the form
60      * "package.package.OuterClass$InnerClass#MethodName".
61      * The list can be empty but must not be null.
62      * <p/>
63      * This usage is deprecated. Please use method 'delegates' instead.
64      */
65     @Override
getOverriddenMethods()66     public String[] getOverriddenMethods() {
67         return OVERRIDDEN_METHODS;
68     }
69 
70     /**
71      * Returns the list of classes to rename, must be an even list: the binary FQCN
72      * of class to replace followed by the new FQCN.
73      * The list can be empty but must not be null.
74      */
75     @Override
getRenamedClasses()76     public String[] getRenamedClasses() {
77         return RENAMED_CLASSES;
78     }
79 
80     /**
81      * Returns the list of classes for which the methods returning them should be deleted.
82      * The array contains a list of null terminated section starting with the name of the class
83      * to rename in which the methods are deleted, followed by a list of return types identifying
84      * the methods to delete.
85      * The list can be empty but must not be null.
86      */
87     @Override
getDeleteReturns()88     public String[] getDeleteReturns() {
89         return DELETE_RETURNS;
90     }
91 
92     /**
93      * Returns the list of classes to refactor, must be an even list: the binary FQCN of class to
94      * replace followed by the new FQCN. All references to the old class should be updated to the
95      * new class. The list can be empty but must not be null.
96      */
97     @Override
getJavaPkgClasses()98     public String[] getJavaPkgClasses() {
99       return JAVA_PKG_CLASSES;
100     }
101     //-----
102 
103     /**
104      * The list of class from layoutlib_create to inject in layoutlib.
105      */
106     private final static Class<?>[] INJECTED_CLASSES = new Class<?>[] {
107             OverrideMethod.class,
108             MethodListener.class,
109             MethodAdapter.class,
110             ICreateInfo.class,
111             CreateInfo.class,
112             LayoutlibDelegate.class,
113             /* Java package classes */
114             AutoCloseable.class,
115             Objects.class,
116             IntegralToString.class,
117             UnsafeByteSequence.class,
118             Charsets.class,
119         };
120 
121     /**
122      * The list of methods to rewrite as delegates.
123      */
124     public final static String[] DELEGATE_METHODS = new String[] {
125         "android.app.Fragment#instantiate", //(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)Landroid/app/Fragment;",
126         "android.content.res.Resources$Theme#obtainStyledAttributes",
127         "android.content.res.Resources$Theme#resolveAttribute",
128         "android.content.res.TypedArray#getValueAt",
129         "android.graphics.BitmapFactory#finishDecode",
130         "android.os.Handler#sendMessageAtTime",
131         "android.os.HandlerThread#run",
132         "android.os.Build#getString",
133         "android.text.format.DateFormat#is24HourFormat",
134         "android.view.Choreographer#getRefreshRate",
135         "android.view.Display#updateDisplayInfoLocked",
136         "android.view.LayoutInflater#rInflate",
137         "android.view.LayoutInflater#parseInclude",
138         "android.view.View#isInEditMode",
139         "android.view.ViewRootImpl#isInTouchMode",
140         "android.view.WindowManagerGlobal#getWindowManagerService",
141         "android.view.inputmethod.InputMethodManager#getInstance",
142         "com.android.internal.util.XmlUtils#convertValueToInt",
143         "com.android.internal.textservice.ITextServicesManager$Stub#asInterface",
144     };
145 
146     /**
147      * The list of classes on which to delegate all native methods.
148      */
149     public final static String[] DELEGATE_CLASS_NATIVES = new String[] {
150         "android.animation.PropertyValuesHolder",
151         "android.graphics.AvoidXfermode",
152         "android.graphics.Bitmap",
153         "android.graphics.BitmapFactory",
154         "android.graphics.BitmapShader",
155         "android.graphics.BlurMaskFilter",
156         "android.graphics.Canvas",
157         "android.graphics.ColorFilter",
158         "android.graphics.ColorMatrixColorFilter",
159         "android.graphics.ComposePathEffect",
160         "android.graphics.ComposeShader",
161         "android.graphics.CornerPathEffect",
162         "android.graphics.DashPathEffect",
163         "android.graphics.DiscretePathEffect",
164         "android.graphics.DrawFilter",
165         "android.graphics.EmbossMaskFilter",
166         "android.graphics.LayerRasterizer",
167         "android.graphics.LightingColorFilter",
168         "android.graphics.LinearGradient",
169         "android.graphics.MaskFilter",
170         "android.graphics.Matrix",
171         "android.graphics.NinePatch",
172         "android.graphics.Paint",
173         "android.graphics.PaintFlagsDrawFilter",
174         "android.graphics.Path",
175         "android.graphics.PathDashPathEffect",
176         "android.graphics.PathEffect",
177         "android.graphics.PixelXorXfermode",
178         "android.graphics.PorterDuffColorFilter",
179         "android.graphics.PorterDuffXfermode",
180         "android.graphics.RadialGradient",
181         "android.graphics.Rasterizer",
182         "android.graphics.Region",
183         "android.graphics.Shader",
184         "android.graphics.SumPathEffect",
185         "android.graphics.SweepGradient",
186         "android.graphics.Typeface",
187         "android.graphics.Xfermode",
188         "android.os.SystemClock",
189         "android.text.AndroidBidi",
190         "android.text.format.Time",
191         "android.util.FloatMath",
192         "android.view.Display",
193         "libcore.icu.DateIntervalFormat",
194         "libcore.icu.ICU",
195     };
196 
197     /**
198      * The list of methods to stub out. Each entry must be in the form
199      *  "package.package.OuterClass$InnerClass#MethodName".
200      *  This usage is deprecated. Please use method 'delegates' instead.
201      */
202     private final static String[] OVERRIDDEN_METHODS = new String[] {
203     };
204 
205     /**
206      *  The list of classes to rename, must be an even list: the binary FQCN
207      *  of class to replace followed by the new FQCN.
208      */
209     private final static String[] RENAMED_CLASSES =
210         new String[] {
211             "android.os.ServiceManager",                       "android.os._Original_ServiceManager",
212             "android.util.LruCache",                           "android.util._Original_LruCache",
213             "android.view.SurfaceView",                        "android.view._Original_SurfaceView",
214             "android.view.accessibility.AccessibilityManager", "android.view.accessibility._Original_AccessibilityManager",
215             "android.webkit.WebView",                          "android.webkit._Original_WebView",
216             "com.android.internal.policy.PolicyManager",       "com.android.internal.policy._Original_PolicyManager",
217         };
218 
219     /**
220      * The list of class references to update, must be an even list: the binary
221      * FQCN of class to replace followed by the new FQCN. The classes to
222      * replace are to be excluded from the output.
223      */
224     private final static String[] JAVA_PKG_CLASSES =
225         new String[] {
226             "java.lang.AutoCloseable",                         "com.android.tools.layoutlib.java.AutoCloseable",
227             "java.util.Objects",                               "com.android.tools.layoutlib.java.Objects",
228             "java.nio.charset.Charsets",                       "com.android.tools.layoutlib.java.Charsets",
229             "java.lang.IntegralToString",                      "com.android.tools.layoutlib.java.IntegralToString",
230             "java.lang.UnsafeByteSequence",                    "com.android.tools.layoutlib.java.UnsafeByteSequence",
231         };
232 
233     /**
234      * List of classes for which the methods returning them should be deleted.
235      * The array contains a list of null terminated section starting with the name of the class
236      * to rename in which the methods are deleted, followed by a list of return types identifying
237      * the methods to delete.
238      */
239     private final static String[] DELETE_RETURNS =
240         new String[] {
241             null };                         // separator, for next class/methods list.
242 }
243 
244