* 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.
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);
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;
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;
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;
}
}
+ @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()));