aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2016-10-07 11:33:22 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2016-10-07 11:33:23 +0000
commitee4c7c48c645eed006bb1055ca71e19d0f398535 (patch)
tree6d8eecd231c959206aca68df1451f7c228e82334
parentd4118f22f609d9a254918923a5503c55b2a6c4dd (diff)
parent676f9f5cbf179043ea6ef4d18517a0922f783836 (diff)
downloadsmali-ee4c7c48c645eed006bb1055ca71e19d0f398535.tar.gz
Merge "Properly implement the art <-> api version map"android-n-mr1-preview-2android-n-mr1-preview-1
-rw-r--r--dexlib2/src/main/java/org/jf/dexlib2/Opcodes.java24
-rw-r--r--dexlib2/src/main/java/org/jf/dexlib2/VersionMap.java36
2 files changed, 47 insertions, 13 deletions
diff --git a/dexlib2/src/main/java/org/jf/dexlib2/Opcodes.java b/dexlib2/src/main/java/org/jf/dexlib2/Opcodes.java
index 17f80132..9f7d128d 100644
--- a/dexlib2/src/main/java/org/jf/dexlib2/Opcodes.java
+++ b/dexlib2/src/main/java/org/jf/dexlib2/Opcodes.java
@@ -39,6 +39,10 @@ import javax.annotation.Nullable;
import java.util.EnumMap;
import java.util.HashMap;
+import static org.jf.dexlib2.VersionMap.NO_VERSION;
+import static org.jf.dexlib2.VersionMap.mapApiToArtVersion;
+import static org.jf.dexlib2.VersionMap.mapArtVersionToApi;
+
public class Opcodes {
/**
@@ -52,12 +56,12 @@ public class Opcodes {
@Nonnull
public static Opcodes forApi(int api) {
- return new Opcodes(api, VersionMap.mapApiToArtVersion(api), false);
+ return new Opcodes(api, NO_VERSION, false);
}
@Nonnull
public static Opcodes forApi(int api, boolean experimental) {
- return new Opcodes(api, VersionMap.mapApiToArtVersion(api), experimental);
+ return new Opcodes(api, NO_VERSION, experimental);
}
@Nonnull
@@ -67,7 +71,7 @@ public class Opcodes {
@Nonnull
public static Opcodes forArtVersion(int artVersion, boolean experimental) {
- return new Opcodes(VersionMap.mapArtVersionToApi(artVersion), artVersion, experimental);
+ return new Opcodes(NO_VERSION, artVersion, experimental);
}
@Deprecated
@@ -81,8 +85,16 @@ public class Opcodes {
}
private Opcodes(int api, int artVersion, boolean experimental) {
- this.api = api;
- this.artVersion = artVersion;
+ if (api >= 21) {
+ this.api = api;
+ this.artVersion = mapApiToArtVersion(api);
+ } else if (artVersion >= 0 && artVersion < 39) {
+ this.api = mapArtVersionToApi(artVersion);
+ this.artVersion = artVersion;
+ } else {
+ this.api = api;
+ this.artVersion = artVersion;
+ }
opcodeValues = new EnumMap<Opcode, Short>(Opcode.class);
opcodesByName = Maps.newHashMap();
@@ -142,6 +154,6 @@ public class Opcodes {
}
public boolean isArt() {
- return artVersion != VersionMap.NO_VERSION;
+ return artVersion != NO_VERSION;
}
}
diff --git a/dexlib2/src/main/java/org/jf/dexlib2/VersionMap.java b/dexlib2/src/main/java/org/jf/dexlib2/VersionMap.java
index 42802bc0..e0e1a6bb 100644
--- a/dexlib2/src/main/java/org/jf/dexlib2/VersionMap.java
+++ b/dexlib2/src/main/java/org/jf/dexlib2/VersionMap.java
@@ -35,16 +35,38 @@ public class VersionMap {
public static final int NO_VERSION = -1;
public static int mapArtVersionToApi(int artVersion) {
- // TODO: implement this
- return 20;
+ if (artVersion >= 79) {
+ return 24;
+ }
+ if (artVersion >= 64) {
+ return 23;
+ }
+ if (artVersion >= 45) {
+ return 22;
+ }
+ if (artVersion >= 39) {
+ return 21;
+ }
+ return 19;
}
public static int mapApiToArtVersion(int api) {
- // TODO: implement this
- if (api < 20) {
- return NO_VERSION;
- } else {
- return 56;
+ switch (api) {
+ case 19:
+ case 20:
+ return 7;
+ case 21:
+ return 39;
+ case 22:
+ return 45;
+ case 23:
+ return 64;
+ case 24:
+ return 79;
+ }
+ if (api > 24) {
+ return 79;
}
+ return NO_VERSION;
}
}