Search in sources :

Example 46 with BuildApksResult

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

the class InstallApksCommandTest method bundleWithDeviceTierTargeting_deviceTierSet_filtersByTier.

@Test
@Theory
public void bundleWithDeviceTierTargeting_deviceTierSet_filtersByTier(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    ZipPath baseMasterApk = ZipPath.create("base-master.apk");
    ZipPath baseLowApk = ZipPath.create("base-tier_0.apk");
    ZipPath baseHighApk = ZipPath.create("base-tier_1.apk");
    ZipPath asset1MasterApk = ZipPath.create("asset1-master.apk");
    ZipPath asset1LowApk = ZipPath.create("asset1-tier_0.apk");
    ZipPath asset1HighApk = ZipPath.create("asset1-tier_1.apk");
    BuildApksResult tableOfContent = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseMasterApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    0, /* alternatives= */
    ImmutableList.of(1))), baseLowApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    1, /* alternatives= */
    ImmutableList.of(0))), baseHighApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName("asset1").setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(createMasterApkDescription(ApkTargeting.getDefaultInstance(), asset1MasterApk)).addApkDescription(splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    0, /* alternatives= */
    ImmutableList.of(1))), asset1LowApk)).addApkDescription(splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    1, /* alternatives= */
    ImmutableList.of(0))), asset1HighApk))).setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing")).addDefaultTargetingValue(DefaultTargetingValue.newBuilder().setDimension(Value.DEVICE_TIER).setDefaultValue("0")).build();
    Path apksFile = createApks(tableOfContent, apksInDirectory);
    List<Path> installedApks = new ArrayList<>();
    List<Path> pushedFiles = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
    fakeDevice.setPushSideEffect((files, installOptions) -> pushedFiles.addAll(files));
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setDeviceTier(1).build().execute();
    // Base only, the on demand asset is not installed. Low tier splits are filtered out.
    assertThat(getFileNames(installedApks)).containsExactly(baseMasterApk.toString(), baseHighApk.toString());
    // Base config splits and on-demand assets. Low tier splits are filtered out.
    assertThat(getFileNames(pushedFiles)).containsExactly(baseHighApk.toString(), asset1MasterApk.toString(), asset1HighApk.toString());
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) ZipPath(com.android.tools.build.bundletool.model.ZipPath) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Example 47 with BuildApksResult

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

the class InstallApksCommandTest method bundleWithDeviceTierTargeting_noDeviceTierSpecifiedNorDefault_usesZeroAsDefault.

@Test
public void bundleWithDeviceTierTargeting_noDeviceTierSpecifiedNorDefault_usesZeroAsDefault() throws Exception {
    ZipPath baseMasterApk = ZipPath.create("base-master.apk");
    ZipPath baseLowApk = ZipPath.create("base-tier_0.apk");
    ZipPath baseHighApk = ZipPath.create("base-tier_1.apk");
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseMasterApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    0, /* alternatives= */
    ImmutableList.of(1))), baseLowApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    1, /* alternatives= */
    ImmutableList.of(0))), baseHighApk)))).build();
    Path apksFile = createApksArchiveFile(buildApksResult, tmpDir.resolve("bundle.apks"));
    List<Path> installedApks = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).build().execute();
    // Base only, the on demand asset is not installed. Tier 0 splits are returned, since it is the
    // default when unspecified.
    assertThat(getFileNames(installedApks)).containsExactly(baseMasterApk.toString(), baseLowApk.toString());
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) ZipPath(com.android.tools.build.bundletool.model.ZipPath) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 48 with BuildApksResult

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

the class InstallApksCommandTest method bundleWithDeviceTierTargeting_noDeviceTierSpecified_usesDefaultValue.

@Test
public void bundleWithDeviceTierTargeting_noDeviceTierSpecified_usesDefaultValue() throws Exception {
    ZipPath baseMasterApk = ZipPath.create("base-master.apk");
    ZipPath baseLowApk = ZipPath.create("base-tier_0.apk");
    ZipPath baseHighApk = ZipPath.create("base-tier_1.apk");
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseMasterApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    0, /* alternatives= */
    ImmutableList.of(1))), baseLowApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    1, /* alternatives= */
    ImmutableList.of(0))), baseHighApk)))).addDefaultTargetingValue(DefaultTargetingValue.newBuilder().setDimension(Value.DEVICE_TIER).setDefaultValue("1")).build();
    Path apksFile = createApksArchiveFile(buildApksResult, tmpDir.resolve("bundle.apks"));
    List<Path> installedApks = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).build().execute();
    // Base only, the on demand asset is not installed. Low tier splits are filtered out.
    assertThat(getFileNames(installedApks)).containsExactly(baseMasterApk.toString(), baseHighApk.toString());
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) ZipPath(com.android.tools.build.bundletool.model.ZipPath) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 49 with BuildApksResult

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

the class InstallApksCommandTest method installAssetModules.

@Test
@Theory
public void installAssetModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    String installTimeModule1 = "installtime_assetmodule1";
    String installTimeModule2 = "installtime_assetmodule2";
    String onDemandModule = "ondemand_assetmodule";
    ZipPath installTimeMasterApk1 = ZipPath.create(installTimeModule1 + "-master.apk");
    ZipPath installTimeEnApk1 = ZipPath.create(installTimeModule1 + "-en.apk");
    ZipPath installTimeMasterApk2 = ZipPath.create(installTimeModule2 + "-master.apk");
    ZipPath installTimeEnApk2 = ZipPath.create(installTimeModule2 + "-en.apk");
    ZipPath onDemandMasterApk = ZipPath.create(onDemandModule + "-master.apk");
    ZipPath baseApk = ZipPath.create("base-master.apk");
    BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule1).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk1)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk1))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule2).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk2)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk2))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandModule).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandMasterApk))).build();
    Path apksFile = createApks(tableOfContent, apksInDirectory);
    List<Path> installedApks = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of(installTimeModule1)).build().execute();
    assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), installTimeMasterApk1.toString(), installTimeEnApk1.toString());
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) ZipPath(com.android.tools.build.bundletool.model.ZipPath) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Example 50 with BuildApksResult

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

the class InstallMultiApksCommandTest method execute_includeEqualVersionInstalled.

@Test
public void execute_includeEqualVersionInstalled() throws Exception {
    // GIVEN fake .apks files, one of which will have an equal 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 both packages to be installed.
    createFakeAdbCommand(ImmutableListMultimap.<String, String>builder().putAll(expectedInstallApks(PKG_NAME_1, tableOfContents1)).putAll(expectedInstallApks(PKG_NAME_2, tableOfContents2)).build(), /* expectedStaged= */
    false, /* expectedEnableRollback= */
    false, Optional.of(DEVICE_ID))).build();
    device.injectShellCommandOutput("pm list packages --show-versioncode", () -> String.format("package:%s versionCode:1\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)

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