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