@Test public void testGetMinSdkVersionForValidCodename() throws Exception { assertEquals(1, ApkUtils.getMinSdkVersionForCodename("AAAA")); assertEquals(2, ApkUtils.getMinSdkVersionForCodename("CUPCAKE")); assertEquals(7, ApkUtils.getMinSdkVersionForCodename("FROYO")); assertEquals(23, ApkUtils.getMinSdkVersionForCodename("N")); assertEquals(23, ApkUtils.getMinSdkVersionForCodename("NMR1")); assertEquals(25, ApkUtils.getMinSdkVersionForCodename("OMG")); assertEquals(27, ApkUtils.getMinSdkVersionForCodename("QQQ")); }
static int getMinSdkVersionForCodename(String codename) throws CodenameMinSdkVersionException { char firstChar = codename.isEmpty() ? ' ' : codename.charAt(0); if ((firstChar >= 'A') && (firstChar <= 'Z')) { Pair<Character, Integer>[] sortedCodenamesFirstCharToApiLevel = CodenamesLazyInitializer.SORTED_CODENAMES_FIRST_CHAR_TO_API_LEVEL; int searchResult = Arrays.binarySearch( sortedCodenamesFirstCharToApiLevel, Pair.of(firstChar, null), CodenamesLazyInitializer.CODENAME_FIRST_CHAR_COMPARATOR); if (searchResult >= 0) { return sortedCodenamesFirstCharToApiLevel[searchResult].getSecond(); } int insertionIndex = -1 - searchResult; if (insertionIndex == 0) { return 1; } else { Pair<Character, Integer> newestOlderCodenameMapping = sortedCodenamesFirstCharToApiLevel[insertionIndex - 1]; char newestOlderCodenameFirstChar = newestOlderCodenameMapping.getFirst(); int newestOlderCodenameApiLevel = newestOlderCodenameMapping.getSecond(); return newestOlderCodenameApiLevel + (firstChar - newestOlderCodenameFirstChar); } } throw new CodenameMinSdkVersionException( "Unable to determine APK's minimum supported Android platform version" + " : Unsupported codename in " + ANDROID_MANIFEST_ZIP_ENTRY_NAME + "'s minSdkVersion: \"" + codename + "\"", codename); }
ApkUtils { static int getMinSdkVersionForCodename(String codename) throws CodenameMinSdkVersionException { char firstChar = codename.isEmpty() ? ' ' : codename.charAt(0); if ((firstChar >= 'A') && (firstChar <= 'Z')) { Pair<Character, Integer>[] sortedCodenamesFirstCharToApiLevel = CodenamesLazyInitializer.SORTED_CODENAMES_FIRST_CHAR_TO_API_LEVEL; int searchResult = Arrays.binarySearch( sortedCodenamesFirstCharToApiLevel, Pair.of(firstChar, null), CodenamesLazyInitializer.CODENAME_FIRST_CHAR_COMPARATOR); if (searchResult >= 0) { return sortedCodenamesFirstCharToApiLevel[searchResult].getSecond(); } int insertionIndex = -1 - searchResult; if (insertionIndex == 0) { return 1; } else { Pair<Character, Integer> newestOlderCodenameMapping = sortedCodenamesFirstCharToApiLevel[insertionIndex - 1]; char newestOlderCodenameFirstChar = newestOlderCodenameMapping.getFirst(); int newestOlderCodenameApiLevel = newestOlderCodenameMapping.getSecond(); return newestOlderCodenameApiLevel + (firstChar - newestOlderCodenameFirstChar); } } throw new CodenameMinSdkVersionException( "Unable to determine APK's minimum supported Android platform version" + " : Unsupported codename in " + ANDROID_MANIFEST_ZIP_ENTRY_NAME + "'s minSdkVersion: \"" + codename + "\"", codename); } }
ApkUtils { static int getMinSdkVersionForCodename(String codename) throws CodenameMinSdkVersionException { char firstChar = codename.isEmpty() ? ' ' : codename.charAt(0); if ((firstChar >= 'A') && (firstChar <= 'Z')) { Pair<Character, Integer>[] sortedCodenamesFirstCharToApiLevel = CodenamesLazyInitializer.SORTED_CODENAMES_FIRST_CHAR_TO_API_LEVEL; int searchResult = Arrays.binarySearch( sortedCodenamesFirstCharToApiLevel, Pair.of(firstChar, null), CodenamesLazyInitializer.CODENAME_FIRST_CHAR_COMPARATOR); if (searchResult >= 0) { return sortedCodenamesFirstCharToApiLevel[searchResult].getSecond(); } int insertionIndex = -1 - searchResult; if (insertionIndex == 0) { return 1; } else { Pair<Character, Integer> newestOlderCodenameMapping = sortedCodenamesFirstCharToApiLevel[insertionIndex - 1]; char newestOlderCodenameFirstChar = newestOlderCodenameMapping.getFirst(); int newestOlderCodenameApiLevel = newestOlderCodenameMapping.getSecond(); return newestOlderCodenameApiLevel + (firstChar - newestOlderCodenameFirstChar); } } throw new CodenameMinSdkVersionException( "Unable to determine APK's minimum supported Android platform version" + " : Unsupported codename in " + ANDROID_MANIFEST_ZIP_ENTRY_NAME + "'s minSdkVersion: \"" + codename + "\"", codename); } private  ApkUtils(); }
ApkUtils { static int getMinSdkVersionForCodename(String codename) throws CodenameMinSdkVersionException { char firstChar = codename.isEmpty() ? ' ' : codename.charAt(0); if ((firstChar >= 'A') && (firstChar <= 'Z')) { Pair<Character, Integer>[] sortedCodenamesFirstCharToApiLevel = CodenamesLazyInitializer.SORTED_CODENAMES_FIRST_CHAR_TO_API_LEVEL; int searchResult = Arrays.binarySearch( sortedCodenamesFirstCharToApiLevel, Pair.of(firstChar, null), CodenamesLazyInitializer.CODENAME_FIRST_CHAR_COMPARATOR); if (searchResult >= 0) { return sortedCodenamesFirstCharToApiLevel[searchResult].getSecond(); } int insertionIndex = -1 - searchResult; if (insertionIndex == 0) { return 1; } else { Pair<Character, Integer> newestOlderCodenameMapping = sortedCodenamesFirstCharToApiLevel[insertionIndex - 1]; char newestOlderCodenameFirstChar = newestOlderCodenameMapping.getFirst(); int newestOlderCodenameApiLevel = newestOlderCodenameMapping.getSecond(); return newestOlderCodenameApiLevel + (firstChar - newestOlderCodenameFirstChar); } } throw new CodenameMinSdkVersionException( "Unable to determine APK's minimum supported Android platform version" + " : Unsupported codename in " + ANDROID_MANIFEST_ZIP_ENTRY_NAME + "'s minSdkVersion: \"" + codename + "\"", codename); } private  ApkUtils(); static ZipSections findZipSections(DataSource apk); static void setZipEocdCentralDirectoryOffset(
            ByteBuffer zipEndOfCentralDirectory, long offset); static ApkSigningBlock findApkSigningBlock(DataSource apk, ZipSections zipSections); static ByteBuffer getAndroidManifest(DataSource apk); static int getMinSdkVersionFromBinaryAndroidManifest(
            ByteBuffer androidManifestContents); static boolean getDebuggableFromBinaryAndroidManifest(
            ByteBuffer androidManifestContents); static String getPackageNameFromBinaryAndroidManifest(
            ByteBuffer androidManifestContents); }
