Search in sources :

Example 51 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class InstallMultiApksCommandTest method execute_skipHigherVersionInstalled.

@Test
public void execute_skipHigherVersionInstalled() throws Exception {
    // GIVEN fake .apks files, one of which will have an higher version already installed...
    BuildApksResult tableOfContents1 = fakeTableOfContents(PKG_NAME_1);
    Path apksPath1 = createApksArchiveFile(tableOfContents1, tmpDir.resolve("package1.apks"));
    BuildApksResult tableOfContents2 = fakeTableOfContents(PKG_NAME_2);
    Path apksPath2 = createApksArchiveFile(tableOfContents2, tmpDir.resolve("package2.apks"));
    InstallMultiApksCommand command = InstallMultiApksCommand.builder().setAdbServer(fakeServerOneDevice(device)).setDeviceId(DEVICE_ID).setAdbPath(adbPath).setApksArchivePaths(ImmutableList.of(apksPath1, apksPath2)).setAapt2Command(createFakeAapt2Command(ImmutableMap.of(PKG_NAME_1, 1L, PKG_NAME_2, 2L))).setAdbCommand(// EXPECT only the higher version package to be installed.
    createFakeAdbCommand(expectedInstallApks(PKG_NAME_2, tableOfContents2), /* expectedStaged= */
    false, /* expectedEnableRollback= */
    false, Optional.of(DEVICE_ID))).build();
    device.injectShellCommandOutput("pm list packages --show-versioncode", () -> String.format("package:%s versionCode:3\npackage:%s versionCode:1", PKG_NAME_1, PKG_NAME_2));
    device.injectShellCommandOutput("pm list packages --apex-only --show-versioncode", () -> "");
    command.execute();
    assertAdbCommandExecuted();
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) Test(org.junit.Test)

Example 52 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class InstallMultiApksCommandTest method execute_extractZipWithSdkDirectories.

@Test
public void execute_extractZipWithSdkDirectories() throws Exception {
    // GIVEN a zip file containing fake .apks files
    BuildApksResult tableOfContent1 = fakeTableOfContents(PKG_NAME_1);
    Path package1Apks = createApksArchiveFile(tableOfContent1, tmpDir.resolve("package1.apks"));
    BuildApksResult tableOfContent2 = fakeTableOfContents(PKG_NAME_2);
    Path package2Apks = createApksArchiveFile(tableOfContent2, tmpDir.resolve("package2.apks"));
    BuildApksResult tableOfContent3 = BuildApksResult.newBuilder().setPackageName(PKG_NAME_1).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create(PKG_NAME_1 + "base-master.apk"))), createSplitApkSet("feature3", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create(PKG_NAME_1 + "feature3-master.apk"))), createSplitApkSet("feature4", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create(PKG_NAME_1 + "feature4-master.apk"))))).build();
    Path package1v2Apks = createApksArchiveFile(tableOfContent3, tmpDir.resolve("package3.apks"));
    ZipBuilder bundleBuilder = new ZipBuilder();
    bundleBuilder.addFileFromDisk(ZipPath.create("29/package1.apks"), package1Apks.toFile()).addFileFromDisk(ZipPath.create("30/package1.apks"), package1v2Apks.toFile()).addFileFromDisk(ZipPath.create("package2.apks"), package2Apks.toFile());
    Path zipBundle = bundleBuilder.writeTo(tmpDir.resolve("bundle.zip"));
    AtomicReference<Integer> counter = new AtomicReference<>(3);
    InstallMultiApksCommand command = InstallMultiApksCommand.builder().setAdbServer(fakeServerOneDevice(device)).setDeviceId(DEVICE_ID).setAdbPath(adbPath).setApksArchiveZipPath(zipBundle).setAapt2Command(createFakeAapt2CommandFromSupplier(ImmutableMap.of(PKG_NAME_2, () -> ImmutableList.of(String.format("package: name='%s' versionCode='%d' ", PKG_NAME_2, 2)), PKG_NAME_1, () -> ImmutableList.of(String.format("package: name='%s' versionCode='%d' ", PKG_NAME_1, counter.getAndSet(counter.get() + 1)))))).setAdbCommand(createFakeAdbCommand(ImmutableListMultimap.<String, String>builder().putAll(PKG_NAME_1, ImmutableList.of(Paths.get(PKG_NAME_1, PKG_NAME_1 + "base-master.apk").toString(), Paths.get(PKG_NAME_1, PKG_NAME_1 + "feature3-master.apk").toString(), Paths.get(PKG_NAME_1, PKG_NAME_1 + "feature4-master.apk").toString())).putAll(PKG_NAME_2, Paths.get(PKG_NAME_2, PKG_NAME_2 + "base-master.apk").toString(), Paths.get(PKG_NAME_2, PKG_NAME_2 + "feature1-master.apk").toString(), Paths.get(PKG_NAME_2, PKG_NAME_2 + "feature2-master.apk").toString()).build(), /* expectedStaged= */
    false, /* expectedEnableRollback= */
    false, Optional.of(DEVICE_ID))).build();
    // EXPECT
    // 1) Get existing packages.
    device.injectShellCommandOutput("pm list packages --show-versioncode", () -> "");
    device.injectShellCommandOutput("pm list packages --apex-only --show-versioncode", () -> "");
    // 2) Install command (above)
    command.execute();
    assertAdbCommandExecuted();
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 53 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class InstallMultiApksCommandTest method execute_updateOnly_apex.

