Added API level check to adding methods to vtable.

This commit is contained in:
Izzat Bahadirov 2013-04-29 16:09:36 -04:00
parent 2206c7638b
commit 64898161b3
2 changed files with 13 additions and 7 deletions

View File

@ -55,14 +55,15 @@ public class ClassPath {
@Nonnull private final TypeProto unknownClass;
@Nonnull private DexFile[] dexFiles;
@Nonnull private HashMap<String, TypeProto> loadedClasses = Maps.newHashMap();
@Nonnull private int api;
/**
* Creates a new ClassPath instance that can load classes from the given dex files
*
* @param classPath An array of DexFile objects. When loading a class, these dex files will be searched in order
*/
public ClassPath(DexFile... classPath) throws IOException {
this(classPath, true);
public ClassPath(int api, DexFile... classPath) throws IOException {
this(api, classPath, true);
}
/**
@ -70,11 +71,11 @@ public class ClassPath {
*
* @param classPath An iterable of DexFile objects. When loading a class, these dex files will be searched in order
*/
public ClassPath(Iterable<DexFile> classPath) {
this(Iterables.toArray(classPath, DexFile.class), false);
public ClassPath(int api, Iterable<DexFile> classPath) {
this(api, Iterables.toArray(classPath, DexFile.class), false);
}
private ClassPath(@Nonnull DexFile[] classPath, boolean copyArray) {
private ClassPath(int api, @Nonnull DexFile[] classPath, boolean copyArray) {
if (copyArray) {
dexFiles = new DexFile[classPath.length+1];
System.arraycopy(classPath, 0, dexFiles, 0, classPath.length);
@ -86,6 +87,7 @@ public class ClassPath {
unknownClass = new UnknownClassProto(this);
loadedClasses.put(unknownClass.getType(), unknownClass);
this.api = api;
loadPrimitiveType("Z");
loadPrimitiveType("B");
@ -150,6 +152,10 @@ public class ClassPath {
return unknownClass;
}
public int getApi() {
return api;
}
@Nonnull
public static ClassPath fromClassPath(Iterable<String> classPathDirs, Iterable<String> classPath, DexFile dexFile,
int api) {
@ -159,7 +165,7 @@ public class ClassPath {
dexFiles.add(loadClassPathEntry(classPathDirs, classPathEntry, api));
}
dexFiles.add(dexFile);
return new ClassPath(dexFiles);
return new ClassPath(api, dexFiles);
}
private static final Pattern dalvikCacheOdexPattern = Pattern.compile("@([^@]+)@classes.dex$");

View File

@ -534,7 +534,7 @@ public class ClassProto implements TypeProto {
for (int i=0; i<vtable.size(); i++) {
Method superMethod = vtable.get(i);
if (methodSignaturesMatch(superMethod, virtualMethod)) {
if (canAccess(superMethod)) {
if (classPath.getApi() < 17 || canAccess(superMethod)) {
found = true;
vtable.set(i, virtualMethod);
break;