Search in sources :

Example 96 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class ApkMatcherTest method assetModuleMatch.

@Test
public void assetModuleMatch() {
    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 buildApksResult = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(oneApkSplitApkVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), ApkTargeting.getDefaultInstance(), baseApk)).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule1).setDeliveryType(INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk1)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk1))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule2).setDeliveryType(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();
    DeviceSpec enDevice = lDeviceWithLocales("en");
    assertThat(new ApkMatcher(enDevice).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(installTimeMasterApk1, installTimeModule1, INSTALL_TIME), matchedApk(installTimeEnApk1, installTimeModule1, INSTALL_TIME), matchedApk(installTimeMasterApk2, installTimeModule2, INSTALL_TIME), matchedApk(installTimeEnApk2, installTimeModule2, INSTALL_TIME));
    DeviceSpec esDevice = lDeviceWithLocales("fr");
    assertThat(new ApkMatcher(esDevice).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(installTimeMasterApk1, installTimeModule1, INSTALL_TIME), matchedApk(installTimeMasterApk2, installTimeModule2, INSTALL_TIME));
    assertThat(createMatcher(enDevice, Optional.of(ImmutableSet.of(installTimeModule1, onDemandModule))).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(installTimeMasterApk1, installTimeModule1, INSTALL_TIME), matchedApk(installTimeEnApk1, installTimeModule1, INSTALL_TIME), matchedApk(onDemandMasterApk, onDemandModule, ON_DEMAND));
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 97 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class ApkMatcherTest method apkMatch_withModuleNameFiltering_instantApks_checksModuleName_exists.

@Test
public void apkMatch_withModuleNameFiltering_instantApks_checksModuleName_exists() {
    DeviceSpec device = deviceWithSdk(21);
    ZipPath apk = ZipPath.create("master-de-fr.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
    "base", instantApkDescription(ApkTargeting.getDefaultInstance(), apk))));
    Optional<ImmutableSet<String>> allModules = Optional.empty();
    assertThat(createInstantMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
    Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
    assertThat(createInstantMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
    Optional<ImmutableSet<String>> unknownModuleOnly = Optional.of(ImmutableSet.of("unknown_module"));
    InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createInstantMatcher(device, unknownModuleOnly).getMatchingApks(buildApksResult));
    assertThat(exception).hasMessageThat().contains("The APK Set archive does not contain the following modules: [unknown_module]");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) ImmutableSet(com.google.common.collect.ImmutableSet) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 98 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class ApkMatcherTest method splitApk_conditionalModule_deviceEligible.

@Test
public void splitApk_conditionalModule_deviceEligible() {
    DeviceSpec device = mergeSpecs(deviceWithSdk(24), deviceFeatures("android.hardware.camera.ar", "reqGlEsVersion=0x30002"), deviceGroups("highRam"));
    ZipPath baseApk = ZipPath.create("base-master.apk");
    ZipPath feature1Apk = ZipPath.create("ar-master.apk");
    ZipPath feature2Apk = ZipPath.create("opengl-master.apk");
    ZipPath feature3Apk = ZipPath.create("high_end-master.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(variantSdkTargeting(21), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), createConditionalApkSet(/* moduleName= */
    "ar", mergeModuleTargeting(moduleFeatureTargeting("android.hardware.camera.ar"), moduleMinSdkVersionTargeting(24)), splitApkDescription(ApkTargeting.getDefaultInstance(), feature1Apk)), createConditionalApkSet(/* moduleName= */
    "opengl", mergeModuleTargeting(moduleFeatureTargeting("android.hardware.opengles.version", 0x30001), moduleMinSdkVersionTargeting(21)), splitApkDescription(ApkTargeting.getDefaultInstance(), feature2Apk)), createConditionalApkSet(/* moduleName= */
    "high_end", mergeModuleTargeting(moduleDeviceGroupsTargeting("highRam"), moduleMinSdkVersionTargeting(21)), splitApkDescription(ApkTargeting.getDefaultInstance(), feature3Apk))));
    assertThat(new ApkMatcher(device).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName= */
    "ar", INSTALL_TIME), matchedApk(feature2Apk, /* moduleName= */
    "opengl", INSTALL_TIME), matchedApk(feature3Apk, /* moduleName= */
    "high_end", INSTALL_TIME));
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 99 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class ApkMatcherTest method apkMatch_withModuleTypeFiltering_splitApks_installTimeModules_deprecatedOnDemand.

@Test
public void apkMatch_withModuleTypeFiltering_splitApks_installTimeModules_deprecatedOnDemand() {
    DeviceSpec device = deviceWithSdk(21);
    ZipPath baseApk = ZipPath.create("master-base.apk");
    ZipPath onDemandFeatureApk = ZipPath.create("master-feature1.apk");
    ApkSet onDemandFeature = splitApkSet(/* moduleName= */
    "onDemandFeature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureApk));
    ApkSet onDemandFeatureWithDeprecatedField = onDemandFeature.toBuilder().setModuleMetadata(onDemandFeature.getModuleMetadata().toBuilder().setOnDemandDeprecated(true)).build();
    BuildApksResult buildApksResult = buildApksResult(/* bundletoolVersion= */
    "0.10.0", createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), onDemandFeatureWithDeprecatedField));
    // By default only install-time module are matched.
    Optional<ImmutableSet<String>> allModules = Optional.empty();
    assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) ApkSet(com.android.bundle.Commands.ApkSet) ApksArchiveHelpers.createConditionalApkSet(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createConditionalApkSet) ApkSetUtils.splitApkSet(com.android.tools.build.bundletool.testing.ApkSetUtils.splitApkSet) ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 100 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class DeviceAnalyzerTest method activityManagerFails_noProperties_defaultLocaleFallback.

@Test
public void activityManagerFails_noProperties_defaultLocaleFallback() {
    // It creates no properties, hence locale fetch via properties should also fall back.
    FakeDevice fakeDevice = createDeviceWithNoProperties("a", /* sdkVersion= */
    26, /* locale= */
    "de-DE");
    fakeDevice.injectShellCommandOutput("am get-config", () -> "error");
    FakeAdbServer fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, /* devices= */
    ImmutableList.of(fakeDevice));
    fakeAdbServer.init(Paths.get("path/to/adb"));
    DeviceSpec spec = new DeviceAnalyzer(fakeAdbServer).getDeviceSpec(Optional.empty());
    assertThat(spec.getScreenDensity()).isEqualTo(480);
    assertThat(spec.getSupportedAbisList()).containsExactly("armeabi");
    assertThat(spec.getSdkVersion()).isEqualTo(26);
    // We couldn't detect locale so we expect to fallback to en-US.
    assertThat(spec.getSupportedLocalesList()).containsExactly("en-US");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Aggregations

DeviceSpec (com.android.bundle.Devices.DeviceSpec)124 Test (org.junit.Test)113 Path (java.nio.file.Path)71 BuildApksResult (com.android.bundle.Commands.BuildApksResult)68 ZipPath (com.android.tools.build.bundletool.model.ZipPath)64 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)19 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)18 AdbServer (com.android.tools.build.bundletool.device.AdbServer)15 ImmutableSet (com.google.common.collect.ImmutableSet)14 Theory (org.junit.experimental.theories.Theory)13 IncompatibleDeviceException (com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)12 Variant (com.android.bundle.Commands.Variant)11 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)11 ZipFile (java.util.zip.ZipFile)11 ApkSet (com.android.bundle.Commands.ApkSet)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 SystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider)7 PrintStream (java.io.PrintStream)7