@Test
public void execute_updateOnly_apex() throws Exception {
    // GIVEN a zip file containing fake .apks files for multiple packages, one of which is an
    // apex.
    BuildApksResult tableOfContent1 = fakeTableOfContents(PKG_NAME_1);
    Path package1Apks = createApksArchiveFile(tableOfContent1, tmpDir.resolve("package1.apks"));
    BuildApksResult apexTableOfContents = BuildApksResult.newBuilder().setPackageName(PKG_NAME_2).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(apexVariant(VariantTargeting.getDefaultInstance(), ApkTargeting.getDefaultInstance(), ZipPath.create(PKG_NAME_2 + "base.apex"))).build();
    Path package2Apks = createApksArchiveFile(apexTableOfContents, tmpDir.resolve("package2.apks"));
    ZipBuilder bundleBuilder = new ZipBuilder();
    bundleBuilder.addFileFromDisk(ZipPath.create("package1.apks"), package1Apks.toFile()).addFileFromDisk(ZipPath.create("package2.apks"), package2Apks.toFile());
    Path zipBundle = bundleBuilder.writeTo(tmpDir.resolve("bundle.zip"));
    // GIVEN only one of the packages is installed on the device...
    device.injectShellCommandOutput("pm list packages --show-versioncode", () -> "");
    device.injectShellCommandOutput("pm list packages --apex-only --show-versioncode", () -> String.format("package:%s versionCode:1\njunk_to_ignore", PKG_NAME_2));
    // GIVEN the --update-only flag is set on the command...
    InstallMultiApksCommand command = InstallMultiApksCommand.builder().setAdbServer(fakeServerOneDevice(device)).setUpdateOnly(true).setDeviceId(DEVICE_ID).setAdbPath(adbPath).setApksArchiveZipPath(zipBundle).setAapt2Command(createFakeAapt2Command(ImmutableMap.of(PKG_NAME_1, 2L, PKG_NAME_2, 2L))).setAdbCommand(createFakeAdbCommand(expectedInstallApks(PKG_NAME_2, apexTableOfContents), /* expectedStaged= */
    false, /* expectedEnableRollback= */
    false, Optional.of(DEVICE_ID))).build();
    // EXPECT only one of the packages
    command.execute();
    assertAdbCommandExecuted();
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) Test(org.junit.Test)

Example 54 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class InstallMultiApksCommandTest method execute_staged.

@Test
public void execute_staged() throws Exception {
    // GIVEN a fake .apks file with an .apex file.
    BuildApksResult toc = fakeTableOfContents(PKG_NAME_1);
    Path apksPath = createApksArchiveFile(toc, tmpDir.resolve("package1.apks"));
    // GIVEN an install command with the --staged flag...
    InstallMultiApksCommand command = InstallMultiApksCommand.builder().setAdbServer(fakeServerOneDevice(device)).setDeviceId(DEVICE_ID).setAdbPath(adbPath).setStaged(true).setApksArchivePaths(ImmutableList.of(apksPath)).setAapt2Command(createFakeAapt2Command(ImmutableMap.of(PKG_NAME_1, 1L))).setAdbCommand(// EXPECT the --staged flag to be included.
    createFakeAdbCommand(expectedInstallApks(PKG_NAME_1, toc), /* expectedStaged= */
    true, /* expectedEnableRollback= */
    false, /* expectedTimeout= */
    Optional.empty(), Optional.of(DEVICE_ID))).build();
    givenEmptyListPackages(device);
    command.execute();
    assertAdbCommandExecuted();
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) Test(org.junit.Test)

Example 55 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class InstallMultiApksCommandTest method execute_enableRollback.

@Test
public void execute_enableRollback() throws Exception {
    // GIVEN a fake .apks file with an .apex file.
    BuildApksResult apexTableOfContents = BuildApksResult.newBuilder().setPackageName(PKG_NAME_1).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(apexVariant(VariantTargeting.getDefaultInstance(), ApkTargeting.getDefaultInstance(), ZipPath.create(PKG_NAME_1 + "base.apex"))).build();
    Path apksPath = createApksArchiveFile(apexTableOfContents, tmpDir.resolve("package1.apks"));
    // GIVEN an install command with the --enable-rollback flag...
    InstallMultiApksCommand command = InstallMultiApksCommand.builder().setAdbServer(fakeServerOneDevice(device)).setDeviceId(DEVICE_ID).setAdbPath(adbPath).setEnableRollback(true).setApksArchivePaths(ImmutableList.of(apksPath)).setAapt2Command(createFakeAapt2Command(ImmutableMap.of(PKG_NAME_1, 1L))).setAdbCommand(// EXPECT the --enable-rollback flag to be included.
    createFakeAdbCommand(expectedInstallApks(PKG_NAME_1, apexTableOfContents), /* expectedStaged= */
    false, /* expectedEnableRollback= */
    true, Optional.of(DEVICE_ID))).build();
    givenEmptyListPackages(device);
    command.execute();
    assertAdbCommandExecuted();
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) Test(org.junit.Test)

Aggregations

BuildApksResult (com.android.bundle.Commands.BuildApksResult)282 Test (org.junit.Test)276 ZipPath (com.android.tools.build.bundletool.model.ZipPath)234 Path (java.nio.file.Path)180 Variant (com.android.bundle.Commands.Variant)120 ZipFile (java.util.zip.ZipFile)109 AppBundle (com.android.tools.build.bundletool.model.AppBundle)96 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)93 ImmutableSet (com.google.common.collect.ImmutableSet)88 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)87 Theory (org.junit.experimental.theories.Theory)86 ApkSet (com.android.bundle.Commands.ApkSet)84 AdbServer (com.android.tools.build.bundletool.device.AdbServer)84 ApkDescription (com.android.bundle.Commands.ApkDescription)82 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)78 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)78 File (java.io.File)78 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)77 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)77 IOException (java.io.IOException)76