diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2014-12-04 07:00:14 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-12-04 07:00:14 +0000 |
commit | 302a7cc13a02863ef2e9d9102df761e92150de65 (patch) | |
tree | 419bf0aa94d2f5e2ebfd887e7b518c2b2100bab1 /tools/layoutlib/create | |
parent | b2ded18a84b3b23a76b462644dcd24b3c33f5234 (diff) | |
parent | 4628d51a0d01641ca7fe2cf8403ad551ea6f50ce (diff) | |
download | frameworks_base-302a7cc13a02863ef2e9d9102df761e92150de65.zip frameworks_base-302a7cc13a02863ef2e9d9102df761e92150de65.tar.gz frameworks_base-302a7cc13a02863ef2e9d9102df761e92150de65.tar.bz2 |
am 4628d51a: am 141c7614: Merge "Fix AnalogClock rendering" into lmp-dev
* commit '4628d51a0d01641ca7fe2cf8403ad551ea6f50ce':
Fix AnalogClock rendering
Diffstat (limited to 'tools/layoutlib/create')
3 files changed, 99 insertions, 31 deletions
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java index 4e6f456..5a979e8 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java @@ -21,6 +21,7 @@ import com.android.tools.layoutlib.java.AutoCloseable; import com.android.tools.layoutlib.java.Charsets; import com.android.tools.layoutlib.java.IntegralToString; import com.android.tools.layoutlib.java.Objects; +import com.android.tools.layoutlib.java.System_Delegate; import com.android.tools.layoutlib.java.UnsafeByteSequence; import java.util.Arrays; @@ -131,6 +132,7 @@ public final class CreateInfo implements ICreateInfo { IntegralToString.class, UnsafeByteSequence.class, Charsets.class, + System_Delegate.class, }; /** @@ -170,7 +172,11 @@ public final class CreateInfo implements ICreateInfo { "com.android.internal.view.menu.MenuBuilder#createNewMenuItem", "com.android.internal.util.XmlUtils#convertValueToInt", "com.android.internal.textservice.ITextServicesManager$Stub#asInterface", - "dalvik.system.VMRuntime#newUnpaddedArray" + "dalvik.system.VMRuntime#newUnpaddedArray", + "libcore.io.MemoryMappedFile#mmapRO", + "libcore.io.MemoryMappedFile#close", + "libcore.io.MemoryMappedFile#bigEndianIterator", + "libcore.util.ZoneInfo$WallTime#createGregorianCalendar", }; /** @@ -261,6 +267,7 @@ public final class CreateInfo implements ICreateInfo { "java.nio.charset.Charsets", "com.android.tools.layoutlib.java.Charsets", "java.lang.IntegralToString", "com.android.tools.layoutlib.java.IntegralToString", "java.lang.UnsafeByteSequence", "com.android.tools.layoutlib.java.UnsafeByteSequence", + "java.nio.charset.StandardCharsets", "com.android.tools.layoutlib.java.Charsets", }; private final static String[] EXCLUDED_CLASSES = diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ReplaceMethodCallsAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ReplaceMethodCallsAdapter.java index 9c6fbac..1e2623f 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ReplaceMethodCallsAdapter.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/ReplaceMethodCallsAdapter.java @@ -16,6 +16,8 @@ package com.android.tools.layoutlib.create; +import com.android.tools.layoutlib.java.System_Delegate; + import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; @@ -47,24 +49,25 @@ public class ReplaceMethodCallsAdapter extends ClassVisitor { private static final String ANDROID_LOCALE_CLASS = "com/android/layoutlib/bridge/android/AndroidLocale"; - private static final String JAVA_LOCALE_CLASS = "java/util/Locale"; + private static final String JAVA_LOCALE_CLASS = Type.getInternalName(java.util.Locale.class); private static final Type STRING = Type.getType(String.class); + private static final String JAVA_LANG_SYSTEM = Type.getInternalName(System.class); + // Static initialization block to initialize METHOD_REPLACERS. static { // Case 1: java.lang.System.arraycopy() METHOD_REPLACERS.add(new MethodReplacer() { @Override public boolean isNeeded(String owner, String name, String desc) { - return "java/lang/System".equals(owner) && "arraycopy".equals(name) && + return JAVA_LANG_SYSTEM.equals(owner) && "arraycopy".equals(name) && ARRAYCOPY_DESCRIPTORS.contains(desc); } @Override - public void replace(int[] opcode, String[] methodInformation) { - assert methodInformation.length == 3 && isNeeded(methodInformation[0], methodInformation[1], methodInformation[2]) - && opcode.length == 1; - methodInformation[2] = "(Ljava/lang/Object;ILjava/lang/Object;II)V"; + public void replace(MethodInformation mi) { + assert isNeeded(mi.owner, mi.name, mi.desc); + mi.desc = "(Ljava/lang/Object;ILjava/lang/Object;II)V"; } }); @@ -80,12 +83,11 @@ public class ReplaceMethodCallsAdapter extends ClassVisitor { } @Override - public void replace(int[] opcode, String[] methodInformation) { - assert methodInformation.length == 3 && isNeeded(methodInformation[0], methodInformation[1], methodInformation[2]) - && opcode.length == 1; - opcode[0] = Opcodes.INVOKESTATIC; - methodInformation[0] = ANDROID_LOCALE_CLASS; - methodInformation[2] = LOCALE_TO_STRING; + public void replace(MethodInformation mi) { + assert isNeeded(mi.owner, mi.name, mi.desc); + mi.opcode = Opcodes.INVOKESTATIC; + mi.owner = ANDROID_LOCALE_CLASS; + mi.desc = LOCALE_TO_STRING; } }); @@ -104,10 +106,27 @@ public class ReplaceMethodCallsAdapter extends ClassVisitor { } @Override - public void replace(int[] opcode, String[] methodInformation) { - assert methodInformation.length == 3 && isNeeded(methodInformation[0], methodInformation[1], methodInformation[2]) - && opcode.length == 1; - methodInformation[0] = ANDROID_LOCALE_CLASS; + public void replace(MethodInformation mi) { + assert isNeeded(mi.owner, mi.name, mi.desc); + mi.owner = ANDROID_LOCALE_CLASS; + } + }); + + // Case 4: java.lang.System.log?() + METHOD_REPLACERS.add(new MethodReplacer() { + @Override + public boolean isNeeded(String owner, String name, String desc) { + return JAVA_LANG_SYSTEM.equals(owner) && name.length() == 4 + && name.startsWith("log"); + } + + @Override + public void replace(MethodInformation mi) { + assert isNeeded(mi.owner, mi.name, mi.desc); + assert mi.desc.equals("(Ljava/lang/String;Ljava/lang/Throwable;)V") + || mi.desc.equals("(Ljava/lang/String;)V"); + mi.name = "log"; + mi.owner = Type.getInternalName(System_Delegate.class); } }); } @@ -141,13 +160,12 @@ public class ReplaceMethodCallsAdapter extends ClassVisitor { public void visitMethodInsn(int opcode, String owner, String name, String desc) { for (MethodReplacer replacer : METHOD_REPLACERS) { if (replacer.isNeeded(owner, name, desc)) { - String[] methodInformation = {owner, name, desc}; - int[] opcodeOut = {opcode}; - replacer.replace(opcodeOut, methodInformation); - opcode = opcodeOut[0]; - owner = methodInformation[0]; - name = methodInformation[1]; - desc = methodInformation[2]; + MethodInformation mi = new MethodInformation(opcode, owner, name, desc); + replacer.replace(mi); + opcode = mi.opcode; + owner = mi.owner; + name = mi.name; + desc = mi.desc; break; } } @@ -155,19 +173,28 @@ public class ReplaceMethodCallsAdapter extends ClassVisitor { } } + private static class MethodInformation { + public int opcode; + public String owner; + public String name; + public String desc; + + public MethodInformation(int opcode, String owner, String name, String desc) { + this.opcode = opcode; + this.owner = owner; + this.name = name; + this.desc = desc; + } + } + private interface MethodReplacer { public boolean isNeeded(String owner, String name, String desc); /** - * This method must update the arrays with the new values of the method attributes - + * Updates the MethodInformation with the new values of the method attributes - * opcode, owner, name and desc. - * @param opcode This array should contain the original value of the opcode. The value is - * modified by the method if needed. The size of the array must be 1. * - * @param methodInformation This array should contain the original values of the method - * attributes - owner, name and desc in that order. The values - * may be modified as needed. The size of the array must be 3. */ - public void replace(int[] opcode, String[] methodInformation); + public void replace(MethodInformation mi); } } diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/java/System_Delegate.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/java/System_Delegate.java new file mode 100644 index 0000000..613c8d9 --- /dev/null +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/java/System_Delegate.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.tools.layoutlib.java; + +import com.android.tools.layoutlib.create.ReplaceMethodCallsAdapter; + +/** + * Provides dummy implementation of methods that don't exist on the host VM. + * + * @see ReplaceMethodCallsAdapter + */ +public class System_Delegate { + public static void log(String message) { + // ignore. + } + + public static void log(String message, Throwable th) { + // ignore. + } +} |