1 /* 2 * Copyright 2015, Google LLC 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * Neither the name of Google LLC nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 package com.android.tools.smali.dexlib2; 32 33 public class VersionMap { 34 public static final int NO_VERSION = -1; 35 mapDexVersionToApi(int dexVersion)36 public static int mapDexVersionToApi(int dexVersion) { 37 switch (dexVersion) { 38 case 35: 39 return 23; 40 case 37: 41 return 25; 42 case 38: 43 return 27; 44 case 39: 45 return 28; 46 case 40: 47 return 34; 48 case 41: 49 return 35; 50 default: 51 return NO_VERSION; 52 } 53 } 54 mapApiToDexVersion(int api)55 public static int mapApiToDexVersion(int api) { 56 if (api <= 23) { // Android M/6 57 return 35; 58 } 59 switch (api) { 60 case 24: // Android N/7 61 case 25: // Android N/7.1 62 return 37; 63 case 26: // Android O/8 64 case 27: // Android O/8.1 65 return 38; 66 case 28: // Android P/9 67 return 39; 68 case 29: // Android Q/10 69 case 30: // Android R/11 70 case 31: // Android S/12 71 case 32: // Android S/12.1 72 case 33: // Android T/13 73 case 34: // Android U/14 74 return 40; 75 case 35: // Android V/15 76 return 41; 77 } 78 return NO_VERSION; 79 } 80 mapArtVersionToApi(int artVersion)81 public static int mapArtVersionToApi(int artVersion) { 82 if (artVersion >= 170) { 83 return 29; 84 } 85 if (artVersion >= 138) { 86 return 28; 87 } 88 if (artVersion >= 131) { 89 return 27; 90 } 91 if (artVersion >= 124) { 92 return 26; 93 } 94 if (artVersion >= 79) { 95 return 24; 96 } 97 if (artVersion >= 64) { 98 return 23; 99 } 100 if (artVersion >= 45) { 101 return 22; 102 } 103 if (artVersion >= 39) { 104 return 21; 105 } 106 return 19; 107 } 108 mapApiToArtVersion(int api)109 public static int mapApiToArtVersion(int api) { 110 if (api < 19) { 111 return NO_VERSION; 112 } 113 114 switch (api) { 115 case 19: 116 case 20: 117 return 7; 118 case 21: 119 return 39; 120 case 22: 121 return 45; 122 case 23: 123 return 64; 124 case 24: 125 case 25: 126 return 79; 127 case 26: 128 return 124; 129 case 27: 130 return 131; 131 case 28: 132 return 138; 133 case 29: 134 return 170; 135 default: 136 // 178 is the current version in the master branch of AOSP as of 2020-02-02 137 return 178; 138 } 139 } 140 } 141