CreateInfo.java revision 5280c911d81a7db5ec8854850bef60d8b0951358
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
17package com.android.tools.layoutlib.create;
18
19import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
20import com.android.tools.layoutlib.java.AutoCloseable;
21import com.android.tools.layoutlib.java.ModifiedUtf8;
22import com.android.tools.layoutlib.java.Charsets;
23import com.android.tools.layoutlib.java.IntegralToString;
24import com.android.tools.layoutlib.java.UnsafeByteSequence;
25
26/**
27 * Describes the work to be done by {@link AsmGenerator}.
28 */
29public 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
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
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
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
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
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
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
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            IntegralToString.class,
116            UnsafeByteSequence.class,
117            ModifiedUtf8.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.AssetManager#newTheme",
129        "android.content.res.AssetManager#deleteTheme",
130        "android.content.res.AssetManager#applyThemeStyle",
131        "android.content.res.TypedArray#getValueAt",
132        "android.graphics.BitmapFactory#finishDecode",
133        "android.os.Handler#sendMessageAtTime",
134        "android.os.HandlerThread#run",
135        "android.os.Build#getString",
136        "android.view.Choreographer#getRefreshRate",
137        "android.view.Display#updateDisplayInfoLocked",
138        "android.view.Display#getWindowManager",
139        "android.view.LayoutInflater#rInflate",
140        "android.view.LayoutInflater#parseInclude",
141        "android.view.View#isInEditMode",
142        "android.view.ViewRootImpl#isInTouchMode",
143        "android.view.WindowManagerGlobal#getWindowManagerService",
144        "android.view.inputmethod.InputMethodManager#getInstance",
145        "android.view.MenuInflater#registerMenu",
146        "com.android.internal.view.menu.MenuBuilder#createNewMenuItem",
147        "com.android.internal.util.XmlUtils#convertValueToInt",
148        "com.android.internal.textservice.ITextServicesManager$Stub#asInterface",
149    };
150
151    /**
152     * The list of classes on which to delegate all native methods.
153     */
154    public final static String[] DELEGATE_CLASS_NATIVES = new String[] {
155        "android.animation.PropertyValuesHolder",
156        "android.graphics.AvoidXfermode",
157        "android.graphics.Bitmap",
158        "android.graphics.BitmapFactory",
159        "android.graphics.BitmapShader",
160        "android.graphics.BlurMaskFilter",
161        "android.graphics.Canvas",
162        "android.graphics.ColorFilter",
163        "android.graphics.ColorMatrixColorFilter",
164        "android.graphics.ComposePathEffect",
165        "android.graphics.ComposeShader",
166        "android.graphics.CornerPathEffect",
167        "android.graphics.DashPathEffect",
168        "android.graphics.DiscretePathEffect",
169        "android.graphics.DrawFilter",
170        "android.graphics.EmbossMaskFilter",
171        "android.graphics.LayerRasterizer",
172        "android.graphics.LightingColorFilter",
173        "android.graphics.LinearGradient",
174        "android.graphics.MaskFilter",
175        "android.graphics.Matrix",
176        "android.graphics.NinePatch",
177        "android.graphics.Paint",
178        "android.graphics.PaintFlagsDrawFilter",
179        "android.graphics.Path",
180        "android.graphics.PathDashPathEffect",
181        "android.graphics.PathEffect",
182        "android.graphics.PixelXorXfermode",
183        "android.graphics.PorterDuffColorFilter",
184        "android.graphics.PorterDuffXfermode",
185        "android.graphics.RadialGradient",
186        "android.graphics.Rasterizer",
187        "android.graphics.Region",
188        "android.graphics.Shader",
189        "android.graphics.SumPathEffect",
190        "android.graphics.SweepGradient",
191        "android.graphics.Typeface",
192        "android.graphics.Xfermode",
193        "android.os.SystemClock",
194        "android.text.AndroidBidi",
195        "android.text.format.Time",
196        "android.util.FloatMath",
197        "android.view.Display",
198        "libcore.icu.ICU",
199    };
200
201    /**
202     * The list of methods to stub out. Each entry must be in the form
203     *  "package.package.OuterClass$InnerClass#MethodName".
204     *  This usage is deprecated. Please use method 'delegates' instead.
205     */
206    private final static String[] OVERRIDDEN_METHODS = new String[] {
207    };
208
209    /**
210     *  The list of classes to rename, must be an even list: the binary FQCN
211     *  of class to replace followed by the new FQCN.
212     */
213    private final static String[] RENAMED_CLASSES =
214        new String[] {
215            "android.os.ServiceManager",                       "android.os._Original_ServiceManager",
216            "android.util.LruCache",                           "android.util._Original_LruCache",
217            "android.view.SurfaceView",                        "android.view._Original_SurfaceView",
218            "android.view.accessibility.AccessibilityManager", "android.view.accessibility._Original_AccessibilityManager",
219            "android.webkit.WebView",                          "android.webkit._Original_WebView",
220            "com.android.internal.policy.PolicyManager",       "com.android.internal.policy._Original_PolicyManager",
221        };
222
223    /**
224     * The list of class references to update, must be an even list: the binary
225     * FQCN of class to replace followed by the new FQCN. The classes to
226     * replace are to be excluded from the output.
227     */
228    private final static String[] JAVA_PKG_CLASSES =
229        new String[] {
230            "java.lang.AutoCloseable",                         "com.android.tools.layoutlib.java.AutoCloseable",
231            "java.nio.charset.ModifiedUtf8",                   "com.android.tools.layoutlib.java.ModifiedUtf8",
232            "java.nio.charset.Charsets",                       "com.android.tools.layoutlib.java.Charsets",
233            "java.lang.IntegralToString",                      "com.android.tools.layoutlib.java.IntegralToString",
234            "java.lang.UnsafeByteSequence",                    "com.android.tools.layoutlib.java.UnsafeByteSequence",
235        };
236
237    /**
238     * List of classes for which the methods returning them should be deleted.
239     * The array contains a list of null terminated section starting with the name of the class
240     * to rename in which the methods are deleted, followed by a list of return types identifying
241     * the methods to delete.
242     */
243    private final static String[] DELETE_RETURNS =
244        new String[] {
245            null };                         // separator, for next class/methods list.
246}
247
248