Loading core/java/android/content/pm/dex/DexMetadataHelper.java +3 −3 Original line number Diff line number Diff line Loading @@ -107,8 +107,8 @@ public class DexMetadataHelper { * For each code path (.apk) the method checks if a matching dex metadata file (.dm) exists. * If it does it adds the pair to the returned map. * * Note that this method will do a strict * matching based on the extension ('foo.dm' will only match 'foo.apk'). * Note that this method will do a loose * matching based on the extension ('foo.dm' will match 'foo.apk' or 'foo'). * * This should only be used for code paths extracted from a package structure after the naming * was enforced in the installer. Loading @@ -118,7 +118,7 @@ public class DexMetadataHelper { ArrayMap<String, String> result = new ArrayMap<>(); for (int i = codePaths.size() - 1; i >= 0; i--) { String codePath = codePaths.get(i); String dexMetadataPath = buildDexMetadataPathForApk(codePath); String dexMetadataPath = buildDexMetadataPathForFile(new File(codePath)); if (Files.exists(Paths.get(dexMetadataPath))) { result.put(codePath, dexMetadataPath); Loading core/tests/coretests/src/android/content/pm/dex/DexMetadataHelperTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -24,7 +24,9 @@ import static org.junit.Assert.fail; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.PackageParser; import android.content.pm.PackageParser.ApkLite; import android.content.pm.PackageParser.Package; import android.content.pm.PackageParser.PackageLite; import android.content.pm.PackageParser.PackageParserException; import android.os.FileUtils; import android.support.test.InstrumentationRegistry; Loading @@ -34,6 +36,7 @@ import android.test.suitebuilder.annotation.SmallTest; import com.android.frameworks.coretests.R; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; Loading @@ -45,6 +48,7 @@ import java.util.zip.ZipOutputStream; import libcore.io.IoUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -201,6 +205,31 @@ public class DexMetadataHelperTest { } } @Test public void testPackageSizeWithDmFile() throws IOException, PackageParserException { copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base); File dm = createDexMetadataFile("install_split_base.apk"); PackageParser.PackageLite pkg = new PackageParser().parsePackageLite(mTmpDir, 0 /* flags */); Assert.assertEquals(dm.length(), DexMetadataHelper.getPackageDexMetadataSize(pkg)); } // This simulates the 'adb shell pm install' flow. @Test public void testPackageSizeWithPartialPackageLite() throws IOException, PackageParserException { File base = copyApkToToTmpDir("install_split_base", R.raw.install_split_base); File dm = createDexMetadataFile("install_split_base.apk"); try (FileInputStream is = new FileInputStream(base)) { ApkLite baseApk = PackageParser.parseApkLite(is.getFD(), base.getAbsolutePath(), 0); PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null, null, null, null); Assert.assertEquals(dm.length(), DexMetadataHelper.getPackageDexMetadataSize(pkgLite)); } } private static boolean isDexMetadataForApk(String dmaPath, String apkPath) { return apkPath.substring(0, apkPath.length() - APK_FILE_EXTENSION.length()).equals( dmaPath.substring(0, dmaPath.length() - DEX_METADATA_FILE_EXTENSION.length())); Loading Loading
core/java/android/content/pm/dex/DexMetadataHelper.java +3 −3 Original line number Diff line number Diff line Loading @@ -107,8 +107,8 @@ public class DexMetadataHelper { * For each code path (.apk) the method checks if a matching dex metadata file (.dm) exists. * If it does it adds the pair to the returned map. * * Note that this method will do a strict * matching based on the extension ('foo.dm' will only match 'foo.apk'). * Note that this method will do a loose * matching based on the extension ('foo.dm' will match 'foo.apk' or 'foo'). * * This should only be used for code paths extracted from a package structure after the naming * was enforced in the installer. Loading @@ -118,7 +118,7 @@ public class DexMetadataHelper { ArrayMap<String, String> result = new ArrayMap<>(); for (int i = codePaths.size() - 1; i >= 0; i--) { String codePath = codePaths.get(i); String dexMetadataPath = buildDexMetadataPathForApk(codePath); String dexMetadataPath = buildDexMetadataPathForFile(new File(codePath)); if (Files.exists(Paths.get(dexMetadataPath))) { result.put(codePath, dexMetadataPath); Loading
core/tests/coretests/src/android/content/pm/dex/DexMetadataHelperTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -24,7 +24,9 @@ import static org.junit.Assert.fail; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.PackageParser; import android.content.pm.PackageParser.ApkLite; import android.content.pm.PackageParser.Package; import android.content.pm.PackageParser.PackageLite; import android.content.pm.PackageParser.PackageParserException; import android.os.FileUtils; import android.support.test.InstrumentationRegistry; Loading @@ -34,6 +36,7 @@ import android.test.suitebuilder.annotation.SmallTest; import com.android.frameworks.coretests.R; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; Loading @@ -45,6 +48,7 @@ import java.util.zip.ZipOutputStream; import libcore.io.IoUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -201,6 +205,31 @@ public class DexMetadataHelperTest { } } @Test public void testPackageSizeWithDmFile() throws IOException, PackageParserException { copyApkToToTmpDir("install_split_base.apk", R.raw.install_split_base); File dm = createDexMetadataFile("install_split_base.apk"); PackageParser.PackageLite pkg = new PackageParser().parsePackageLite(mTmpDir, 0 /* flags */); Assert.assertEquals(dm.length(), DexMetadataHelper.getPackageDexMetadataSize(pkg)); } // This simulates the 'adb shell pm install' flow. @Test public void testPackageSizeWithPartialPackageLite() throws IOException, PackageParserException { File base = copyApkToToTmpDir("install_split_base", R.raw.install_split_base); File dm = createDexMetadataFile("install_split_base.apk"); try (FileInputStream is = new FileInputStream(base)) { ApkLite baseApk = PackageParser.parseApkLite(is.getFD(), base.getAbsolutePath(), 0); PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null, null, null, null); Assert.assertEquals(dm.length(), DexMetadataHelper.getPackageDexMetadataSize(pkgLite)); } } private static boolean isDexMetadataForApk(String dmaPath, String apkPath) { return apkPath.substring(0, apkPath.length() - APK_FILE_EXTENSION.length()).equals( dmaPath.substring(0, dmaPath.length() - DEX_METADATA_FILE_EXTENSION.length())); Loading