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