summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib/create/src/com/android
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2014-11-21 00:53:41 +0000
committerDeepanshu Gupta <deepanshu@google.com>2014-11-26 12:03:39 +0000
commit17a6170c62e6f74f2881623a9c16f0b6fea54721 (patch)
tree9b00a9ffbe17fc54f270ddb8d768d2f0e61a4fc8 /tools/layoutlib/create/src/com/android
parentcb09bc45c58740af953874f9915306d351fc3d9d (diff)
downloadframeworks_base-17a6170c62e6f74f2881623a9c16f0b6fea54721.zip
frameworks_base-17a6170c62e6f74f2881623a9c16f0b6fea54721.tar.gz
frameworks_base-17a6170c62e6f74f2881623a9c16f0b6fea54721.tar.bz2
Fix AnalogClock rendering
1. Change calls to java.lang.System.log* since they don't exist on the host. 2. Clean up method rewrite mechanism in ReplaceMethodCallsAdapter. 3. Stub out creation of uninitialized GregorianCalendar. 4. Memory map the time zone data base file and provide a custom implementation of BufferIterator for use by ZoneInfoDB 5. Delete unused Time_Delegate Also fixed a comment in BridgeAssetManager and an error message in FontFamily_Delegate. Bug: http://b.android.com/79160 Change-Id: Iae5ef65678f0e6c7c5af520c45bd15980ce3fa55
Diffstat (limited to 'tools/layoutlib/create/src/com/android')
-rw-r--r--tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java9
-rw-r--r--tools/layoutlib/create/src/com/android/tools/layoutlib/create/ReplaceMethodCallsAdapter.java87
-rw-r--r--tools/layoutlib/create/src/com/android/tools/layoutlib/java/System_Delegate.java34
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 1f11ac0..500c338 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,
};
/**
@@ -171,7 +173,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",
};
/**
@@ -262,6 +268,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.
+ }
+}