ApkUtils { static int getMinSdkVersionForCodename(String codename) throws CodenameMinSdkVersionException { char firstChar = codename.isEmpty() ? ' ' : codename.charAt(0); if ((firstChar >= 'A') && (firstChar <= 'Z')) { Pair<Character, Integer>[] sortedCodenamesFirstCharToApiLevel = CodenamesLazyInitializer.SORTED_CODENAMES_FIRST_CHAR_TO_API_LEVEL; int searchResult = Arrays.binarySearch( sortedCodenamesFirstCharToApiLevel, Pair.of(firstChar, null), CodenamesLazyInitializer.CODENAME_FIRST_CHAR_COMPARATOR); if (searchResult >= 0) { return sortedCodenamesFirstCharToApiLevel[searchResult].getSecond(); } int insertionIndex = -1 - searchResult; if (insertionIndex == 0) { return 1; } else { Pair<Character, Integer> newestOlderCodenameMapping = sortedCodenamesFirstCharToApiLevel[insertionIndex - 1]; char newestOlderCodenameFirstChar = newestOlderCodenameMapping.getFirst(); int newestOlderCodenameApiLevel = newestOlderCodenameMapping.getSecond(); return newestOlderCodenameApiLevel + (firstChar - newestOlderCodenameFirstChar); } } throw new CodenameMinSdkVersionException( "Unable to determine APK's minimum supported Android platform version" + " : Unsupported codename in " + ANDROID_MANIFEST_ZIP_ENTRY_NAME + "'s minSdkVersion: \"" + codename + "\"", codename); } private  ApkUtils(); static ZipSections findZipSections(DataSource apk); static void setZipEocdCentralDirectoryOffset(
            ByteBuffer zipEndOfCentralDirectory, long offset); static ApkSigningBlock findApkSigningBlock(DataSource apk, ZipSections zipSections); static ByteBuffer getAndroidManifest(DataSource apk); static int getMinSdkVersionFromBinaryAndroidManifest(
            ByteBuffer androidManifestContents); static boolean getDebuggableFromBinaryAndroidManifest(
            ByteBuffer androidManifestContents); static String getPackageNameFromBinaryAndroidManifest(
            ByteBuffer androidManifestContents); static final String ANDROID_MANIFEST_ZIP_ENTRY_NAME; }